Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@esri/arcgis-rest-auth

Package Overview
Dependencies
Maintainers
8
Versions
118
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@esri/arcgis-rest-auth - npm Package Compare versions

Comparing version 2.20.0 to 2.21.0

dist/esm/app-tokens.d.ts

8

dist/esm/UserSession.d.ts

@@ -15,2 +15,3 @@ /// <reference types="node" />

import { IUser } from "@esri/arcgis-rest-types";
import { IAppAccess } from "./validate-app-access";
export declare type AuthenticationProvider = "arcgis" | "facebook" | "google" | "github" | "apple";

@@ -359,2 +360,9 @@ /**

getToken(url: string, requestOptions?: ITokenRequestOptions): Promise<string>;
/**
* Get application access information for the current user
* see `validateAppAccess` function for details
*
* @param clientId application client id
*/
validateAppAccess(clientId: string): Promise<IAppAccess>;
toJSON(): IUserSessionOptions;

@@ -361,0 +369,0 @@ serialize(): string;

86

dist/esm/UserSession.js
/* Copyright (c) 2017-2019 Environmental Systems Research Institute, Inc.
* Apache-2.0 */
import { __assign } from "tslib";
import { request, ArcGISAuthError, cleanUrl, encodeQueryString, decodeQueryString } from "@esri/arcgis-rest-request";
import { request, ArcGISAuthError, cleanUrl, encodeQueryString, decodeQueryString, } from "@esri/arcgis-rest-request";
import { generateToken } from "./generate-token";
import { fetchToken } from "./fetch-token";
import { canUseOnlineToken, isFederated } from "./federation-utils";
import { validateAppAccess } from "./validate-app-access";
function defer() {

@@ -12,3 +13,3 @@ var deferred = {

resolve: null,
reject: null
reject: null,
};

@@ -76,3 +77,3 @@ deferred.promise = new Promise(function (resolve, reject) {

token: options.token,
expires: options.tokenExpires
expires: options.tokenExpires,
};

@@ -138,3 +139,3 @@ }

state: options.clientId,
locale: ""
locale: "",
}, options), portal = _a.portal, provider = _a.provider, clientId = _a.clientId, duration = _a.duration, redirectUri = _a.redirectUri, popup = _a.popup, state = _a.state, locale = _a.locale, params = _a.params;

@@ -171,3 +172,3 @@ var url;

tokenExpires: new Date(oauthInfo.expires),
username: oauthInfo.username
username: oauthInfo.username,
}));

@@ -232,3 +233,3 @@ }

tokenExpires: oauthInfo.expires,
username: oauthInfo.username
username: oauthInfo.username,
});

@@ -254,3 +255,3 @@ }

ssl: ssl,
username: username
username: username,
});

@@ -291,7 +292,6 @@ };

// add listener
win.addEventListener('message', handler, false);
win.parent.postMessage({ type: 'arcgis:auth:requestCredential' }, parentOrigin);
})
.then(function (session) {
win.removeEventListener('message', handler, false);
win.addEventListener("message", handler, false);
win.parent.postMessage({ type: "arcgis:auth:requestCredential" }, parentOrigin);
}).then(function (session) {
win.removeEventListener("message", handler, false);
return session;

@@ -309,3 +309,3 @@ });

response.writeHead(301, {
Location: portal + "/oauth2/authorize?client_id=" + clientId + "&duration=" + duration + "&response_type=code&redirect_uri=" + encodeURIComponent(redirectUri)
Location: portal + "/oauth2/authorize?client_id=" + clientId + "&duration=" + duration + "&response_type=code&redirect_uri=" + encodeURIComponent(redirectUri),
});

@@ -323,3 +323,3 @@ response.end();

portal: "https://www.arcgis.com/sharing/rest",
refreshTokenTTL: 1440
refreshTokenTTL: 1440,
}, options), portal = _a.portal, clientId = _a.clientId, redirectUri = _a.redirectUri, refreshTokenTTL = _a.refreshTokenTTL;

@@ -331,4 +331,4 @@ return fetchToken(portal + "/oauth2/token", {

redirect_uri: redirectUri,
code: authorizationCode
}
code: authorizationCode,
},
}).then(function (response) {

@@ -345,3 +345,3 @@ return new UserSession({

tokenExpires: response.expires,
username: response.username
username: response.username,
});

@@ -364,3 +364,3 @@ });

redirectUri: options.redirectUri,
refreshTokenTTL: options.refreshTokenTTL
refreshTokenTTL: options.refreshTokenTTL,
});

@@ -388,3 +388,3 @@ };

username: credential.userId,
tokenExpires: new Date(credential.expires)
tokenExpires: new Date(credential.expires),
});

@@ -397,10 +397,10 @@ };

UserSession.parentMessageHandler = function (event) {
if (event.data.type === 'arcgis:auth:credential') {
if (event.data.type === "arcgis:auth:credential") {
return UserSession.fromCredential(event.data.credential);
}
if (event.data.type === 'arcgis:auth:rejected') {
if (event.data.type === "arcgis:auth:rejected") {
throw new Error(event.data.message);
}
else {
throw new Error('Unknown message type.');
throw new Error("Unknown message type.");
}

@@ -423,3 +423,3 @@ };

token: this.token,
userId: this.username
userId: this.username,
};

@@ -500,2 +500,13 @@ };

};
/**
* Get application access information for the current user
* see `validateAppAccess` function for details
*
* @param clientId application client id
*/
UserSession.prototype.validateAppAccess = function (clientId) {
return this.getToken(this.portal).then(function (token) {
return validateAppAccess(token, clientId);
});
};
UserSession.prototype.toJSON = function () {

@@ -514,3 +525,3 @@ return {

redirectUri: this.redirectUri,
refreshTokenTTL: this.refreshTokenTTL
refreshTokenTTL: this.refreshTokenTTL,
};

@@ -536,3 +547,3 @@ };

this._hostHandler = this.createPostMessageHandler(validChildOrigins);
win.addEventListener('message', this._hostHandler, false);
win.addEventListener("message", this._hostHandler, false);
};

@@ -549,3 +560,3 @@ /**

}
win.removeEventListener('message', this._hostHandler, false);
win.removeEventListener("message", this._hostHandler, false);
};

@@ -595,6 +606,9 @@ /**

var credential = _this.toCredential();
event.source.postMessage({ type: 'arcgis:auth:credential', credential: credential }, event.origin);
event.source.postMessage({ type: "arcgis:auth:credential", credential: credential }, event.origin);
}
else {
event.source.postMessage({ type: 'arcgis:auth:rejected', message: "Rejected authentication request." }, event.origin);
event.source.postMessage({
type: "arcgis:auth:rejected",
message: "Rejected authentication request.",
}, event.origin);
}

@@ -662,4 +676,4 @@ };

expiration: _this.tokenDuration,
client: "referer"
}
client: "referer",
},
});

@@ -674,4 +688,4 @@ // generate an entirely fresh token if necessary

expiration: _this.tokenDuration,
client: "referer"
}
client: "referer",
},
}).then(function (response) {

@@ -687,3 +701,3 @@ _this._token = response.token;

expires: new Date(response.expires),
token: response.token
token: response.token,
};

@@ -725,3 +739,3 @@ delete _this._pendingTokenRequests[root];

password: this.password,
expiration: this.tokenDuration
expiration: this.tokenDuration,
} }, requestOptions);

@@ -747,3 +761,3 @@ return generateToken(this.portal + "/generateToken", options).then(function (response) {

refresh_token: this.refreshToken,
grant_type: "refresh_token"
grant_type: "refresh_token",
} }, requestOptions);

@@ -766,3 +780,3 @@ return fetchToken(this.portal + "/oauth2/token", options).then(function (response) {

redirect_uri: this.redirectUri,
grant_type: "exchange_refresh_token"
grant_type: "exchange_refresh_token",
} }, requestOptions);

@@ -769,0 +783,0 @@ return fetchToken(this.portal + "/oauth2/token", options).then(function (response) {

@@ -11,2 +11,3 @@ "use strict";

var federation_utils_1 = require("./federation-utils");
var validate_app_access_1 = require("./validate-app-access");
function defer() {

@@ -16,3 +17,3 @@ var deferred = {

resolve: null,
reject: null
reject: null,
};

@@ -80,3 +81,3 @@ deferred.promise = new Promise(function (resolve, reject) {

token: options.token,
expires: options.tokenExpires
expires: options.tokenExpires,
};

@@ -142,3 +143,3 @@ }

state: options.clientId,
locale: ""
locale: "",
}, options), portal = _a.portal, provider = _a.provider, clientId = _a.clientId, duration = _a.duration, redirectUri = _a.redirectUri, popup = _a.popup, state = _a.state, locale = _a.locale, params = _a.params;

@@ -175,3 +176,3 @@ var url;

tokenExpires: new Date(oauthInfo.expires),
username: oauthInfo.username
username: oauthInfo.username,
}));

@@ -236,3 +237,3 @@ }

tokenExpires: oauthInfo.expires,
username: oauthInfo.username
username: oauthInfo.username,
});

@@ -258,3 +259,3 @@ }

ssl: ssl,
username: username
username: username,
});

@@ -295,7 +296,6 @@ };

// add listener
win.addEventListener('message', handler, false);
win.parent.postMessage({ type: 'arcgis:auth:requestCredential' }, parentOrigin);
})
.then(function (session) {
win.removeEventListener('message', handler, false);
win.addEventListener("message", handler, false);
win.parent.postMessage({ type: "arcgis:auth:requestCredential" }, parentOrigin);
}).then(function (session) {
win.removeEventListener("message", handler, false);
return session;

@@ -313,3 +313,3 @@ });

response.writeHead(301, {
Location: portal + "/oauth2/authorize?client_id=" + clientId + "&duration=" + duration + "&response_type=code&redirect_uri=" + encodeURIComponent(redirectUri)
Location: portal + "/oauth2/authorize?client_id=" + clientId + "&duration=" + duration + "&response_type=code&redirect_uri=" + encodeURIComponent(redirectUri),
});

@@ -327,3 +327,3 @@ response.end();

portal: "https://www.arcgis.com/sharing/rest",
refreshTokenTTL: 1440
refreshTokenTTL: 1440,
}, options), portal = _a.portal, clientId = _a.clientId, redirectUri = _a.redirectUri, refreshTokenTTL = _a.refreshTokenTTL;

@@ -335,4 +335,4 @@ return fetch_token_1.fetchToken(portal + "/oauth2/token", {

redirect_uri: redirectUri,
code: authorizationCode
}
code: authorizationCode,
},
}).then(function (response) {

@@ -349,3 +349,3 @@ return new UserSession({

tokenExpires: response.expires,
username: response.username
username: response.username,
});

@@ -368,3 +368,3 @@ });

redirectUri: options.redirectUri,
refreshTokenTTL: options.refreshTokenTTL
refreshTokenTTL: options.refreshTokenTTL,
});

@@ -392,3 +392,3 @@ };

username: credential.userId,
tokenExpires: new Date(credential.expires)
tokenExpires: new Date(credential.expires),
});

@@ -401,10 +401,10 @@ };

UserSession.parentMessageHandler = function (event) {
if (event.data.type === 'arcgis:auth:credential') {
if (event.data.type === "arcgis:auth:credential") {
return UserSession.fromCredential(event.data.credential);
}
if (event.data.type === 'arcgis:auth:rejected') {
if (event.data.type === "arcgis:auth:rejected") {
throw new Error(event.data.message);
}
else {
throw new Error('Unknown message type.');
throw new Error("Unknown message type.");
}

@@ -427,3 +427,3 @@ };

token: this.token,
userId: this.username
userId: this.username,
};

@@ -504,2 +504,13 @@ };

};
/**
* Get application access information for the current user
* see `validateAppAccess` function for details
*
* @param clientId application client id
*/
UserSession.prototype.validateAppAccess = function (clientId) {
return this.getToken(this.portal).then(function (token) {
return validate_app_access_1.validateAppAccess(token, clientId);
});
};
UserSession.prototype.toJSON = function () {

@@ -518,3 +529,3 @@ return {

redirectUri: this.redirectUri,
refreshTokenTTL: this.refreshTokenTTL
refreshTokenTTL: this.refreshTokenTTL,
};

@@ -540,3 +551,3 @@ };

this._hostHandler = this.createPostMessageHandler(validChildOrigins);
win.addEventListener('message', this._hostHandler, false);
win.addEventListener("message", this._hostHandler, false);
};

@@ -553,3 +564,3 @@ /**

}
win.removeEventListener('message', this._hostHandler, false);
win.removeEventListener("message", this._hostHandler, false);
};

@@ -599,6 +610,9 @@ /**

var credential = _this.toCredential();
event.source.postMessage({ type: 'arcgis:auth:credential', credential: credential }, event.origin);
event.source.postMessage({ type: "arcgis:auth:credential", credential: credential }, event.origin);
}
else {
event.source.postMessage({ type: 'arcgis:auth:rejected', message: "Rejected authentication request." }, event.origin);
event.source.postMessage({
type: "arcgis:auth:rejected",
message: "Rejected authentication request.",
}, event.origin);
}

@@ -666,4 +680,4 @@ };

expiration: _this.tokenDuration,
client: "referer"
}
client: "referer",
},
});

@@ -678,4 +692,4 @@ // generate an entirely fresh token if necessary

expiration: _this.tokenDuration,
client: "referer"
}
client: "referer",
},
}).then(function (response) {

@@ -691,3 +705,3 @@ _this._token = response.token;

expires: new Date(response.expires),
token: response.token
token: response.token,
};

@@ -729,3 +743,3 @@ delete _this._pendingTokenRequests[root];

password: this.password,
expiration: this.tokenDuration
expiration: this.tokenDuration,
} }, requestOptions);

@@ -751,3 +765,3 @@ return generate_token_1.generateToken(this.portal + "/generateToken", options).then(function (response) {

refresh_token: this.refreshToken,
grant_type: "refresh_token"
grant_type: "refresh_token",
} }, requestOptions);

@@ -770,3 +784,3 @@ return fetch_token_1.fetchToken(this.portal + "/oauth2/token", options).then(function (response) {

redirect_uri: this.redirectUri,
grant_type: "exchange_refresh_token"
grant_type: "exchange_refresh_token",
} }, requestOptions);

@@ -773,0 +787,0 @@ return fetch_token_1.fetchToken(this.portal + "/oauth2/token", options).then(function (response) {

/* @preserve
* @esri/arcgis-rest-auth - v2.20.0 - Apache-2.0
* @esri/arcgis-rest-auth - v2.21.0 - Apache-2.0
* Copyright (c) 2017-2020 Esri, Inc.
* Tue Oct 20 2020 10:34:01 GMT-0600 (Mountain Daylight Time)
* Wed Nov 11 2020 14:29:27 GMT-0800 (Pacific Standard Time)
*/

@@ -182,2 +182,53 @@ (function (global, factory) {

/* Copyright (c) 2018-2020 Environmental Systems Research Institute, Inc.
* Apache-2.0 */
/**
* 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-auth';
*
* return validateAppAccess('your-token', 'theClientId')
* .then((result) => {
* if (!result.valud) {
* // 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) {
if (portal === void 0) { portal = "https://www.arcgis.com/sharing/rest"; }
var url = portal + "/oauth2/validateAppAccess";
var ro = {
method: "POST",
params: {
f: "json",
client_id: clientId,
token: token,
},
};
return arcgisRestRequest.request(url, ro);
}
/* Copyright (c) 2017-2019 Environmental Systems Research Institute, Inc.

@@ -189,3 +240,3 @@ * Apache-2.0 */

resolve: null,
reject: null
reject: null,
};

@@ -241,3 +292,3 @@ deferred.promise = new Promise(function (resolve, reject) {

token: options.token,
expires: options.tokenExpires
expires: options.tokenExpires,
};

@@ -303,3 +354,3 @@ }

state: options.clientId,
locale: ""
locale: "",
}, options), portal = _a.portal, provider = _a.provider, clientId = _a.clientId, duration = _a.duration, redirectUri = _a.redirectUri, popup = _a.popup, state = _a.state, locale = _a.locale, params = _a.params;

@@ -336,3 +387,3 @@ var url;

tokenExpires: new Date(oauthInfo.expires),
username: oauthInfo.username
username: oauthInfo.username,
}));

@@ -397,3 +448,3 @@ }

tokenExpires: oauthInfo.expires,
username: oauthInfo.username
username: oauthInfo.username,
});

@@ -419,3 +470,3 @@ }

ssl: ssl,
username: username
username: username,
});

@@ -456,7 +507,6 @@ };

// add listener
win.addEventListener('message', handler, false);
win.parent.postMessage({ type: 'arcgis:auth:requestCredential' }, parentOrigin);
})
.then(function (session) {
win.removeEventListener('message', handler, false);
win.addEventListener("message", handler, false);
win.parent.postMessage({ type: "arcgis:auth:requestCredential" }, parentOrigin);
}).then(function (session) {
win.removeEventListener("message", handler, false);
return session;

@@ -474,3 +524,3 @@ });

response.writeHead(301, {
Location: portal + "/oauth2/authorize?client_id=" + clientId + "&duration=" + duration + "&response_type=code&redirect_uri=" + encodeURIComponent(redirectUri)
Location: portal + "/oauth2/authorize?client_id=" + clientId + "&duration=" + duration + "&response_type=code&redirect_uri=" + encodeURIComponent(redirectUri),
});

@@ -488,3 +538,3 @@ response.end();

portal: "https://www.arcgis.com/sharing/rest",
refreshTokenTTL: 1440
refreshTokenTTL: 1440,
}, options), portal = _a.portal, clientId = _a.clientId, redirectUri = _a.redirectUri, refreshTokenTTL = _a.refreshTokenTTL;

@@ -496,4 +546,4 @@ return fetchToken(portal + "/oauth2/token", {

redirect_uri: redirectUri,
code: authorizationCode
}
code: authorizationCode,
},
}).then(function (response) {

@@ -510,3 +560,3 @@ return new UserSession({

tokenExpires: response.expires,
username: response.username
username: response.username,
});

@@ -529,3 +579,3 @@ });

redirectUri: options.redirectUri,
refreshTokenTTL: options.refreshTokenTTL
refreshTokenTTL: options.refreshTokenTTL,
});

@@ -553,3 +603,3 @@ };

username: credential.userId,
tokenExpires: new Date(credential.expires)
tokenExpires: new Date(credential.expires),
});

@@ -562,10 +612,10 @@ };

UserSession.parentMessageHandler = function (event) {
if (event.data.type === 'arcgis:auth:credential') {
if (event.data.type === "arcgis:auth:credential") {
return UserSession.fromCredential(event.data.credential);
}
if (event.data.type === 'arcgis:auth:rejected') {
if (event.data.type === "arcgis:auth:rejected") {
throw new Error(event.data.message);
}
else {
throw new Error('Unknown message type.');
throw new Error("Unknown message type.");
}

@@ -588,3 +638,3 @@ };

token: this.token,
userId: this.username
userId: this.username,
};

@@ -665,2 +715,13 @@ };

};
/**
* Get application access information for the current user
* see `validateAppAccess` function for details
*
* @param clientId application client id
*/
UserSession.prototype.validateAppAccess = function (clientId) {
return this.getToken(this.portal).then(function (token) {
return validateAppAccess(token, clientId);
});
};
UserSession.prototype.toJSON = function () {

@@ -679,3 +740,3 @@ return {

redirectUri: this.redirectUri,
refreshTokenTTL: this.refreshTokenTTL
refreshTokenTTL: this.refreshTokenTTL,
};

@@ -701,3 +762,3 @@ };

this._hostHandler = this.createPostMessageHandler(validChildOrigins);
win.addEventListener('message', this._hostHandler, false);
win.addEventListener("message", this._hostHandler, false);
};

@@ -714,3 +775,3 @@ /**

}
win.removeEventListener('message', this._hostHandler, false);
win.removeEventListener("message", this._hostHandler, false);
};

@@ -760,6 +821,9 @@ /**

var credential = _this.toCredential();
event.source.postMessage({ type: 'arcgis:auth:credential', credential: credential }, event.origin);
event.source.postMessage({ type: "arcgis:auth:credential", credential: credential }, event.origin);
}
else {
event.source.postMessage({ type: 'arcgis:auth:rejected', message: "Rejected authentication request." }, event.origin);
event.source.postMessage({
type: "arcgis:auth:rejected",
message: "Rejected authentication request.",
}, event.origin);
}

@@ -827,4 +891,4 @@ };

expiration: _this.tokenDuration,
client: "referer"
}
client: "referer",
},
});

@@ -839,4 +903,4 @@ // generate an entirely fresh token if necessary

expiration: _this.tokenDuration,
client: "referer"
}
client: "referer",
},
}).then(function (response) {

@@ -852,3 +916,3 @@ _this._token = response.token;

expires: new Date(response.expires),
token: response.token
token: response.token,
};

@@ -890,3 +954,3 @@ delete _this._pendingTokenRequests[root];

password: this.password,
expiration: this.tokenDuration
expiration: this.tokenDuration,
} }, requestOptions);

@@ -912,3 +976,3 @@ return generateToken(this.portal + "/generateToken", options).then(function (response) {

refresh_token: this.refreshToken,
grant_type: "refresh_token"
grant_type: "refresh_token",
} }, requestOptions);

@@ -931,3 +995,3 @@ return fetchToken(this.portal + "/oauth2/token", options).then(function (response) {

redirect_uri: this.redirectUri,
grant_type: "exchange_refresh_token"
grant_type: "exchange_refresh_token",
} }, requestOptions);

@@ -934,0 +998,0 @@ return fetchToken(this.portal + "/oauth2/token", options).then(function (response) {

/* @preserve
* @esri/arcgis-rest-auth - v2.20.0 - Apache-2.0
* @esri/arcgis-rest-auth - v2.21.0 - Apache-2.0
* Copyright (c) 2017-2020 Esri, Inc.
* Tue Oct 20 2020 10:34:05 GMT-0600 (Mountain Daylight Time)
* Wed Nov 11 2020 14:29:29 GMT-0800 (Pacific Standard Time)
*/
!function(e,r){"object"==typeof exports&&"undefined"!=typeof module?r(exports,require("@esri/arcgis-rest-request")):"function"==typeof define&&define.amd?define(["exports","@esri/arcgis-rest-request"],r):r((e="undefined"!=typeof globalThis?globalThis:e||self).arcgisRest=e.arcgisRest||{},e.arcgisRest)}(this,function(e,k){"use strict";var g=function(){return(g=Object.assign||function(e){for(var r,t=1,n=arguments.length;t<n;t++)for(var s in r=arguments[t])Object.prototype.hasOwnProperty.call(r,s)&&(e[s]=r[s]);return e}).apply(this,arguments)};function a(e,r){var t=r;return t.rawResponse=!1,k.request(e,t).then(function(e){var r={token:e.access_token,username:e.username,expires:new Date(Date.now()+(1e3*e.expires_in-1e3)),ssl:!0===e.ssl};return e.refresh_token&&(r.refreshToken=e.refresh_token),r})}var r=(t.prototype.getToken=function(e,r){return this.token&&this.expires&&this.expires.getTime()>Date.now()?Promise.resolve(this.token):(this._pendingTokenRequest||(this._pendingTokenRequest=this.refreshToken(r)),this._pendingTokenRequest)},t.prototype.refreshToken=function(e){var r=this,t=g({params:{client_id:this.clientId,client_secret:this.clientSecret,grant_type:"client_credentials",expiration:this.duration}},e);return a(this.portal+"/oauth2/token/",t).then(function(e){return r._pendingTokenRequest=null,r.token=e.token,r.expires=e.expires,e.token})},t.prototype.refreshSession=function(){var e=this;return this.refreshToken().then(function(){return e})},t);function t(e){this.clientId=e.clientId,this.clientSecret=e.clientSecret,this.token=e.token,this.expires=e.expires,this.portal=e.portal||"https://www.arcgis.com/sharing/rest",this.duration=e.duration||7200}function o(e,r){var t=r;return"undefined"!=typeof window&&window.location&&window.location.host?t.params.referer=window.location.host:t.params.referer=k.NODEJS_DEFAULT_REFERER_HEADER,k.request(e,t)}var s=/^https?:\/\/(\S+)\.arcgis\.com.+/;function h(e){return s.test(e)}function p(e){if(!s.test(e))return null;var r=e.match(s)[1].split(".").pop();return r.includes("dev")?"dev":r.includes("qa")?"qa":"production"}function i(e,r){var t=k.cleanUrl(function(e){if(!s.test(e))return e;switch(p(e)){case"dev":return"https://devext.arcgis.com/sharing/rest";case"qa":return"https://qaext.arcgis.com/sharing/rest";default:return"https://www.arcgis.com/sharing/rest"}}(r)).replace(/https?:\/\//,""),n=k.cleanUrl(e).replace(/https?:\/\//,"");return new RegExp(n,"i").test(t)}var n=(Object.defineProperty(w.prototype,"token",{get:function(){return this._token},enumerable:!1,configurable:!0}),Object.defineProperty(w.prototype,"tokenExpires",{get:function(){return this._tokenExpires},enumerable:!1,configurable:!0}),Object.defineProperty(w.prototype,"refreshToken",{get:function(){return this._refreshToken},enumerable:!1,configurable:!0}),Object.defineProperty(w.prototype,"refreshTokenExpires",{get:function(){return this._refreshTokenExpires},enumerable:!1,configurable:!0}),w.beginOAuth2=function(e,r){void 0===r&&(r=window);var t=g({portal:"https://www.arcgis.com/sharing/rest",provider:"arcgis",duration:20160,popup:!0,state:e.clientId,locale:""},e),s=t.portal,n=t.provider,o=t.clientId,i=t.duration,a=t.redirectUri,h=t.popup,p=t.state,u=t.locale,c=t.params,l="arcgis"===n?s+"/oauth2/authorize?client_id="+o+"&response_type=token&expiration="+i+"&redirect_uri="+encodeURIComponent(a)+"&state="+p+"&locale="+u:s+"/oauth2/social/authorize?client_id="+o+"&socialLoginProviderName="+n+"&autoAccountCreateForSocial=true&response_type=token&expiration="+i+"&redirect_uri="+encodeURIComponent(a)+"&state="+p+"&locale="+u;if(c&&(l=l+"&"+k.encodeQueryString(c)),h){var d,f=((d={promise:null,resolve:null,reject:null}).promise=new Promise(function(e,r){d.resolve=e,d.reject=r}),d);return r["__ESRI_REST_AUTH_HANDLER_"+o]=function(e,r){var t,n;e?(t=JSON.parse(e),f.reject(new k.ArcGISAuthError(t.errorMessage,t.error))):r&&(n=JSON.parse(r),f.resolve(new w({clientId:o,portal:s,ssl:n.ssl,token:n.token,tokenExpires:new Date(n.expires),username:n.username})))},r.open(l,"oauth-window","height=400,width=600,menubar=no,location=yes,resizable=yes,scrollbars=yes,status=yes"),f.promise}r.location.href=l},w.completeOAuth2=function(e,s){void 0===s&&(s=window);var r=g({portal:"https://www.arcgis.com/sharing/rest",popup:!0},e),o=r.portal,i=r.clientId,a=r.popup;function t(e,r){try{var t=void 0,n="__ESRI_REST_AUTH_HANDLER_"+i;if(a&&(s.opener?s.opener.parent&&s.opener.parent[n]?t=s.opener.parent[n]:s.opener&&s.opener[n]&&(t=s.opener[n]):s!==s.parent&&s.parent&&s.parent[n]&&(t=s.parent[n]),t))return t(e?JSON.stringify(e):void 0,JSON.stringify(r)),void s.close()}catch(e){throw new k.ArcGISAuthError('Unable to complete authentication. It\'s possible you specified popup based oAuth2 but no handler from "beginOAuth2()" present. This generally happens because the "popup" option differs between "beginOAuth2()" and "completeOAuth2()".')}if(e)throw new k.ArcGISAuthError(e.errorMessage,e.error);return new w({clientId:i,portal:o,ssl:r.ssl,token:r.token,tokenExpires:r.expires,username:r.username})}var n=k.decodeQueryString(s.location.hash);if(!n.access_token){var h=void 0,p="Unknown error";return n.error&&(h=n.error,p=n.error_description),t({error:h,errorMessage:p})}var u=n.access_token,c=new Date(Date.now()+1e3*parseInt(n.expires_in,10)-6e4),l=n.username;return t(void 0,{token:u,expires:c,ssl:"true"===n.ssl,username:l})},w.fromParent=function(n,s){var o;return!s&&window&&(s=window),new Promise(function(r,t){o=function(e){if(e.origin===n)try{return r(w.parentMessageHandler(e))}catch(e){return t(e)}},s.addEventListener("message",o,!1),s.parent.postMessage({type:"arcgis:auth:requestCredential"},n)}).then(function(e){return s.removeEventListener("message",o,!1),e})},w.authorize=function(e,r){var t=g({portal:"https://arcgis.com/sharing/rest",duration:20160},e),n=t.portal,s=t.clientId,o=t.duration,i=t.redirectUri;r.writeHead(301,{Location:n+"/oauth2/authorize?client_id="+s+"&duration="+o+"&response_type=code&redirect_uri="+encodeURIComponent(i)}),r.end()},w.exchangeAuthorizationCode=function(e,r){var t=g({portal:"https://www.arcgis.com/sharing/rest",refreshTokenTTL:1440},e),n=t.portal,s=t.clientId,o=t.redirectUri,i=t.refreshTokenTTL;return a(n+"/oauth2/token",{params:{grant_type:"authorization_code",client_id:s,redirect_uri:o,code:r}}).then(function(e){return new w({clientId:s,portal:n,ssl:e.ssl,redirectUri:o,refreshToken:e.refreshToken,refreshTokenTTL:i,refreshTokenExpires:new Date(Date.now()+1e3*(i-1)),token:e.token,tokenExpires:e.expires,username:e.username})})},w.deserialize=function(e){var r=JSON.parse(e);return new w({clientId:r.clientId,refreshToken:r.refreshToken,refreshTokenExpires:new Date(r.refreshTokenExpires),username:r.username,password:r.password,token:r.token,tokenExpires:new Date(r.tokenExpires),portal:r.portal,ssl:r.ssl,tokenDuration:r.tokenDuration,redirectUri:r.redirectUri,refreshTokenTTL:r.refreshTokenTTL})},w.fromCredential=function(e){return new w({portal:e.server.includes("sharing/rest")?e.server:e.server+"/sharing/rest",ssl:e.ssl,token:e.token,username:e.userId,tokenExpires:new Date(e.expires)})},w.parentMessageHandler=function(e){if("arcgis:auth:credential"===e.data.type)return w.fromCredential(e.data.credential);throw"arcgis:auth:rejected"===e.data.type?new Error(e.data.message):new Error("Unknown message type.")},w.prototype.toCredential=function(){return{expires:this.tokenExpires.getTime(),server:this.portal,ssl:this.ssl,token:this.token,userId:this.username}},w.prototype.getUser=function(e){var r=this;if(this._pendingUserRequest)return this._pendingUserRequest;if(this._user)return Promise.resolve(this._user);var t=this.portal+"/community/self",n=g(g({httpMethod:"GET",authentication:this},e),{rawResponse:!1});return this._pendingUserRequest=k.request(t,n).then(function(e){return r._user=e,r._pendingUserRequest=null,e}),this._pendingUserRequest},w.prototype.getUsername=function(){return this.username?Promise.resolve(this.username):this._user?Promise.resolve(this._user.username):this.getUser().then(function(e){return e.username})},w.prototype.getToken=function(e,r){return t=this.portal,n=e,s=h(t),o=h(n),i=p(t),a=p(n),s&&o&&i===a||new RegExp(this.portal,"i").test(e)?this.getFreshToken(r):this.getTokenForServer(e,r);var t,n,s,o,i,a},w.prototype.toJSON=function(){return{clientId:this.clientId,refreshToken:this.refreshToken,refreshTokenExpires:this.refreshTokenExpires,username:this.username,password:this.password,token:this.token,tokenExpires:this.tokenExpires,portal:this.portal,ssl:this.ssl,tokenDuration:this.tokenDuration,redirectUri:this.redirectUri,refreshTokenTTL:this.refreshTokenTTL}},w.prototype.serialize=function(){return JSON.stringify(this)},w.prototype.enablePostMessageAuth=function(e,r){!r&&window&&(r=window),this._hostHandler=this.createPostMessageHandler(e),r.addEventListener("message",this._hostHandler,!1)},w.prototype.disablePostMessageAuth=function(e){!e&&window&&(e=window),e.removeEventListener("message",this._hostHandler,!1)},w.prototype.refreshSession=function(e){return this._user=null,this.username&&this.password?this.refreshWithUsernameAndPassword(e):this.clientId&&this.refreshToken?this.refreshWithRefreshToken():Promise.reject(new k.ArcGISAuthError("Unable to refresh token."))},w.prototype.getServerRootUrl=function(e){var r=k.cleanUrl(e).split(/\/rest(\/admin)?\/services(?:\/|#|\?|$)/)[0].match(/(https?:\/\/)(.+)/),t=(r[0],r[1]),n=r[2].split("/"),s=n[0],o=n.slice(1);return""+t+s.toLowerCase()+"/"+o.join("/")},w.prototype.createPostMessageHandler=function(t){var n=this;return function(e){var r;-1<t.indexOf(e.origin)?(r=n.toCredential(),e.source.postMessage({type:"arcgis:auth:credential",credential:r},e.origin)):e.source.postMessage({type:"arcgis:auth:rejected",message:"Rejected authentication request."},e.origin)}},w.prototype.getTokenForServer=function(r,t){var n=this,s=this.getServerRootUrl(r),e=this.trustedServers[s];return e&&e.expires&&e.expires.getTime()>Date.now()?Promise.resolve(e.token):(this._pendingTokenRequests[s]||(this._pendingTokenRequests[s]=k.request(s+"/rest/info").then(function(e){if(e.owningSystemUrl){if(i(e.owningSystemUrl,n.portal))return k.request(e.owningSystemUrl+"/sharing/rest/info",t);throw new k.ArcGISAuthError(r+" is not federated with "+n.portal+".","NOT_FEDERATED")}if(e.authInfo&&void 0!==n.trustedServers[s])return Promise.resolve({authInfo:e.authInfo});throw new k.ArcGISAuthError(r+" is not federated with any portal and is not explicitly trusted.","NOT_FEDERATED")}).then(function(e){return e.authInfo.tokenServicesUrl}).then(function(e){return n.token&&n.tokenExpires.getTime()>Date.now()?o(e,{params:{token:n.token,serverUrl:r,expiration:n.tokenDuration,client:"referer"}}):o(e,{params:{username:n.username,password:n.password,expiration:n.tokenDuration,client:"referer"}}).then(function(e){return n._token=e.token,n._tokenExpires=new Date(e.expires),e})}).then(function(e){return n.trustedServers[s]={expires:new Date(e.expires),token:e.token},delete n._pendingTokenRequests[s],e.token})),this._pendingTokenRequests[s])},w.prototype.getFreshToken=function(e){var r=this;return this.token&&!this.tokenExpires||this.token&&this.tokenExpires&&this.tokenExpires.getTime()>Date.now()?Promise.resolve(this.token):(this._pendingTokenRequests[this.portal]||(this._pendingTokenRequests[this.portal]=this.refreshSession(e).then(function(e){return r._pendingTokenRequests[r.portal]=null,e.token})),this._pendingTokenRequests[this.portal])},w.prototype.refreshWithUsernameAndPassword=function(e){var r=this,t=g({params:{username:this.username,password:this.password,expiration:this.tokenDuration}},e);return o(this.portal+"/generateToken",t).then(function(e){return r._token=e.token,r._tokenExpires=new Date(e.expires),r})},w.prototype.refreshWithRefreshToken=function(e){var r=this;if(this.refreshToken&&this.refreshTokenExpires&&this.refreshTokenExpires.getTime()<Date.now())return this.refreshRefreshToken(e);var t=g({params:{client_id:this.clientId,refresh_token:this.refreshToken,grant_type:"refresh_token"}},e);return a(this.portal+"/oauth2/token",t).then(function(e){return r._token=e.token,r._tokenExpires=e.expires,r})},w.prototype.refreshRefreshToken=function(e){var r=this,t=g({params:{client_id:this.clientId,refresh_token:this.refreshToken,redirect_uri:this.redirectUri,grant_type:"exchange_refresh_token"}},e);return a(this.portal+"/oauth2/token",t).then(function(e){return r._token=e.token,r._tokenExpires=e.expires,r._refreshToken=e.refreshToken,r._refreshTokenExpires=new Date(Date.now()+60*(r.refreshTokenTTL-1)*1e3),r})},w);function w(e){var r;this.clientId=e.clientId,this._refreshToken=e.refreshToken,this._refreshTokenExpires=e.refreshTokenExpires,this.username=e.username,this.password=e.password,this._token=e.token,this._tokenExpires=e.tokenExpires,this.portal=e.portal?k.cleanUrl(e.portal):"https://www.arcgis.com/sharing/rest",this.ssl=e.ssl,this.provider=e.provider||"arcgis",this.tokenDuration=e.tokenDuration||20160,this.redirectUri=e.redirectUri,this.refreshTokenTTL=e.refreshTokenTTL||1440,this.trustedServers={},e.server&&(r=this.getServerRootUrl(e.server),this.trustedServers[r]={token:e.token,expires:e.tokenExpires}),this._pendingTokenRequests={}}e.ApplicationSession=r,e.UserSession=n,e.fetchToken=a,e.generateToken=o,Object.defineProperty(e,"__esModule",{value:!0})});
!function(e,r){"object"==typeof exports&&"undefined"!=typeof module?r(exports,require("@esri/arcgis-rest-request")):"function"==typeof define&&define.amd?define(["exports","@esri/arcgis-rest-request"],r):r((e="undefined"!=typeof globalThis?globalThis:e||self).arcgisRest=e.arcgisRest||{},e.arcgisRest)}(this,function(e,k){"use strict";var g=function(){return(g=Object.assign||function(e){for(var r,t=1,n=arguments.length;t<n;t++)for(var s in r=arguments[t])Object.prototype.hasOwnProperty.call(r,s)&&(e[s]=r[s]);return e}).apply(this,arguments)};function a(e,r){var t=r;return t.rawResponse=!1,k.request(e,t).then(function(e){var r={token:e.access_token,username:e.username,expires:new Date(Date.now()+(1e3*e.expires_in-1e3)),ssl:!0===e.ssl};return e.refresh_token&&(r.refreshToken=e.refresh_token),r})}var r=(t.prototype.getToken=function(e,r){return this.token&&this.expires&&this.expires.getTime()>Date.now()?Promise.resolve(this.token):(this._pendingTokenRequest||(this._pendingTokenRequest=this.refreshToken(r)),this._pendingTokenRequest)},t.prototype.refreshToken=function(e){var r=this,t=g({params:{client_id:this.clientId,client_secret:this.clientSecret,grant_type:"client_credentials",expiration:this.duration}},e);return a(this.portal+"/oauth2/token/",t).then(function(e){return r._pendingTokenRequest=null,r.token=e.token,r.expires=e.expires,e.token})},t.prototype.refreshSession=function(){var e=this;return this.refreshToken().then(function(){return e})},t);function t(e){this.clientId=e.clientId,this.clientSecret=e.clientSecret,this.token=e.token,this.expires=e.expires,this.portal=e.portal||"https://www.arcgis.com/sharing/rest",this.duration=e.duration||7200}function o(e,r){var t=r;return"undefined"!=typeof window&&window.location&&window.location.host?t.params.referer=window.location.host:t.params.referer=k.NODEJS_DEFAULT_REFERER_HEADER,k.request(e,t)}var s=/^https?:\/\/(\S+)\.arcgis\.com.+/;function h(e){return s.test(e)}function p(e){if(!s.test(e))return null;var r=e.match(s)[1].split(".").pop();return r.includes("dev")?"dev":r.includes("qa")?"qa":"production"}function i(e,r){var t=k.cleanUrl(function(e){if(!s.test(e))return e;switch(p(e)){case"dev":return"https://devext.arcgis.com/sharing/rest";case"qa":return"https://qaext.arcgis.com/sharing/rest";default:return"https://www.arcgis.com/sharing/rest"}}(r)).replace(/https?:\/\//,""),n=k.cleanUrl(e).replace(/https?:\/\//,"");return new RegExp(n,"i").test(t)}var n=(Object.defineProperty(w.prototype,"token",{get:function(){return this._token},enumerable:!1,configurable:!0}),Object.defineProperty(w.prototype,"tokenExpires",{get:function(){return this._tokenExpires},enumerable:!1,configurable:!0}),Object.defineProperty(w.prototype,"refreshToken",{get:function(){return this._refreshToken},enumerable:!1,configurable:!0}),Object.defineProperty(w.prototype,"refreshTokenExpires",{get:function(){return this._refreshTokenExpires},enumerable:!1,configurable:!0}),w.beginOAuth2=function(e,r){void 0===r&&(r=window);var t=g({portal:"https://www.arcgis.com/sharing/rest",provider:"arcgis",duration:20160,popup:!0,state:e.clientId,locale:""},e),s=t.portal,n=t.provider,o=t.clientId,i=t.duration,a=t.redirectUri,h=t.popup,p=t.state,u=t.locale,c=t.params,l="arcgis"===n?s+"/oauth2/authorize?client_id="+o+"&response_type=token&expiration="+i+"&redirect_uri="+encodeURIComponent(a)+"&state="+p+"&locale="+u:s+"/oauth2/social/authorize?client_id="+o+"&socialLoginProviderName="+n+"&autoAccountCreateForSocial=true&response_type=token&expiration="+i+"&redirect_uri="+encodeURIComponent(a)+"&state="+p+"&locale="+u;if(c&&(l=l+"&"+k.encodeQueryString(c)),h){var d,f=((d={promise:null,resolve:null,reject:null}).promise=new Promise(function(e,r){d.resolve=e,d.reject=r}),d);return r["__ESRI_REST_AUTH_HANDLER_"+o]=function(e,r){var t,n;e?(t=JSON.parse(e),f.reject(new k.ArcGISAuthError(t.errorMessage,t.error))):r&&(n=JSON.parse(r),f.resolve(new w({clientId:o,portal:s,ssl:n.ssl,token:n.token,tokenExpires:new Date(n.expires),username:n.username})))},r.open(l,"oauth-window","height=400,width=600,menubar=no,location=yes,resizable=yes,scrollbars=yes,status=yes"),f.promise}r.location.href=l},w.completeOAuth2=function(e,s){void 0===s&&(s=window);var r=g({portal:"https://www.arcgis.com/sharing/rest",popup:!0},e),o=r.portal,i=r.clientId,a=r.popup;function t(e,r){try{var t=void 0,n="__ESRI_REST_AUTH_HANDLER_"+i;if(a&&(s.opener?s.opener.parent&&s.opener.parent[n]?t=s.opener.parent[n]:s.opener&&s.opener[n]&&(t=s.opener[n]):s!==s.parent&&s.parent&&s.parent[n]&&(t=s.parent[n]),t))return t(e?JSON.stringify(e):void 0,JSON.stringify(r)),void s.close()}catch(e){throw new k.ArcGISAuthError('Unable to complete authentication. It\'s possible you specified popup based oAuth2 but no handler from "beginOAuth2()" present. This generally happens because the "popup" option differs between "beginOAuth2()" and "completeOAuth2()".')}if(e)throw new k.ArcGISAuthError(e.errorMessage,e.error);return new w({clientId:i,portal:o,ssl:r.ssl,token:r.token,tokenExpires:r.expires,username:r.username})}var n=k.decodeQueryString(s.location.hash);if(!n.access_token){var h=void 0,p="Unknown error";return n.error&&(h=n.error,p=n.error_description),t({error:h,errorMessage:p})}var u=n.access_token,c=new Date(Date.now()+1e3*parseInt(n.expires_in,10)-6e4),l=n.username;return t(void 0,{token:u,expires:c,ssl:"true"===n.ssl,username:l})},w.fromParent=function(n,s){var o;return!s&&window&&(s=window),new Promise(function(r,t){o=function(e){if(e.origin===n)try{return r(w.parentMessageHandler(e))}catch(e){return t(e)}},s.addEventListener("message",o,!1),s.parent.postMessage({type:"arcgis:auth:requestCredential"},n)}).then(function(e){return s.removeEventListener("message",o,!1),e})},w.authorize=function(e,r){var t=g({portal:"https://arcgis.com/sharing/rest",duration:20160},e),n=t.portal,s=t.clientId,o=t.duration,i=t.redirectUri;r.writeHead(301,{Location:n+"/oauth2/authorize?client_id="+s+"&duration="+o+"&response_type=code&redirect_uri="+encodeURIComponent(i)}),r.end()},w.exchangeAuthorizationCode=function(e,r){var t=g({portal:"https://www.arcgis.com/sharing/rest",refreshTokenTTL:1440},e),n=t.portal,s=t.clientId,o=t.redirectUri,i=t.refreshTokenTTL;return a(n+"/oauth2/token",{params:{grant_type:"authorization_code",client_id:s,redirect_uri:o,code:r}}).then(function(e){return new w({clientId:s,portal:n,ssl:e.ssl,redirectUri:o,refreshToken:e.refreshToken,refreshTokenTTL:i,refreshTokenExpires:new Date(Date.now()+1e3*(i-1)),token:e.token,tokenExpires:e.expires,username:e.username})})},w.deserialize=function(e){var r=JSON.parse(e);return new w({clientId:r.clientId,refreshToken:r.refreshToken,refreshTokenExpires:new Date(r.refreshTokenExpires),username:r.username,password:r.password,token:r.token,tokenExpires:new Date(r.tokenExpires),portal:r.portal,ssl:r.ssl,tokenDuration:r.tokenDuration,redirectUri:r.redirectUri,refreshTokenTTL:r.refreshTokenTTL})},w.fromCredential=function(e){return new w({portal:e.server.includes("sharing/rest")?e.server:e.server+"/sharing/rest",ssl:e.ssl,token:e.token,username:e.userId,tokenExpires:new Date(e.expires)})},w.parentMessageHandler=function(e){if("arcgis:auth:credential"===e.data.type)return w.fromCredential(e.data.credential);throw"arcgis:auth:rejected"===e.data.type?new Error(e.data.message):new Error("Unknown message type.")},w.prototype.toCredential=function(){return{expires:this.tokenExpires.getTime(),server:this.portal,ssl:this.ssl,token:this.token,userId:this.username}},w.prototype.getUser=function(e){var r=this;if(this._pendingUserRequest)return this._pendingUserRequest;if(this._user)return Promise.resolve(this._user);var t=this.portal+"/community/self",n=g(g({httpMethod:"GET",authentication:this},e),{rawResponse:!1});return this._pendingUserRequest=k.request(t,n).then(function(e){return r._user=e,r._pendingUserRequest=null,e}),this._pendingUserRequest},w.prototype.getUsername=function(){return this.username?Promise.resolve(this.username):this._user?Promise.resolve(this._user.username):this.getUser().then(function(e){return e.username})},w.prototype.getToken=function(e,r){return t=this.portal,n=e,s=h(t),o=h(n),i=p(t),a=p(n),s&&o&&i===a||new RegExp(this.portal,"i").test(e)?this.getFreshToken(r):this.getTokenForServer(e,r);var t,n,s,o,i,a},w.prototype.validateAppAccess=function(r){return this.getToken(this.portal).then(function(e){return function(e,r,t){void 0===t&&(t="https://www.arcgis.com/sharing/rest");var n=t+"/oauth2/validateAppAccess",s={method:"POST",params:{f:"json",client_id:r,token:e}};return k.request(n,s)}(e,r)})},w.prototype.toJSON=function(){return{clientId:this.clientId,refreshToken:this.refreshToken,refreshTokenExpires:this.refreshTokenExpires,username:this.username,password:this.password,token:this.token,tokenExpires:this.tokenExpires,portal:this.portal,ssl:this.ssl,tokenDuration:this.tokenDuration,redirectUri:this.redirectUri,refreshTokenTTL:this.refreshTokenTTL}},w.prototype.serialize=function(){return JSON.stringify(this)},w.prototype.enablePostMessageAuth=function(e,r){!r&&window&&(r=window),this._hostHandler=this.createPostMessageHandler(e),r.addEventListener("message",this._hostHandler,!1)},w.prototype.disablePostMessageAuth=function(e){!e&&window&&(e=window),e.removeEventListener("message",this._hostHandler,!1)},w.prototype.refreshSession=function(e){return this._user=null,this.username&&this.password?this.refreshWithUsernameAndPassword(e):this.clientId&&this.refreshToken?this.refreshWithRefreshToken():Promise.reject(new k.ArcGISAuthError("Unable to refresh token."))},w.prototype.getServerRootUrl=function(e){var r=k.cleanUrl(e).split(/\/rest(\/admin)?\/services(?:\/|#|\?|$)/)[0].match(/(https?:\/\/)(.+)/),t=(r[0],r[1]),n=r[2].split("/"),s=n[0],o=n.slice(1);return""+t+s.toLowerCase()+"/"+o.join("/")},w.prototype.createPostMessageHandler=function(t){var n=this;return function(e){var r;-1<t.indexOf(e.origin)?(r=n.toCredential(),e.source.postMessage({type:"arcgis:auth:credential",credential:r},e.origin)):e.source.postMessage({type:"arcgis:auth:rejected",message:"Rejected authentication request."},e.origin)}},w.prototype.getTokenForServer=function(r,t){var n=this,s=this.getServerRootUrl(r),e=this.trustedServers[s];return e&&e.expires&&e.expires.getTime()>Date.now()?Promise.resolve(e.token):(this._pendingTokenRequests[s]||(this._pendingTokenRequests[s]=k.request(s+"/rest/info").then(function(e){if(e.owningSystemUrl){if(i(e.owningSystemUrl,n.portal))return k.request(e.owningSystemUrl+"/sharing/rest/info",t);throw new k.ArcGISAuthError(r+" is not federated with "+n.portal+".","NOT_FEDERATED")}if(e.authInfo&&void 0!==n.trustedServers[s])return Promise.resolve({authInfo:e.authInfo});throw new k.ArcGISAuthError(r+" is not federated with any portal and is not explicitly trusted.","NOT_FEDERATED")}).then(function(e){return e.authInfo.tokenServicesUrl}).then(function(e){return n.token&&n.tokenExpires.getTime()>Date.now()?o(e,{params:{token:n.token,serverUrl:r,expiration:n.tokenDuration,client:"referer"}}):o(e,{params:{username:n.username,password:n.password,expiration:n.tokenDuration,client:"referer"}}).then(function(e){return n._token=e.token,n._tokenExpires=new Date(e.expires),e})}).then(function(e){return n.trustedServers[s]={expires:new Date(e.expires),token:e.token},delete n._pendingTokenRequests[s],e.token})),this._pendingTokenRequests[s])},w.prototype.getFreshToken=function(e){var r=this;return this.token&&!this.tokenExpires||this.token&&this.tokenExpires&&this.tokenExpires.getTime()>Date.now()?Promise.resolve(this.token):(this._pendingTokenRequests[this.portal]||(this._pendingTokenRequests[this.portal]=this.refreshSession(e).then(function(e){return r._pendingTokenRequests[r.portal]=null,e.token})),this._pendingTokenRequests[this.portal])},w.prototype.refreshWithUsernameAndPassword=function(e){var r=this,t=g({params:{username:this.username,password:this.password,expiration:this.tokenDuration}},e);return o(this.portal+"/generateToken",t).then(function(e){return r._token=e.token,r._tokenExpires=new Date(e.expires),r})},w.prototype.refreshWithRefreshToken=function(e){var r=this;if(this.refreshToken&&this.refreshTokenExpires&&this.refreshTokenExpires.getTime()<Date.now())return this.refreshRefreshToken(e);var t=g({params:{client_id:this.clientId,refresh_token:this.refreshToken,grant_type:"refresh_token"}},e);return a(this.portal+"/oauth2/token",t).then(function(e){return r._token=e.token,r._tokenExpires=e.expires,r})},w.prototype.refreshRefreshToken=function(e){var r=this,t=g({params:{client_id:this.clientId,refresh_token:this.refreshToken,redirect_uri:this.redirectUri,grant_type:"exchange_refresh_token"}},e);return a(this.portal+"/oauth2/token",t).then(function(e){return r._token=e.token,r._tokenExpires=e.expires,r._refreshToken=e.refreshToken,r._refreshTokenExpires=new Date(Date.now()+60*(r.refreshTokenTTL-1)*1e3),r})},w);function w(e){var r;this.clientId=e.clientId,this._refreshToken=e.refreshToken,this._refreshTokenExpires=e.refreshTokenExpires,this.username=e.username,this.password=e.password,this._token=e.token,this._tokenExpires=e.tokenExpires,this.portal=e.portal?k.cleanUrl(e.portal):"https://www.arcgis.com/sharing/rest",this.ssl=e.ssl,this.provider=e.provider||"arcgis",this.tokenDuration=e.tokenDuration||20160,this.redirectUri=e.redirectUri,this.refreshTokenTTL=e.refreshTokenTTL||1440,this.trustedServers={},e.server&&(r=this.getServerRootUrl(e.server),this.trustedServers[r]={token:e.token,expires:e.tokenExpires}),this._pendingTokenRequests={}}e.ApplicationSession=r,e.UserSession=n,e.fetchToken=a,e.generateToken=o,Object.defineProperty(e,"__esModule",{value:!0})});
//# sourceMappingURL=auth.umd.min.js.map
{
"name": "@esri/arcgis-rest-auth",
"version": "2.20.0",
"version": "2.21.0",
"description": "Authentication helpers for @esri/arcgis-rest-js.",

@@ -16,7 +16,7 @@ "main": "dist/node/index.js",

"dependencies": {
"@esri/arcgis-rest-types": "^2.20.0",
"@esri/arcgis-rest-types": "^2.21.0",
"tslib": "^1.13.0"
},
"devDependencies": {
"@esri/arcgis-rest-request": "^2.20.0"
"@esri/arcgis-rest-request": "^2.21.0"
},

@@ -23,0 +23,0 @@ "peerDependencies": {

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc