-
Notifications
You must be signed in to change notification settings - Fork 303
/
ClientGrantsManager.js
150 lines (134 loc) · 3.72 KB
/
ClientGrantsManager.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
var RestClient = require('rest-facade').Client;
var ArgumentError = require('rest-facade').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 = {
errorFormatter: { message: 'message', name: 'error' },
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;