@esri/arcgis-rest-request
Version:
Common methods and utilities for @esri/arcgis-rest-js packages.
55 lines • 1.91 kB
JavaScript
;
/* Copyright (c) 2018-2020 Environmental Systems Research Institute, Inc.
* Apache-2.0 */
Object.defineProperty(exports, "__esModule", { value: true });
exports.validateAppAccess = void 0;
const request_js_1 = require("./request.js");
/**
* Validates that the user has access to the application
* and if they user should be presented a "View Only" mode
*
* This is only needed/valid for Esri applications that are "licensed"
* and shipped in ArcGIS Online or ArcGIS Enterprise. Most custom applications
* should not need or use this.
*
* ```js
* import { validateAppAccess } from '@esri/arcgis-rest-request';
*
* return validateAppAccess('your-token', 'theClientId')
* .then((result) => {
* if (!result.value) {
* // redirect or show some other ui
* } else {
* if (result.viewOnlyUserTypeApp) {
* // use this to inform your app to show a "View Only" mode
* }
* }
* })
* .catch((err) => {
* // two possible errors
* // invalid clientId: {"error":{"code":400,"messageCode":"GWM_0007","message":"Invalid request","details":[]}}
* // invalid token: {"error":{"code":498,"message":"Invalid token.","details":[]}}
* })
* ```
*
* Note: This is only usable by Esri applications hosted on *arcgis.com, *esri.com or within
* an ArcGIS Enterprise installation. Custom applications can not use this.
*
* @param token platform token
* @param clientId application client id
* @param portal Optional
*/
function validateAppAccess(token, clientId, portal = "https://www.arcgis.com/sharing/rest") {
const url = `${portal}/oauth2/validateAppAccess`;
const ro = {
method: "POST",
params: {
f: "json",
client_id: clientId,
token
}
};
return (0, request_js_1.request)(url, ro);
}
exports.validateAppAccess = validateAppAccess;
//# sourceMappingURL=validate-app-access.js.map