A node & browser compatible client for communicating to Factern

Usage no npm install needed!

<script type="module">
  import facternClient from 'https://cdn.skypack.dev/factern-client';


Factern JavaScript Client


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,

        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) {
        .set('Authorization', `Bearer ${accessToken}`)
        .end((err, res) => {
            if (err || !res.ok) {
                done(err || res, null);
            } else {
                done(null, res.body);