@esri/arcgis-rest-developer-credentials 2.1.1-alpha.1 → 4.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/bundled/developer-credentials.esm.js +12 -12
- package/dist/bundled/developer-credentials.esm.js.map +1 -1
- package/dist/bundled/developer-credentials.esm.min.js +4 -4
- package/dist/bundled/developer-credentials.esm.min.js.map +1 -1
- package/dist/bundled/developer-credentials.umd.js +731 -733
- package/dist/bundled/developer-credentials.umd.js.map +1 -1
- package/dist/bundled/developer-credentials.umd.min.js +4 -4
- package/dist/bundled/developer-credentials.umd.min.js.map +1 -1
- package/dist/cjs/createApiKey.js +2 -3
- package/dist/cjs/createApiKey.js.map +1 -1
- package/dist/cjs/createOAuthApp.js +2 -3
- package/dist/cjs/createOAuthApp.js.map +1 -1
- package/dist/cjs/getApiKey.js +2 -3
- package/dist/cjs/getApiKey.js.map +1 -1
- package/dist/cjs/getOAuthApp.js +2 -3
- package/dist/cjs/getOAuthApp.js.map +1 -1
- package/dist/cjs/index.js +15 -15
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/invalidateApiKey.js +1 -2
- package/dist/cjs/invalidateApiKey.js.map +1 -1
- package/dist/cjs/shared/generateApiKeyToken.js +1 -2
- package/dist/cjs/shared/generateApiKeyToken.js.map +1 -1
- package/dist/cjs/shared/getRegisteredAppInfo.js +2 -3
- package/dist/cjs/shared/getRegisteredAppInfo.js.map +1 -1
- package/dist/cjs/shared/helpers.js +11 -11
- package/dist/cjs/shared/helpers.js.map +1 -1
- package/dist/cjs/shared/registerApp.js +2 -3
- package/dist/cjs/shared/registerApp.js.map +1 -1
- package/dist/cjs/shared/types/apiKeyType.js.map +1 -1
- package/dist/cjs/shared/types/appType.js.map +1 -1
- package/dist/cjs/shared/types/oAuthType.js.map +1 -1
- package/dist/cjs/shared/unregisterApp.js +2 -3
- package/dist/cjs/shared/unregisterApp.js.map +1 -1
- package/dist/cjs/updateApiKey.js +2 -3
- package/dist/cjs/updateApiKey.js.map +1 -1
- package/dist/cjs/updateOAuthApp.js +2 -3
- package/dist/cjs/updateOAuthApp.js.map +1 -1
- package/dist/esm/createApiKey.d.ts +1 -1
- package/dist/esm/createApiKey.js +1 -1
- package/dist/esm/createApiKey.js.map +1 -1
- package/dist/esm/createOAuthApp.d.ts +1 -1
- package/dist/esm/createOAuthApp.js +1 -1
- package/dist/esm/createOAuthApp.js.map +1 -1
- package/dist/esm/getApiKey.d.ts +1 -1
- package/dist/esm/getApiKey.js +1 -1
- package/dist/esm/getApiKey.js.map +1 -1
- package/dist/esm/getOAuthApp.d.ts +1 -1
- package/dist/esm/getOAuthApp.js +1 -1
- package/dist/esm/getOAuthApp.js.map +1 -1
- package/dist/esm/shared/enum/privileges.d.ts +1 -1
- package/dist/esm/shared/getRegisteredAppInfo.d.ts +1 -1
- package/dist/esm/shared/getRegisteredAppInfo.js +1 -1
- package/dist/esm/shared/getRegisteredAppInfo.js.map +1 -1
- package/dist/esm/shared/helpers.d.ts +1 -1
- package/dist/esm/shared/helpers.js.map +1 -1
- package/dist/esm/shared/registerApp.d.ts +1 -1
- package/dist/esm/shared/registerApp.js +1 -1
- package/dist/esm/shared/registerApp.js.map +1 -1
- package/dist/esm/shared/types/apiKeyType.d.ts +4 -4
- package/dist/esm/shared/types/apiKeyType.js.map +1 -1
- package/dist/esm/shared/types/appType.d.ts +4 -4
- package/dist/esm/shared/types/appType.js.map +1 -1
- package/dist/esm/shared/types/oAuthType.d.ts +4 -4
- package/dist/esm/shared/types/oAuthType.js.map +1 -1
- package/dist/esm/shared/unregisterApp.d.ts +1 -1
- package/dist/esm/shared/unregisterApp.js +1 -1
- package/dist/esm/shared/unregisterApp.js.map +1 -1
- package/dist/esm/updateApiKey.d.ts +1 -1
- package/dist/esm/updateApiKey.js +1 -1
- package/dist/esm/updateApiKey.js.map +1 -1
- package/dist/esm/updateOAuthApp.d.ts +1 -1
- package/dist/esm/updateOAuthApp.js +1 -1
- package/dist/esm/updateOAuthApp.js.map +1 -1
- package/package.json +5 -5
|
@@ -1,753 +1,751 @@
|
|
|
1
1
|
/* @preserve
|
|
2
|
-
* @esri/arcgis-rest-developer-credentials -
|
|
3
|
-
* Copyright (c) 2017-
|
|
4
|
-
*
|
|
2
|
+
* @esri/arcgis-rest-developer-credentials - v4.8.0 - Apache-2.0
|
|
3
|
+
* Copyright (c) 2017-2026 Esri, Inc.
|
|
4
|
+
* Fri Jan 16 2026 01:29:33 GMT+0000 (Coordinated Universal Time)
|
|
5
5
|
*/
|
|
6
6
|
(function (global, factory) {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
7
|
+
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@esri/arcgis-rest-portal'), require('@esri/arcgis-rest-request')) :
|
|
8
|
+
typeof define === 'function' && define.amd ? define(['exports', '@esri/arcgis-rest-portal', '@esri/arcgis-rest-request'], factory) :
|
|
9
|
+
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.arcgisRest = global.arcgisRest || {}, global.arcgisRest, global.arcgisRest));
|
|
10
10
|
})(this, (function (exports, arcgisRestPortal, arcgisRestRequest) { 'use strict';
|
|
11
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
|
-
|
|
12
|
+
/* Copyright (c) 2023 Environmental Systems Research Institute, Inc.
|
|
13
|
+
* Apache-2.0 */
|
|
14
|
+
/**
|
|
15
|
+
* Used to retrieve registered app info. See the [REST Documentation](https://developers.arcgis.com/rest/users-groups-and-items/registered-app-info.htm) for more information.
|
|
16
|
+
*
|
|
17
|
+
* ```js
|
|
18
|
+
* import { getRegisteredAppInfo, IApp } from '@esri/arcgis-rest-developer-credentials';
|
|
19
|
+
* import { ArcGISIdentityManager } from "@esri/arcgis-rest-request";
|
|
20
|
+
*
|
|
21
|
+
* const authSession: ArcGISIdentityManager = await ArcGISIdentityManager.signIn({
|
|
22
|
+
* username: "xyz_usrName",
|
|
23
|
+
* password: "xyz_pw"
|
|
24
|
+
* });
|
|
25
|
+
*
|
|
26
|
+
* getRegisteredAppInfo({
|
|
27
|
+
* itemId: "xyz_itemId",
|
|
28
|
+
* authentication: authSession
|
|
29
|
+
* }).then((registeredApp: IApp) => {
|
|
30
|
+
* // => {client_id: "xyz_id", client_secret: "xyz_secret", ...}
|
|
31
|
+
* }).catch(e => {
|
|
32
|
+
* // => an exception object
|
|
33
|
+
* });
|
|
34
|
+
* ```
|
|
35
|
+
*
|
|
36
|
+
* @param requestOptions - Options for {@linkcode getRegisteredAppInfo | getRegisteredAppInfo()}, including an itemId of which app to retrieve and an {@linkcode @esri/arcgis-rest-request!ArcGISIdentityManager} authentication session.
|
|
37
|
+
* @returns A Promise that will resolve to an {@linkcode IApp} object representing successfully retrieved app.
|
|
38
|
+
*/
|
|
39
|
+
async function getRegisteredAppInfo(requestOptions) {
|
|
40
|
+
const userName = await requestOptions.authentication.getUsername();
|
|
41
|
+
const url = arcgisRestPortal.getPortalUrl(requestOptions) +
|
|
42
|
+
`/content/users/${userName}/items/${requestOptions.itemId}/registeredAppInfo`;
|
|
43
|
+
requestOptions.httpMethod = "POST";
|
|
44
|
+
const registeredAppResponse = await arcgisRestRequest.request(url, Object.assign(Object.assign({}, requestOptions), { params: { f: "json" } }));
|
|
45
|
+
return registeredAppResponseToApp(registeredAppResponse);
|
|
46
|
+
}
|
|
47
47
|
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
48
|
+
async function generateApiKeyToken(options) {
|
|
49
|
+
const portal = arcgisRestPortal.getPortalUrl(options);
|
|
50
|
+
const url = `${portal}/oauth2/token`;
|
|
51
|
+
const appInfo = await getRegisteredAppInfo({
|
|
52
|
+
itemId: options.itemId,
|
|
53
|
+
authentication: options.authentication
|
|
54
|
+
});
|
|
55
|
+
const params = {
|
|
56
|
+
client_id: appInfo.client_id,
|
|
57
|
+
client_secret: appInfo.client_secret,
|
|
58
|
+
apiToken: options.apiKey,
|
|
59
|
+
regenerateApiToken: true,
|
|
60
|
+
grant_type: "client_credentials"
|
|
61
|
+
};
|
|
62
|
+
// authentication is not being passed to the request because client_secret acts as the auth
|
|
63
|
+
return arcgisRestRequest.request(url, {
|
|
64
|
+
params
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
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
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
68
|
+
/**
|
|
69
|
+
* @internal
|
|
70
|
+
* Encode special params value (e.g. array type...) in advance in order to make {@linkcode encodeParam} works correctly. Usage is case by case.
|
|
71
|
+
*/
|
|
72
|
+
const stringifyArrays = (requestOptions) => {
|
|
73
|
+
Object.entries(requestOptions.params).forEach((entry) => {
|
|
74
|
+
const [key, value] = entry;
|
|
75
|
+
if (value.constructor.name === "Array") {
|
|
76
|
+
requestOptions.params[key] = JSON.stringify(value);
|
|
77
|
+
}
|
|
78
|
+
});
|
|
79
|
+
};
|
|
80
|
+
/**
|
|
81
|
+
* @internal
|
|
82
|
+
* Used to convert {@linkcode IRegisteredAppResponse} to {@linkcode IApp}.
|
|
83
|
+
*/
|
|
84
|
+
function registeredAppResponseToApp(response) {
|
|
85
|
+
const omittedKeys = [
|
|
86
|
+
"apnsProdCert",
|
|
87
|
+
"apnsSandboxCert",
|
|
88
|
+
"gcmApiKey",
|
|
89
|
+
"isBeta",
|
|
90
|
+
"customAppLoginShowTriage"
|
|
91
|
+
];
|
|
92
|
+
const dateKeys = ["modified", "registered"];
|
|
93
|
+
return Object.keys(response)
|
|
94
|
+
.filter((key) => !omittedKeys.includes(key))
|
|
95
|
+
.reduce((obj, key) => {
|
|
96
|
+
if (dateKeys.includes(key)) {
|
|
97
|
+
obj[key] = new Date(response[key]);
|
|
98
|
+
}
|
|
99
|
+
else {
|
|
100
|
+
obj[key] = response[key];
|
|
101
|
+
}
|
|
102
|
+
return obj;
|
|
103
|
+
}, {});
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* @internal
|
|
107
|
+
* Used to convert {@linkcode IApp} to {@linkcode IApiKeyInfo} only if `appType` is "apikey".
|
|
108
|
+
*/
|
|
109
|
+
function appToApiKeyProperties(response) {
|
|
110
|
+
delete response.client_secret;
|
|
111
|
+
delete response.redirect_uris;
|
|
112
|
+
delete response.appType;
|
|
113
|
+
delete response.customAppLoginShowTriage;
|
|
114
|
+
delete response.apiKey;
|
|
115
|
+
return response;
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* @internal
|
|
119
|
+
* Used to convert {@linkcode IApp} to {@linkcode IOAuthAppInfo}.
|
|
120
|
+
*/
|
|
121
|
+
function appToOAuthAppProperties(response) {
|
|
122
|
+
delete response.appType;
|
|
123
|
+
delete response.httpReferrers;
|
|
124
|
+
delete response.privileges;
|
|
125
|
+
delete response.apiKey;
|
|
126
|
+
delete response.customAppLoginShowTriage;
|
|
127
|
+
delete response.isPersonalAPIToken;
|
|
128
|
+
delete response.apiToken1Active;
|
|
129
|
+
delete response.apiToken2Active;
|
|
130
|
+
return response;
|
|
131
|
+
}
|
|
132
|
+
/**
|
|
133
|
+
* @internal
|
|
134
|
+
* Used to extract base request options from a hybrid option and exclude `params` and `authentication`.
|
|
135
|
+
*/
|
|
136
|
+
function extractBaseRequestOptions(options) {
|
|
137
|
+
const requestOptionsProperties = [
|
|
138
|
+
"credentials",
|
|
139
|
+
"headers",
|
|
140
|
+
"hideToken",
|
|
141
|
+
"httpMethod",
|
|
142
|
+
"maxUrlLength",
|
|
143
|
+
"portal",
|
|
144
|
+
"rawResponse",
|
|
145
|
+
"signal",
|
|
146
|
+
"suppressWarnings"
|
|
147
|
+
];
|
|
148
|
+
return filterKeys(options, requestOptionsProperties);
|
|
149
|
+
}
|
|
150
|
+
/**
|
|
151
|
+
* @internal
|
|
152
|
+
* Used to create a new object including only specified keys from another object.
|
|
153
|
+
*/
|
|
154
|
+
function filterKeys(object, includedKeys) {
|
|
155
|
+
return includedKeys.reduce((obj, ele) => {
|
|
156
|
+
if (ele in object) {
|
|
157
|
+
obj[ele] = object[ele];
|
|
158
|
+
}
|
|
159
|
+
return obj;
|
|
160
|
+
}, {});
|
|
161
|
+
}
|
|
162
|
+
/**
|
|
163
|
+
* Used to determine if a generated key is in slot 1 or slot 2 key. The full API key should be passed. `undefined` will be returned if the proper slot could not be identified.
|
|
164
|
+
*/
|
|
165
|
+
function slotForKey(key) {
|
|
166
|
+
const slot = parseInt(key.substring(key.length - 10, key.length - 9));
|
|
167
|
+
if (slot === 1 || slot === 2) {
|
|
168
|
+
return slot;
|
|
169
|
+
}
|
|
170
|
+
return undefined;
|
|
171
|
+
}
|
|
172
|
+
/**
|
|
173
|
+
* @internal
|
|
174
|
+
* Used to determine which slot to invalidate a key in given a number or a full or patial key.
|
|
175
|
+
*/
|
|
176
|
+
function slotForInvalidationKey(param) {
|
|
177
|
+
if (param === 1 || param === 2) {
|
|
178
|
+
return param;
|
|
179
|
+
}
|
|
180
|
+
if (typeof param !== "string") {
|
|
181
|
+
return undefined;
|
|
182
|
+
}
|
|
183
|
+
const fullKeySlot = slotForKey(param);
|
|
184
|
+
if (fullKeySlot) {
|
|
185
|
+
return fullKeySlot;
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
/**
|
|
189
|
+
* @internal
|
|
190
|
+
* Used to generate tokens in slot 1 and/or 2 of an API key.
|
|
191
|
+
*/
|
|
192
|
+
function generateApiKeyTokens(itemId, slots, requestOptions) {
|
|
193
|
+
return Promise.all(slots.map((slot) => {
|
|
194
|
+
return generateApiKeyToken(Object.assign({ itemId, apiKey: slot }, requestOptions));
|
|
195
|
+
})).then((responses) => {
|
|
196
|
+
return responses
|
|
197
|
+
.map((responses) => responses.access_token)
|
|
198
|
+
.reduce((obj, token, index) => {
|
|
199
|
+
obj[`accessToken${slotForKey(token)}`] = token;
|
|
200
|
+
return obj;
|
|
201
|
+
}, {});
|
|
202
|
+
});
|
|
203
|
+
}
|
|
204
|
+
/**
|
|
205
|
+
* @internal
|
|
206
|
+
* Convert boolean flags to an array of slots for {@linkcode generateApiKeyTokens}.
|
|
207
|
+
*/
|
|
208
|
+
function generateOptionsToSlots(generateToken1, generateToken2) {
|
|
209
|
+
const slots = [];
|
|
210
|
+
if (generateToken1) {
|
|
211
|
+
slots.push(1);
|
|
212
|
+
}
|
|
213
|
+
if (generateToken2) {
|
|
214
|
+
slots.push(2);
|
|
215
|
+
}
|
|
216
|
+
return slots;
|
|
217
|
+
}
|
|
218
|
+
/**
|
|
219
|
+
* @internal
|
|
220
|
+
* Build params for updating expiration dates
|
|
221
|
+
*/
|
|
222
|
+
function buildExpirationDateParams(requestOptions, fillDefaults) {
|
|
223
|
+
const updateparams = {};
|
|
224
|
+
if (requestOptions.apiToken1ExpirationDate) {
|
|
225
|
+
updateparams.apiToken1ExpirationDate =
|
|
226
|
+
requestOptions.apiToken1ExpirationDate;
|
|
227
|
+
}
|
|
228
|
+
if (requestOptions.apiToken2ExpirationDate) {
|
|
229
|
+
updateparams.apiToken2ExpirationDate =
|
|
230
|
+
requestOptions.apiToken2ExpirationDate;
|
|
231
|
+
}
|
|
232
|
+
if (fillDefaults && !updateparams.apiToken1ExpirationDate) {
|
|
233
|
+
updateparams.apiToken1ExpirationDate = -1;
|
|
234
|
+
}
|
|
235
|
+
if (fillDefaults && !updateparams.apiToken2ExpirationDate) {
|
|
236
|
+
updateparams.apiToken2ExpirationDate = -1;
|
|
237
|
+
}
|
|
238
|
+
return updateparams;
|
|
239
|
+
}
|
|
240
240
|
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
241
|
+
/* Copyright (c) 2023 Environmental Systems Research Institute, Inc.
|
|
242
|
+
* Apache-2.0 */
|
|
243
|
+
/**
|
|
244
|
+
* Used to register an app. See the [REST Documentation](https://developers.arcgis.com/rest/users-groups-and-items/register-app.htm) for more information.
|
|
245
|
+
*
|
|
246
|
+
* Accepted app types:
|
|
247
|
+
* - apikey
|
|
248
|
+
* - multiple
|
|
249
|
+
* - browser
|
|
250
|
+
* - server
|
|
251
|
+
* - native
|
|
252
|
+
*
|
|
253
|
+
* ```js
|
|
254
|
+
* import { registerApp, IApp } from '@esri/arcgis-rest-developer-credentials';
|
|
255
|
+
* import { ArcGISIdentityManager } from "@esri/arcgis-rest-request";
|
|
256
|
+
*
|
|
257
|
+
* const authSession: ArcGISIdentityManager = await ArcGISIdentityManager.signIn({
|
|
258
|
+
* username: "xyz_usrName",
|
|
259
|
+
* password: "xyz_pw"
|
|
260
|
+
* });
|
|
261
|
+
*
|
|
262
|
+
* registerApp({
|
|
263
|
+
* itemId: "xyz_itemId",
|
|
264
|
+
* appType: "multiple",
|
|
265
|
+
* redirect_uris: ["http://localhost:3000/"],
|
|
266
|
+
* httpReferrers: ["http://localhost:3000/"],
|
|
267
|
+
* privileges: ["premium:user:geocode:temporary", Privileges.FeatureReport],
|
|
268
|
+
* authentication: authSession
|
|
269
|
+
* }).then((registeredApp: IApp) => {
|
|
270
|
+
* // => {client_id: "xyz_id", client_secret: "xyz_secret", ...}
|
|
271
|
+
* }).catch(e => {
|
|
272
|
+
* // => an exception object
|
|
273
|
+
* });
|
|
274
|
+
* ```
|
|
275
|
+
*
|
|
276
|
+
* @param requestOptions - Options for {@linkcode registerApp | registerApp()}, including necessary params to register an app and an {@linkcode @esri/arcgis-rest-request!ArcGISIdentityManager} authentication session.
|
|
277
|
+
* @returns A Promise that will resolve to an {@linkcode IApp} object representing the newly registered app.
|
|
278
|
+
*/
|
|
279
|
+
async function registerApp(requestOptions) {
|
|
280
|
+
// build params
|
|
281
|
+
const options = arcgisRestRequest.appendCustomParams(requestOptions, [
|
|
282
|
+
"itemId",
|
|
283
|
+
"appType",
|
|
284
|
+
"redirect_uris",
|
|
285
|
+
"httpReferrers",
|
|
286
|
+
"privileges"
|
|
287
|
+
]);
|
|
288
|
+
// encode special params value (e.g. array type...) in advance in order to make encodeQueryString() works correctly
|
|
289
|
+
stringifyArrays(options);
|
|
290
|
+
const url = arcgisRestPortal.getPortalUrl(options) + "/oauth2/registerApp";
|
|
291
|
+
options.httpMethod = "POST";
|
|
292
|
+
options.params.f = "json";
|
|
293
|
+
const registeredAppResponse = await arcgisRestRequest.request(url, options);
|
|
294
|
+
return registeredAppResponseToApp(registeredAppResponse);
|
|
295
|
+
}
|
|
296
296
|
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
297
|
+
/* Copyright (c) 2023 Environmental Systems Research Institute, Inc.
|
|
298
|
+
* Apache-2.0 */
|
|
299
|
+
/**
|
|
300
|
+
* Used to register an API key. See the [security and authentication](https://developers.arcgis.com/documentation/mapping-apis-and-services/security/api-keys/) for more information about API key.
|
|
301
|
+
*
|
|
302
|
+
* ```js
|
|
303
|
+
* import { createApiKey, IApiKeyResponse } from '@esri/arcgis-rest-developer-credentials';
|
|
304
|
+
* import { ArcGISIdentityManager } from "@esri/arcgis-rest-request";
|
|
305
|
+
*
|
|
306
|
+
* const authSession: ArcGISIdentityManager = await ArcGISIdentityManager.signIn({
|
|
307
|
+
* username: "xyz_usrName",
|
|
308
|
+
* password: "xyz_pw"
|
|
309
|
+
* });
|
|
310
|
+
*
|
|
311
|
+
* const threeDaysFromToday = new Date();
|
|
312
|
+
* threeDaysFromToday.setDate(threeDaysFromToday.getDate() + 3);
|
|
313
|
+
* threeDaysFromToday.setHours(23, 59, 59, 999);
|
|
314
|
+
*
|
|
315
|
+
* createApiKey({
|
|
316
|
+
* title: "xyz_title",
|
|
317
|
+
* description: "xyz_desc",
|
|
318
|
+
* tags: ["xyz_tag1", "xyz_tag2"],
|
|
319
|
+
* privileges: ["premium:user:networkanalysis:routing"],
|
|
320
|
+
* authentication: authSession,
|
|
321
|
+
* generateToken1: true, // optional,generate a new token
|
|
322
|
+
* apiToken1ExpirationDate: threeDaysFromToday // optional, update expiration date
|
|
323
|
+
* }).then((registeredAPIKey: IApiKeyResponse) => {
|
|
324
|
+
* // => {accessToken1: "xyz_key", item: {tags: ["xyz_tag1", "xyz_tag2"], ...}, ...}
|
|
325
|
+
* }).catch(e => {
|
|
326
|
+
* // => an exception object
|
|
327
|
+
* });
|
|
328
|
+
* ```
|
|
329
|
+
*
|
|
330
|
+
* @param requestOptions - Options for {@linkcode createApiKey | createApiKey()}, including necessary params to register an API key and an {@linkcode @esri/arcgis-rest-request!ArcGISIdentityManager} authentication session.
|
|
331
|
+
* @returns A Promise that will resolve to an {@linkcode IApiKeyResponse} object representing the newly registered API key.
|
|
332
|
+
*/
|
|
333
|
+
async function createApiKey(requestOptions) {
|
|
334
|
+
requestOptions.httpMethod = "POST";
|
|
335
|
+
// filter param buckets:
|
|
336
|
+
const baseRequestOptions = extractBaseRequestOptions(requestOptions); // snapshot of basic IRequestOptions before customized params being built into it
|
|
337
|
+
const itemAddProperties = [
|
|
338
|
+
"categories",
|
|
339
|
+
"culture",
|
|
340
|
+
"description",
|
|
341
|
+
"documentation",
|
|
342
|
+
"extent",
|
|
343
|
+
"owner",
|
|
344
|
+
"properties",
|
|
345
|
+
"snippet",
|
|
346
|
+
"spatialReference",
|
|
347
|
+
"tags",
|
|
348
|
+
"title",
|
|
349
|
+
"type",
|
|
350
|
+
"typeKeywords",
|
|
351
|
+
"url"
|
|
352
|
+
];
|
|
353
|
+
/**
|
|
354
|
+
* step 1: create item
|
|
355
|
+
*/
|
|
356
|
+
const createItemOption = Object.assign(Object.assign({ item: Object.assign(Object.assign({}, filterKeys(requestOptions, itemAddProperties)), { type: "Application" }) }, baseRequestOptions), { authentication: requestOptions.authentication, params: {
|
|
357
|
+
f: "json"
|
|
358
|
+
} });
|
|
359
|
+
const createItemResponse = await arcgisRestPortal.createItem(createItemOption);
|
|
360
|
+
/**
|
|
361
|
+
* getRegisteredAppInfoRoute
|
|
362
|
+
*/
|
|
363
|
+
const registerAppOptions = Object.assign(Object.assign({ itemId: createItemResponse.id, appType: "multiple", redirect_uris: ["urn:ietf:wg:oauth:2.0:oob"], httpReferrers: requestOptions.httpReferrers || [], privileges: requestOptions.privileges }, baseRequestOptions), { authentication: requestOptions.authentication });
|
|
364
|
+
const registeredAppResponse = await registerApp(registerAppOptions);
|
|
365
|
+
/**
|
|
366
|
+
* step 3: update item with desired expiration dates
|
|
367
|
+
* you cannot set the expiration date propierties until you
|
|
368
|
+
* regiester the app so this has to be a seperate step
|
|
369
|
+
*/
|
|
370
|
+
await arcgisRestPortal.updateItem(Object.assign(Object.assign({}, baseRequestOptions), { item: Object.assign({ id: createItemResponse.id }, buildExpirationDateParams(requestOptions, true)), authentication: requestOptions.authentication }));
|
|
371
|
+
/*
|
|
372
|
+
* step 4: get item info
|
|
373
|
+
*/
|
|
374
|
+
const itemInfo = await arcgisRestPortal.getItem(registeredAppResponse.itemId, Object.assign(Object.assign({}, baseRequestOptions), { authentication: requestOptions.authentication, params: { f: "json" } }));
|
|
375
|
+
/**
|
|
376
|
+
* step 5: generate tokens if requested
|
|
377
|
+
*/
|
|
378
|
+
const generatedTokens = await generateApiKeyTokens(itemInfo.id, generateOptionsToSlots(requestOptions.generateToken1, requestOptions.generateToken2), Object.assign(Object.assign({}, baseRequestOptions), { authentication: requestOptions.authentication }));
|
|
379
|
+
/**
|
|
380
|
+
* step 6: get registered app info to get updated active key status
|
|
381
|
+
*/
|
|
382
|
+
const updatedRegisteredAppResponse = await getRegisteredAppInfo(Object.assign(Object.assign({}, baseRequestOptions), { itemId: itemInfo.id, authentication: requestOptions.authentication }));
|
|
383
|
+
return Object.assign(Object.assign(Object.assign({}, generatedTokens), appToApiKeyProperties(updatedRegisteredAppResponse)), { item: itemInfo });
|
|
384
|
+
}
|
|
385
385
|
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
386
|
+
/* Copyright (c) 2023 Environmental Systems Research Institute, Inc.
|
|
387
|
+
* Apache-2.0 */
|
|
388
|
+
/**
|
|
389
|
+
* Used to update an API key.
|
|
390
|
+
*
|
|
391
|
+
* Notes about `privileges` and `httpReferrers` options:
|
|
392
|
+
* 1. Provided option will override corresponding old option.
|
|
393
|
+
* 2. Unprovided option will not trigger corresponding option updates.
|
|
394
|
+
*
|
|
395
|
+
* ```js
|
|
396
|
+
* import { updateApiKey, IApiKeyResponse } from '@esri/arcgis-rest-developer-credentials';
|
|
397
|
+
* import { ArcGISIdentityManager } from "@esri/arcgis-rest-request";
|
|
398
|
+
*
|
|
399
|
+
* const authSession: ArcGISIdentityManager = await ArcGISIdentityManager.signIn({
|
|
400
|
+
* username: "xyz_usrName",
|
|
401
|
+
* password: "xyz_pw"
|
|
402
|
+
* });
|
|
403
|
+
*
|
|
404
|
+
* const threeDaysFromToday = new Date();
|
|
405
|
+
* threeDaysFromToday.setDate(threeDaysFromToday.getDate() + 3);
|
|
406
|
+
* threeDaysFromToday.setHours(23, 59, 59, 999);
|
|
407
|
+
*
|
|
408
|
+
* updateApiKey({
|
|
409
|
+
* itemId: "xyz_itemId",
|
|
410
|
+
* privileges: ["premium:user:geocode:temporary"],
|
|
411
|
+
* httpReferrers: [], // httpReferrers will be set to be empty
|
|
412
|
+
* authentication: authSession
|
|
413
|
+
* generateToken1: true, // optional,generate a new token
|
|
414
|
+
* apiToken1ExpirationDate: threeDaysFromToday // optional, update expiration date
|
|
415
|
+
* }).then((updatedAPIKey: IApiKeyResponse) => {
|
|
416
|
+
* // => {accessToken1: "xyz_key", item: {tags: ["xyz_tag1", "xyz_tag2"], ...}, ...}
|
|
417
|
+
* }).catch(e => {
|
|
418
|
+
* // => an exception object
|
|
419
|
+
* });
|
|
420
|
+
* ```
|
|
421
|
+
*
|
|
422
|
+
* @param requestOptions - Options for {@linkcode updateApiKey | updateApiKey()}, including `itemId` of which API key to be operated on, optional new `privileges`, optional new `httpReferrers` and an {@linkcode @esri/arcgis-rest-request!ArcGISIdentityManager} authentication session.
|
|
423
|
+
* @returns A Promise that will resolve to an {@linkcode IApiKeyResponse} object representing updated API key.
|
|
424
|
+
*/
|
|
425
|
+
async function updateApiKey(requestOptions) {
|
|
426
|
+
requestOptions.httpMethod = "POST";
|
|
427
|
+
const baseRequestOptions = extractBaseRequestOptions(requestOptions); // get base requestOptions snapshot
|
|
428
|
+
/**
|
|
429
|
+
* step 1: update expiration dates if provided. Build the object up to avoid overwriting any existing properties.
|
|
430
|
+
*/
|
|
431
|
+
if (requestOptions.apiToken1ExpirationDate ||
|
|
432
|
+
requestOptions.apiToken2ExpirationDate) {
|
|
433
|
+
const updateParams = buildExpirationDateParams(requestOptions);
|
|
434
|
+
await arcgisRestPortal.updateItem(Object.assign(Object.assign({}, baseRequestOptions), { item: Object.assign({ id: requestOptions.itemId }, updateParams), authentication: requestOptions.authentication }));
|
|
435
|
+
}
|
|
436
|
+
/**
|
|
437
|
+
* step 2: update privileges and httpReferrers if provided. Build the object up to avoid overwriting any existing properties.
|
|
438
|
+
*/
|
|
439
|
+
if (requestOptions.privileges || requestOptions.httpReferrers) {
|
|
440
|
+
const getAppOption = Object.assign(Object.assign({}, baseRequestOptions), { authentication: requestOptions.authentication, itemId: requestOptions.itemId });
|
|
441
|
+
const appResponse = await getRegisteredAppInfo(getAppOption);
|
|
442
|
+
const clientId = appResponse.client_id;
|
|
443
|
+
const options = arcgisRestRequest.appendCustomParams(Object.assign(Object.assign({}, appResponse), requestOptions), // object with the custom params to look in
|
|
444
|
+
["privileges", "httpReferrers"] // keys you want copied to the params object
|
|
445
|
+
);
|
|
446
|
+
options.params.f = "json";
|
|
447
|
+
// encode special params value (e.g. array type...) in advance in order to make encodeQueryString() works correctly
|
|
448
|
+
stringifyArrays(options);
|
|
449
|
+
const url = arcgisRestPortal.getPortalUrl(options) + `/oauth2/apps/${clientId}/update`;
|
|
450
|
+
// Raw response from `/oauth2/apps/${clientId}/update`, apiKey not included because key is same.
|
|
451
|
+
await arcgisRestRequest.request(url, Object.assign(Object.assign({}, options), { authentication: requestOptions.authentication }));
|
|
452
|
+
}
|
|
453
|
+
/**
|
|
454
|
+
* step 3: get the updated item info to return to the user.
|
|
455
|
+
*/
|
|
456
|
+
const updatedItemInfo = await arcgisRestPortal.getItem(requestOptions.itemId, Object.assign(Object.assign({}, baseRequestOptions), { authentication: requestOptions.authentication, params: { f: "json" } }));
|
|
457
|
+
/**
|
|
458
|
+
* step 4: generate tokens if requested
|
|
459
|
+
*/
|
|
460
|
+
const generatedTokens = await generateApiKeyTokens(requestOptions.itemId, generateOptionsToSlots(requestOptions.generateToken1, requestOptions.generateToken2), Object.assign(Object.assign({}, baseRequestOptions), { authentication: requestOptions.authentication }));
|
|
461
|
+
/**
|
|
462
|
+
* step 5: get updated registered app info
|
|
463
|
+
*/
|
|
464
|
+
const updatedRegisteredAppResponse = await getRegisteredAppInfo(Object.assign(Object.assign({}, baseRequestOptions), { itemId: requestOptions.itemId, authentication: requestOptions.authentication }));
|
|
465
|
+
return Object.assign(Object.assign(Object.assign({}, generatedTokens), appToApiKeyProperties(updatedRegisteredAppResponse)), { item: updatedItemInfo });
|
|
466
|
+
}
|
|
467
467
|
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
468
|
+
/* Copyright (c) 2023 Environmental Systems Research Institute, Inc.
|
|
469
|
+
* Apache-2.0 */
|
|
470
|
+
/**
|
|
471
|
+
* Used to retrieve the API key with given `itemId`. See the [security and authentication](https://developers.arcgis.com/documentation/mapping-apis-and-services/security/api-keys/) for more information about API key.
|
|
472
|
+
*
|
|
473
|
+
* ```js
|
|
474
|
+
* import { getApiKey, IApiKeyResponse } from '@esri/arcgis-rest-developer-credentials';
|
|
475
|
+
* import { ArcGISIdentityManager } from "@esri/arcgis-rest-request";
|
|
476
|
+
*
|
|
477
|
+
* const authSession: ArcGISIdentityManager = await ArcGISIdentityManager.signIn({
|
|
478
|
+
* username: "xyz_usrName",
|
|
479
|
+
* password: "xyz_pw"
|
|
480
|
+
* });
|
|
481
|
+
*
|
|
482
|
+
* getApiKey({
|
|
483
|
+
* itemId: "xyz_itemId",
|
|
484
|
+
* authentication: authSession
|
|
485
|
+
* }).then((retrievedAPIKey: IApiKeyResponse) => {
|
|
486
|
+
* // => {apiKey: "xyz_key", item: {tags: ["xyz_tag1", "xyz_tag2"], ...}, ...}
|
|
487
|
+
* }).catch(e => {
|
|
488
|
+
* // => an exception object
|
|
489
|
+
* });
|
|
490
|
+
* ```
|
|
491
|
+
*
|
|
492
|
+
* @param requestOptions - Options for {@linkcode getApiKey | getApiKey()}, including `itemId` of which API key to retrieve and an {@linkcode @esri/arcgis-rest-request!ArcGISIdentityManager} authentication session.
|
|
493
|
+
* @returns A Promise that will resolve to an {@linkcode IApiKeyResponse} object representing successfully retrieved API key.
|
|
494
|
+
*/
|
|
495
|
+
async function getApiKey(requestOptions) {
|
|
496
|
+
const appResponse = await getRegisteredAppInfo(requestOptions);
|
|
497
|
+
const itemInfo = await arcgisRestPortal.getItem(requestOptions.itemId, Object.assign(Object.assign({}, extractBaseRequestOptions(requestOptions)), { authentication: requestOptions.authentication }));
|
|
498
|
+
return Object.assign(Object.assign({}, appToApiKeyProperties(appResponse)), { item: itemInfo });
|
|
499
|
+
}
|
|
500
500
|
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
501
|
+
/* Copyright (c) 2023 Environmental Systems Research Institute, Inc.
|
|
502
|
+
* Apache-2.0 */
|
|
503
|
+
/**
|
|
504
|
+
* Used to invalidate an API key.
|
|
505
|
+
*
|
|
506
|
+
* ```js
|
|
507
|
+
* import { invalidateApiKey } from "@esri/arcgis-rest-developer-credentials";
|
|
508
|
+
*
|
|
509
|
+
* invalidateApiKey({
|
|
510
|
+
* itemId: ITEM_ID,
|
|
511
|
+
* authentication,
|
|
512
|
+
* apiKey: 1, // invalidate the key in slot 1
|
|
513
|
+
* }).then((response) => {
|
|
514
|
+
* // => {success: true}
|
|
515
|
+
* }).catch(e => {
|
|
516
|
+
* // => an exception object
|
|
517
|
+
* });
|
|
518
|
+
*/
|
|
519
|
+
async function invalidateApiKey(requestOptions) {
|
|
520
|
+
const portal = arcgisRestPortal.getPortalUrl(requestOptions);
|
|
521
|
+
const url = `${portal}/oauth2/revokeToken`;
|
|
522
|
+
const appInfo = await getRegisteredAppInfo({
|
|
523
|
+
itemId: requestOptions.itemId,
|
|
524
|
+
authentication: requestOptions.authentication
|
|
525
|
+
});
|
|
526
|
+
const params = {
|
|
527
|
+
client_id: appInfo.client_id,
|
|
528
|
+
client_secret: appInfo.client_secret,
|
|
529
|
+
apiToken: slotForInvalidationKey(requestOptions.apiKey),
|
|
530
|
+
regenerateApiToken: true,
|
|
531
|
+
grant_type: "client_credentials"
|
|
532
|
+
};
|
|
533
|
+
// authentication is not being passed to the request because client_secret acts as the auth
|
|
534
|
+
return arcgisRestRequest.request(url, {
|
|
535
|
+
params
|
|
536
|
+
});
|
|
537
|
+
}
|
|
538
538
|
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
539
|
+
/* Copyright (c) 2023 Environmental Systems Research Institute, Inc.
|
|
540
|
+
* Apache-2.0 */
|
|
541
|
+
/**
|
|
542
|
+
* Used to retrieve the OAuth2.0 app with given `itemId`. See the [OAuth2.0](https://developers.arcgis.com/documentation/mapping-apis-and-services/security/oauth-2.0/) for more information.
|
|
543
|
+
*
|
|
544
|
+
* ```js
|
|
545
|
+
* import { getOAuthApp, IOAuthApp } from '@esri/arcgis-rest-developer-credentials';
|
|
546
|
+
* import { ArcGISIdentityManager } from "@esri/arcgis-rest-request";
|
|
547
|
+
*
|
|
548
|
+
* const authSession: ArcGISIdentityManager = await ArcGISIdentityManager.signIn({
|
|
549
|
+
* username: "xyz_usrName",
|
|
550
|
+
* password: "xyz_pw"
|
|
551
|
+
* });
|
|
552
|
+
*
|
|
553
|
+
* getOAuthApp({
|
|
554
|
+
* itemId: "xyz_itemId",
|
|
555
|
+
* authentication: authSession
|
|
556
|
+
* }).then((retrievedOAuthApp: IOAuthApp) => {
|
|
557
|
+
* // => {redirect_uris: ["http://localhost:3000/"], item: {tags: ["xyz_tag1", "xyz_tag2"], ...}, ...}
|
|
558
|
+
* }).catch(e => {
|
|
559
|
+
* // => an exception object
|
|
560
|
+
* });
|
|
561
|
+
* ```
|
|
562
|
+
*
|
|
563
|
+
* @param requestOptions - Options for {@linkcode getOAuthApp | getOAuthApp()}, including `itemId` of which OAuth app to retrieve and an {@linkcode @esri/arcgis-rest-request!ArcGISIdentityManager} authentication session.
|
|
564
|
+
* @returns A Promise that will resolve to an {@linkcode IOAuthApp} object representing successfully retrieved OAuth app.
|
|
565
|
+
*/
|
|
566
|
+
async function getOAuthApp(requestOptions) {
|
|
567
|
+
const appResponse = await getRegisteredAppInfo(requestOptions);
|
|
568
|
+
const itemInfo = await arcgisRestPortal.getItem(requestOptions.itemId, Object.assign(Object.assign({}, extractBaseRequestOptions(requestOptions)), { authentication: requestOptions.authentication }));
|
|
569
|
+
return Object.assign(Object.assign({}, appToOAuthAppProperties(appResponse)), { item: itemInfo });
|
|
570
|
+
}
|
|
571
571
|
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
572
|
+
/* Copyright (c) 2023 Environmental Systems Research Institute, Inc.
|
|
573
|
+
* Apache-2.0 */
|
|
574
|
+
/**
|
|
575
|
+
* Used to update an OAuth2.0 app.
|
|
576
|
+
*
|
|
577
|
+
* Notes about `redirect_uris` options:
|
|
578
|
+
* 1. Provided option will override corresponding old option.
|
|
579
|
+
* 2. Unprovided option will not trigger corresponding option updates.
|
|
580
|
+
*
|
|
581
|
+
* ```js
|
|
582
|
+
* import { updateOAuthApp, IOAuthApp } from '@esri/arcgis-rest-developer-credentials';
|
|
583
|
+
* import { ArcGISIdentityManager } from "@esri/arcgis-rest-request";
|
|
584
|
+
*
|
|
585
|
+
* const authSession: ArcGISIdentityManager = await ArcGISIdentityManager.signIn({
|
|
586
|
+
* username: "xyz_usrName",
|
|
587
|
+
* password: "xyz_pw"
|
|
588
|
+
* });
|
|
589
|
+
*
|
|
590
|
+
* updateOAuthApp({
|
|
591
|
+
* itemId: "xyz_itemId",
|
|
592
|
+
* authentication: authSession
|
|
593
|
+
* }).then((updatedOAuthApp: IOAuthApp) => {
|
|
594
|
+
* // => This OAuth app will be not be updated because its redirect_uris is not provided.
|
|
595
|
+
* // => {redirect_uris: ["http://localhost:3000/"], item: {tags: ["xyz_tag1", "xyz_tag2"], ...}, ...}
|
|
596
|
+
* }).catch(e => {
|
|
597
|
+
* // => an exception object
|
|
598
|
+
* });
|
|
599
|
+
* ```
|
|
600
|
+
*
|
|
601
|
+
* @param requestOptions - Options for {@linkcode updateOAuthApp | updateOAuthApp()}, including `itemId` of which OAuth app to be operated on, optional new `redirect_uris` and an {@linkcode @esri/arcgis-rest-request!ArcGISIdentityManager} authentication session.
|
|
602
|
+
* @returns A Promise that will resolve to an {@linkcode IOAuthApp} object representing updated OAuth app.
|
|
603
|
+
*/
|
|
604
|
+
async function updateOAuthApp(requestOptions) {
|
|
605
|
+
requestOptions.httpMethod = "POST";
|
|
606
|
+
// get app
|
|
607
|
+
const baseRequestOptions = extractBaseRequestOptions(requestOptions); // get base requestOptions snapshot
|
|
608
|
+
const getAppOption = Object.assign(Object.assign({}, baseRequestOptions), { authentication: requestOptions.authentication, itemId: requestOptions.itemId });
|
|
609
|
+
const appResponse = await getRegisteredAppInfo(getAppOption);
|
|
610
|
+
if (appResponse.appType === "apikey") {
|
|
611
|
+
throw new Error("Item is not an OAuth 2.0 app.");
|
|
612
|
+
}
|
|
613
|
+
const clientId = appResponse.client_id;
|
|
614
|
+
const options = arcgisRestRequest.appendCustomParams(Object.assign(Object.assign({}, appResponse), requestOptions), [
|
|
615
|
+
"redirect_uris"
|
|
616
|
+
]);
|
|
617
|
+
options.params.f = "json";
|
|
618
|
+
options.params.appType = "multiple";
|
|
619
|
+
// encode special params value (e.g. array type...) in advance in order to make encodeQueryString() works correctly
|
|
620
|
+
stringifyArrays(options);
|
|
621
|
+
const url = arcgisRestPortal.getPortalUrl(options) + `/oauth2/apps/${clientId}/update`;
|
|
622
|
+
// Raw response from `/oauth2/apps/${clientId}/update`.
|
|
623
|
+
const updateResponse = await arcgisRestRequest.request(url, Object.assign(Object.assign({}, options), { authentication: requestOptions.authentication }));
|
|
624
|
+
const app = registeredAppResponseToApp(updateResponse);
|
|
625
|
+
const itemInfo = await arcgisRestPortal.getItem(requestOptions.itemId, Object.assign(Object.assign({}, baseRequestOptions), { authentication: requestOptions.authentication, params: { f: "json" } }));
|
|
626
|
+
return Object.assign(Object.assign({}, appToOAuthAppProperties(app)), { item: itemInfo });
|
|
627
|
+
}
|
|
628
628
|
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
629
|
+
/* Copyright (c) 2023 Environmental Systems Research Institute, Inc.
|
|
630
|
+
* Apache-2.0 */
|
|
631
|
+
/**
|
|
632
|
+
* Used to register an OAuth2.0 app. See the [OAuth2.0](https://developers.arcgis.com/documentation/mapping-apis-and-services/security/oauth-2.0/) for more information.
|
|
633
|
+
*
|
|
634
|
+
* ```js
|
|
635
|
+
* import { createOAuthApp, IOAuthApp } from '@esri/arcgis-rest-developer-credentials';
|
|
636
|
+
* import { ArcGISIdentityManager } from "@esri/arcgis-rest-request";
|
|
637
|
+
*
|
|
638
|
+
* const authSession: ArcGISIdentityManager = await ArcGISIdentityManager.signIn({
|
|
639
|
+
* username: "xyz_usrName",
|
|
640
|
+
* password: "xyz_pw"
|
|
641
|
+
* });
|
|
642
|
+
*
|
|
643
|
+
* createOAuthApp({
|
|
644
|
+
* title: "xyz_title",
|
|
645
|
+
* description: "xyz_desc",
|
|
646
|
+
* tags: ["xyz_tag1", "xyz_tag2"],
|
|
647
|
+
* redirect_uris: ["http://localhost:3000/"],
|
|
648
|
+
* authentication: authSession
|
|
649
|
+
* }).then((registeredOAuthApp: IOAuthApp) => {
|
|
650
|
+
* // => {redirect_uris: ["http://localhost:3000/"], item: {tags: ["xyz_tag1", "xyz_tag2"], ...}, ...}
|
|
651
|
+
* }).catch(e => {
|
|
652
|
+
* // => an exception object
|
|
653
|
+
* });
|
|
654
|
+
* ```
|
|
655
|
+
*
|
|
656
|
+
* @param requestOptions - Options for {@linkcode createOAuthApp | createOAuthApp()}, including necessary params to register an OAuth app and an {@linkcode @esri/arcgis-rest-request!ArcGISIdentityManager} authentication session.
|
|
657
|
+
* @returns A Promise that will resolve to an {@linkcode IOAuthApp} object representing the newly registered OAuth app.
|
|
658
|
+
*/
|
|
659
|
+
async function createOAuthApp(requestOptions) {
|
|
660
|
+
requestOptions.httpMethod = "POST";
|
|
661
|
+
// filter param buckets:
|
|
662
|
+
const baseRequestOptions = extractBaseRequestOptions(requestOptions);
|
|
663
|
+
const itemAddProperties = [
|
|
664
|
+
"categories",
|
|
665
|
+
"culture",
|
|
666
|
+
"description",
|
|
667
|
+
"documentation",
|
|
668
|
+
"extent",
|
|
669
|
+
"owner",
|
|
670
|
+
"properties",
|
|
671
|
+
"snippet",
|
|
672
|
+
"spatialReference",
|
|
673
|
+
"tags",
|
|
674
|
+
"title",
|
|
675
|
+
"type",
|
|
676
|
+
"typeKeywords",
|
|
677
|
+
"url"
|
|
678
|
+
];
|
|
679
|
+
// step 1: add item
|
|
680
|
+
const createItemOption = Object.assign(Object.assign({ item: Object.assign(Object.assign({}, filterKeys(requestOptions, itemAddProperties)), { type: "Application" }) }, baseRequestOptions), { authentication: requestOptions.authentication, params: {
|
|
681
|
+
f: "json"
|
|
682
|
+
} });
|
|
683
|
+
const createItemResponse = await arcgisRestPortal.createItem(createItemOption);
|
|
684
|
+
// step 2: register app
|
|
685
|
+
const registerAppOption = Object.assign(Object.assign({ itemId: createItemResponse.id, appType: "multiple", redirect_uris: requestOptions.redirect_uris || [], httpReferrers: [], privileges: [] }, baseRequestOptions), { authentication: requestOptions.authentication });
|
|
686
|
+
const registeredAppResponse = await registerApp(registerAppOption);
|
|
687
|
+
const itemInfo = await arcgisRestPortal.getItem(registeredAppResponse.itemId, Object.assign(Object.assign({}, baseRequestOptions), { authentication: requestOptions.authentication, params: { f: "json" } }));
|
|
688
|
+
return Object.assign(Object.assign({}, appToOAuthAppProperties(registeredAppResponse)), { item: itemInfo });
|
|
689
|
+
}
|
|
690
690
|
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
691
|
+
/**
|
|
692
|
+
* Used to unregister the app with given `itemId`. See the [REST Documentation](https://developers.arcgis.com/rest/users-groups-and-items/unregister-app.htm) for more information.
|
|
693
|
+
*
|
|
694
|
+
* ```js
|
|
695
|
+
* import { unregisterApp, IUnregisterAppResponse } from '@esri/arcgis-rest-developer-credentials';
|
|
696
|
+
* import { ArcGISIdentityManager } from "@esri/arcgis-rest-request";
|
|
697
|
+
*
|
|
698
|
+
* const authSession: ArcGISIdentityManager = await ArcGISIdentityManager.signIn({
|
|
699
|
+
* username: "xyz_usrName",
|
|
700
|
+
* password: "xyz_pw"
|
|
701
|
+
* });
|
|
702
|
+
*
|
|
703
|
+
* unregisterApp({
|
|
704
|
+
* itemId: "xyz_itemId",
|
|
705
|
+
* authentication: authSession
|
|
706
|
+
* }).then((unregisteredApp: IUnregisterAppResponse) => {
|
|
707
|
+
* // => {itemId: "xyz_itemId", success: true}
|
|
708
|
+
* }).catch(e => {
|
|
709
|
+
* // => an exception object
|
|
710
|
+
* });
|
|
711
|
+
* ```
|
|
712
|
+
*
|
|
713
|
+
* @param requestOptions - Options for {@linkcode unregisterApp | unregisterApp()}, including `itemId` of which app to be un-registered and an {@linkcode @esri/arcgis-rest-request!ArcGISIdentityManager} authentication session.
|
|
714
|
+
* @returns A Promise that will resolve to an {@linkcode IUnregisterAppResponse} object representing un-registration status.
|
|
715
|
+
*/
|
|
716
|
+
async function unregisterApp(requestOptions) {
|
|
717
|
+
requestOptions.httpMethod = "POST";
|
|
718
|
+
// get app
|
|
719
|
+
const baseRequestOptions = extractBaseRequestOptions(requestOptions);
|
|
720
|
+
const getAppOption = Object.assign(Object.assign({}, baseRequestOptions), { authentication: requestOptions.authentication, itemId: requestOptions.itemId });
|
|
721
|
+
const appResponse = await getRegisteredAppInfo(getAppOption);
|
|
722
|
+
const clientId = appResponse.client_id;
|
|
723
|
+
const url = arcgisRestPortal.getPortalUrl(requestOptions) + `/oauth2/apps/${clientId}/unregister`;
|
|
724
|
+
const unregisterAppResponse = await arcgisRestRequest.request(url, Object.assign(Object.assign({}, baseRequestOptions), { authentication: requestOptions.authentication, params: { f: "json" } }));
|
|
725
|
+
return unregisterAppResponse;
|
|
726
|
+
}
|
|
727
727
|
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
Object.defineProperty(exports, '__esModule', { value: true });
|
|
728
|
+
exports.appToApiKeyProperties = appToApiKeyProperties;
|
|
729
|
+
exports.appToOAuthAppProperties = appToOAuthAppProperties;
|
|
730
|
+
exports.buildExpirationDateParams = buildExpirationDateParams;
|
|
731
|
+
exports.createApiKey = createApiKey;
|
|
732
|
+
exports.createOAuthApp = createOAuthApp;
|
|
733
|
+
exports.extractBaseRequestOptions = extractBaseRequestOptions;
|
|
734
|
+
exports.filterKeys = filterKeys;
|
|
735
|
+
exports.generateApiKeyTokens = generateApiKeyTokens;
|
|
736
|
+
exports.generateOptionsToSlots = generateOptionsToSlots;
|
|
737
|
+
exports.getApiKey = getApiKey;
|
|
738
|
+
exports.getOAuthApp = getOAuthApp;
|
|
739
|
+
exports.getRegisteredAppInfo = getRegisteredAppInfo;
|
|
740
|
+
exports.invalidateApiKey = invalidateApiKey;
|
|
741
|
+
exports.registerApp = registerApp;
|
|
742
|
+
exports.registeredAppResponseToApp = registeredAppResponseToApp;
|
|
743
|
+
exports.slotForInvalidationKey = slotForInvalidationKey;
|
|
744
|
+
exports.slotForKey = slotForKey;
|
|
745
|
+
exports.stringifyArrays = stringifyArrays;
|
|
746
|
+
exports.unregisterApp = unregisterApp;
|
|
747
|
+
exports.updateApiKey = updateApiKey;
|
|
748
|
+
exports.updateOAuthApp = updateOAuthApp;
|
|
751
749
|
|
|
752
750
|
}));
|
|
753
751
|
//# sourceMappingURL=developer-credentials.umd.js.map
|