factern-client
v0.0.1
Published
A node & browser compatible client for communicating to Factern
Downloads
2
Readme
Factern JavaScript Client
Installation
npm install factern-client --save
You will also need some OAuth2 library to handle authentication of users against the Factern auth service. You can use anyone you want. In our examples we have used PassportJS.
npm install passport passport-oauth2 --save
Passport config
const strategy = new OAuth2Strategy({
authorizationURL: 'https://sso.factern.com/auth/authorize',
tokenURL: 'https://sso.factern.com/auth/token',
clientID: '<your_client_id>',
clientSecret: '<your_client_secret>',
callbackURL: '<registered_callback_url>',
},
function(accessToken, refreshToken, profile, done) {
const user = {
id: profile.sub,
accessToken
};
console.log('Auth Success: ', user)
// You can load user details from some DB or do whatever else you'd like here.
// In this case we just "store" the details we were given.
done(null, user);
});
strategy.userProfile = function getUserDetails(accessToken, done) {
request
.get('https://sso.factern.com/auth/userinfo')
.set('Authorization', `Bearer ${accessToken}`)
.end((err, res) => {
if (err || !res.ok) {
done(err || res, null);
} else {
done(null, res.body);
}
});
}