Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Updated name convention on using simple oauth2 configuration bloc

  • Loading branch information...
commit 0eee76463aa4ee04d8e61b57c3ceca05310eb258 1 parent 9fa121b
@andreareginato authored
View
26 README.md
@@ -39,11 +39,11 @@ along with its client secret to the Lelylan in order to get the access token.
```javascript
// Set the client credentials and the OAuth2 server
-var credentials = { client: {
- id: '<client-id>',
- secret: '<client-secret>',
- site: 'https://api.oauth.com'
-}};
+var credentials = {
+ clientID: '<client-id>',
+ clientSecret: '<client-secret>',
+ site: 'https://api.oauth.com'
+};
// Initialize the OAuth2 Library
var OAuth2 = require('simple-oauth2')(credentials);
@@ -142,9 +142,9 @@ OAuth2.AuthCode.getToken(function(error, token) {
Simple OAuth2 accepts an object with the following valid params.
-* `client.id` - Required registered Client ID.
-* `client.secret` - Required registered Client secret.
-* `client.site` - Required registered Client site.
+* `clientID` - Required registered Client ID.
+* `clientSecret` - Required registered Client secret.
+* `site` - Required OAuth2 server site.
* `authorizationPath` - Authorization path for the OAuth2 server.
Simple OAuth2 uses `/oauth/authorize` as default
* `tokenPath` - Access token path for the OAuth2 server.
@@ -152,13 +152,13 @@ Simple OAuth2 uses `/oauth/token` as default.
```javascript
// Set the configuration settings
-var credentials = { client: {
- id: '<client-id>',
- secret: '<client-secret>',
- site: 'https://api.oauth.com',
+var credentials = {
+ clientID: '<client-id>',
+ clientSecret: '<client-secret>',
+ site: 'https://www.oauth2.com',
authorizationPath: '/oauth2/authorization',
tokenPath: '/oauth2/access_token'
-}};
+};
// Initialize the OAuth2 Library
var OAuth2 = require('simple-oauth2')(credentials);
View
4 lib/client/auth-code.js
@@ -16,9 +16,9 @@ module.exports = function(config) {
//
function authorizeURL(params) {
params.response_type = 'code';
- params.client_id = config.client.id;
+ params.client_id = config.clientID;
- return config.client.site + config.authorizationPath + '?' + qs.stringify(params);
+ return config.site + config.authorizationPath + '?' + qs.stringify(params);
}
//
View
4 lib/config.js
@@ -1,5 +1,7 @@
module.exports = {
'authorizationPath' : '/oauth/authorize',
'tokenPath' : '/oauth/token',
- 'client': {},
+ 'clientID': null,
+ 'clientSecret': null,
+ 'site': null
}
View
8 lib/core.js
@@ -17,7 +17,7 @@ module.exports = function(config) {
}
if (process.env.DEBUG) console.log('OAuth2 Node Request');
- var url = config.client.site + path;
+ var url = config.site + path;
call(method, url, params, function(error, response, body) {
data(error, response, body, callback);
@@ -29,7 +29,11 @@ module.exports = function(config) {
function call(method, url, params, callback) {
var options = { uri: url, method: method }
- if (config.client) options.headers = { 'Authorization': 'Basic ' + new Buffer(config.client.id + ':' + config.client.secret).toString('base64') }
+ if (!config.clientID || !config.clientSecret || !config.site)
+ throw new Error('Configuration missing. You need to specify the client id, the client secret and the oauth2 server');
+
+ if (config.clientID)
+ options.headers = { 'Authorization': 'Basic ' + new Buffer(config.clientID + ':' + config.clientSecret).toString('base64') }
if (isEmpty(params)) params = null;
if (method != 'GET') options.form = params;
View
2  test/access_token.js
@@ -1,4 +1,4 @@
-var credentials = { client: { id: 'client-id', secret: 'client-secret', site: 'https://example.org' },
+var credentials = { clientID: 'client-id', clientSecret: 'client-secret', site: 'https://example.org' },
OAuth2 = require('./../lib/simple-oauth2.js')(credentials),
qs = require('querystring'),
nock = require('nock');
View
2  test/auth-code.js
@@ -1,4 +1,4 @@
-var credentials = { client: { id: 'client-id', secret: 'client-secret', site: 'https://example.org' },
+var credentials = { clientID: 'client-id', clientSecret: 'client-secret', site: 'https://example.org' },
OAuth2 = require('./../lib/simple-oauth2.js')(credentials),
qs = require('querystring'),
nock = require('nock');
View
2  test/errors.js
@@ -1,4 +1,4 @@
-var credentials = { client: { id: 'client-id', secret: 'client-secret', site: 'https://example.org' },
+var credentials = { clientID: 'client-id', clientSecret: 'client-secret', site: 'https://example.org' },
OAuth2 = require('./../lib/simple-oauth2.js')(credentials),
qs = require('querystring'),
nock = require('nock');
View
2  test/password.js
@@ -1,4 +1,4 @@
-var credentials = { client: { id: 'client-id', secret: 'client-secret', site: 'https://example.org' },
+var credentials = { clientID: 'client-id', clientSecret: 'client-secret', site: 'https://example.org' },
OAuth2 = require('./../lib/simple-oauth2.js')(credentials),
qs = require('querystring'),
nock = require('nock');
Please sign in to comment.
Something went wrong with that request. Please try again.