Skip to content

Commit

Permalink
Force federation accross different ArcGIS Online environments (#572)
Browse files Browse the repository at this point in the history
* extend logic of #560 to ArcGIS Dev environment

* doc

* comment for clairity
  • Loading branch information
patrickarlt committed May 20, 2019
1 parent 5267661 commit 1db161b
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions packages/arcgis-rest-auth/src/UserSession.ts
Expand Up @@ -65,6 +65,21 @@ function defer<T>(): IDeferred<T> {
return deferred as IDeferred<T>;
}

/**
* Used to test if a URL is an ArcGIS Online URL
*/
const arcgisOnlineUrlRegex = /^https?:\/\/\S+\.arcgis\.com.+/;

/**
* Used to test if a URL is production ArcGIS Online Portal
*/
const arcgisOnlinePortalRegex = /^https?:\/\/www\.arcgis\.com\/sharing\/rest+/;

/**
* Used to test if a URL is an ArcGIS Online Organization Portal
*/
const arcgisOnlineOrgPortalRegex = /^https?:\/\/(?:[a-z0-9-]+\.maps)?.\arcgis\.com\/sharing\/rest/;

/**
* Options for static OAuth 2.0 helper methods on `UserSession`.
*/
Expand Down Expand Up @@ -709,8 +724,9 @@ export class UserSession implements IAuthenticationManager {
*/
public getToken(url: string, requestOptions?: ITokenRequestOptions) {
if (
/^https?:\/\/\S+\.arcgis\.com\/sharing\/rest/.test(this.portal) &&
/^https?:\/\/\S+\.arcgis\.com.+/.test(url)
(arcgisOnlinePortalRegex.test(this.portal) ||
arcgisOnlineOrgPortalRegex.test(this.portal)) &&
arcgisOnlineUrlRegex.test(url)
) {
return this.getFreshToken(requestOptions);
} else if (new RegExp(this.portal, "i").test(url)) {
Expand Down

0 comments on commit 1db161b

Please sign in to comment.