-
Notifications
You must be signed in to change notification settings - Fork 303
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add manager for the Client Grants endpoint (updated) (#142)
* Add a manager for the Client Grants endpoint. Issue #128 * Add tests for the ClientGrantsManager. Issue #128 * Fix URL in ClientGrantsManager. Issue #128 * Update tests for the management SDK. Issue #128 * Added missing client grants manager methods to management client.
- Loading branch information
Showing
4 changed files
with
633 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,149 @@ | ||
var RestClient = require('rest-facade').Client; | ||
var ArgumentError = require('../exceptions').ArgumentError; | ||
var utils = require('../utils'); | ||
|
||
|
||
/** | ||
* @class ClientGrantsManager | ||
* Auth0 Client Grants Manager. | ||
* | ||
* See {@link https://auth0.com/docs/api/v2#!/Client_Grants Client Grants} | ||
* | ||
* @constructor | ||
* @memberOf module:management | ||
* | ||
* @param {Object} options The client options. | ||
* @param {String} options.baseUrl The URL of the API. | ||
* @param {Object} [options.headers] Headers to be included in all requests. | ||
*/ | ||
var ClientGrantsManager = function (options) { | ||
if (options === null || typeof options !== 'object') { | ||
throw new ArgumentError('Must provide client options'); | ||
} | ||
|
||
if (options.baseUrl === null || options.baseUrl === undefined) { | ||
throw new ArgumentError('Must provide a base URL for the API'); | ||
} | ||
|
||
if ('string' !== typeof options.baseUrl || options.baseUrl.length === 0) { | ||
throw new ArgumentError('The provided base URL is invalid'); | ||
} | ||
|
||
/** | ||
* Options object for the Rest Client instance. | ||
* | ||
* @type {Object} | ||
*/ | ||
var clientOptions = { | ||
headers: options.headers, | ||
query: { repeatParams: false } | ||
}; | ||
|
||
/** | ||
* Provides an abstraction layer for consuming the | ||
* {@link https://auth0.com/docs/api/v2#!/Client_Grants Auth0 Client Grantss endpoint}. | ||
* | ||
* @type {external:RestClient} | ||
*/ | ||
this.resource = new RestClient(options.baseUrl + '/client-grants/:id', clientOptions); | ||
}; | ||
|
||
|
||
/** | ||
* Create an Auth0 client grant. | ||
* | ||
* @method create | ||
* @memberOf module:management.ClientGrantsManager.prototype | ||
* | ||
* @example | ||
* management.clientGrants.create(data, function (err) { | ||
* if (err) { | ||
* // Handle error. | ||
* } | ||
* | ||
* // Client grant created. | ||
* }); | ||
* | ||
* @param {Object} data The client data object. | ||
* @param {Function} [cb] Callback function. | ||
* | ||
* @return {Promise|undefined} | ||
*/ | ||
utils.wrapPropertyMethod(ClientGrantsManager, 'create', 'resource.create'); | ||
|
||
|
||
/** | ||
* Get all Auth0 Client Grants. | ||
* | ||
* @method getAll | ||
* @memberOf module:management.ClientGrantsManager.prototype | ||
* | ||
* @example | ||
* management.clientGrants.getAll(function (err, grants) { | ||
* console.log(grants.length); | ||
* }); | ||
* | ||
* @param {Function} [cb] Callback function. | ||
* | ||
* @return {Promise|undefined} | ||
*/ | ||
utils.wrapPropertyMethod(ClientGrantsManager, 'getAll', 'resource.getAll'); | ||
|
||
|
||
/** | ||
* Update an Auth0 client grant. | ||
* | ||
* @method update | ||
* @memberOf module:management.ClientGrantsManager.prototype | ||
* | ||
* @example | ||
* var data = { | ||
* client_id: CLIENT_ID, | ||
* audience: AUDIENCE, | ||
* scope: [] | ||
* }; | ||
* var params = { id: CLIENT_GRANT_ID }; | ||
* | ||
* management.clientGrants.update(params, data, function (err, grant) { | ||
* if (err) { | ||
* // Handle error. | ||
* } | ||
* | ||
* console.log(grant.id); | ||
* }); | ||
* | ||
* @param {Object} params Client parameters. | ||
* @param {String} params.id Client grant ID. | ||
* @param {Object} data Updated client data. | ||
* @param {Function} [cb] Callback function. | ||
* | ||
* @return {Promise|undefined} | ||
*/ | ||
utils.wrapPropertyMethod(ClientGrantsManager, 'update', 'resource.patch'); | ||
|
||
|
||
/** | ||
* Delete an Auth0 client grant. | ||
* | ||
* @method delete | ||
* @memberOf module:management.ClientGrantsManager.prototype | ||
* | ||
* @example | ||
* management.clientGrants.delete({ id: GRANT_ID }, function (err) { | ||
* if (err) { | ||
* // Handle error. | ||
* } | ||
* | ||
* // Grant deleted. | ||
* }); | ||
* | ||
* @param {Object} params Client parameters. | ||
* @param {String} params.id Client grant ID. | ||
* @param {Function} [cb] Callback function. | ||
* | ||
* @return {Promise|undefined} | ||
*/ | ||
utils.wrapPropertyMethod(ClientGrantsManager, 'delete', 'resource.delete'); | ||
|
||
|
||
module.exports = ClientGrantsManager; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.