Passport strategy for authenticating with Telegram using the Telegram Login Widget.
This module lets you authenticate using Telegram in your Node.js applications. By plugging into Passport, Telegram authentication can be easily and unobtrusively integrated into any application or framework that supports Connect-style middleware, including Express.
$ npm install passport-telegram-login
The Telegram authentication strategy authenticates users using a Telegram Bot. Check the Telegram Login Widget page for information on how to create bot and get the bot token.
passport.use(new TelegramStrategy({
botToken: TELEGRAM_BOT_TOKEN,
},
function(profile, done) {
User.findOrCreate({ telegramId: profile.id }, function (err, user) {
return done(err, user);
});
}
));
Use passport.authenticate()
, specifying the telegram-login
strategy, to
authenticate requests.
For example, as route middleware in an Express application:
app.get('/auth/telegram-login/callback',
passport.authenticate('telegram-login', { failureRedirect: '/login' }),
function(req, res) {
// Successful authentication, redirect home.
res.redirect('/');
});
And in your Telegram login widget configuration set
data-auth-url="/auth/telegram/callback"
Take a look at the examples folder for a minimal express example
Copyright (c) 2018 Svetlozar Argirov <http://broken-by.me/>