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
16
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.3.0 to 1.4.0

27

dist/esm/UserSession.d.ts
/// <reference types="node" />
import * as http from "http";
import { IAuthenticationManager } from "@esri/arcgis-rest-request";
import { IUser } from "@esri/arcgis-rest-common-types";
/**

@@ -105,2 +106,8 @@ * Options for static OAuth 2.0 helper methods on `UserSession`.

/**
* ```js
* const session = new UserSession({
* username: "jsmith",
* password: "123456"
* })
* ```
* Used to manage the authentication of ArcGIS Online and ArcGIS Enterprise users

@@ -110,2 +117,3 @@ * in `request`. This class also includes several

* server applications.
*
*/

@@ -141,2 +149,6 @@ export declare class UserSession implements IAuthenticationManager {

readonly refreshTokenTTL: number;
/**
* Hydrated by a call to [getUser()](#getUser-summary).
*/
_user: IUser;
private _token;

@@ -205,3 +217,16 @@ private _tokenExpires;

/**
* Gets a appropriate token for the given URL. If `portal` is ArcGIS Online and
* Returns information about the currently logged in [user](https://developers.arcgis.com/rest/users-groups-and-items/user.htm). Subsequent calls will *not* result in additional web traffic.
*
* ```js
* session.getUser()
* .then(response => {
* console.log(response.role); // "org_admin"
* })
* ```
*
* @returns A Promise that will resolve with the data from the response.
*/
getUser(): Promise<IUser>;
/**
* Gets an appropriate token for the given URL. If `portal` is ArcGIS Online and
* the request is to an ArcGIS Online domain `token` will be used. If the request

@@ -208,0 +233,0 @@ * is to the current `portal` the current `token` will also be used. However if

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

/**
* ```js
* const session = new UserSession({
* username: "jsmith",
* password: "123456"
* })
* ```
* Used to manage the authentication of ArcGIS Online and ArcGIS Enterprise users

@@ -25,2 +31,3 @@ * in `request`. This class also includes several

* server applications.
*
*/

@@ -236,3 +243,31 @@ var UserSession = /** @class */ (function () {

/**
* Gets a appropriate token for the given URL. If `portal` is ArcGIS Online and
* Returns information about the currently logged in [user](https://developers.arcgis.com/rest/users-groups-and-items/user.htm). Subsequent calls will *not* result in additional web traffic.
*
* ```js
* session.getUser()
* .then(response => {
* console.log(response.role); // "org_admin"
* })
* ```
*
* @returns A Promise that will resolve with the data from the response.
*/
UserSession.prototype.getUser = function () {
var _this = this;
if (this._user && this._user.username === this.username) {
return new Promise(function (resolve) { return resolve(_this._user); });
}
else {
var url = this.portal + "/community/users/" + encodeURIComponent(this.username);
return request(url, {
httpMethod: "GET",
authentication: this
}).then(function (response) {
_this._user = response;
return response;
});
}
};
/**
* Gets an appropriate token for the given URL. If `portal` is ArcGIS Online and
* the request is to an ArcGIS Online domain `token` will be used. If the request

@@ -239,0 +274,0 @@ * is to the current `portal` the current `token` will also be used. However if

@@ -22,2 +22,8 @@ "use strict";

/**
* ```js
* const session = new UserSession({
* username: "jsmith",
* password: "123456"
* })
* ```
* Used to manage the authentication of ArcGIS Online and ArcGIS Enterprise users

@@ -27,2 +33,3 @@ * in `request`. This class also includes several

* server applications.
*
*/

@@ -238,3 +245,31 @@ var UserSession = /** @class */ (function () {

/**
* Gets a appropriate token for the given URL. If `portal` is ArcGIS Online and
* Returns information about the currently logged in [user](https://developers.arcgis.com/rest/users-groups-and-items/user.htm). Subsequent calls will *not* result in additional web traffic.
*
* ```js
* session.getUser()
* .then(response => {
* console.log(response.role); // "org_admin"
* })
* ```
*
* @returns A Promise that will resolve with the data from the response.
*/
UserSession.prototype.getUser = function () {
var _this = this;
if (this._user && this._user.username === this.username) {
return new Promise(function (resolve) { return resolve(_this._user); });
}
else {
var url = this.portal + "/community/users/" + encodeURIComponent(this.username);
return arcgis_rest_request_1.request(url, {
httpMethod: "GET",
authentication: this
}).then(function (response) {
_this._user = response;
return response;
});
}
};
/**
* Gets an appropriate token for the given URL. If `portal` is ArcGIS Online and
* the request is to an ArcGIS Online domain `token` will be used. If the request

@@ -241,0 +276,0 @@ * is to the current `portal` the current `token` will also be used. However if

/* @preserve
* @esri/arcgis-rest-auth - v1.3.0 - Wed May 23 2018 11:30:39 GMT-0700 (PDT)
* @esri/arcgis-rest-auth - v1.4.0 - Wed Jun 06 2018 09:52:03 GMT-0700 (PDT)
* Copyright (c) 2017 - 2018 Environmental Systems Research Institute, Inc.

@@ -127,2 +127,8 @@ * Apache-2.0

/**
* ```js
* const session = new UserSession({
* username: "jsmith",
* password: "123456"
* })
* ```
* Used to manage the authentication of ArcGIS Online and ArcGIS Enterprise users

@@ -132,2 +138,3 @@ * in `request`. This class also includes several

* server applications.
*
*/

@@ -343,3 +350,31 @@ var UserSession = /** @class */ (function () {

/**
* Gets a appropriate token for the given URL. If `portal` is ArcGIS Online and
* Returns information about the currently logged in [user](https://developers.arcgis.com/rest/users-groups-and-items/user.htm). Subsequent calls will *not* result in additional web traffic.
*
* ```js
* session.getUser()
* .then(response => {
* console.log(response.role); // "org_admin"
* })
* ```
*
* @returns A Promise that will resolve with the data from the response.
*/
UserSession.prototype.getUser = function () {
var _this = this;
if (this._user && this._user.username === this.username) {
return new Promise(function (resolve) { return resolve(_this._user); });
}
else {
var url = this.portal + "/community/users/" + encodeURIComponent(this.username);
return arcgisRestRequest.request(url, {
httpMethod: "GET",
authentication: this
}).then(function (response) {
_this._user = response;
return response;
});
}
};
/**
* Gets an appropriate token for the given URL. If `portal` is ArcGIS Online and
* the request is to an ArcGIS Online domain `token` will be used. If the request

@@ -346,0 +381,0 @@ * is to the current `portal` the current `token` will also be used. However if

4

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

@@ -18,6 +18,8 @@ "main": "dist/node/index.js",

"peerDependencies": {
"@esri/arcgis-common-types": "^1.2.1",
"@esri/arcgis-rest-request": "^1.2.1"
},
"devDependencies": {
"@esri/arcgis-rest-request": "^1.3.0"
"@esri/arcgis-rest-common-types": "^1.4.0",
"@esri/arcgis-rest-request": "^1.4.0"
},

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

@@ -50,3 +50,3 @@ [![npm version][npm-img]][npm-url]

Copyright 2017 Esri
Copyright &copy; 2017-2018 Esri

@@ -53,0 +53,0 @@ Licensed under the Apache License, Version 2.0 (the "License");

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