| lib | ||
| .gitignore | ||
| LICENSE | ||
| package.json | ||
| README.md | ||
Archived
This repository is a fork and is now maintained by jonathan.boisclair@moyskleytech.com.
passport-fluxer
Passport strategy for authentication with Fluxer (https://web.fluxer.app) through the OAuth 2.0 API.
Before using this strategy, review the Fluxer OAuth docs for scopes and behavior.
Usage
Install directly from this git repository:
npm install git+https://git.moyskleytech.com/MoyskleyTech/passport-fluxer.git --save
Configure Strategy
The Fluxer authentication strategy authenticates users via a Fluxer account and OAuth 2.0 token(s). A Fluxer 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 user's profile. The verify callback must also call cb providing a user to complete the authentication.
var FluxerStrategy = require('passport-fluxer').Strategy;
var scopes = ['identify', 'email'];
passport.use(new FluxerStrategy({
clientID: 'id',
clientSecret: 'secret',
callbackURL: 'callbackURL',
scope: scopes
},
function(accessToken, refreshToken, profile, cb) {
User.findOrCreate({ fluxerId: profile.id }, function(err, user) {
if (err) return cb(err);
return cb(null, user);
});
}));
Authentication Requests
Use passport.authenticate(), and specify the 'fluxer' strategy to authenticate requests.
For example, as a route middleware in an Express app:
app.get('/auth/fluxer', passport.authenticate('fluxer'));
app.get('/auth/fluxer/callback', passport.authenticate('fluxer', {
failureRedirect: '/'
}), function(req, res) {
res.redirect('/secretstuff') // Successful auth
});
Refresh Token Usage
If you need to refresh access tokens, a package such as passport-oauth2-refresh can assist in doing this.
Example:
npm install passport-oauth2-refresh --save
var FluxerStrategy = require('passport-fluxer').Strategy
, refresh = require('passport-oauth2-refresh');
var fluxerStrat = new FluxerStrategy({
clientID: 'id',
clientSecret: 'secret',
callbackURL: 'callbackURL'
},
function(accessToken, refreshToken, profile, cb) {
profile.refreshToken = refreshToken; // store this for later refreshes
User.findOrCreate({ fluxerId: profile.id }, function(err, user) {
if (err) return cb(err);
return cb(null, user);
});
});
passport.use(fluxerStrat);
refresh.use(fluxerStrat);
... then to request a new access token:
refresh.requestNewAccessToken('fluxer', profile.refreshToken, function(err, accessToken, refreshToken) {
if (err) throw err;
profile.accessToken = accessToken; // store this new one for our new requests
});
Credits
- Jared Hanson - used passport-github to understand passport more and kind of as a base.
License
Licensed under the ISC license. The full license text can be found in the root of the project repository.