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
17
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 1.11.0 to 1.11.1

12

dist/esm/ApplicationSession.d.ts

@@ -24,2 +24,14 @@ import { IAuthenticationManager, ITokenRequestOptions } from "@esri/arcgis-rest-request";

}
/**
* ```js
* // visit https://developers.arcgis.com to generate your own clientid and secret
* const session = new ApplicationSession({
* clientId,
* clientSecret
* })
* ```
* You can use [App Login](https://developers.arcgis.com/documentation/core-concepts/security-and-authentication/accessing-arcgis-online-services/) to access premium content and services in ArcGIS Online.
* in `request`.
*
*/
export declare class ApplicationSession implements IAuthenticationManager {

@@ -26,0 +38,0 @@ portal: string;

@@ -5,2 +5,14 @@ /* Copyright (c) 2017 Environmental Systems Research Institute, Inc.

import { fetchToken } from "./fetch-token";
/**
* ```js
* // visit https://developers.arcgis.com to generate your own clientid and secret
* const session = new ApplicationSession({
* clientId,
* clientSecret
* })
* ```
* You can use [App Login](https://developers.arcgis.com/documentation/core-concepts/security-and-authentication/accessing-arcgis-online-services/) to access premium content and services in ArcGIS Online.
* in `request`.
*
*/
var ApplicationSession = /** @class */ (function () {

@@ -7,0 +19,0 @@ function ApplicationSession(options) {

1

dist/esm/fetch-token.d.ts

@@ -6,4 +6,5 @@ import { IFetchTokenParams, ITokenRequestOptions } from "@esri/arcgis-rest-request";

username: string;
ssl: boolean;
refreshToken?: string;
}
export declare function fetchToken(url: string, requestOptions: IFetchTokenParams | ITokenRequestOptions): Promise<IFetchTokenResponse>;

3

dist/esm/fetch-token.js

@@ -14,3 +14,4 @@ /* Copyright (c) 2017 Environmental Systems Research Institute, Inc.

username: response.username,
expires: new Date(Date.now() + (response.expires_in * 60 * 1000 - 60 * 1000))
expires: new Date(Date.now() + (response.expires_in * 60 * 1000 - 60 * 1000)),
ssl: response.ssl === true
};

@@ -17,0 +18,0 @@ if (response.refresh_token) {

@@ -112,2 +112,6 @@ /// <reference types="node" />

/**
* This value is set to true automatically if the ArcGIS Organization requires that requests be made over https.
*/
ssl?: boolean;
/**
* ArcGIS Authentication is used by default. Specifying an alternative will take users directly to the corresponding provider's OAuth page.

@@ -156,2 +160,6 @@ */

/**
* This value is set to true automatically if the ArcGIS Organization requires that requests be made over https.
*/
readonly ssl: boolean;
/**
* The authentication provider to use.

@@ -292,7 +300,7 @@ */

*/
private getTokenForServer(url, requestOptions?);
private getTokenForServer;
/**
* Returns an unexpired token for the current `portal`.
*/
private getFreshToken(requestOptions?);
private getFreshToken;
/**

@@ -302,7 +310,7 @@ * Refreshes the current `token` and `tokenExpires` with `username` and

*/
private refreshWithUsernameAndPassword(requestOptions?);
private refreshWithUsernameAndPassword;
/**
* Refreshes the current `token` and `tokenExpires` with `refreshToken`.
*/
private refreshWithRefreshToken(requestOptions?);
private refreshWithRefreshToken;
/**

@@ -312,3 +320,3 @@ * Exchanges an expired `refreshToken` for a new one also updates `token` and

*/
private refreshRefreshToken(requestOptions?);
private refreshRefreshToken;
}

@@ -42,2 +42,3 @@ /* Copyright (c) 2017-2018 Environmental Systems Research Institute, Inc.

this.portal = options.portal || "https://www.arcgis.com/sharing/rest";
this.ssl = options.ssl;
this.provider = options.provider || "arcgis";

@@ -131,2 +132,3 @@ this.tokenDuration = options.tokenDuration || 20160;

portal: portal,
ssl: oauthInfo.ssl,
token: oauthInfo.token,

@@ -169,2 +171,3 @@ tokenExpires: new Date(oauthInfo.expires),

portal: portal,
ssl: oauthInfo.ssl,
token: oauthInfo.token,

@@ -185,5 +188,8 @@ tokenExpires: oauthInfo.expires,

var username = decodeURIComponent(match[3]);
var ssl = win.location.href.indexOf("&ssl=true") > -1 ||
win.location.href.indexOf("#ssl=true") > -1;
return completeSignIn(undefined, {
token: token,
expires: expires,
ssl: ssl,
username: username

@@ -225,2 +231,3 @@ });

portal: portal,
ssl: response.ssl,
redirectUri: redirectUri,

@@ -247,2 +254,3 @@ refreshToken: response.refreshToken,

portal: options.portal,
ssl: options.ssl,
tokenDuration: options.tokenDuration,

@@ -268,2 +276,3 @@ redirectUri: options.redirectUri,

portal: credential.server + "/sharing/rest",
ssl: credential.ssl,
token: credential.token,

@@ -287,3 +296,3 @@ username: credential.userId,

server: this.portal,
ssl: true,
ssl: this.ssl,
token: this.token,

@@ -348,2 +357,3 @@ userId: this.username

portal: this.portal,
ssl: this.ssl,
tokenDuration: this.tokenDuration,

@@ -375,3 +385,4 @@ redirectUri: this.redirectUri,

var _this = this;
var root = url.split("/rest/services/")[0];
// requests to /rest/services/ and /rest/admin/services/ are both valid
var root = url.split(/\/rest(\/admin)?\/services\//)[0];
var existingToken = this.trustedServers[root];

@@ -378,0 +389,0 @@ if (existingToken && existingToken.expires.getTime() > Date.now()) {

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

var fetch_token_1 = require("./fetch-token");
/**
* ```js
* // visit https://developers.arcgis.com to generate your own clientid and secret
* const session = new ApplicationSession({
* clientId,
* clientSecret
* })
* ```
* You can use [App Login](https://developers.arcgis.com/documentation/core-concepts/security-and-authentication/accessing-arcgis-online-services/) to access premium content and services in ArcGIS Online.
* in `request`.
*
*/
var ApplicationSession = /** @class */ (function () {

@@ -9,0 +21,0 @@ function ApplicationSession(options) {

@@ -16,3 +16,4 @@ "use strict";

username: response.username,
expires: new Date(Date.now() + (response.expires_in * 60 * 1000 - 60 * 1000))
expires: new Date(Date.now() + (response.expires_in * 60 * 1000 - 60 * 1000)),
ssl: response.ssl === true
};

@@ -19,0 +20,0 @@ if (response.refresh_token) {

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

this.portal = options.portal || "https://www.arcgis.com/sharing/rest";
this.ssl = options.ssl;
this.provider = options.provider || "arcgis";

@@ -133,2 +134,3 @@ this.tokenDuration = options.tokenDuration || 20160;

portal: portal,
ssl: oauthInfo.ssl,
token: oauthInfo.token,

@@ -171,2 +173,3 @@ tokenExpires: new Date(oauthInfo.expires),

portal: portal,
ssl: oauthInfo.ssl,
token: oauthInfo.token,

@@ -187,5 +190,8 @@ tokenExpires: oauthInfo.expires,

var username = decodeURIComponent(match[3]);
var ssl = win.location.href.indexOf("&ssl=true") > -1 ||
win.location.href.indexOf("#ssl=true") > -1;
return completeSignIn(undefined, {
token: token,
expires: expires,
ssl: ssl,
username: username

@@ -227,2 +233,3 @@ });

portal: portal,
ssl: response.ssl,
redirectUri: redirectUri,

@@ -249,2 +256,3 @@ refreshToken: response.refreshToken,

portal: options.portal,
ssl: options.ssl,
tokenDuration: options.tokenDuration,

@@ -270,2 +278,3 @@ redirectUri: options.redirectUri,

portal: credential.server + "/sharing/rest",
ssl: credential.ssl,
token: credential.token,

@@ -289,3 +298,3 @@ username: credential.userId,

server: this.portal,
ssl: true,
ssl: this.ssl,
token: this.token,

@@ -350,2 +359,3 @@ userId: this.username

portal: this.portal,
ssl: this.ssl,
tokenDuration: this.tokenDuration,

@@ -377,3 +387,4 @@ redirectUri: this.redirectUri,

var _this = this;
var root = url.split("/rest/services/")[0];
// requests to /rest/services/ and /rest/admin/services/ are both valid
var root = url.split(/\/rest(\/admin)?\/services\//)[0];
var existingToken = this.trustedServers[root];

@@ -380,0 +391,0 @@ if (existingToken && existingToken.expires.getTime() > Date.now()) {

/* @preserve
* @esri/arcgis-rest-auth - v1.11.0 - Apache-2.0
* @esri/arcgis-rest-auth - v1.11.1 - Apache-2.0
* Copyright (c) 2017-2018 Esri, Inc.
* Wed Sep 19 2018 14:12:15 GMT-0600 (MDT)
* Tue Sep 25 2018 14:09:59 GMT-0700 (PDT)
*/

@@ -50,3 +50,4 @@ (function (global, factory) {

username: response.username,
expires: new Date(Date.now() + (response.expires_in * 60 * 1000 - 60 * 1000))
expires: new Date(Date.now() + (response.expires_in * 60 * 1000 - 60 * 1000)),
ssl: response.ssl === true
};

@@ -62,2 +63,14 @@ if (response.refresh_token) {

* Apache-2.0 */
/**
* ```js
* // visit https://developers.arcgis.com to generate your own clientid and secret
* const session = new ApplicationSession({
* clientId,
* clientSecret
* })
* ```
* You can use [App Login](https://developers.arcgis.com/documentation/core-concepts/security-and-authentication/accessing-arcgis-online-services/) to access premium content and services in ArcGIS Online.
* in `request`.
*
*/
var ApplicationSession = /** @class */ (function () {

@@ -160,2 +173,3 @@ function ApplicationSession(options) {

this.portal = options.portal || "https://www.arcgis.com/sharing/rest";
this.ssl = options.ssl;
this.provider = options.provider || "arcgis";

@@ -249,2 +263,3 @@ this.tokenDuration = options.tokenDuration || 20160;

portal: portal,
ssl: oauthInfo.ssl,
token: oauthInfo.token,

@@ -287,2 +302,3 @@ tokenExpires: new Date(oauthInfo.expires),

portal: portal,
ssl: oauthInfo.ssl,
token: oauthInfo.token,

@@ -303,5 +319,8 @@ tokenExpires: oauthInfo.expires,

var username = decodeURIComponent(match[3]);
var ssl = win.location.href.indexOf("&ssl=true") > -1 ||
win.location.href.indexOf("#ssl=true") > -1;
return completeSignIn(undefined, {
token: token,
expires: expires,
ssl: ssl,
username: username

@@ -343,2 +362,3 @@ });

portal: portal,
ssl: response.ssl,
redirectUri: redirectUri,

@@ -365,2 +385,3 @@ refreshToken: response.refreshToken,

portal: options.portal,
ssl: options.ssl,
tokenDuration: options.tokenDuration,

@@ -386,2 +407,3 @@ redirectUri: options.redirectUri,

portal: credential.server + "/sharing/rest",
ssl: credential.ssl,
token: credential.token,

@@ -405,3 +427,3 @@ username: credential.userId,

server: this.portal,
ssl: true,
ssl: this.ssl,
token: this.token,

@@ -466,2 +488,3 @@ userId: this.username

portal: this.portal,
ssl: this.ssl,
tokenDuration: this.tokenDuration,

@@ -493,3 +516,4 @@ redirectUri: this.redirectUri,

var _this = this;
var root = url.split("/rest/services/")[0];
// requests to /rest/services/ and /rest/admin/services/ are both valid
var root = url.split(/\/rest(\/admin)?\/services\//)[0];
var existingToken = this.trustedServers[root];

@@ -496,0 +520,0 @@ if (existingToken && existingToken.expires.getTime() > Date.now()) {

/* @preserve
* @esri/arcgis-rest-auth - v1.11.0 - Apache-2.0
* @esri/arcgis-rest-auth - v1.11.1 - Apache-2.0
* Copyright (c) 2017-2018 Esri, Inc.
* Wed Sep 19 2018 14:12:19 GMT-0600 (MDT)
* Tue Sep 25 2018 14:10:02 GMT-0700 (PDT)
*/
!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.arcgisRest=e.arcgisRest||{},e.arcgisRest)}(this,function(e,r){"use strict";var t=Object.assign||function(e){for(var r,t=1,n=arguments.length;t<n;t++)for(var o in r=arguments[t])Object.prototype.hasOwnProperty.call(r,o)&&(e[o]=r[o]);return e};function n(e,t){var n=t.params?t:{params:t};return r.request(e,n).then(function(e){var r={token:e.access_token,username:e.username,expires:new Date(Date.now()+(60*e.expires_in*1e3-6e4))};return e.refresh_token&&(r.refreshToken=e.refresh_token),r})}var o=function(){function e(e){this.clientId=e.clientId,this.clientSecret=e.clientSecret,this.token=e.token,this.expires=e.expires,this.portal="https://www.arcgis.com/sharing/rest"}return e.prototype.getToken=function(e,r){return this.token&&this.expires&&this.expires.getTime()>Date.now()?Promise.resolve(this.token):this._pendingTokenRequest?this._pendingTokenRequest:(this._pendingTokenRequest=this.refreshToken(r),this._pendingTokenRequest)},e.prototype.refreshToken=function(e){var r=this,o=t({params:{client_id:this.clientId,client_secret:this.clientSecret,grant_type:"client_credentials"}},e);return n(this.portal+"/oauth2/token/",o).then(function(e){return r._pendingTokenRequest=null,r.token=e.token,r.expires=e.expires,e.token})},e.prototype.refreshSession=function(){var e=this;return this.refreshToken().then(function(){return e})},e}();function s(e,t){var n=t.params?t:{params:t};return"undefined"!=typeof window&&window.location&&window.location.host?n.params.referer=window.location.host:n.params.referer="@esri.arcgis-rest-auth",r.request(e,n)}var i=function(){function e(e){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||"https://www.arcgis.com/sharing/rest",this.provider=e.provider||"arcgis",this.tokenDuration=e.tokenDuration||20160,this.redirectUri=e.redirectUri,this.refreshTokenTTL=e.refreshTokenTTL||1440,this.trustedServers={},this._pendingTokenRequests={}}return Object.defineProperty(e.prototype,"token",{get:function(){return this._token},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"tokenExpires",{get:function(){return this._tokenExpires},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"refreshToken",{get:function(){return this._refreshToken},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"refreshTokenExpires",{get:function(){return this._refreshTokenExpires},enumerable:!0,configurable:!0}),e.beginOAuth2=function(n,o){void 0===o&&(o=window);var s,i=t({portal:"https://www.arcgis.com/sharing/rest",provider:"arcgis",duration:20160,popup:!0,state:n.clientId,locale:""},n),a=i.portal,h=i.provider,p=i.clientId,u=i.duration,c=i.redirectUri,f=i.popup,k=i.state,d=i.locale;if(s="arcgis"===h?a+"/oauth2/authorize?client_id="+p+"&response_type=token&expiration="+u+"&redirect_uri="+encodeURIComponent(c)+"&state="+k+"&locale="+d:a+"/oauth2/social/authorize?client_id="+p+"&socialLoginProviderName="+h+"&autoAccountCreateForSocial=true&response_type=token&expiration="+u+"&redirect_uri="+encodeURIComponent(c)+"&state="+k+"&locale="+d,f){var l,T=((l={promise:null,resolve:null,reject:null}).promise=new Promise(function(e,r){l.resolve=e,l.reject=r}),l);return o["__ESRI_REST_AUTH_HANDLER_"+p]=function(t,n){if(t){var o=JSON.parse(t);T.reject(new r.ArcGISAuthError(o.errorMessage,o.error))}else if(n){var s=JSON.parse(n);T.resolve(new e({clientId:p,portal:a,token:s.token,tokenExpires:new Date(s.expires),username:s.username}))}},o.open(s,"oauth-window","height=400,width=600,menubar=no,location=yes,resizable=yes,scrollbars=yes,status=yes"),T.promise}o.location.href=s},e.completeOAuth2=function(n,o){void 0===o&&(o=window);var s=t({portal:"https://www.arcgis.com/sharing/rest"},n),i=s.portal,a=s.clientId;function h(t,n){if(o.opener&&o.opener.parent)return o.opener.parent["__ESRI_REST_AUTH_HANDLER_"+a](t?JSON.stringify(t):void 0,JSON.stringify(n)),void o.close();if(o!==o.parent)return o.parent["__ESRI_REST_AUTH_HANDLER_"+a](t?JSON.stringify(t):void 0,JSON.stringify(n)),void o.close();if(t)throw new r.ArcGISAuthError(t.errorMessage,t.error);return new e({clientId:a,portal:i,token:n.token,tokenExpires:n.expires,username:n.username})}var p=o.location.href.match(/access_token=(.+)&expires_in=(.+)&username=([^&]+)/);if(!p){var u=o.location.href.match(/error=(.+)&error_description=(.+)/);return h({error:u[1],errorMessage:decodeURIComponent(u[2])})}return h(void 0,{token:p[1],expires:new Date(Date.now()+1e3*parseInt(p[2],10)-6e4),username:decodeURIComponent(p[3])})},e.authorize=function(e,r){var n=t({portal:"https://arcgis.com/sharing/rest",duration:20160},e),o=n.portal,s=n.clientId,i=n.duration,a=n.redirectUri;r.writeHead(301,{Location:o+"/oauth2/authorize?client_id="+s+"&duration="+i+"&response_type=code&redirect_uri="+encodeURIComponent(a)}),r.end()},e.exchangeAuthorizationCode=function(r,o){var s=t({portal:"https://www.arcgis.com/sharing/rest",refreshTokenTTL:1440},r),i=s.portal,a=s.clientId,h=s.redirectUri,p=s.refreshTokenTTL;return n(i+"/oauth2/token",{grant_type:"authorization_code",client_id:a,redirect_uri:h,code:o}).then(function(r){return new e({clientId:a,portal:i,redirectUri:h,refreshToken:r.refreshToken,refreshTokenTTL:p,refreshTokenExpires:new Date(Date.now()+1e3*(p-1)),token:r.token,tokenExpires:r.expires,username:r.username})})},e.deserialize=function(r){var t=JSON.parse(r);return new e({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,tokenDuration:t.tokenDuration,redirectUri:t.redirectUri,refreshTokenTTL:t.refreshTokenTTL})},e.fromCredential=function(r){return new e({portal:r.server+"/sharing/rest",token:r.token,username:r.userId,tokenExpires:new Date(r.expires)})},e.prototype.toCredential=function(){return{expires:this.tokenExpires.getTime(),server:this.portal,ssl:!0,token:this.token,userId:this.username}},e.prototype.getUser=function(e){var n=this;if(this._user&&this._user.username===this.username)return Promise.resolve(this._user);var o=this.portal+"/community/users/"+encodeURIComponent(this.username),s=t({httpMethod:"GET",authentication:this},e);return r.request(o,s).then(function(e){return n._user=e,e})},e.prototype.getToken=function(e,r){return/^https?:\/\/\S+\.arcgis\.com\/sharing\/rest/.test(this.portal)&&/^https?:\/\/\S+\.arcgis\.com.+/.test(e)?this.getFreshToken(r):new RegExp(this.portal).test(e)?this.getFreshToken(r):this.getTokenForServer(e,r)},e.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,tokenDuration:this.tokenDuration,redirectUri:this.redirectUri,refreshTokenTTL:this.refreshTokenTTL}},e.prototype.serialize=function(){return JSON.stringify(this)},e.prototype.refreshSession=function(e){return this.username&&this.password?this.refreshWithUsernameAndPassword(e):this.clientId&&this.refreshToken?this.refreshWithRefreshToken():Promise.reject(new r.ArcGISAuthError("Unable to refresh token."))},e.prototype.getTokenForServer=function(e,t){var n=this,o=e.split("/rest/services/")[0],i=this.trustedServers[o];return i&&i.expires.getTime()>Date.now()?Promise.resolve(i.token):this._pendingTokenRequests[o]?this._pendingTokenRequests[o]:(this._pendingTokenRequests[o]=r.request(o+"/rest/info").then(function(e){return e.owningSystemUrl}).then(function(o){if(!o||!new RegExp(o).test(n.portal))throw new r.ArcGISAuthError(e+" is not federated with "+n.portal+".","NOT_FEDERATED");return r.request(o+"/sharing/rest/info",t)}).then(function(e){return e.authInfo.tokenServicesUrl}).then(function(r){return n.token?s(r,{params:{token:n.token,serverUrl:e,expiration:n.tokenDuration}}):s(r,{params:{username:n.username,password:n.password,expiration:n.tokenDuration}}).then(function(e){return n._token=e.token,n._tokenExpires=new Date(e.expires),e})}).then(function(e){return n.trustedServers[o]={expires:new Date(e.expires),token:e.token},e.token}),this._pendingTokenRequests[o])},e.prototype.getFreshToken=function(e){var r=this;return 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])},e.prototype.refreshWithUsernameAndPassword=function(e){var r=this,n=t({params:{username:this.username,password:this.password,expiration:this.tokenDuration}},e);return s(this.portal+"/generateToken",n).then(function(e){return r._token=e.token,r._tokenExpires=new Date(e.expires),r})},e.prototype.refreshWithRefreshToken=function(e){var r=this;if(this.refreshToken&&this.refreshTokenExpires&&this.refreshTokenExpires.getTime()<Date.now())return this.refreshRefreshToken(e);var o=t({params:{client_id:this.clientId,refresh_token:this.refreshToken,grant_type:"refresh_token"}},e);return n(this.portal+"/oauth2/token",o).then(function(e){return r._token=e.token,r._tokenExpires=e.expires,r})},e.prototype.refreshRefreshToken=function(e){var r=this,o=t({params:{client_id:this.clientId,refresh_token:this.refreshToken,redirect_uri:this.redirectUri,grant_type:"exchange_refresh_token"}},e);return n(this.portal+"/oauth2/token",o).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})},e}();e.ApplicationSession=o,e.UserSession=i,e.fetchToken=n,e.generateToken=s,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.arcgisRest=e.arcgisRest||{},e.arcgisRest)}(this,function(e,r){"use strict";var t=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};function n(e,t){var n=t.params?t:{params:t};return r.request(e,n).then(function(e){var r={token:e.access_token,username:e.username,expires:new Date(Date.now()+(60*e.expires_in*1e3-6e4)),ssl:!0===e.ssl};return e.refresh_token&&(r.refreshToken=e.refresh_token),r})}var s=function(){function e(e){this.clientId=e.clientId,this.clientSecret=e.clientSecret,this.token=e.token,this.expires=e.expires,this.portal="https://www.arcgis.com/sharing/rest"}return e.prototype.getToken=function(e,r){return this.token&&this.expires&&this.expires.getTime()>Date.now()?Promise.resolve(this.token):this._pendingTokenRequest?this._pendingTokenRequest:(this._pendingTokenRequest=this.refreshToken(r),this._pendingTokenRequest)},e.prototype.refreshToken=function(e){var r=this,s=t({params:{client_id:this.clientId,client_secret:this.clientSecret,grant_type:"client_credentials"}},e);return n(this.portal+"/oauth2/token/",s).then(function(e){return r._pendingTokenRequest=null,r.token=e.token,r.expires=e.expires,e.token})},e.prototype.refreshSession=function(){var e=this;return this.refreshToken().then(function(){return e})},e}();function o(e,t){var n=t.params?t:{params:t};return"undefined"!=typeof window&&window.location&&window.location.host?n.params.referer=window.location.host:n.params.referer="@esri.arcgis-rest-auth",r.request(e,n)}var i=function(){function e(e){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||"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={},this._pendingTokenRequests={}}return Object.defineProperty(e.prototype,"token",{get:function(){return this._token},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"tokenExpires",{get:function(){return this._tokenExpires},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"refreshToken",{get:function(){return this._refreshToken},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"refreshTokenExpires",{get:function(){return this._refreshTokenExpires},enumerable:!0,configurable:!0}),e.beginOAuth2=function(n,s){void 0===s&&(s=window);var o,i=t({portal:"https://www.arcgis.com/sharing/rest",provider:"arcgis",duration:20160,popup:!0,state:n.clientId,locale:""},n),a=i.portal,h=i.provider,p=i.clientId,u=i.duration,c=i.redirectUri,f=i.popup,k=i.state,l=i.locale;if(o="arcgis"===h?a+"/oauth2/authorize?client_id="+p+"&response_type=token&expiration="+u+"&redirect_uri="+encodeURIComponent(c)+"&state="+k+"&locale="+l:a+"/oauth2/social/authorize?client_id="+p+"&socialLoginProviderName="+h+"&autoAccountCreateForSocial=true&response_type=token&expiration="+u+"&redirect_uri="+encodeURIComponent(c)+"&state="+k+"&locale="+l,f){var d,T=((d={promise:null,resolve:null,reject:null}).promise=new Promise(function(e,r){d.resolve=e,d.reject=r}),d);return s["__ESRI_REST_AUTH_HANDLER_"+p]=function(t,n){if(t){var s=JSON.parse(t);T.reject(new r.ArcGISAuthError(s.errorMessage,s.error))}else if(n){var o=JSON.parse(n);T.resolve(new e({clientId:p,portal:a,ssl:o.ssl,token:o.token,tokenExpires:new Date(o.expires),username:o.username}))}},s.open(o,"oauth-window","height=400,width=600,menubar=no,location=yes,resizable=yes,scrollbars=yes,status=yes"),T.promise}s.location.href=o},e.completeOAuth2=function(n,s){void 0===s&&(s=window);var o=t({portal:"https://www.arcgis.com/sharing/rest"},n),i=o.portal,a=o.clientId;function h(t,n){if(s.opener&&s.opener.parent)return s.opener.parent["__ESRI_REST_AUTH_HANDLER_"+a](t?JSON.stringify(t):void 0,JSON.stringify(n)),void s.close();if(s!==s.parent)return s.parent["__ESRI_REST_AUTH_HANDLER_"+a](t?JSON.stringify(t):void 0,JSON.stringify(n)),void s.close();if(t)throw new r.ArcGISAuthError(t.errorMessage,t.error);return new e({clientId:a,portal:i,ssl:n.ssl,token:n.token,tokenExpires:n.expires,username:n.username})}var p=s.location.href.match(/access_token=(.+)&expires_in=(.+)&username=([^&]+)/);if(!p){var u=s.location.href.match(/error=(.+)&error_description=(.+)/);return h({error:u[1],errorMessage:decodeURIComponent(u[2])})}var c=p[1],f=new Date(Date.now()+1e3*parseInt(p[2],10)-6e4),k=decodeURIComponent(p[3]);return h(void 0,{token:c,expires:f,ssl:s.location.href.indexOf("&ssl=true")>-1||s.location.href.indexOf("#ssl=true")>-1,username:k})},e.authorize=function(e,r){var n=t({portal:"https://arcgis.com/sharing/rest",duration:20160},e),s=n.portal,o=n.clientId,i=n.duration,a=n.redirectUri;r.writeHead(301,{Location:s+"/oauth2/authorize?client_id="+o+"&duration="+i+"&response_type=code&redirect_uri="+encodeURIComponent(a)}),r.end()},e.exchangeAuthorizationCode=function(r,s){var o=t({portal:"https://www.arcgis.com/sharing/rest",refreshTokenTTL:1440},r),i=o.portal,a=o.clientId,h=o.redirectUri,p=o.refreshTokenTTL;return n(i+"/oauth2/token",{grant_type:"authorization_code",client_id:a,redirect_uri:h,code:s}).then(function(r){return new e({clientId:a,portal:i,ssl:r.ssl,redirectUri:h,refreshToken:r.refreshToken,refreshTokenTTL:p,refreshTokenExpires:new Date(Date.now()+1e3*(p-1)),token:r.token,tokenExpires:r.expires,username:r.username})})},e.deserialize=function(r){var t=JSON.parse(r);return new e({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})},e.fromCredential=function(r){return new e({portal:r.server+"/sharing/rest",ssl:r.ssl,token:r.token,username:r.userId,tokenExpires:new Date(r.expires)})},e.prototype.toCredential=function(){return{expires:this.tokenExpires.getTime(),server:this.portal,ssl:this.ssl,token:this.token,userId:this.username}},e.prototype.getUser=function(e){var n=this;if(this._user&&this._user.username===this.username)return Promise.resolve(this._user);var s=this.portal+"/community/users/"+encodeURIComponent(this.username),o=t({httpMethod:"GET",authentication:this},e);return r.request(s,o).then(function(e){return n._user=e,e})},e.prototype.getToken=function(e,r){return/^https?:\/\/\S+\.arcgis\.com\/sharing\/rest/.test(this.portal)&&/^https?:\/\/\S+\.arcgis\.com.+/.test(e)?this.getFreshToken(r):new RegExp(this.portal).test(e)?this.getFreshToken(r):this.getTokenForServer(e,r)},e.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}},e.prototype.serialize=function(){return JSON.stringify(this)},e.prototype.refreshSession=function(e){return this.username&&this.password?this.refreshWithUsernameAndPassword(e):this.clientId&&this.refreshToken?this.refreshWithRefreshToken():Promise.reject(new r.ArcGISAuthError("Unable to refresh token."))},e.prototype.getTokenForServer=function(e,t){var n=this,s=e.split(/\/rest(\/admin)?\/services\//)[0],i=this.trustedServers[s];return i&&i.expires.getTime()>Date.now()?Promise.resolve(i.token):this._pendingTokenRequests[s]?this._pendingTokenRequests[s]:(this._pendingTokenRequests[s]=r.request(s+"/rest/info").then(function(e){return e.owningSystemUrl}).then(function(s){if(!s||!new RegExp(s).test(n.portal))throw new r.ArcGISAuthError(e+" is not federated with "+n.portal+".","NOT_FEDERATED");return r.request(s+"/sharing/rest/info",t)}).then(function(e){return e.authInfo.tokenServicesUrl}).then(function(r){return n.token?o(r,{params:{token:n.token,serverUrl:e,expiration:n.tokenDuration}}):o(r,{params:{username:n.username,password:n.password,expiration:n.tokenDuration}}).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},e.token}),this._pendingTokenRequests[s])},e.prototype.getFreshToken=function(e){var r=this;return 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])},e.prototype.refreshWithUsernameAndPassword=function(e){var r=this,n=t({params:{username:this.username,password:this.password,expiration:this.tokenDuration}},e);return o(this.portal+"/generateToken",n).then(function(e){return r._token=e.token,r._tokenExpires=new Date(e.expires),r})},e.prototype.refreshWithRefreshToken=function(e){var r=this;if(this.refreshToken&&this.refreshTokenExpires&&this.refreshTokenExpires.getTime()<Date.now())return this.refreshRefreshToken(e);var s=t({params:{client_id:this.clientId,refresh_token:this.refreshToken,grant_type:"refresh_token"}},e);return n(this.portal+"/oauth2/token",s).then(function(e){return r._token=e.token,r._tokenExpires=e.expires,r})},e.prototype.refreshRefreshToken=function(e){var r=this,s=t({params:{client_id:this.clientId,refresh_token:this.refreshToken,redirect_uri:this.redirectUri,grant_type:"exchange_refresh_token"}},e);return n(this.portal+"/oauth2/token",s).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})},e}();e.ApplicationSession=s,e.UserSession=i,e.fetchToken=n,e.generateToken=o,Object.defineProperty(e,"__esModule",{value:!0})});
//# sourceMappingURL=auth.umd.min.js.map
{
"name": "@esri/arcgis-rest-auth",
"version": "1.11.0",
"version": "1.11.1",
"description": "Authentication helpers for @esri/arcgis-rest-*.",

@@ -22,4 +22,4 @@ "main": "dist/node/index.js",

"devDependencies": {
"@esri/arcgis-rest-common-types": "^1.11.0",
"@esri/arcgis-rest-request": "^1.11.0"
"@esri/arcgis-rest-common-types": "^1.11.1",
"@esri/arcgis-rest-request": "^1.11.1"
},

@@ -26,0 +26,0 @@ "scripts": {

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

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

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