simple-oauth2.js | |
---|---|
Node.js client library for OAuth2 OAuth2 lets users grant the access to the desired resources to third party applications, giving them the possibility to enable and disable those accesses whenever they want. Simple OAuth2 supports the following flows.
Installation
Authorization Code flowThe Authorization Code flow is made up from two parts. At first your application asks to the user the permission to access their data. If the user approves Lelylan sends to the client an authorization code. In the second part, the client POST the authorization code along with its client secret to the Lelylan in order to get the access token. Learn more about.
Password Credentials FlowThis flow is suitable when the resource owner has a trust relationship with the client, such as its computer operating system or a highly privileged application. Use this flow only when other flows are not viable or when you need a fast way to test your application. Learn more about.
Access Token objectWhen a token expires we need to refresh it. Simple OAuth2 offers the AccessToken class that add a couple of useful methods to refresh the access token when it is expired. Learn more about.
ErrorsExceptions are raised when a 4xx or 5xx status code is returned.
Through the error message attribute you can access the JSON representation
based on HTTP | |
ConfigurationsSimple OAuth2 accepts an object with the following valid params.
| var appConfig = require('./config');
module.exports = function(config) {
function configure(config) {
config = config || {};
mergeDefaults(config, appConfig);
return config;
}
config = configure(config);
var core = require('./core')(config);
function mergeDefaults(o1, o2) {
for (var p in o2) {
try { if (typeof o2[p] == 'object') { o1[p] = mergeDefaults(o1[p], o2[p]); } else if (typeof o1[p] == 'undefined') { o1[p] = o2[p]; } }
catch(e) { o1[p] = o2[p]; }
}
return o1;
}
return {
'AuthCode': require('./client/auth-code')(config),
'Password': require('./client/password')(config),
'AccessToken': require('./client/access-token')(config)
}
};
|