0.0.1 • Published 8 years ago

factern-client v0.0.1

Weekly downloads
2
License
MIT
Repository
bitbucket
Last release
8 years ago

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);
            }
        });
}
0.0.6

8 years ago

0.0.5

8 years ago

0.0.4

8 years ago

0.0.3

8 years ago

0.0.2

8 years ago

0.0.1

8 years ago