TelegramProviderOptions class

Configuration for the Telegram Login Widget provider.

Setup

  1. Create a bot via @BotFather
  2. Use /setdomain to link your website's domain to the bot
  3. Embed the Telegram Login Widget on your page

Callback URL

https://example.com/auth/callback/telegram

Widget Example

<script async src="https://telegram.org/js/telegram-widget.js?22"
  data-telegram-login="YOUR_BOT_USERNAME"
  data-size="large"
  data-auth-url="https://example.com/auth/callback/telegram"
  data-request-access="write">
</script>

Usage

import 'package:server_auth/server_auth.dart';
import 'package:server_auth/server_auth.dart';

final manager = AuthManager(
  AuthOptions(
    store: InMemoryAuthStore(),
    storeMode: AuthStoreMode.ephemeral,
    providers: [
      telegramProvider(
        TelegramProviderOptions(
          botToken: env('TELEGRAM_BOT_TOKEN'),
          botUsername: env('TELEGRAM_BOT_USERNAME'),
          redirectUri: 'https://example.com/auth/callback/telegram',
        ),
      ),
    ],
  ),
);

Notes

  • Telegram uses a widget-based flow, not standard OAuth.
  • The bot token is used to verify the HMAC-SHA-256 hash.
  • Set authDateMaxAge to reject stale authentications.

Constructors

TelegramProviderOptions({required String botToken, required String botUsername, required String redirectUri, Duration authDateMaxAge = const Duration(minutes: 5), String successRedirect = '/profile'})
Creates a new TelegramProviderOptions configuration.
const

Properties

authDateMaxAge → Duration
Maximum age of auth_date before rejecting (default: 5 minutes).
final
botToken → String
Bot token from @BotFather (used for HMAC verification).
final
botUsername → String
Bot username (without @).
final
hashCode → int
The hash code for this object.
no setterinherited
redirectUri → String
Redirect URI for the callback.
final
runtimeType → Type
A representation of the runtime type of the object.
no setterinherited
successRedirect → String
Where to redirect after successful authentication.
final

Methods

noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toString() → String
A string representation of this object.
inherited

Operators

operator ==(Object other) → bool
The equality operator.
inherited