dadi / passport

A library for generating access tokens to authenticate with DADI platform components
7 stars 3 forks source link

Change the way wallets are included #4

Closed eduardoboucas closed 8 years ago

eduardoboucas commented 8 years ago

Currently, a token wallet is included as such:

var passport = require('dadi-passport')({
    // (...)
    wallet: require('./wallets/file'), // <-- function
    walletOptions: {
        path: './token.txt'
    }
});

This has the disadvantage of forcing users to know the location of the wallet module, which you shouldn't really care about if you're including the library with npm.

For that reason, I shifted the responsibility of including the wallet file to the library itself, asking users to simply specify the name of the wallet as a string (e.g. 'file'), which will link to /wallets/file.js. The previous syntax is still accepted for people that wish to implement their own wallet modules (which will live outside the library directory).

Example:

// Using the `file` wallet (new syntax)
var passport = require('dadi-passport')({
    uri: 'http://api.eb.dev.dadi.technology',
    credentials: {
        clientId: 'johndoe',
        secret: 'f00b4r'        
    },
    wallet: 'file', // <-- string
    walletOptions: {
        path: './token.txt'
    }
});

// Using a custom wallet (existing syntax)
var passport = require('dadi-passport')({
    uri: 'http://api.eb.dev.dadi.technology',
    credentials: {
        clientId: 'johndoe',
        secret: 'f00b4r'        
    },
    wallet: require('./lib/my-custom-wallet'), // <-- function
    walletOptions: {
        path: './token.txt'
    }
});