oc-plugin-oauth2-client
v1.0.0
Published
OpenComponents plugin for integration with OAUTH2
Downloads
21
Readme
oc-plugin-oauth2-client
OpenComponents plugin for integration with OAUTH2. Currently supports only fetching client credentials token.
Requirements
- Node version: min 6
- OC Registry
Install
npm i oc-plugin-oauth2-client --save
Registry setup
More information regarding integrating OpenComponents plugins can be found here.
const registry = oc.registry(configuration);
registry.register({
name: 'getOAUTH2Token',
register: require('oc-plugin-oauth2-client').getClientCredentialsToken,
options: {
clientId: '<id of your application in oauth2 server>',
clientSecret: '<client secret assigned to your application>',
accessTokenUri: '<https://example.server/connect/token>',
authorizationUri: '<https://example.server/connect/authorize>',
redirectUri: '<redirect uri assigned to your application>',
scopes: ['list', 'of', 'required', 'scopes']
}
})
Usage inside components
module.exports.data = (context, callback) => {
context.plugins.getOAUTH2Token((error, generatedToken) => {
if (error) {
// Handle errors that occured while obtaining token
callback(error);
}
// generatedToken ->
// { access_token: '<generatedToken>',
// expires_in: 60,
// token_type: 'Bearer'
// }
callback(null, { generatedToken: generatedToken });
});
};