passport-infogym v0.0.1
Passport-InfoGym
Passport strategy for authenticating with InfoGym using the OAuth 2.0 API.
This module lets you authenticate using InfoGym in your Node.js applications. By plugging into Passport, InfoGym authentication can be easily and unobtrusively integrated into any application or framework that supports Connect-style middleware, including Express.
Install
npm install passport-infogym --saveUsage
Configure Strategy
The InfoGym authentication strategy authenticates users using a InfoGym account
and OAuth 2.0 tokens. The strategy requires a verify callback, which accepts
these credentials and calls done providing a user, as well as options
specifying a client id, client secret, and callback url.
const strategyOptions =
{ clientID: INFOGYM_CLIENT_ID
, clientSecret: INFOGYM_CLIENT_SECRET
, callbackURL: 'https://www.example.com/auth/infogym/callback'
}
passport.use(new InfoGymStrategy(strategyOptions, verifyInfoGym))
function verifyInfoGym(accessToken, refreshToken, profile, done) {
User.findOrCreate({ infogymId: profile.id }, function(err, user) {
return done(err, user)
})
}Authenticate Requests
Use passport.authenticate(), specifying the 'infogym' strategy, to
authenticate requests.
For example, as route middleware in an Express application:
app.get('/auth/infogym', passport.authenticate('infogym'));
app.get('/auth/infogym/callback',
passport.authenticate('infogym', { failureRedirect: '/login' }),
function(req, res) {
// Successful authentication, redirect home.
res.redirect('/');
});License
10 years ago