-
Notifications
You must be signed in to change notification settings - Fork 126
Expand file tree
/
Copy pathunregisterApp.ts
More file actions
65 lines (59 loc) · 2.29 KB
/
Copy pathunregisterApp.ts
File metadata and controls
65 lines (59 loc) · 2.29 KB
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
import {
IGetAppInfoOptions,
IUnregisterAppOptions,
IUnregisterAppResponse
} from "./types/appType.js";
import { extractBaseRequestOptions } from "./helpers.js";
import { getRegisteredAppInfo } from "./getRegisteredAppInfo.js";
import { getPortalUrl } from "@esri/arcgis-rest-portal";
import { request } from "@esri/arcgis-rest-request";
/**
* 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.
*
* ```js
* import { unregisterApp, IUnregisterAppResponse } from '@esri/arcgis-rest-developer-credentials';
* import { ArcGISIdentityManager } from "@esri/arcgis-rest-request";
*
* const authSession: ArcGISIdentityManager = await ArcGISIdentityManager.signIn({
* username: "xyz_usrName",
* password: "xyz_pw"
* });
*
* unregisterApp({
* itemId: "xyz_itemId",
* authentication: authSession
* }).then((unregisteredApp: IUnregisterAppResponse) => {
* // => {itemId: "xyz_itemId", success: true}
* }).catch(e => {
* // => an exception object
* });
* ```
*
* @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.
* @returns A Promise that will resolve to an {@linkcode IUnregisterAppResponse} object representing un-registration status.
*/
export async function unregisterApp(
requestOptions: IUnregisterAppOptions
): Promise<IUnregisterAppResponse> {
requestOptions.fetchOptions = {
...requestOptions.fetchOptions,
method: "POST"
};
// get app
const baseRequestOptions = extractBaseRequestOptions(requestOptions);
const getAppOption: IGetAppInfoOptions = {
...baseRequestOptions,
authentication: requestOptions.authentication,
itemId: requestOptions.itemId
};
const appResponse = await getRegisteredAppInfo(getAppOption);
const clientId = appResponse.client_id;
const url =
getPortalUrl(requestOptions) + `/oauth2/apps/${clientId}/unregister`;
const unregisterAppResponse: IUnregisterAppResponse = await request(url, {
...baseRequestOptions,
authentication: requestOptions.authentication,
params: { f: "json" }
});
return unregisterAppResponse;
}