passport-oauth-mail-ru
TypeScript icon, indicating that this package has built-in type declarations

1.0.0 • Public • Published

passport-oauth-mail-ru

Passport strategy for authenticating with Mail using the OAuth 2.0 API.

This module lets you authenticate using Mail in your Node.js applications.

Install

$ npm install passport-oauth-mail-ru

Usage

Create an Application

Before using passport-oauth-mail-ru, you must register an application with Mail.

Configure Strategy

var MailStrategy = require('passport-oauth-mail-ru');

passport.use(new MailStrategy({
    clientID: process.env['MAIL_RU_APP_ID'],
    clientSecret: process.env['MAIL_RU_APP_SECRET'],
    callbackURL: "http://example.com/auth/mail/callback"
  },
  function(accessToken, refreshToken, profile, done) {
    User.findOrCreate({ mailId: profile.id }, function (err, user) {
      return done(err, user);
    });
  }
));

Authenticate Requests

Use passport.authenticate(), specifying the 'mail' strategy, to authenticate requests.

For example, as route middleware in an Express application:

app.get('/auth/mail',
  passport.authenticate('mail'));

app.get('/auth/mail/callback', 
  passport.authenticate('mail', { failureRedirect: '/login' }),
  function(req, res) {
    // Successful authentication, redirect home.
    res.redirect('/');
  });

License

The MIT License

Copyright (c) 2023 FTB_lag

Package Sidebar

Install

npm i passport-oauth-mail-ru

Weekly Downloads

10

Version

1.0.0

License

MIT

Unpacked Size

5.65 kB

Total Files

6

Last publish

Collaborators

  • ftb_lag