oniyi-http-plugin-credentials
A plugin for oniyi-http-client for automatic attachment of user credentials
This plugin is designed to work with the third-party login component loopback framework.
The third-party login component is heavily based on passportjs.
To make things work more broadly, I also wrote a loopback extension to allow the usage of custom auth schemes oniyi-loopback-passport-custom-schemes.
Installation
$ npm install --save oniyi-http-plugin-credentials
Usage
const OniyiHttpClient = require('oniyi-http-client');
const oniyiHttpPluginCredentials = require('oniyi-http-plugin-credentials');
const clientOptions = {};
const httpClient = new OniyiHttpClient(clientOptions);
const pluginOptions = {};
const plugin = oniyiHttpPluginCredentials(pluginOptions);
httpClient.use(plugin);
Plugin Options
The oniyi-http-plugin-credentials
module exports a factory function that takes a single options argument.
available options are:
- providerName: undefined (string, required) - name of the passport-strategy to be used. Note: passport-strategy must be registered first
- removeUserProp: true (boolean, optional) - indicates if the
user
property should be removed from the request options - areCredentialsExpired: (function, optional) - async function that checks if credentials are expired. Must take two arguments (
credentials
, callback(err, isExpired)
) - refreshCredentials: (function, optional) - async function that provides refreshed credentials. Must take three arguments (
strategy
, currentCredentials
, callback(err, freshCredentials)
) - makeAuthParams: (function, optional) - async function that provides an object literal to be merged with request parameters. Must take two arguments (
credentials
, callback(err, authParams)
) - userRelationProp:
/-link$/.test(pluginOptions.providerName) ? 'credentials' : 'identities'
, (string, optional) - name of the relation on req.user
that we should search for user credentials - credentialsProp: 'credentials' (string, optional) - name of the property in the relation's document to be used for credentials
All options of type function
have default values that can with OAuth2 strategies.
License
MIT © Benjamin Kroeger