Skip to content

Latest commit

 

History

History
68 lines (48 loc) · 1.82 KB

README.md

File metadata and controls

68 lines (48 loc) · 1.82 KB

passport-telegram-login

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.

Install

$ npm install passport-telegram-login

Usage

Configure Strategy

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);
    });
  }
));

Authenticate Requests

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"

Examples

Take a look at the examples folder for a minimal express example

License

The MIT License

Copyright (c) 2018 Svetlozar Argirov <http://broken-by.me/>