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

@esri/arcgis-rest-auth

Package Overview
Dependencies
Maintainers
8
Versions
118
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

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

Comparing version 2.15.0 to 2.16.0

4

dist/esm/ApplicationSession.js
/* Copyright (c) 2017-2018 Environmental Systems Research Institute, Inc.
* Apache-2.0 */
import * as tslib_1 from "tslib";
import { __assign } from "tslib";
import { fetchToken } from "./fetch-token";

@@ -39,3 +39,3 @@ /**

var _this = this;
var options = tslib_1.__assign({ params: {
var options = __assign({ params: {
client_id: this.clientId,

@@ -42,0 +42,0 @@ client_secret: this.clientSecret,

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

export * from "./generate-token";
export * from "./authenticated-request-options";
//# sourceMappingURL=index.js.map

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

*/
readonly token: string;
get token(): string;
/**
* The expiration time of the current `token`.
*/
readonly tokenExpires: Date;
get tokenExpires(): Date;
/**
* The current token to ArcGIS Online or ArcGIS Enterprise.
*/
readonly refreshToken: string;
get refreshToken(): string;
/**
* The expiration time of the current `refreshToken`.
*/
readonly refreshTokenExpires: Date;
get refreshTokenExpires(): Date;
constructor(options: IUserSessionOptions);

@@ -300,0 +300,0 @@ /**

/* Copyright (c) 2017-2019 Environmental Systems Research Institute, Inc.
* Apache-2.0 */
import * as tslib_1 from "tslib";
import { __assign } from "tslib";
import { request, ArcGISAuthError, cleanUrl, encodeQueryString, decodeQueryString } from "@esri/arcgis-rest-request";

@@ -90,3 +90,3 @@ import { generateToken } from "./generate-token";

if (win === void 0) { win = window; }
var _a = tslib_1.__assign({
var _a = __assign({
portal: "https://www.arcgis.com/sharing/rest",

@@ -147,3 +147,3 @@ provider: "arcgis",

if (win === void 0) { win = window; }
var _a = tslib_1.__assign({ portal: "https://www.arcgis.com/sharing/rest", popup: true }, options), portal = _a.portal, clientId = _a.clientId, popup = _a.popup;
var _a = __assign({ portal: "https://www.arcgis.com/sharing/rest", popup: true }, options), portal = _a.portal, clientId = _a.clientId, popup = _a.popup;
function completeSignIn(error, oauthInfo) {

@@ -221,3 +221,3 @@ try {

UserSession.authorize = function (options, response) {
var _a = tslib_1.__assign({ portal: "https://arcgis.com/sharing/rest", duration: 20160 }, options), portal = _a.portal, clientId = _a.clientId, duration = _a.duration, redirectUri = _a.redirectUri;
var _a = __assign({ portal: "https://arcgis.com/sharing/rest", duration: 20160 }, options), portal = _a.portal, clientId = _a.clientId, duration = _a.duration, redirectUri = _a.redirectUri;
response.writeHead(301, {

@@ -235,3 +235,3 @@ Location: portal + "/oauth2/authorize?client_id=" + clientId + "&duration=" + duration + "&response_type=code&redirect_uri=" + encodeURIComponent(redirectUri)

UserSession.exchangeAuthorizationCode = function (options, authorizationCode) {
var _a = tslib_1.__assign({
var _a = __assign({
portal: "https://www.arcgis.com/sharing/rest",

@@ -309,3 +309,3 @@ refreshTokenTTL: 1440

},
enumerable: true,
enumerable: false,
configurable: true

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

},
enumerable: true,
enumerable: false,
configurable: true

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

},
enumerable: true,
enumerable: false,
configurable: true

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

},
enumerable: true,
enumerable: false,
configurable: true

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

var url = this.portal + "/community/self";
var options = tslib_1.__assign({ httpMethod: "GET", authentication: this }, requestOptions, { rawResponse: false });
var options = __assign(__assign({ httpMethod: "GET", authentication: this }, requestOptions), { rawResponse: false });
this._pendingUserRequest = request(url, options).then(function (response) {

@@ -600,3 +600,3 @@ _this._user = response;

var _this = this;
var options = tslib_1.__assign({ params: {
var options = __assign({ params: {
username: this.username,

@@ -622,3 +622,3 @@ password: this.password,

}
var options = tslib_1.__assign({ params: {
var options = __assign({ params: {
client_id: this.clientId,

@@ -640,3 +640,3 @@ refresh_token: this.refreshToken,

var _this = this;
var options = tslib_1.__assign({ params: {
var options = __assign({ params: {
client_id: this.clientId,

@@ -643,0 +643,0 @@ refresh_token: this.refreshToken,

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

Object.defineProperty(exports, "__esModule", { value: true });
exports.ApplicationSession = void 0;
var tslib_1 = require("tslib");

@@ -7,0 +8,0 @@ var fetch_token_1 = require("./fetch-token");

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.canUseOnlineToken = exports.isFederated = exports.getOnlineEnvironment = exports.normalizeOnlinePortalUrl = exports.isOnline = void 0;
var arcgis_rest_request_1 = require("@esri/arcgis-rest-request");

@@ -4,0 +5,0 @@ /**

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

Object.defineProperty(exports, "__esModule", { value: true });
exports.fetchToken = void 0;
var arcgis_rest_request_1 = require("@esri/arcgis-rest-request");

@@ -7,0 +8,0 @@ function fetchToken(url, requestOptions) {

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

Object.defineProperty(exports, "__esModule", { value: true });
exports.generateToken = void 0;
var arcgis_rest_request_1 = require("@esri/arcgis-rest-request");

@@ -7,0 +8,0 @@ function generateToken(url, requestOptions) {

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

tslib_1.__exportStar(require("./generate-token"), exports);
tslib_1.__exportStar(require("./authenticated-request-options"), exports);
//# sourceMappingURL=index.js.map

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

Object.defineProperty(exports, "__esModule", { value: true });
exports.UserSession = void 0;
var tslib_1 = require("tslib");

@@ -308,3 +309,3 @@ var arcgis_rest_request_1 = require("@esri/arcgis-rest-request");

},
enumerable: true,
enumerable: false,
configurable: true

@@ -319,3 +320,3 @@ });

},
enumerable: true,
enumerable: false,
configurable: true

@@ -330,3 +331,3 @@ });

},
enumerable: true,
enumerable: false,
configurable: true

@@ -341,3 +342,3 @@ });

},
enumerable: true,
enumerable: false,
configurable: true

@@ -386,3 +387,3 @@ });

var url = this.portal + "/community/self";
var options = tslib_1.__assign({ httpMethod: "GET", authentication: this }, requestOptions, { rawResponse: false });
var options = tslib_1.__assign(tslib_1.__assign({ httpMethod: "GET", authentication: this }, requestOptions), { rawResponse: false });
this._pendingUserRequest = arcgis_rest_request_1.request(url, options).then(function (response) {

@@ -389,0 +390,0 @@ _this._user = response;

/* @preserve
* @esri/arcgis-rest-auth - v2.15.0 - Apache-2.0
* @esri/arcgis-rest-auth - v2.16.0 - Apache-2.0
* Copyright (c) 2017-2020 Esri, Inc.
* Wed Aug 19 2020 11:58:42 GMT-0600 (Mountain Daylight Time)
* Mon Aug 31 2020 16:09:10 GMT-0600 (Mountain Daylight Time)
*/

@@ -9,18 +9,18 @@ (function (global, factory) {

typeof define === 'function' && define.amd ? define(['exports', '@esri/arcgis-rest-request'], factory) :
(global = global || self, factory(global.arcgisRest = global.arcgisRest || {}, global.arcgisRest));
}(this, function (exports, arcgisRestRequest) { 'use strict';
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.arcgisRest = global.arcgisRest || {}, global.arcgisRest));
}(this, (function (exports, arcgisRestRequest) { 'use strict';
/*! *****************************************************************************
Copyright (c) Microsoft Corporation. All rights reserved.
Licensed under the Apache License, Version 2.0 (the "License"); you may not use
this file except in compliance with the License. You may obtain a copy of the
License at http://www.apache.org/licenses/LICENSE-2.0
Copyright (c) Microsoft Corporation.
THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
MERCHANTABLITY OR NON-INFRINGEMENT.
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted.
See the Apache Version 2.0 License for specific language governing permissions
and limitations under the License.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
***************************************************************************** */

@@ -470,3 +470,3 @@

},
enumerable: true,
enumerable: false,
configurable: true

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

},
enumerable: true,
enumerable: false,
configurable: true

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

},
enumerable: true,
enumerable: false,
configurable: true

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

},
enumerable: true,
enumerable: false,
configurable: true

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

var url = this.portal + "/community/self";
var options = __assign({ httpMethod: "GET", authentication: this }, requestOptions, { rawResponse: false });
var options = __assign(__assign({ httpMethod: "GET", authentication: this }, requestOptions), { rawResponse: false });
this._pendingUserRequest = arcgisRestRequest.request(url, options).then(function (response) {

@@ -823,3 +823,3 @@ _this._user = response;

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

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

"dependencies": {
"@esri/arcgis-rest-types": "^2.15.0",
"tslib": "^1.9.3"
"@esri/arcgis-rest-types": "^2.16.0",
"tslib": "^1.13.0"
},
"devDependencies": {
"@esri/arcgis-rest-request": "^2.15.0"
"@esri/arcgis-rest-request": "^2.16.0"
},

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

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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