[GH-ISSUE #3526] Sign in with Telegram Login Widget #18263

Closed
opened 2026-04-15 16:40:57 -05:00 by GiteaMirror · 22 comments
Owner

Originally created by @Re4GD on GitHub (Jul 21, 2025).
Original GitHub issue: https://github.com/better-auth/better-auth/issues/3526

https://core.telegram.org/widgets/login

Telegram login does not follow the standard oauth implementation. Custom plugin for submitting and validating the window.Telegram.Login.auth() callback is needed. I can open a PR to implement this plugin

Originally created by @Re4GD on GitHub (Jul 21, 2025). Original GitHub issue: https://github.com/better-auth/better-auth/issues/3526 https://core.telegram.org/widgets/login Telegram login does not follow the standard oauth implementation. Custom plugin for submitting and validating the window.Telegram.Login.auth() callback is needed. I can open a PR to implement this plugin
GiteaMirror added the locked label 2026-04-15 16:40:57 -05:00
Author
Owner

@Kinfe123 commented on GitHub (Jul 22, 2025):

Yeah. feel free to do that.

<!-- gh-comment-id:3101974810 --> @Kinfe123 commented on GitHub (Jul 22, 2025): Yeah. feel free to do that.
Author
Owner

@iatomic1 commented on GitHub (Jul 26, 2025):

@Re4GD wen pr?

<!-- gh-comment-id:3121663813 --> @iatomic1 commented on GitHub (Jul 26, 2025): @Re4GD wen pr?
Author
Owner

@Re4GD commented on GitHub (Jul 26, 2025):

I'll open in a few days, been busy. Also trying to polish the plugin

<!-- gh-comment-id:3121666600 --> @Re4GD commented on GitHub (Jul 26, 2025): I'll open in a few days, been busy. Also trying to polish the plugin
Author
Owner

@iatomic1 commented on GitHub (Jul 26, 2025):

I'll open in a few days, been busy. Also trying to polish the plugin

Okay man, would ur plugin also provide linking an already existing user to their tg acct?

<!-- gh-comment-id:3121797844 --> @iatomic1 commented on GitHub (Jul 26, 2025): > I'll open in a few days, been busy. Also trying to polish the plugin Okay man, would ur plugin also provide linking an already existing user to their tg acct?
Author
Owner

@Re4GD commented on GitHub (Jul 26, 2025):

Didn’t think of that actually, I will add that for sure

<!-- gh-comment-id:3121803898 --> @Re4GD commented on GitHub (Jul 26, 2025): Didn’t think of that actually, I will add that for sure
Author
Owner

@iatomic1 commented on GitHub (Jul 26, 2025):

Is this authentication plugin designed exclusively for bots?
I'm building a Telegram bot (not a mini app) and want to add authentication to restrict access to certain commands until the user successfully authenticates

<!-- gh-comment-id:3122186553 --> @iatomic1 commented on GitHub (Jul 26, 2025): Is this authentication plugin designed exclusively for bots? I'm building a Telegram bot (not a mini app) and want to add authentication to restrict access to certain commands until the user successfully authenticates
Author
Owner

@Re4GD commented on GitHub (Jul 26, 2025):

The plugin is for Telegram login via Telegram Login Widget. Essentially like social Telegram login. (Just like sign in with Google, it opens a window, you sign in, it gets redirected to your page or a callback is called)

What do you mean by “authentication” and “until the user successfully authenticates”? Do you want to connect the tg bot with your web app? What is the use case here

<!-- gh-comment-id:3122195164 --> @Re4GD commented on GitHub (Jul 26, 2025): The plugin is for Telegram login via Telegram Login Widget. Essentially like social Telegram login. (Just like sign in with Google, it opens a window, you sign in, it gets redirected to your page or a callback is called) What do you mean by “authentication” and “until the user successfully authenticates”? Do you want to connect the tg bot with your web app? What is the use case here
Author
Owner

@iatomic1 commented on GitHub (Jul 26, 2025):

Yes wanna connect the tg bot to my web app
Currently building like a wallet tracker app, web app is done auth is in better auth of course but I want users to be able to manage their wallets through my tg bot as well
Tried using ott one time token my bot verifies it but when I get the session it returns null so I thought your plugin could fix it
Ig they are 2 diff things

<!-- gh-comment-id:3122301873 --> @iatomic1 commented on GitHub (Jul 26, 2025): Yes wanna connect the tg bot to my web app Currently building like a wallet tracker app, web app is done auth is in better auth of course but I want users to be able to manage their wallets through my tg bot as well Tried using ott one time token my bot verifies it but when I get the session it returns null so I thought your plugin could fix it Ig they are 2 diff things
Author
Owner

@Re4GD commented on GitHub (Jul 26, 2025):

This plugin can partially fix your problem,

The telegram user ids are unique so what you can do is:

  • if the user is on web, make them login with telegram, or link with telegram (this is about this plugin). then tell them that you have a tg bot as well (you can link them to the bot with a start param: t . me/mybot?start=param1, it was something like that. you can use the verification table for creating an otp. verification => telegram-otp-{id}=param1 )

  • if the user is on telegram, before every command check for your database (you can cache this), query account table with providerId=telegram & accountId=ctx.from.userId. if both match, then the user is authenticated through both web (user has account on db) and telegram (tg bot is always authed). show them their wallets

  • if the user is on telegram and does not have an account, you can retry the otp approach. create them a credential account, and ask them to connect their tg on web for the bot to correctly function (then the user will have a credential account and a telegram provider account). If that is too much to ask from the user, after credential sign in, create an account with accountId={tg id} & provider=telegram-bot (differrent from web login). so the user will have both credential account and a tg bot connection account (different from this plugin).

<!-- gh-comment-id:3122677150 --> @Re4GD commented on GitHub (Jul 26, 2025): This plugin can partially fix your problem, The telegram user ids are unique so what you can do is: - if the user is on web, make them login with telegram, or link with telegram (this is about this plugin). then tell them that you have a tg bot as well (you can link them to the bot with a start param: t . me/mybot?start=param1, it was something like that. you can use the verification table for creating an otp. verification => telegram-otp-{id}=param1 ) - if the user is on telegram, before every command check for your database (you can cache this), query account table with providerId=telegram & accountId=ctx.from.userId. if both match, then the user is authenticated through both web (user has account on db) and telegram (tg bot is always authed). show them their wallets - if the user is on telegram and does not have an account, you can retry the otp approach. create them a credential account, and ask them to connect their tg on web for the bot to correctly function (then the user will have a credential account and a telegram provider account). If that is too much to ask from the user, after credential sign in, create an account with accountId={tg id} & provider=`telegram-bot` (differrent from web login). so the user will have both credential account and a tg bot connection account (different from this plugin).
Author
Owner

@iatomic1 commented on GitHub (Jul 27, 2025):

Okay man can't wait to use it then
For now just using ott, then when verified i save the session token in redis

<!-- gh-comment-id:3124271582 --> @iatomic1 commented on GitHub (Jul 27, 2025): Okay man can't wait to use it then For now just using ott, then when verified i save the session token in redis
Author
Owner

@vitalygashkov commented on GitHub (Aug 7, 2025):

If anyone is interested, I've already implemented a similar plugin: vitalygashkov/telegram-better-auth

<!-- gh-comment-id:3163439475 --> @vitalygashkov commented on GitHub (Aug 7, 2025): If anyone is interested, I've already implemented a similar plugin: [vitalygashkov/telegram-better-auth](https://github.com/vitalygashkov/telegram-better-auth)
Author
Owner

@Re4GD commented on GitHub (Aug 30, 2025):

Plugin is almost ready, doing flow tests and writing docs.

  • Added support for account linking as @iatomic1 requested
  • Added callbackURLs for identical oauth flows and flexibility
  • Supports Telegram Login Widget's both callback/redirect flows

The plugin API is exactly like the oauth providers:

export type TelegramOptions = {
  /**
   * Bot token created from BotFather
   */
  botToken: string;
  /**
   * Custom function to map the user profile to a User object.
   */
  mapProfileToUser?: (profile: TelegramProfile) =>
    | {
        id?: string;
        name?: string;
        email?: string | null;
        image?: string;
        emailVerified?: boolean;
        [key: string]: any;
      }
    | Promise<{
        id?: string;
        name?: string;
        email?: string | null;
        image?: string;
        emailVerified?: boolean;
        [key: string]: any;
      }>;
};
<!-- gh-comment-id:3239183483 --> @Re4GD commented on GitHub (Aug 30, 2025): Plugin is almost ready, doing flow tests and writing docs. - Added support for account linking as @iatomic1 requested - Added callbackURLs for identical oauth flows and flexibility - Supports Telegram Login Widget's both callback/redirect flows The plugin API is exactly like the oauth providers: ```ts export type TelegramOptions = { /** * Bot token created from BotFather */ botToken: string; /** * Custom function to map the user profile to a User object. */ mapProfileToUser?: (profile: TelegramProfile) => | { id?: string; name?: string; email?: string | null; image?: string; emailVerified?: boolean; [key: string]: any; } | Promise<{ id?: string; name?: string; email?: string | null; image?: string; emailVerified?: boolean; [key: string]: any; }>; }; ```
Author
Owner

@vcode-sh commented on GitHub (Oct 1, 2025):

Hey! I built better-auth-telegram which implements everything requested here:

Telegram Login Widget with callback/redirect flows
Account linking & unlinking
Telegram Mini Apps support (bonus!)
100% test coverage
Full TypeScript support
Published on npm

npm install better-auth-telegram

GitHub: https://github.com/vcode-sh/better-auth-telegram
Docs: https://github.com/vcode-sh/better-auth-telegram#readme

Feedback welcome!

<!-- gh-comment-id:3356033683 --> @vcode-sh commented on GitHub (Oct 1, 2025): Hey! I built `better-auth-telegram` which implements everything requested here: ✅ Telegram Login Widget with callback/redirect flows ✅ Account linking & unlinking ✅ Telegram Mini Apps support (bonus!) ✅ 100% test coverage ✅ Full TypeScript support ✅ Published on npm npm install better-auth-telegram GitHub: https://github.com/vcode-sh/better-auth-telegram Docs: https://github.com/vcode-sh/better-auth-telegram#readme Feedback welcome!
Author
Owner

@mi3lix9 commented on GitHub (Oct 18, 2025):

Hi, I have a strange use case, my bot server is separated from web server, and I want to authorize my users using better auth.

Any one tried to achieve this or has better idea?

<!-- gh-comment-id:3418461408 --> @mi3lix9 commented on GitHub (Oct 18, 2025): Hi, I have a strange use case, my bot server is separated from web server, and I want to authorize my users using better auth. Any one tried to achieve this or has better idea?
Author
Owner

@iatomic1 commented on GitHub (Oct 18, 2025):

Like the docs, very engaging😅, Question(tho I prlly know the answer to this) so I'm not using mini apps, just using the telegram bot as is, and there are some commands that needs User being authenticated, but I cannot for the love of God get better auth to run on it, prlly because better auth relies on Web cookies or smthn, does this plugin fixes that? Great plugin btw

Hey! I built better-auth-telegram which implements everything requested here:

Telegram Login Widget with callback/redirect flows
Account linking & unlinking
Telegram Mini Apps support (bonus!)
100% test coverage
Full TypeScript support
Published on npm

npm install better-auth-telegram

GitHub: https://github.com/vcode-sh/better-auth-telegram
Docs: https://github.com/vcode-sh/better-auth-telegram#readme

Feedback welcome!

<!-- gh-comment-id:3418702951 --> @iatomic1 commented on GitHub (Oct 18, 2025): Like the docs, very engaging😅, Question(tho I prlly know the answer to this) so I'm not using mini apps, just using the telegram bot as is, and there are some commands that needs User being authenticated, but I cannot for the love of God get better auth to run on it, prlly because better auth relies on Web cookies or smthn, does this plugin fixes that? Great plugin btw > Hey! I built `better-auth-telegram` which implements everything requested here: > > ✅ Telegram Login Widget with callback/redirect flows > ✅ Account linking & unlinking > ✅ Telegram Mini Apps support (bonus!) > ✅ 100% test coverage > ✅ Full TypeScript support > ✅ Published on npm > > npm install better-auth-telegram > > GitHub: https://github.com/vcode-sh/better-auth-telegram > Docs: https://github.com/vcode-sh/better-auth-telegram#readme > > Feedback welcome!
Author
Owner

@iatomic1 commented on GitHub (Oct 19, 2025):

Hey @vcode-sh i left an issue on the repo

Hey! I built better-auth-telegram which implements everything requested here:

Telegram Login Widget with callback/redirect flows Account linking & unlinking Telegram Mini Apps support (bonus!) 100% test coverage Full TypeScript support Published on npm

npm install better-auth-telegram

GitHub: https://github.com/vcode-sh/better-auth-telegram Docs: https://github.com/vcode-sh/better-auth-telegram#readme

Feedback welcome!

<!-- gh-comment-id:3419102049 --> @iatomic1 commented on GitHub (Oct 19, 2025): Hey @vcode-sh i left an issue on the repo > Hey! I built `better-auth-telegram` which implements everything requested here: > > ✅ Telegram Login Widget with callback/redirect flows ✅ Account linking & unlinking ✅ Telegram Mini Apps support (bonus!) ✅ 100% test coverage ✅ Full TypeScript support ✅ Published on npm > > npm install better-auth-telegram > > GitHub: https://github.com/vcode-sh/better-auth-telegram Docs: https://github.com/vcode-sh/better-auth-telegram#readme > > Feedback welcome!
Author
Owner

@philippfo9 commented on GitHub (Nov 11, 2025):

Hey! I built better-auth-telegram which implements everything requested here:

Telegram Login Widget with callback/redirect flows Account linking & unlinking Telegram Mini Apps support (bonus!) 100% test coverage Full TypeScript support Published on npm

npm install better-auth-telegram

GitHub: https://github.com/vcode-sh/better-auth-telegram Docs: https://github.com/vcode-sh/better-auth-telegram#readme

Feedback welcome!

Do you support the login url for web login to directly login users?

<!-- gh-comment-id:3515854706 --> @philippfo9 commented on GitHub (Nov 11, 2025): > Hey! I built `better-auth-telegram` which implements everything requested here: > > ✅ Telegram Login Widget with callback/redirect flows ✅ Account linking & unlinking ✅ Telegram Mini Apps support (bonus!) ✅ 100% test coverage ✅ Full TypeScript support ✅ Published on npm > > npm install better-auth-telegram > > GitHub: https://github.com/vcode-sh/better-auth-telegram Docs: https://github.com/vcode-sh/better-auth-telegram#readme > > Feedback welcome! Do you support the login url for web login to directly login users?
Author
Owner

@dosubot[bot] commented on GitHub (Feb 10, 2026):

Hi, @Re4GD. I'm Dosu, and I'm helping the better-auth team manage their backlog and am marking this issue as stale.

Issue Summary

  • You proposed adding support for Telegram's Login Widget with its unique OAuth flow and developed a nearly complete plugin.
  • Your plugin supports account linking, callback URLs, and both callback and redirect flows.
  • Other contributors shared similar plugins, including vcode-sh's "better-auth-telegram" with advanced features like Mini Apps support and full TypeScript coverage.
  • The discussion also explored use cases involving Telegram bots connecting with web apps and related authentication challenges.

Next Steps

  • Please let me know if this issue is still relevant to the latest version of better-auth by commenting here to keep the discussion open.
  • If I don’t hear back within 7 days, I will automatically close this issue.

Thanks for your understanding and contribution!

<!-- gh-comment-id:3878974683 --> @dosubot[bot] commented on GitHub (Feb 10, 2026): Hi, @Re4GD. I'm [Dosu](https://dosu.dev), and I'm helping the better-auth team manage their backlog and am marking this issue as stale. **Issue Summary** - You proposed adding support for Telegram's Login Widget with its unique OAuth flow and developed a nearly complete plugin. - Your plugin supports account linking, callback URLs, and both callback and redirect flows. - Other contributors shared similar plugins, including vcode-sh's "better-auth-telegram" with advanced features like Mini Apps support and full TypeScript coverage. - The discussion also explored use cases involving Telegram bots connecting with web apps and related authentication challenges. **Next Steps** - Please let me know if this issue is still relevant to the latest version of better-auth by commenting here to keep the discussion open. - If I don’t hear back within 7 days, I will automatically close this issue. Thanks for your understanding and contribution!
Author
Owner

@Re4GD commented on GitHub (Feb 16, 2026):

not stale

<!-- gh-comment-id:3908543096 --> @Re4GD commented on GitHub (Feb 16, 2026): not stale
Author
Owner

@khashvin commented on GitHub (Mar 4, 2026):

Telegram now supports the standard oauth implementation https://core.telegram.org/bots/telegram-login
I opened a PR implementing it as a social provider #8359

<!-- gh-comment-id:3996206711 --> @khashvin commented on GitHub (Mar 4, 2026): Telegram now supports the standard oauth implementation https://core.telegram.org/bots/telegram-login I opened a PR implementing it as a social provider #8359
Author
Owner

@ping-maxwell commented on GitHub (Mar 25, 2026):

check out https://github.com/vcode-sh/better-auth-telegram

<!-- gh-comment-id:4128896185 --> @ping-maxwell commented on GitHub (Mar 25, 2026): check out https://github.com/vcode-sh/better-auth-telegram
Author
Owner

@github-actions[bot] commented on GitHub (Apr 2, 2026):

This issue has been locked as it was closed more than 7 days ago. If you're experiencing a similar problem or you have additional context, please open a new issue and reference this one.

<!-- gh-comment-id:4173717728 --> @github-actions[bot] commented on GitHub (Apr 2, 2026): This issue has been locked as it was closed more than 7 days ago. If you're experiencing a similar problem or you have additional context, please open a new issue and reference this one.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#18263