Skip to content

Latest commit

 

History

History
53 lines (39 loc) · 2.11 KB

README.md

File metadata and controls

53 lines (39 loc) · 2.11 KB

passport-frontier

Passport strategy for authentication with Frontier Store through the OAuth 2.0 API.

The official docs page found here details how OAuth2 is set up for Frontier. (Requires Frontier account to access)

Usage

npm install passport-frontier --save

Configure Strategy

The Frontier authentication strategy authenticates users via a Frontier Store user account and OAuth 2.0 token(s). A Frontier API client ID, secret and redirect URL must be supplied when using this strategy. The strategy also requires a verify callback, which receives the access token and an optional refresh token, as well as a profile which contains the authenticated Frontier user's profile. The verify callback must also call cb providing a user to complete the authentication.

let FrontierStrategy = require('passport-frontier').Strategy;

let scopes = ['auth', 'capi'];

passport.use(new FrontierStrategy({
    clientID: 'id',
    clientSecret: 'secret',
    callbackURL: 'callbackURL',
    scope: scopes
},
function(accessToken, refreshToken, profile, cb) {
    User.findOrCreate({ frontierId: profile.id }, function(err, user) {
        return cb(err, user);
    });
}));

Authentication Requests

Use passport.authenticate(), and specify the 'frontier' strategy to authenticate requests.

For example, as a route middleware in an Express app:

app.get('/auth/frontier', passport.authenticate('frontier'));
app.get('/auth/frontier/callback', passport.authenticate('frontier', {
    failureRedirect: '/'
}), function(req, res) {
    res.redirect('/secretstuff') // Successful auth
});

Examples

An Express server example can be found in the /example directory. Be sure to npm install in that directory to get the dependencies.

Credits

License

Licensed under the Apache License 2.0.