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 3.0.3 to 3.0.4

4

dist/umd/auth.umd.js
/* @preserve
* @esri/arcgis-rest-auth - v3.0.3 - Apache-2.0
* @esri/arcgis-rest-auth - v3.0.4 - Apache-2.0
* Copyright (c) 2017-2021 Esri, Inc.
* Thu Mar 18 2021 13:21:44 GMT-0700 (Pacific Daylight Time)
* Fri Mar 26 2021 13:01:41 GMT-0700 (Pacific Daylight Time)
*/

@@ -6,0 +6,0 @@ (function (global, factory) {

/* @preserve
* @esri/arcgis-rest-auth - v3.0.3 - Apache-2.0
* @esri/arcgis-rest-auth - v3.0.4 - Apache-2.0
* Copyright (c) 2017-2021 Esri, Inc.
* Thu Mar 18 2021 13:21:47 GMT-0700 (Pacific Daylight Time)
* Fri Mar 26 2021 13:01:44 GMT-0700 (Pacific 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="undefined"!=typeof globalThis?globalThis:e||self).arcgisRest=e.arcgisRest||{},e.arcgisRest)}(this,function(e,g){"use strict";var w=function(){return(w=Object.assign||function(e){for(var 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,g.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=w({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}var n=(s.prototype.getToken=function(e){return Promise.resolve(this.key)},s);function s(e){this.key=e.key}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=g.NODEJS_DEFAULT_REFERER_HEADER,g.request(e,t)}var i=/^https?:\/\/(\S+)\.arcgis\.com.+/;function h(e){return i.test(e)}function p(e){if(!i.test(e))return null;var r=e.match(i)[1].split(".").pop();return r.includes("dev")?"dev":r.includes("qa")?"qa":"production"}function u(e,r){var t=g.cleanUrl(function(e){if(!i.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=g.cleanUrl(e).replace(/https?:\/\//,"");return new RegExp(n,"i").test(t)}function c(e,r,t){void 0===t&&(t="https://www.arcgis.com/sharing/rest");var n=t+"/oauth2/validateAppAccess",s={method:"POST",params:{f:"json",client_id:r,token:e}};return g.request(n,s)}var l=(Object.defineProperty(m.prototype,"token",{get:function(){return this._token},enumerable:!1,configurable:!0}),Object.defineProperty(m.prototype,"tokenExpires",{get:function(){return this._tokenExpires},enumerable:!1,configurable:!0}),Object.defineProperty(m.prototype,"refreshToken",{get:function(){return this._refreshToken},enumerable:!1,configurable:!0}),Object.defineProperty(m.prototype,"refreshTokenExpires",{get:function(){return this._refreshTokenExpires},enumerable:!1,configurable:!0}),m.beginOAuth2=function(e,r){void 0===r&&(r=window);var t=w({portal:"https://www.arcgis.com/sharing/rest",provider:"arcgis",duration:20160,popup:!0,popupWindowFeatures:"height=400,width=600,menubar=no,location=yes,resizable=yes,scrollbars=yes,status=yes",state:e.clientId,locale:""},e),s=t.portal,n=t.provider,o=t.clientId,i=t.duration,a=t.redirectUri,h=t.popup,p=t.popupWindowFeatures,u=t.state,c=t.locale,l=t.params,d="arcgis"===n?s+"/oauth2/authorize?client_id="+o+"&response_type=token&expiration="+i+"&redirect_uri="+encodeURIComponent(a)+"&state="+u+"&locale="+c:s+"/oauth2/social/authorize?client_id="+o+"&socialLoginProviderName="+n+"&autoAccountCreateForSocial=true&response_type=token&expiration="+i+"&redirect_uri="+encodeURIComponent(a)+"&state="+u+"&locale="+c;if(l&&(d=d+"&"+g.encodeQueryString(l)),h){var f,k=((f={promise:null,resolve:null,reject:null}).promise=new Promise(function(e,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),k.reject(new g.ArcGISAuthError(t.errorMessage,t.error))):r&&(n=JSON.parse(r),k.resolve(new m({clientId:o,portal:s,ssl:n.ssl,token:n.token,tokenExpires:new Date(n.expires),username:n.username})))},r.open(d,"oauth-window",p),k.promise}r.location.href=d},m.completeOAuth2=function(e,s){void 0===s&&(s=window);var r=w({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 g.ArcGISAuthError('Unable to complete authentication. It\'s possible you specified popup based oAuth2 but no handler from "beginOAuth2()" present. This generally happens because the "popup" option differs between "beginOAuth2()" and "completeOAuth2()".')}if(e)throw new g.ArcGISAuthError(e.errorMessage,e.error);return new m({clientId:i,portal:o,ssl:r.ssl,token:r.token,tokenExpires:r.expires,username:r.username})}var n=g.decodeQueryString(s.location.hash);if(!n.access_token){var h=void 0,p="Unknown error";return n.error&&(h=n.error,p=n.error_description),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})},m.fromParent=function(e,n){var s;return!n&&window&&(n=window),new Promise(function(r,t){s=function(e){if(e.source===n.parent&&e.data)try{return r(m.parentMessageHandler(e))}catch(e){return t(e)}},n.addEventListener("message",s,!1),n.parent.postMessage({type:"arcgis:auth:requestCredential"},e)}).then(function(e){return n.removeEventListener("message",s,!1),e})},m.authorize=function(e,r){var t=w({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()},m.exchangeAuthorizationCode=function(e,r){var t=w({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 m({clientId:s,portal:n,ssl:e.ssl,redirectUri:o,refreshToken:e.refreshToken,refreshTokenTTL:i,refreshTokenExpires:new Date(Date.now()+1e3*(i-1)),token:e.token,tokenExpires:e.expires,username:e.username})})},m.deserialize=function(e){var r=JSON.parse(e);return new m({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})},m.fromCredential=function(e){var r=void 0===e.ssl||e.ssl,t=e.expires||Date.now()+72e5;return new m({portal:e.server.includes("sharing/rest")?e.server:e.server+"/sharing/rest",ssl:r,token:e.token,username:e.userId,tokenExpires:new Date(t)})},m.parentMessageHandler=function(e){if("arcgis:auth:credential"===e.data.type)return m.fromCredential(e.data.credential);if("arcgis:auth:error"!==e.data.type)throw new Error("Unknown message type.");var r=new Error(e.data.error.message);throw r.name=e.data.error.name,r},m.prototype.toCredential=function(){return{expires:this.tokenExpires.getTime(),server:this.portal,ssl:this.ssl,token:this.token,userId:this.username}},m.prototype.getUser=function(e){var r=this;if(this._pendingUserRequest)return this._pendingUserRequest;if(this._user)return Promise.resolve(this._user);var t=this.portal+"/community/self",n=w(w({httpMethod:"GET",authentication:this},e),{rawResponse:!1});return this._pendingUserRequest=g.request(t,n).then(function(e){return r._user=e,r._pendingUserRequest=null,e}),this._pendingUserRequest},m.prototype.getUsername=function(){return this.username?Promise.resolve(this.username):this._user?Promise.resolve(this._user.username):this.getUser().then(function(e){return e.username})},m.prototype.getToken=function(e,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},m.prototype.validateAppAccess=function(r){return this.getToken(this.portal).then(function(e){return c(e,r)})},m.prototype.toJSON=function(){return{clientId:this.clientId,refreshToken:this.refreshToken,refreshTokenExpires:this.refreshTokenExpires,username:this.username,password:this.password,token:this.token,tokenExpires:this.tokenExpires,portal:this.portal,ssl:this.ssl,tokenDuration:this.tokenDuration,redirectUri:this.redirectUri,refreshTokenTTL:this.refreshTokenTTL}},m.prototype.serialize=function(){return JSON.stringify(this)},m.prototype.enablePostMessageAuth=function(e,r){!r&&window&&(r=window),this._hostHandler=this.createPostMessageHandler(e),r.addEventListener("message",this._hostHandler,!1)},m.prototype.disablePostMessageAuth=function(e){!e&&window&&(e=window),e.removeEventListener("message",this._hostHandler,!1)},m.prototype.refreshSession=function(e){return this._user=null,this.username&&this.password?this.refreshWithUsernameAndPassword(e):this.clientId&&this.refreshToken?this.refreshWithRefreshToken():Promise.reject(new g.ArcGISAuthError("Unable to refresh token."))},m.prototype.getServerRootUrl=function(e){var r=g.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("/")},m.prototype.createPostMessageHandler=function(s){var o=this;return function(e){var r,t=-1<s.indexOf(e.origin),n="arcgis:auth:requestCredential"===e.data.type;t&&n&&((r=o.toCredential()).server=r.server.replace("/sharing/rest",""),e.source.postMessage({type:"arcgis:auth:credential",credential:r},e.origin))}},m.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]=g.request(s+"/rest/info").then(function(e){if(e.owningSystemUrl){if(u(e.owningSystemUrl,n.portal))return g.request(e.owningSystemUrl+"/sharing/rest/info",t);throw new g.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 g.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])},m.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])},m.prototype.refreshWithUsernameAndPassword=function(e){var r=this,t=w({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})},m.prototype.refreshWithRefreshToken=function(e){var r=this;if(this.refreshToken&&this.refreshTokenExpires&&this.refreshTokenExpires.getTime()<Date.now())return this.refreshRefreshToken(e);var t=w({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})},m.prototype.refreshRefreshToken=function(e){var r=this,t=w({params:{client_id:this.clientId,refresh_token:this.refreshToken,redirect_uri:this.redirectUri,grant_type:"exchange_refresh_token"}},e);return a(this.portal+"/oauth2/token",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})},m);function m(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?g.cleanUrl(e.portal):"https://www.arcgis.com/sharing/rest",this.ssl=e.ssl,this.provider=e.provider||"arcgis",this.tokenDuration=e.tokenDuration||20160,this.redirectUri=e.redirectUri,this.refreshTokenTTL=e.refreshTokenTTL||1440,this.trustedServers={},e.server&&(r=this.getServerRootUrl(e.server),this.trustedServers[r]={token:e.token,expires:e.tokenExpires}),this._pendingTokenRequests={}}e.ApiKey=n,e.ApplicationSession=r,e.UserSession=l,e.exchangeToken=function(e,r,t){void 0===t&&(t="https://www.arcgis.com/sharing/rest");var n=t+"/oauth2/exchangeToken",s={method:"POST",params:{f:"json",client_id:r,token:e}};return g.request(n,s).then(function(e){return e.token})},e.fetchToken=a,e.generateToken=o,e.platformSelf=function(e,r,t){void 0===t&&(t="https://www.arcgis.com/sharing/rest");var n=t+"/oauth2/platformSelf?f=json",s={method:"POST",headers:{"X-Esri-Auth-Client-Id":e,"X-Esri-Auth-Redirect-Uri":r},params:{f:"json"}};return g.request(n,s)},e.validateAppAccess=c,Object.defineProperty(e,"__esModule",{value:!0})});
//# sourceMappingURL=auth.umd.min.js.map
{
"name": "@esri/arcgis-rest-auth",
"version": "3.0.3",
"version": "3.0.4",
"description": "Authentication helpers for @esri/arcgis-rest-js.",

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

"dependencies": {
"@esri/arcgis-rest-types": "^3.0.3",
"@esri/arcgis-rest-types": "^3.0.4",
"tslib": "^1.13.0"
},
"devDependencies": {
"@esri/arcgis-rest-request": "^3.0.3"
"@esri/arcgis-rest-request": "^3.0.4"
},

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

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