Comparing version 2.4.0 to 2.5.0
{ | ||
"name": "auth0", | ||
"version": "2.4.0", | ||
"version": "2.5.0", | ||
"description": "SDK for Auth0 API v2", | ||
@@ -5,0 +5,0 @@ "main": "src/index.js", |
@@ -43,6 +43,7 @@ /** @module auth **/ | ||
* | ||
* @param {Object} options Options for the Authentication Client | ||
* SDK. | ||
* @param {String} options.domain AuthenticationClient server domain. | ||
* @param {String} [options.clientId] Default client ID. | ||
* @param {Object} options Options for the Authentication Client | ||
* SDK. | ||
* @param {String} options.domain AuthenticationClient server domain. | ||
* @param {String} [options.clientId] Default client ID. | ||
* @param {String} [options.clientSecret] Default client Secret. | ||
*/ | ||
@@ -62,2 +63,4 @@ var AuthenticationClient = function (options) { | ||
clientId: options.clientId, | ||
domain: options.domain, | ||
clientSecret: options.clientSecret, | ||
headers: { | ||
@@ -481,3 +484,28 @@ 'User-agent': 'node.js/' + process.version.replace('v', ''), | ||
/** | ||
* Gets an access token using the client credentials grant flow. | ||
* | ||
* @method clientCredentialsGrant | ||
* @memberOf module:auth.AuthenticationClient.prototype | ||
* | ||
* @example <caption> | ||
* Gets an access token using the client credentials grant flow. Find more information in the | ||
* <a href="https://auth0.com/docs/api-auth/config/asking-for-access-tokens">API Docs</a>. | ||
* </caption> | ||
* | ||
* auth0.clientCredentialsGrant(data, function (err, response) { | ||
* if (err) { | ||
* // Handle error. | ||
* } | ||
* | ||
* console.log(response); | ||
* }); | ||
* | ||
* @param {String} scope | ||
* | ||
* @return {Promise|undefined} | ||
*/ | ||
utils.wrapPropertyMethod(AuthenticationClient, 'clientCredentialsGrant', 'oauth.clientCredentialsGrant'); | ||
module.exports = AuthenticationClient; |
@@ -14,5 +14,6 @@ var extend = require('util')._extend; | ||
* | ||
* @param {Object} options Authenticator options. | ||
* @param {String} options.baseUrl The auth0 account URL. | ||
* @param {String} [options.clientId] Default client ID. | ||
* @param {Object} options Authenticator options. | ||
* @param {String} options.baseUrl The auth0 account URL. | ||
* @param {String} [options.clientId] Default client ID. | ||
* @param {String} [options.clientSecret] Default client Secret. | ||
*/ | ||
@@ -32,2 +33,3 @@ var OAuthAuthenticator = function (options) { | ||
this.clientId = options.clientId; | ||
this.clientSecret = options.clientSecret; | ||
}; | ||
@@ -141,3 +143,35 @@ | ||
OAuthAuthenticator.prototype.clientCredentialsGrant = function(options, cb) { | ||
var params = { | ||
type: 'token' | ||
}; | ||
var defaultFields = { | ||
grant_type: "client_credentials", | ||
client_id: this.clientId, | ||
client_secret: this.clientSecret | ||
}; | ||
var data = extend(defaultFields, options); | ||
if (!options || typeof options !== 'object') { | ||
throw new ArgumentError('Missing options object'); | ||
} | ||
if (!data.client_id || data.client_id.trim().length === 0) { | ||
throw new ArgumentError('client_id field is required'); | ||
} | ||
if (!data.client_secret || data.client_secret.trim().length === 0) { | ||
throw new ArgumentError('client_secret field is required'); | ||
} | ||
if (cb && cb instanceof Function) { | ||
return this.oauth.create(params, data, cb); | ||
} | ||
return this.oauth.create(params, data); | ||
}; | ||
module.exports = OAuthAuthenticator; |
@@ -75,3 +75,2 @@ var Promise = require('bluebird'); | ||
}); | ||
} |
137057
4463