@esri/arcgis-rest-auth
Advanced tools
Comparing version 1.16.1 to 1.17.0
@@ -10,2 +10,4 @@ /* Copyright (c) 2017 Environmental Systems Research Institute, Inc. | ||
: { params: requestOptions }; | ||
// we generate a response, so we can't return the raw response | ||
options.rawResponse = false; | ||
return request(url, options).then(function (response) { | ||
@@ -12,0 +14,0 @@ var r = { |
/// <reference types="node" /> | ||
/** | ||
* /generateToken returns a token that cannot be refreshed. | ||
* | ||
* oauth2/token can return a token *and* a refreshToken. | ||
* up until the refreshToken expires, you can use it (and a clientId) | ||
* to fetch fresh credentials without a username and password. | ||
* | ||
* the catch is that this 'authorization_code' flow is only utilized | ||
* by server based OAuth 2 Node.js applications that call /authorize first. | ||
*/ | ||
import * as http from "http"; | ||
@@ -56,2 +66,6 @@ import { IRequestOptions, IAuthenticationManager, ITokenRequestOptions } from "@esri/arcgis-rest-request"; | ||
/** | ||
* An unfederated ArcGIS Server instance that recognizes the supplied credentials. | ||
*/ | ||
server?: string; | ||
/** | ||
* The locale assumed to render the login page. | ||
@@ -128,2 +142,6 @@ * | ||
refreshTokenTTL?: number; | ||
/** | ||
* An unfederated ArcGIS Server instance that recognizes the supplied credentials. | ||
*/ | ||
server?: string; | ||
} | ||
@@ -229,2 +247,6 @@ /** | ||
/** | ||
* An unfederated ArcGIS Server instance that recognizes the supplied credentials. | ||
*/ | ||
readonly server: string; | ||
/** | ||
* Hydrated by a call to [getUser()](#getUser-summary). | ||
@@ -284,2 +306,3 @@ */ | ||
* | ||
* @param requestOptions - Options for the request. NOTE: `rawResponse` is not supported by this operation. | ||
* @returns A Promise that will resolve with the data from the response. | ||
@@ -321,3 +344,3 @@ */ | ||
/** | ||
* Exchanges an expired `refreshToken` for a new one also updates `token` and | ||
* Exchanges an unexpired `refreshToken` for a new one, also updates `token` and | ||
* `tokenExpires`. | ||
@@ -324,0 +347,0 @@ */ |
@@ -1,2 +0,2 @@ | ||
/* Copyright (c) 2017-2018 Environmental Systems Research Institute, Inc. | ||
/* Copyright (c) 2017-2019 Environmental Systems Research Institute, Inc. | ||
* Apache-2.0 */ | ||
@@ -54,2 +54,13 @@ import * as tslib_1 from "tslib"; | ||
this.trustedServers = {}; | ||
// if a non-federated server was passed explicitly, it should be trusted. | ||
if (options.server) { | ||
// if the url includes more than '/arcgis/', trim the rest | ||
var serverRoot = options.server | ||
.toLowerCase() | ||
.split(/\/rest(\/admin)?\/services\//)[0]; | ||
this.trustedServers[serverRoot] = { | ||
token: options.token, | ||
expires: options.tokenExpires | ||
}; | ||
} | ||
this._pendingTokenRequests = {}; | ||
@@ -313,2 +324,3 @@ } | ||
* | ||
* @param requestOptions - Options for the request. NOTE: `rawResponse` is not supported by this operation. | ||
* @returns A Promise that will resolve with the data from the response. | ||
@@ -323,3 +335,3 @@ */ | ||
var url = this.portal + "/community/users/" + encodeURIComponent(this.username); | ||
var options = tslib_1.__assign({ httpMethod: "GET", authentication: this }, requestOptions); | ||
var options = tslib_1.__assign({ httpMethod: "GET", authentication: this }, requestOptions, { rawResponse: false }); | ||
return request(url, options).then(function (response) { | ||
@@ -393,3 +405,5 @@ _this._user = response; | ||
var existingToken = this.trustedServers[root]; | ||
if (existingToken && existingToken.expires.getTime() > Date.now()) { | ||
if (existingToken && | ||
existingToken.expires && | ||
existingToken.expires.getTime() > Date.now()) { | ||
return Promise.resolve(existingToken.token); | ||
@@ -402,16 +416,29 @@ } | ||
.then(function (response) { | ||
return response.owningSystemUrl; | ||
}) | ||
.then(function (owningSystemUrl) { | ||
/** | ||
* if this server is not owned by this portal or the stand-alone | ||
* instance of ArcGIS Server doesn't advertise federation, | ||
* bail out with an error since we know we wont | ||
* be able to generate a token | ||
*/ | ||
if (!owningSystemUrl || | ||
!new RegExp(owningSystemUrl, "i").test(_this.portal)) { | ||
throw new ArcGISAuthError(url + " is not federated with " + _this.portal + ".", "NOT_FEDERATED"); | ||
if (response.owningSystemUrl) { | ||
/** | ||
* if this server is not owned by this portal | ||
* bail out with an error since we know we wont | ||
* be able to generate a token | ||
*/ | ||
if (!new RegExp(response.owningSystemUrl, "i").test(_this.portal)) { | ||
throw new ArcGISAuthError(url + " is not federated with " + _this.portal + ".", "NOT_FEDERATED"); | ||
} | ||
else { | ||
/** | ||
* if the server is federated, use the relevant token endpoint. | ||
*/ | ||
return request(response.owningSystemUrl + "/sharing/rest/info", requestOptions); | ||
} | ||
} | ||
return request(owningSystemUrl + "/sharing/rest/info", requestOptions); | ||
else if (response.authInfo && | ||
_this.trustedServers[root] !== undefined) { | ||
/** | ||
* if its a stand-alone instance of ArcGIS Server that doesn't advertise | ||
* federation, but the root server url is recognized, use its built in token endpoint. | ||
*/ | ||
return Promise.resolve({ authInfo: response.authInfo }); | ||
} | ||
else { | ||
throw new ArcGISAuthError(url + " is not federated with any portal and is not explicitly trusted.", "NOT_FEDERATED"); | ||
} | ||
}) | ||
@@ -422,3 +449,4 @@ .then(function (response) { | ||
.then(function (tokenServicesUrl) { | ||
if (_this.token) { | ||
// an expired token cant be used to generate a new token | ||
if (_this.token && _this.tokenExpires.getTime() > Date.now()) { | ||
return generateToken(tokenServicesUrl, { | ||
@@ -428,3 +456,4 @@ params: { | ||
serverUrl: url, | ||
expiration: _this.tokenDuration | ||
expiration: _this.tokenDuration, | ||
client: "referer" | ||
} | ||
@@ -439,3 +468,4 @@ }); | ||
password: _this.password, | ||
expiration: _this.tokenDuration | ||
expiration: _this.tokenDuration, | ||
client: "referer" | ||
} | ||
@@ -515,3 +545,3 @@ }).then(function (response) { | ||
/** | ||
* Exchanges an expired `refreshToken` for a new one also updates `token` and | ||
* Exchanges an unexpired `refreshToken` for a new one, also updates `token` and | ||
* `tokenExpires`. | ||
@@ -518,0 +548,0 @@ */ |
@@ -12,2 +12,4 @@ "use strict"; | ||
: { params: requestOptions }; | ||
// we generate a response, so we can't return the raw response | ||
options.rawResponse = false; | ||
return arcgis_rest_request_1.request(url, options).then(function (response) { | ||
@@ -14,0 +16,0 @@ var r = { |
"use strict"; | ||
/* Copyright (c) 2017-2018 Environmental Systems Research Institute, Inc. | ||
/* Copyright (c) 2017-2019 Environmental Systems Research Institute, Inc. | ||
* Apache-2.0 */ | ||
@@ -56,2 +56,13 @@ Object.defineProperty(exports, "__esModule", { value: true }); | ||
this.trustedServers = {}; | ||
// if a non-federated server was passed explicitly, it should be trusted. | ||
if (options.server) { | ||
// if the url includes more than '/arcgis/', trim the rest | ||
var serverRoot = options.server | ||
.toLowerCase() | ||
.split(/\/rest(\/admin)?\/services\//)[0]; | ||
this.trustedServers[serverRoot] = { | ||
token: options.token, | ||
expires: options.tokenExpires | ||
}; | ||
} | ||
this._pendingTokenRequests = {}; | ||
@@ -315,2 +326,3 @@ } | ||
* | ||
* @param requestOptions - Options for the request. NOTE: `rawResponse` is not supported by this operation. | ||
* @returns A Promise that will resolve with the data from the response. | ||
@@ -325,3 +337,3 @@ */ | ||
var url = this.portal + "/community/users/" + encodeURIComponent(this.username); | ||
var options = tslib_1.__assign({ httpMethod: "GET", authentication: this }, requestOptions); | ||
var options = tslib_1.__assign({ httpMethod: "GET", authentication: this }, requestOptions, { rawResponse: false }); | ||
return arcgis_rest_request_1.request(url, options).then(function (response) { | ||
@@ -395,3 +407,5 @@ _this._user = response; | ||
var existingToken = this.trustedServers[root]; | ||
if (existingToken && existingToken.expires.getTime() > Date.now()) { | ||
if (existingToken && | ||
existingToken.expires && | ||
existingToken.expires.getTime() > Date.now()) { | ||
return Promise.resolve(existingToken.token); | ||
@@ -404,16 +418,29 @@ } | ||
.then(function (response) { | ||
return response.owningSystemUrl; | ||
}) | ||
.then(function (owningSystemUrl) { | ||
/** | ||
* if this server is not owned by this portal or the stand-alone | ||
* instance of ArcGIS Server doesn't advertise federation, | ||
* bail out with an error since we know we wont | ||
* be able to generate a token | ||
*/ | ||
if (!owningSystemUrl || | ||
!new RegExp(owningSystemUrl, "i").test(_this.portal)) { | ||
throw new arcgis_rest_request_1.ArcGISAuthError(url + " is not federated with " + _this.portal + ".", "NOT_FEDERATED"); | ||
if (response.owningSystemUrl) { | ||
/** | ||
* if this server is not owned by this portal | ||
* bail out with an error since we know we wont | ||
* be able to generate a token | ||
*/ | ||
if (!new RegExp(response.owningSystemUrl, "i").test(_this.portal)) { | ||
throw new arcgis_rest_request_1.ArcGISAuthError(url + " is not federated with " + _this.portal + ".", "NOT_FEDERATED"); | ||
} | ||
else { | ||
/** | ||
* if the server is federated, use the relevant token endpoint. | ||
*/ | ||
return arcgis_rest_request_1.request(response.owningSystemUrl + "/sharing/rest/info", requestOptions); | ||
} | ||
} | ||
return arcgis_rest_request_1.request(owningSystemUrl + "/sharing/rest/info", requestOptions); | ||
else if (response.authInfo && | ||
_this.trustedServers[root] !== undefined) { | ||
/** | ||
* if its a stand-alone instance of ArcGIS Server that doesn't advertise | ||
* federation, but the root server url is recognized, use its built in token endpoint. | ||
*/ | ||
return Promise.resolve({ authInfo: response.authInfo }); | ||
} | ||
else { | ||
throw new arcgis_rest_request_1.ArcGISAuthError(url + " is not federated with any portal and is not explicitly trusted.", "NOT_FEDERATED"); | ||
} | ||
}) | ||
@@ -424,3 +451,4 @@ .then(function (response) { | ||
.then(function (tokenServicesUrl) { | ||
if (_this.token) { | ||
// an expired token cant be used to generate a new token | ||
if (_this.token && _this.tokenExpires.getTime() > Date.now()) { | ||
return generate_token_1.generateToken(tokenServicesUrl, { | ||
@@ -430,3 +458,4 @@ params: { | ||
serverUrl: url, | ||
expiration: _this.tokenDuration | ||
expiration: _this.tokenDuration, | ||
client: "referer" | ||
} | ||
@@ -441,3 +470,4 @@ }); | ||
password: _this.password, | ||
expiration: _this.tokenDuration | ||
expiration: _this.tokenDuration, | ||
client: "referer" | ||
} | ||
@@ -517,3 +547,3 @@ }).then(function (response) { | ||
/** | ||
* Exchanges an expired `refreshToken` for a new one also updates `token` and | ||
* Exchanges an unexpired `refreshToken` for a new one, also updates `token` and | ||
* `tokenExpires`. | ||
@@ -520,0 +550,0 @@ */ |
/* @preserve | ||
* @esri/arcgis-rest-auth - v1.16.1 - Apache-2.0 | ||
* @esri/arcgis-rest-auth - v1.17.0 - Apache-2.0 | ||
* Copyright (c) 2017-2019 Esri, Inc. | ||
* Wed Jan 30 2019 11:33:15 GMT-0800 (Pacific Standard Time) | ||
* Mon Feb 25 2019 11:04:46 GMT-0800 (Pacific Standard Time) | ||
*/ | ||
@@ -46,2 +46,4 @@ (function (global, factory) { | ||
: { params: requestOptions }; | ||
// we generate a response, so we can't return the raw response | ||
options.rawResponse = false; | ||
return arcgisRestRequest.request(url, options).then(function (response) { | ||
@@ -139,3 +141,3 @@ var r = { | ||
/* Copyright (c) 2017-2018 Environmental Systems Research Institute, Inc. | ||
/* Copyright (c) 2017-2019 Environmental Systems Research Institute, Inc. | ||
* Apache-2.0 */ | ||
@@ -189,2 +191,13 @@ function defer() { | ||
this.trustedServers = {}; | ||
// if a non-federated server was passed explicitly, it should be trusted. | ||
if (options.server) { | ||
// if the url includes more than '/arcgis/', trim the rest | ||
var serverRoot = options.server | ||
.toLowerCase() | ||
.split(/\/rest(\/admin)?\/services\//)[0]; | ||
this.trustedServers[serverRoot] = { | ||
token: options.token, | ||
expires: options.tokenExpires | ||
}; | ||
} | ||
this._pendingTokenRequests = {}; | ||
@@ -448,2 +461,3 @@ } | ||
* | ||
* @param requestOptions - Options for the request. NOTE: `rawResponse` is not supported by this operation. | ||
* @returns A Promise that will resolve with the data from the response. | ||
@@ -458,3 +472,3 @@ */ | ||
var url = this.portal + "/community/users/" + encodeURIComponent(this.username); | ||
var options = __assign({ httpMethod: "GET", authentication: this }, requestOptions); | ||
var options = __assign({ httpMethod: "GET", authentication: this }, requestOptions, { rawResponse: false }); | ||
return arcgisRestRequest.request(url, options).then(function (response) { | ||
@@ -528,3 +542,5 @@ _this._user = response; | ||
var existingToken = this.trustedServers[root]; | ||
if (existingToken && existingToken.expires.getTime() > Date.now()) { | ||
if (existingToken && | ||
existingToken.expires && | ||
existingToken.expires.getTime() > Date.now()) { | ||
return Promise.resolve(existingToken.token); | ||
@@ -537,16 +553,29 @@ } | ||
.then(function (response) { | ||
return response.owningSystemUrl; | ||
}) | ||
.then(function (owningSystemUrl) { | ||
/** | ||
* if this server is not owned by this portal or the stand-alone | ||
* instance of ArcGIS Server doesn't advertise federation, | ||
* bail out with an error since we know we wont | ||
* be able to generate a token | ||
*/ | ||
if (!owningSystemUrl || | ||
!new RegExp(owningSystemUrl, "i").test(_this.portal)) { | ||
throw new arcgisRestRequest.ArcGISAuthError(url + " is not federated with " + _this.portal + ".", "NOT_FEDERATED"); | ||
if (response.owningSystemUrl) { | ||
/** | ||
* if this server is not owned by this portal | ||
* bail out with an error since we know we wont | ||
* be able to generate a token | ||
*/ | ||
if (!new RegExp(response.owningSystemUrl, "i").test(_this.portal)) { | ||
throw new arcgisRestRequest.ArcGISAuthError(url + " is not federated with " + _this.portal + ".", "NOT_FEDERATED"); | ||
} | ||
else { | ||
/** | ||
* if the server is federated, use the relevant token endpoint. | ||
*/ | ||
return arcgisRestRequest.request(response.owningSystemUrl + "/sharing/rest/info", requestOptions); | ||
} | ||
} | ||
return arcgisRestRequest.request(owningSystemUrl + "/sharing/rest/info", requestOptions); | ||
else if (response.authInfo && | ||
_this.trustedServers[root] !== undefined) { | ||
/** | ||
* if its a stand-alone instance of ArcGIS Server that doesn't advertise | ||
* federation, but the root server url is recognized, use its built in token endpoint. | ||
*/ | ||
return Promise.resolve({ authInfo: response.authInfo }); | ||
} | ||
else { | ||
throw new arcgisRestRequest.ArcGISAuthError(url + " is not federated with any portal and is not explicitly trusted.", "NOT_FEDERATED"); | ||
} | ||
}) | ||
@@ -557,3 +586,4 @@ .then(function (response) { | ||
.then(function (tokenServicesUrl) { | ||
if (_this.token) { | ||
// an expired token cant be used to generate a new token | ||
if (_this.token && _this.tokenExpires.getTime() > Date.now()) { | ||
return generateToken(tokenServicesUrl, { | ||
@@ -563,3 +593,4 @@ params: { | ||
serverUrl: url, | ||
expiration: _this.tokenDuration | ||
expiration: _this.tokenDuration, | ||
client: "referer" | ||
} | ||
@@ -574,3 +605,4 @@ }); | ||
password: _this.password, | ||
expiration: _this.tokenDuration | ||
expiration: _this.tokenDuration, | ||
client: "referer" | ||
} | ||
@@ -650,3 +682,3 @@ }).then(function (response) { | ||
/** | ||
* Exchanges an expired `refreshToken` for a new one also updates `token` and | ||
* Exchanges an unexpired `refreshToken` for a new one, also updates `token` and | ||
* `tokenExpires`. | ||
@@ -653,0 +685,0 @@ */ |
/* @preserve | ||
* @esri/arcgis-rest-auth - v1.16.1 - Apache-2.0 | ||
* @esri/arcgis-rest-auth - v1.17.0 - Apache-2.0 | ||
* Copyright (c) 2017-2019 Esri, Inc. | ||
* Wed Jan 30 2019 11:33:21 GMT-0800 (Pacific Standard Time) | ||
* Mon Feb 25 2019 11:04:49 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.arcgisRest=e.arcgisRest||{},e.arcgisRest)}(this,function(e,r){"use strict";var t=function(){return(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}).apply(this,arguments)};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()+(1e3*e.expires_in-1e3)),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=e.portal||"https://www.arcgis.com/sharing/rest",this.duration=e.duration||7200}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",expiration:this.duration}},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=r.NODEJS_DEFAULT_REFERER_HEADER,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?r.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={},this._pendingTokenRequests={}}return 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,l=i.state,k=i.locale;if(o="arcgis"===h?a+"/oauth2/authorize?client_id="+p+"&response_type=token&expiration="+u+"&redirect_uri="+encodeURIComponent(c)+"&state="+l+"&locale="+k:a+"/oauth2/social/authorize?client_id="+p+"&socialLoginProviderName="+h+"&autoAccountCreateForSocial=true&response_type=token&expiration="+u+"&redirect_uri="+encodeURIComponent(c)+"&state="+l+"&locale="+k,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),l=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:l})},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.includes("sharing/rest")?r.server:r.server+"/sharing/rest",ssl:r.ssl,token:r.token,username:r.userId,tokenExpires:new Date(r.expires)})},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.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,"i").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._user=null,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.toLowerCase().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,"i").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})}); | ||
!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=function(){return(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}).apply(this,arguments)};function n(e,t){var n=t.params?t:{params:t};return n.rawResponse=!1,r.request(e,n).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 s=function(){function e(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}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",expiration:this.duration}},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=r.NODEJS_DEFAULT_REFERER_HEADER,r.request(e,n)}var i=function(){function e(e){if(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?r.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){var t=e.server.toLowerCase().split(/\/rest(\/admin)?\/services\//)[0];this.trustedServers[t]={token:e.token,expires:e.tokenExpires}}this._pendingTokenRequests={}}return 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,l=i.state,k=i.locale;if(o="arcgis"===h?a+"/oauth2/authorize?client_id="+p+"&response_type=token&expiration="+u+"&redirect_uri="+encodeURIComponent(c)+"&state="+l+"&locale="+k:a+"/oauth2/social/authorize?client_id="+p+"&socialLoginProviderName="+h+"&autoAccountCreateForSocial=true&response_type=token&expiration="+u+"&redirect_uri="+encodeURIComponent(c)+"&state="+l+"&locale="+k,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),l=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:l})},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.includes("sharing/rest")?r.server:r.server+"/sharing/rest",ssl:r.ssl,token:r.token,username:r.userId,tokenExpires:new Date(r.expires)})},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.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,{rawResponse:!1});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,"i").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._user=null,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.toLowerCase().split(/\/rest(\/admin)?\/services\//)[0],i=this.trustedServers[s];return i&&i.expires&&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(o){if(o.owningSystemUrl){if(new RegExp(o.owningSystemUrl,"i").test(n.portal))return r.request(o.owningSystemUrl+"/sharing/rest/info",t);throw new r.ArcGISAuthError(e+" is not federated with "+n.portal+".","NOT_FEDERATED")}if(o.authInfo&&void 0!==n.trustedServers[s])return Promise.resolve({authInfo:o.authInfo});throw new r.ArcGISAuthError(e+" is not federated with any portal and is not explicitly trusted.","NOT_FEDERATED")}).then(function(e){return e.authInfo.tokenServicesUrl}).then(function(r){return n.token&&n.tokenExpires.getTime()>Date.now()?o(r,{params:{token:n.token,serverUrl:e,expiration:n.tokenDuration,client:"referer"}}):o(r,{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},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.16.1", | ||
"version": "1.17.0", | ||
"description": "Authentication helpers for @esri/arcgis-rest-js.", | ||
@@ -15,11 +15,11 @@ "main": "dist/node/index.js", | ||
"dependencies": { | ||
"tslib": "^1.7.1" | ||
"tslib": "^1.9.3" | ||
}, | ||
"devDependencies": { | ||
"@esri/arcgis-rest-common-types": "^1.16.1", | ||
"@esri/arcgis-rest-request": "^1.16.1" | ||
"@esri/arcgis-rest-common-types": "^1.17.0", | ||
"@esri/arcgis-rest-request": "^1.17.0" | ||
}, | ||
"peerDependencies": { | ||
"@esri/arcgis-rest-common-types": "^1.16.0", | ||
"@esri/arcgis-rest-request": "^1.16.0" | ||
"@esri/arcgis-rest-common-types": "^1.17.0", | ||
"@esri/arcgis-rest-request": "^1.17.0" | ||
}, | ||
@@ -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
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
253415
2540
Updatedtslib@^1.9.3