From 18c3a7fcc774bad8e2cc9eef15444b62c1ed0dd1 Mon Sep 17 00:00:00 2001 From: john gravois Date: Mon, 16 Jul 2018 14:18:57 -0700 Subject: [PATCH] fix(:bug:): treat ArcGIS Online orgs as equivalent to arcgis.com when testing a portal AFFECTS PACKAGES: @esri/arcgis-rest-auth ISSUES CLOSED: #233 --- packages/arcgis-rest-auth/src/UserSession.ts | 4 +++- .../arcgis-rest-auth/test/UserSession.test.ts | 21 +++++++++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/packages/arcgis-rest-auth/src/UserSession.ts b/packages/arcgis-rest-auth/src/UserSession.ts index 1aaa407811..a651a13b59 100644 --- a/packages/arcgis-rest-auth/src/UserSession.ts +++ b/packages/arcgis-rest-auth/src/UserSession.ts @@ -625,7 +625,9 @@ export class UserSession implements IAuthenticationManager { */ getToken(url: string) { if ( - /^https?:\/\/www\.arcgis\.com\/sharing\/rest\/?/.test(this.portal) && + /^https?:\/\/\S+\.maps.arcgis\.com\/sharing\/rest|^https?:\/\/www\.arcgis\.com\/sharing\/rest/.test( + this.portal + ) && /^https?:\/\/\S+\.arcgis\.com.+/.test(url) ) { return this.getFreshToken(); diff --git a/packages/arcgis-rest-auth/test/UserSession.test.ts b/packages/arcgis-rest-auth/test/UserSession.test.ts index af8a1ad281..6eb1d48067 100644 --- a/packages/arcgis-rest-auth/test/UserSession.test.ts +++ b/packages/arcgis-rest-auth/test/UserSession.test.ts @@ -65,6 +65,27 @@ describe("UserSession", () => { }); }); + it("should return unexpired tokens when an org url is passed", done => { + const session = new UserSession({ + clientId: "id", + token: "token", + tokenExpires: TOMORROW, + portal: "https://custom.maps.arcgis.com/sharing/rest" + }); + + session + .getToken( + "https://services1.arcgis.com/MOCK_ORG/arcgis/rest/services/Private_Service/FeatureServer" + ) + .then(token => { + expect(token).toBe("token"); + done(); + }) + .catch(e => { + fail(e); + }); + }); + it("should return unexpired tokens for the configured portal domain", done => { const session = new UserSession({ clientId: "id",