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.25.0 to 3.0.0-beta.0

dist/esm/ApiKey.d.ts

1

dist/esm/index.d.ts
export * from "./ApplicationSession";
export * from "./ApiKey";
export * from "./UserSession";

@@ -3,0 +4,0 @@ export * from "./fetch-token";

/* Copyright (c) 2018 Environmental Systems Research Institute, Inc.
* Apache-2.0 */
export * from "./ApplicationSession";
export * from "./ApiKey";
export * from "./UserSession";

@@ -5,0 +6,0 @@ export * from "./fetch-token";

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

tslib_1.__exportStar(require("./ApplicationSession"), exports);
tslib_1.__exportStar(require("./ApiKey"), exports);
tslib_1.__exportStar(require("./UserSession"), exports);

@@ -9,0 +10,0 @@ tslib_1.__exportStar(require("./fetch-token"), exports);

/* @preserve
* @esri/arcgis-rest-auth - v2.25.0 - Apache-2.0
* @esri/arcgis-rest-auth - v3.0.0-beta.0 - Apache-2.0
* Copyright (c) 2017-2021 Esri, Inc.
* Mon Jan 11 2021 11:45:51 GMT-0700 (Mountain Standard Time)
* Fri Jan 15 2021 13:14:45 GMT-0800 (Pacific Standard Time)
*/

@@ -116,2 +116,24 @@ (function (global, factory) {

/* Copyright (c) 2017-2019 Environmental Systems Research Institute, Inc.
* Apache-2.0 */
/**
* ```js
* import { ApiKey } from '@esri/arcgis-rest-auth';
* const apiKey = new ApiKey("...");
* ```
* Used to authenticate with API Keys.
*/
var ApiKey = /** @class */ (function () {
function ApiKey(options) {
this.key = options.key;
}
/**
* Gets a token (the API Key).
*/
ApiKey.prototype.getToken = function (url) {
return Promise.resolve(this.key);
};
return ApiKey;
}());
/* Copyright (c) 2017-2018 Environmental Systems Research Institute, Inc.

@@ -1087,2 +1109,3 @@ * Apache-2.0 */

exports.ApiKey = ApiKey;
exports.ApplicationSession = ApplicationSession;

@@ -1089,0 +1112,0 @@ exports.UserSession = UserSession;

6

dist/umd/auth.umd.min.js
/* @preserve
* @esri/arcgis-rest-auth - v2.25.0 - Apache-2.0
* @esri/arcgis-rest-auth - v3.0.0-beta.0 - Apache-2.0
* Copyright (c) 2017-2021 Esri, Inc.
* Mon Jan 11 2021 11:45:55 GMT-0700 (Mountain Standard Time)
* Fri Jan 15 2021 13:14:47 GMT-0800 (Pacific Standard Time)
*/
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("@esri/arcgis-rest-request")):"function"==typeof define&&define.amd?define(["exports","@esri/arcgis-rest-request"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).arcgisRest=e.arcgisRest||{},e.arcgisRest)}(this,function(e,g){"use strict";var w=function(){return(w=Object.assign||function(e){for(var t,r=1,n=arguments.length;r<n;r++)for(var s in t=arguments[r])Object.prototype.hasOwnProperty.call(t,s)&&(e[s]=t[s]);return e}).apply(this,arguments)};function a(e,t){var r=t;return r.rawResponse=!1,g.request(e,r).then(function(e){var t={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&&(t.refreshToken=e.refresh_token),t})}var t=(r.prototype.getToken=function(e,t){return this.token&&this.expires&&this.expires.getTime()>Date.now()?Promise.resolve(this.token):(this._pendingTokenRequest||(this._pendingTokenRequest=this.refreshToken(t)),this._pendingTokenRequest)},r.prototype.refreshToken=function(e){var t=this,r=w({params:{client_id:this.clientId,client_secret:this.clientSecret,grant_type:"client_credentials",expiration:this.duration}},e);return a(this.portal+"/oauth2/token/",r).then(function(e){return t._pendingTokenRequest=null,t.token=e.token,t.expires=e.expires,e.token})},r.prototype.refreshSession=function(){var e=this;return this.refreshToken().then(function(){return e})},r);function r(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,t){var r=t;return"undefined"!=typeof window&&window.location&&window.location.host?r.params.referer=window.location.host:r.params.referer=g.NODEJS_DEFAULT_REFERER_HEADER,g.request(e,r)}var s=/^https?:\/\/(\S+)\.arcgis\.com.+/;function h(e){return s.test(e)}function p(e){if(!s.test(e))return null;var t=e.match(s)[1].split(".").pop();return t.includes("dev")?"dev":t.includes("qa")?"qa":"production"}function i(e,t){var r=g.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"}}(t)).replace(/https?:\/\//,""),n=g.cleanUrl(e).replace(/https?:\/\//,"");return new RegExp(n,"i").test(r)}function n(e,t,r){void 0===r&&(r="https://www.arcgis.com/sharing/rest");var n=r+"/oauth2/validateAppAccess",s={method:"POST",params:{f:"json",client_id:t,token:e}};return g.request(n,s)}var u=(Object.defineProperty(m.prototype,"token",{get:function(){return this._token},enumerable:!1,configurable:!0}),Object.defineProperty(m.prototype,"tokenExpires",{get:function(){return this._tokenExpires},enumerable:!1,configurable:!0}),Object.defineProperty(m.prototype,"refreshToken",{get:function(){return this._refreshToken},enumerable:!1,configurable:!0}),Object.defineProperty(m.prototype,"refreshTokenExpires",{get:function(){return this._refreshTokenExpires},enumerable:!1,configurable:!0}),m.beginOAuth2=function(e,t){void 0===t&&(t=window);var r=w({portal:"https://www.arcgis.com/sharing/rest",provider:"arcgis",duration:20160,popup:!0,popupWindowFeatures:"height=400,width=600,menubar=no,location=yes,resizable=yes,scrollbars=yes,status=yes",state:e.clientId,locale:""},e),s=r.portal,n=r.provider,o=r.clientId,i=r.duration,a=r.redirectUri,h=r.popup,p=r.popupWindowFeatures,u=r.state,c=r.locale,l=r.params,d="arcgis"===n?s+"/oauth2/authorize?client_id="+o+"&response_type=token&expiration="+i+"&redirect_uri="+encodeURIComponent(a)+"&state="+u+"&locale="+c:s+"/oauth2/social/authorize?client_id="+o+"&socialLoginProviderName="+n+"&autoAccountCreateForSocial=true&response_type=token&expiration="+i+"&redirect_uri="+encodeURIComponent(a)+"&state="+u+"&locale="+c;if(l&&(d=d+"&"+g.encodeQueryString(l)),h){var f,k=((f={promise:null,resolve:null,reject:null}).promise=new Promise(function(e,t){f.resolve=e,f.reject=t}),f);return t["__ESRI_REST_AUTH_HANDLER_"+o]=function(e,t){var r,n;e?(r=JSON.parse(e),k.reject(new g.ArcGISAuthError(r.errorMessage,r.error))):t&&(n=JSON.parse(t),k.resolve(new m({clientId:o,portal:s,ssl:n.ssl,token:n.token,tokenExpires:new Date(n.expires),username:n.username})))},t.open(d,"oauth-window",p),k.promise}t.location.href=d},m.completeOAuth2=function(e,s){void 0===s&&(s=window);var t=w({portal:"https://www.arcgis.com/sharing/rest",popup:!0},e),o=t.portal,i=t.clientId,a=t.popup;function r(e,t){try{var r=void 0,n="__ESRI_REST_AUTH_HANDLER_"+i;if(a&&(s.opener?s.opener.parent&&s.opener.parent[n]?r=s.opener.parent[n]:s.opener&&s.opener[n]&&(r=s.opener[n]):s!==s.parent&&s.parent&&s.parent[n]&&(r=s.parent[n]),r))return r(e?JSON.stringify(e):void 0,JSON.stringify(t)),void s.close()}catch(e){throw new g.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 g.ArcGISAuthError(e.errorMessage,e.error);return new m({clientId:i,portal:o,ssl:t.ssl,token:t.token,tokenExpires:t.expires,username:t.username})}var n=g.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),r({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 r(void 0,{token:u,expires:c,ssl:"true"===n.ssl,username:l})},m.fromParent=function(n,s){var o;return!s&&window&&(s=window),new Promise(function(t,r){o=function(e){if(e.origin===n)try{return t(m.parentMessageHandler(e))}catch(e){return r(e)}},s.addEventListener("message",o,!1),s.parent.postMessage({type:"arcgis:auth:requestCredential"},n)}).then(function(e){return s.removeEventListener("message",o,!1),e})},m.authorize=function(e,t){var r=w({portal:"https://arcgis.com/sharing/rest",duration:20160},e),n=r.portal,s=r.clientId,o=r.duration,i=r.redirectUri;t.writeHead(301,{Location:n+"/oauth2/authorize?client_id="+s+"&duration="+o+"&response_type=code&redirect_uri="+encodeURIComponent(i)}),t.end()},m.exchangeAuthorizationCode=function(e,t){var r=w({portal:"https://www.arcgis.com/sharing/rest",refreshTokenTTL:1440},e),n=r.portal,s=r.clientId,o=r.redirectUri,i=r.refreshTokenTTL;return a(n+"/oauth2/token",{params:{grant_type:"authorization_code",client_id:s,redirect_uri:o,code:t}}).then(function(e){return new m({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})})},m.deserialize=function(e){var t=JSON.parse(e);return new m({clientId:t.clientId,refreshToken:t.refreshToken,refreshTokenExpires:new Date(t.refreshTokenExpires),username:t.username,password:t.password,token:t.token,tokenExpires:new Date(t.tokenExpires),portal:t.portal,ssl:t.ssl,tokenDuration:t.tokenDuration,redirectUri:t.redirectUri,refreshTokenTTL:t.refreshTokenTTL})},m.fromCredential=function(e){return new m({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)})},m.parentMessageHandler=function(e){if("arcgis:auth:credential"===e.data.type)return m.fromCredential(e.data.credential);throw"arcgis:auth:rejected"===e.data.type?new Error(e.data.message):new Error("Unknown message type.")},m.prototype.toCredential=function(){return{expires:this.tokenExpires.getTime(),server:this.portal,ssl:this.ssl,token:this.token,userId:this.username}},m.prototype.getUser=function(e){var t=this;if(this._pendingUserRequest)return this._pendingUserRequest;if(this._user)return Promise.resolve(this._user);var r=this.portal+"/community/self",n=w(w({httpMethod:"GET",authentication:this},e),{rawResponse:!1});return this._pendingUserRequest=g.request(r,n).then(function(e){return t._user=e,t._pendingUserRequest=null,e}),this._pendingUserRequest},m.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})},m.prototype.getToken=function(e,t){return r=this.portal,n=e,s=h(r),o=h(n),i=p(r),a=p(n),s&&o&&i===a||new RegExp(this.portal,"i").test(e)?this.getFreshToken(t):this.getTokenForServer(e,t);var r,n,s,o,i,a},m.prototype.validateAppAccess=function(t){return this.getToken(this.portal).then(function(e){return n(e,t)})},m.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}},m.prototype.serialize=function(){return JSON.stringify(this)},m.prototype.enablePostMessageAuth=function(e,t){!t&&window&&(t=window),this._hostHandler=this.createPostMessageHandler(e),t.addEventListener("message",this._hostHandler,!1)},m.prototype.disablePostMessageAuth=function(e){!e&&window&&(e=window),e.removeEventListener("message",this._hostHandler,!1)},m.prototype.refreshSession=function(e){return this._user=null,this.username&&this.password?this.refreshWithUsernameAndPassword(e):this.clientId&&this.refreshToken?this.refreshWithRefreshToken():Promise.reject(new g.ArcGISAuthError("Unable to refresh token."))},m.prototype.getServerRootUrl=function(e){var t=g.cleanUrl(e).split(/\/rest(\/admin)?\/services(?:\/|#|\?|$)/)[0].match(/(https?:\/\/)(.+)/),r=(t[0],t[1]),n=t[2].split("/"),s=n[0],o=n.slice(1);return""+r+s.toLowerCase()+"/"+o.join("/")},m.prototype.createPostMessageHandler=function(r){var n=this;return function(e){var t;-1<r.indexOf(e.origin)?(t=n.toCredential(),e.source.postMessage({type:"arcgis:auth:credential",credential:t},e.origin)):e.source.postMessage({type:"arcgis:auth:rejected",message:"Rejected authentication request."},e.origin)}},m.prototype.getTokenForServer=function(t,r){var n=this,s=this.getServerRootUrl(t),e=this.trustedServers[s];return e&&e.expires&&e.expires.getTime()>Date.now()?Promise.resolve(e.token):(this._pendingTokenRequests[s]||(this._pendingTokenRequests[s]=g.request(s+"/rest/info").then(function(e){if(e.owningSystemUrl){if(i(e.owningSystemUrl,n.portal))return g.request(e.owningSystemUrl+"/sharing/rest/info",r);throw new g.ArcGISAuthError(t+" is not federated with "+n.portal+".","NOT_FEDERATED")}if(e.authInfo&&void 0!==n.trustedServers[s])return Promise.resolve({authInfo:e.authInfo});throw new g.ArcGISAuthError(t+" 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:t,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])},m.prototype.getFreshToken=function(e){var t=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 t._pendingTokenRequests[t.portal]=null,e.token})),this._pendingTokenRequests[this.portal])},m.prototype.refreshWithUsernameAndPassword=function(e){var t=this,r=w({params:{username:this.username,password:this.password,expiration:this.tokenDuration}},e);return o(this.portal+"/generateToken",r).then(function(e){return t._token=e.token,t._tokenExpires=new Date(e.expires),t})},m.prototype.refreshWithRefreshToken=function(e){var t=this;if(this.refreshToken&&this.refreshTokenExpires&&this.refreshTokenExpires.getTime()<Date.now())return this.refreshRefreshToken(e);var r=w({params:{client_id:this.clientId,refresh_token:this.refreshToken,grant_type:"refresh_token"}},e);return a(this.portal+"/oauth2/token",r).then(function(e){return t._token=e.token,t._tokenExpires=e.expires,t})},m.prototype.refreshRefreshToken=function(e){var t=this,r=w({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",r).then(function(e){return t._token=e.token,t._tokenExpires=e.expires,t._refreshToken=e.refreshToken,t._refreshTokenExpires=new Date(Date.now()+60*(t.refreshTokenTTL-1)*1e3),t})},m);function m(e){var t;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?g.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&&(t=this.getServerRootUrl(e.server),this.trustedServers[t]={token:e.token,expires:e.tokenExpires}),this._pendingTokenRequests={}}e.ApplicationSession=t,e.UserSession=u,e.exchangeToken=function(e,t,r){void 0===r&&(r="https://www.arcgis.com/sharing/rest");var n=r+"/oauth2/exchangeToken",s={method:"POST",params:{f:"json",client_id:t,token:e}};return g.request(n,s).then(function(e){return e.token})},e.fetchToken=a,e.generateToken=o,e.platformSelf=function(e,t,r){void 0===r&&(r="https://www.arcgis.com/sharing/rest");var n=r+"/oauth2/platformSelf?f=json",s={method:"POST",headers:{"X-Esri-Auth-Client-Id":e,"X-Esri-Auth-Redirect-Uri":t},params:{f:"json"}};return g.request(n,s)},e.validateAppAccess=n,Object.defineProperty(e,"__esModule",{value:!0})});
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("@esri/arcgis-rest-request")):"function"==typeof define&&define.amd?define(["exports","@esri/arcgis-rest-request"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).arcgisRest=e.arcgisRest||{},e.arcgisRest)}(this,function(e,d){"use strict";var f=function(){return(f=Object.assign||function(e){for(var t,r=1,n=arguments.length;r<n;r++)for(var s in t=arguments[r])Object.prototype.hasOwnProperty.call(t,s)&&(e[s]=t[s]);return e}).apply(this,arguments)};function i(e,t){return t.rawResponse=!1,d.request(e,t).then(function(e){var t={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&&(t.refreshToken=e.refresh_token),t})}var t=(r.prototype.getToken=function(e,t){return this.token&&this.expires&&this.expires.getTime()>Date.now()?Promise.resolve(this.token):this._pendingTokenRequest||(this._pendingTokenRequest=this.refreshToken(t),this._pendingTokenRequest)},r.prototype.refreshToken=function(e){var t=this,e=f({params:{client_id:this.clientId,client_secret:this.clientSecret,grant_type:"client_credentials",expiration:this.duration}},e);return i(this.portal+"/oauth2/token/",e).then(function(e){return t._pendingTokenRequest=null,t.token=e.token,t.expires=e.expires,e.token})},r.prototype.refreshSession=function(){var e=this;return this.refreshToken().then(function(){return e})},r);function r(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}var n=(s.prototype.getToken=function(e){return Promise.resolve(this.key)},s);function s(e){this.key=e.key}function o(e,t){return"undefined"!=typeof window&&window.location&&window.location.host?t.params.referer=window.location.host:t.params.referer=d.NODEJS_DEFAULT_REFERER_HEADER,d.request(e,t)}var a=/^https?:\/\/(\S+)\.arcgis\.com.+/;function h(e){return a.test(e)}function p(e){if(!a.test(e))return null;e=e.match(a)[1].split(".").pop();return e.includes("dev")?"dev":e.includes("qa")?"qa":"production"}function u(e,t){t=d.cleanUrl(function(e){if(!a.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"}}(t)).replace(/https?:\/\//,""),e=d.cleanUrl(e).replace(/https?:\/\//,"");return new RegExp(e,"i").test(t)}function c(e,t,r){void 0===r&&(r="https://www.arcgis.com/sharing/rest");r+="/oauth2/validateAppAccess",e={method:"POST",params:{f:"json",client_id:t,token:e}};return d.request(r,e)}var l=(Object.defineProperty(k.prototype,"token",{get:function(){return this._token},enumerable:!1,configurable:!0}),Object.defineProperty(k.prototype,"tokenExpires",{get:function(){return this._tokenExpires},enumerable:!1,configurable:!0}),Object.defineProperty(k.prototype,"refreshToken",{get:function(){return this._refreshToken},enumerable:!1,configurable:!0}),Object.defineProperty(k.prototype,"refreshTokenExpires",{get:function(){return this._refreshTokenExpires},enumerable:!1,configurable:!0}),k.beginOAuth2=function(e,t){void 0===t&&(t=window);var r=f({portal:"https://www.arcgis.com/sharing/rest",provider:"arcgis",duration:20160,popup:!0,popupWindowFeatures:"height=400,width=600,menubar=no,location=yes,resizable=yes,scrollbars=yes,status=yes",state:e.clientId,locale:""},e),n=r.portal,s=r.provider,o=r.clientId,i=r.duration,a=r.redirectUri,h=r.popup,p=r.popupWindowFeatures,u=r.state,e=r.locale,r=r.params,e="arcgis"===s?n+"/oauth2/authorize?client_id="+o+"&response_type=token&expiration="+i+"&redirect_uri="+encodeURIComponent(a)+"&state="+u+"&locale="+e:n+"/oauth2/social/authorize?client_id="+o+"&socialLoginProviderName="+s+"&autoAccountCreateForSocial=true&response_type=token&expiration="+i+"&redirect_uri="+encodeURIComponent(a)+"&state="+u+"&locale="+e;if(r&&(e=e+"&"+d.encodeQueryString(r)),h){var c,l=((c={promise:null,resolve:null,reject:null}).promise=new Promise(function(e,t){c.resolve=e,c.reject=t}),c);return t["__ESRI_REST_AUTH_HANDLER_"+o]=function(e,t){e?(e=JSON.parse(e),l.reject(new d.ArcGISAuthError(e.errorMessage,e.error))):t&&(t=JSON.parse(t),l.resolve(new k({clientId:o,portal:n,ssl:t.ssl,token:t.token,tokenExpires:new Date(t.expires),username:t.username})))},t.open(e,"oauth-window",p),l.promise}t.location.href=e},k.completeOAuth2=function(e,s){void 0===s&&(s=window);var t=f({portal:"https://www.arcgis.com/sharing/rest",popup:!0},e),o=t.portal,i=t.clientId,a=t.popup;function r(e,t){try{var r=void 0,n="__ESRI_REST_AUTH_HANDLER_"+i;if(a&&(s.opener?s.opener.parent&&s.opener.parent[n]?r=s.opener.parent[n]:s.opener&&s.opener[n]&&(r=s.opener[n]):s!==s.parent&&s.parent&&s.parent[n]&&(r=s.parent[n]),r))return r(e?JSON.stringify(e):void 0,JSON.stringify(t)),void s.close()}catch(e){throw new d.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 d.ArcGISAuthError(e.errorMessage,e.error);return new k({clientId:i,portal:o,ssl:t.ssl,token:t.token,tokenExpires:t.expires,username:t.username})}e=d.decodeQueryString(s.location.hash);if(!e.access_token){var n=void 0,h="Unknown error";return e.error&&(n=e.error,h=e.error_description),r({error:n,errorMessage:h})}t=e.access_token,n=new Date(Date.now()+1e3*parseInt(e.expires_in,10)-6e4),h=e.username;return r(void 0,{token:t,expires:n,ssl:"true"===e.ssl,username:h})},k.fromParent=function(n,s){var o;return!s&&window&&(s=window),new Promise(function(t,r){o=function(e){if(e.origin===n)try{return t(k.parentMessageHandler(e))}catch(e){return r(e)}},s.addEventListener("message",o,!1),s.parent.postMessage({type:"arcgis:auth:requestCredential"},n)}).then(function(e){return s.removeEventListener("message",o,!1),e})},k.authorize=function(e,t){var r=f({portal:"https://arcgis.com/sharing/rest",duration:20160},e),n=r.portal,s=r.clientId,e=r.duration,r=r.redirectUri;t.writeHead(301,{Location:n+"/oauth2/authorize?client_id="+s+"&duration="+e+"&response_type=code&redirect_uri="+encodeURIComponent(r)}),t.end()},k.exchangeAuthorizationCode=function(e,t){var e=f({portal:"https://www.arcgis.com/sharing/rest",refreshTokenTTL:1440},e),r=e.portal,n=e.clientId,s=e.redirectUri,o=e.refreshTokenTTL;return i(r+"/oauth2/token",{params:{grant_type:"authorization_code",client_id:n,redirect_uri:s,code:t}}).then(function(e){return new k({clientId:n,portal:r,ssl:e.ssl,redirectUri:s,refreshToken:e.refreshToken,refreshTokenTTL:o,refreshTokenExpires:new Date(Date.now()+1e3*(o-1)),token:e.token,tokenExpires:e.expires,username:e.username})})},k.deserialize=function(e){e=JSON.parse(e);return new k({clientId:e.clientId,refreshToken:e.refreshToken,refreshTokenExpires:new Date(e.refreshTokenExpires),username:e.username,password:e.password,token:e.token,tokenExpires:new Date(e.tokenExpires),portal:e.portal,ssl:e.ssl,tokenDuration:e.tokenDuration,redirectUri:e.redirectUri,refreshTokenTTL:e.refreshTokenTTL})},k.fromCredential=function(e){return new k({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)})},k.parentMessageHandler=function(e){if("arcgis:auth:credential"===e.data.type)return k.fromCredential(e.data.credential);throw"arcgis:auth:rejected"===e.data.type?new Error(e.data.message):new Error("Unknown message type.")},k.prototype.toCredential=function(){return{expires:this.tokenExpires.getTime(),server:this.portal,ssl:this.ssl,token:this.token,userId:this.username}},k.prototype.getUser=function(e){var t=this;if(this._pendingUserRequest)return this._pendingUserRequest;if(this._user)return Promise.resolve(this._user);var r=this.portal+"/community/self",e=f(f({httpMethod:"GET",authentication:this},e),{rawResponse:!1});return this._pendingUserRequest=d.request(r,e).then(function(e){return t._user=e,t._pendingUserRequest=null,e}),this._pendingUserRequest},k.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})},k.prototype.getToken=function(e,t){return r=this.portal,n=e,s=h(r),o=h(n),r=p(r),n=p(n),s&&o&&r===n||new RegExp(this.portal,"i").test(e)?this.getFreshToken(t):this.getTokenForServer(e,t);var r,n,s,o},k.prototype.validateAppAccess=function(t){return this.getToken(this.portal).then(function(e){return c(e,t)})},k.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}},k.prototype.serialize=function(){return JSON.stringify(this)},k.prototype.enablePostMessageAuth=function(e,t){!t&&window&&(t=window),this._hostHandler=this.createPostMessageHandler(e),t.addEventListener("message",this._hostHandler,!1)},k.prototype.disablePostMessageAuth=function(e){!e&&window&&(e=window),e.removeEventListener("message",this._hostHandler,!1)},k.prototype.refreshSession=function(e){return this._user=null,this.username&&this.password?this.refreshWithUsernameAndPassword(e):this.clientId&&this.refreshToken?this.refreshWithRefreshToken():Promise.reject(new d.ArcGISAuthError("Unable to refresh token."))},k.prototype.getServerRootUrl=function(e){var t=d.cleanUrl(e).split(/\/rest(\/admin)?\/services(?:\/|#|\?|$)/)[0].match(/(https?:\/\/)(.+)/),r=(t[0],t[1]),e=t[2].split("/"),t=e[0],e=e.slice(1);return""+r+t.toLowerCase()+"/"+e.join("/")},k.prototype.createPostMessageHandler=function(r){var n=this;return function(e){var t;-1<r.indexOf(e.origin)?(t=n.toCredential(),e.source.postMessage({type:"arcgis:auth:credential",credential:t},e.origin)):e.source.postMessage({type:"arcgis:auth:rejected",message:"Rejected authentication request."},e.origin)}},k.prototype.getTokenForServer=function(t,r){var n=this,s=this.getServerRootUrl(t),e=this.trustedServers[s];return e&&e.expires&&e.expires.getTime()>Date.now()?Promise.resolve(e.token):this._pendingTokenRequests[s]||(this._pendingTokenRequests[s]=d.request(s+"/rest/info").then(function(e){if(e.owningSystemUrl){if(u(e.owningSystemUrl,n.portal))return d.request(e.owningSystemUrl+"/sharing/rest/info",r);throw new d.ArcGISAuthError(t+" is not federated with "+n.portal+".","NOT_FEDERATED")}if(e.authInfo&&void 0!==n.trustedServers[s])return Promise.resolve({authInfo:e.authInfo});throw new d.ArcGISAuthError(t+" 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:t,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])},k.prototype.getFreshToken=function(e){var t=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 t._pendingTokenRequests[t.portal]=null,e.token})),this._pendingTokenRequests[this.portal])},k.prototype.refreshWithUsernameAndPassword=function(e){var t=this,e=f({params:{username:this.username,password:this.password,expiration:this.tokenDuration}},e);return o(this.portal+"/generateToken",e).then(function(e){return t._token=e.token,t._tokenExpires=new Date(e.expires),t})},k.prototype.refreshWithRefreshToken=function(e){var t=this;if(this.refreshToken&&this.refreshTokenExpires&&this.refreshTokenExpires.getTime()<Date.now())return this.refreshRefreshToken(e);e=f({params:{client_id:this.clientId,refresh_token:this.refreshToken,grant_type:"refresh_token"}},e);return i(this.portal+"/oauth2/token",e).then(function(e){return t._token=e.token,t._tokenExpires=e.expires,t})},k.prototype.refreshRefreshToken=function(e){var t=this,e=f({params:{client_id:this.clientId,refresh_token:this.refreshToken,redirect_uri:this.redirectUri,grant_type:"exchange_refresh_token"}},e);return i(this.portal+"/oauth2/token",e).then(function(e){return t._token=e.token,t._tokenExpires=e.expires,t._refreshToken=e.refreshToken,t._refreshTokenExpires=new Date(Date.now()+60*(t.refreshTokenTTL-1)*1e3),t})},k);function k(e){var t;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?d.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&&(t=this.getServerRootUrl(e.server),this.trustedServers[t]={token:e.token,expires:e.tokenExpires}),this._pendingTokenRequests={}}e.ApiKey=n,e.ApplicationSession=t,e.UserSession=l,e.exchangeToken=function(e,t,r){return void 0===r&&(r="https://www.arcgis.com/sharing/rest"),r+="/oauth2/exchangeToken",e={method:"POST",params:{f:"json",client_id:t,token:e}},d.request(r,e).then(function(e){return e.token})},e.fetchToken=i,e.generateToken=o,e.platformSelf=function(e,t,r){return void 0===r&&(r="https://www.arcgis.com/sharing/rest"),r+="/oauth2/platformSelf?f=json",t={method:"POST",headers:{"X-Esri-Auth-Client-Id":e,"X-Esri-Auth-Redirect-Uri":t},params:{f:"json"}},d.request(r,t)},e.validateAppAccess=c,Object.defineProperty(e,"__esModule",{value:!0})});
//# sourceMappingURL=auth.umd.min.js.map
{
"name": "@esri/arcgis-rest-auth",
"version": "2.25.0",
"version": "3.0.0-beta.0",
"description": "Authentication helpers for @esri/arcgis-rest-js.",

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

"dependencies": {
"@esri/arcgis-rest-types": "^2.25.0",
"@esri/arcgis-rest-types": "^3.0.0-beta.0",
"tslib": "^1.13.0"
},
"devDependencies": {
"@esri/arcgis-rest-request": "^2.25.0"
"@esri/arcgis-rest-request": "^3.0.0-beta.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