From 7f33e2c820fb55566b890d9846a1e9a7484f3dbf Mon Sep 17 00:00:00 2001 From: Patrick Arlt Date: Mon, 21 Mar 2022 13:16:30 -0700 Subject: [PATCH 1/7] fix(arcgis-rest-request): add support for server credentials --- demos/jsapi-integration/authenticate.html | 22 +-- demos/jsapi-integration/config.js | 5 +- demos/jsapi-integration/index.html | 54 ++++--- .../src/ArcGISIdentityManager.ts | 68 +++++++-- .../test/ArcGISIdentityManager.test.ts | 139 ++++++++++++++---- 5 files changed, 200 insertions(+), 88 deletions(-) diff --git a/demos/jsapi-integration/authenticate.html b/demos/jsapi-integration/authenticate.html index 77f6416615..b85b329232 100644 --- a/demos/jsapi-integration/authenticate.html +++ b/demos/jsapi-integration/authenticate.html @@ -6,24 +6,12 @@ + diff --git a/demos/jsapi-integration/config.js b/demos/jsapi-integration/config.js index 4b27542a94..6cea071f84 100644 --- a/demos/jsapi-integration/config.js +++ b/demos/jsapi-integration/config.js @@ -3,4 +3,7 @@ You can generate your own clientid by creating an application on the ArcGIS for once you have a clientid of your own, copy/paste it here and rename this file 'config.js' */ -let clientId = "S19JZF92TRf2HZit"; +const config = { + clientId: "3CiiHWyTNMIRNyF1", + redirectUri: "http://localhost:8080/authenticate.html" +}; diff --git a/demos/jsapi-integration/index.html b/demos/jsapi-integration/index.html index 2650b8a02b..ad8bbc553c 100644 --- a/demos/jsapi-integration/index.html +++ b/demos/jsapi-integration/index.html @@ -33,21 +33,25 @@
diff --git a/packages/arcgis-rest-request/src/ArcGISIdentityManager.ts b/packages/arcgis-rest-request/src/ArcGISIdentityManager.ts index 5cd7af3289..3debc0cf2a 100644 --- a/packages/arcgis-rest-request/src/ArcGISIdentityManager.ts +++ b/packages/arcgis-rest-request/src/ArcGISIdentityManager.ts @@ -30,6 +30,8 @@ export interface IFromTokenOptions { token: string; tokenExpires?: Date; portal?: string; + server?: string; + username?: string; } /** @@ -60,6 +62,17 @@ export interface ICredential { userId: string; } +/** + * Represents the [`ServerInfo`](https://developers.arcgis.com/javascript/latest/api-reference/esri-identity-ServerInfo.html) class + * in the ArcGIS API for JavaScript. + */ +export interface IServerInfo { + server: string; + hasPortal: boolean; + hasServer: boolean; + owningSystemUrl: string | null; +} + /** * Options for static OAuth 2.0 helper methods on `ArcGISIdentityManager`. */ @@ -801,27 +814,48 @@ export class ArcGISIdentityManager implements IAuthenticationManager { } /** - * Translates authentication from the format used in the [ArcGIS API for JavaScript](https://developers.arcgis.com/javascript/). + * Translates authentication from the format used in the [`IdentityManager` class in the ArcGIS API for JavaScript](https://developers.arcgis.com/javascript/latest/api-reference/esri-identity-Credential.html). + * + * You will need to call both [`IdentityManger.findCredential`](https://developers.arcgis.com/javascript/latest/api-reference/esri-identity-IdentityManager.html#findCredential) and [`IdentityManger.findServerInfo`](https://developers.arcgis.com/javascript/latest/api-reference/esri-identity-IdentityManager.html#findServerInfo) to obtain both parameters for this method. + * + * This method can be used with {@linkcode ArcGISIdentityManager.toCredential} to interop with the ArcGIS API for JavaScript. * * ```js - * ArcGISIdentityManager.fromCredential({ - * userId: "jsmith", - * token: "secret" + * require(["esri/id"], (esriId) => { + * const credential = esriId.findCredential("https://www.arcgis.com/sharing/rest"); + * const serverInfo = esriId.findServerInfo("https://www.arcgis.com/sharing/rest"); + * + * const manager = ArcGISIdentityManager.fromCredential(credential, serverInfo); * }); * ``` * * @returns ArcGISIdentityManager */ - public static fromCredential(credential: ICredential) { + public static fromCredential( + credential: ICredential, + serverInfo: IServerInfo + ) { // At ArcGIS Online 9.1, credentials no longer include the ssl and expires properties // Here, we provide default values for them to cover this condition const ssl = typeof credential.ssl !== "undefined" ? credential.ssl : true; const expires = credential.expires || Date.now() + 7200000; /* 2 hours */ + if (serverInfo.hasServer) { + return new ArcGISIdentityManager({ + server: credential.server, + ssl, + token: credential.token, + username: credential.userId, + tokenExpires: new Date(expires) + }); + } + console.log(credential.server.includes("sharing/rest")); return new ArcGISIdentityManager({ - portal: credential.server.includes("sharing/rest") - ? credential.server - : credential.server + `/sharing/rest`, + portal: cleanUrl( + credential.server.includes("sharing/rest") + ? credential.server + : credential.server + `/sharing/rest` + ), ssl, token: credential.token, username: credential.userId, @@ -835,7 +869,7 @@ export class ArcGISIdentityManager implements IAuthenticationManager { */ private static parentMessageHandler(event: any): ArcGISIdentityManager { if (event.data.type === "arcgis:auth:credential") { - return ArcGISIdentityManager.fromCredential(event.data.credential); + return new ArcGISIdentityManager(event.data.credential); } if (event.data.type === "arcgis:auth:error") { const err = new Error(event.data.error.message); @@ -1010,10 +1044,15 @@ export class ArcGISIdentityManager implements IAuthenticationManager { } /** - * Returns authentication in a format useable in the [ArcGIS API for JavaScript](https://developers.arcgis.com/javascript/). + * Returns authentication in a format useable in the [`IdentityManager.registerToken()` method in the ArcGIS API for JavaScript](https://developers.arcgis.com/javascript/latest/api-reference/esri-identity-IdentityManager.html#registerToken). + * + * This method can be used with {@linkcode ArcGISIdentityManager.fromCredential} to interop with the ArcGIS API for JavaScript. * * ```js - * esriId.registerToken(manager.toCredential()); + * require(["esri/id"], (esriId) => { + * esriId.registerToken(manager.toCredential()); + * }) + * ``` * * @returns ICredential @@ -1021,7 +1060,7 @@ export class ArcGISIdentityManager implements IAuthenticationManager { public toCredential(): ICredential { return { expires: this.tokenExpires.getTime(), - server: this.portal, + server: this.server || this.portal, ssl: this.ssl, token: this.token, userId: this.username @@ -1301,10 +1340,7 @@ export class ArcGISIdentityManager implements IAuthenticationManager { if (isValidOrigin && isValidType) { let msg = {}; if (isTokenValid) { - const credential = this.toCredential(); - // the following line allows us to conform to our spec without changing other depended-on functionality - // https://github.com/Esri/arcgis-rest-js/blob/master/packages/arcgis-rest-request/post-message-auth-spec.md#arcgisauthcredential - credential.server = credential.server.replace("/sharing/rest", ""); + const credential = this.toJSON(); msg = { type: "arcgis:auth:credential", credential diff --git a/packages/arcgis-rest-request/test/ArcGISIdentityManager.test.ts b/packages/arcgis-rest-request/test/ArcGISIdentityManager.test.ts index 89eac9a547..85e9b923b1 100644 --- a/packages/arcgis-rest-request/test/ArcGISIdentityManager.test.ts +++ b/packages/arcgis-rest-request/test/ArcGISIdentityManager.test.ts @@ -11,7 +11,9 @@ import { ArcGISAccessDeniedError, ErrorTypes, ArcGISTokenRequestError, - ArcGISTokenRequestErrorCodes + ArcGISTokenRequestErrorCodes, + IServerInfo, + ITokenRequestOptions } from "../src/index.js"; import { FormData } from "@esri/arcgis-rest-form-data"; import { @@ -21,6 +23,7 @@ import { isBrowser, isNode } from "../../../scripts/test-helpers.js"; +import { IFromTokenOptions } from "../../arcgis-rest-auth/node_modules/@esri/arcgis-rest-request/dist/esm/ArcGISIdentityManager.js"; describe("ArcGISIdentityManager", () => { afterEach(fetchMock.restore); @@ -1743,30 +1746,35 @@ describe("ArcGISIdentityManager", () => { } }; - const cred = { - expires: TOMORROW.getTime(), - server: "https://www.arcgis.com/sharing/rest", - ssl: false, + const token = { + tokenExpires: TOMORROW, + portal: "https://www.arcgis.com/sharing/rest", token: "token", - userId: "jsmith" + username: "jsmith" }; it(".disablePostMessageAuth removes event listener", () => { const removeSpy = spyOn(MockWindow, "removeEventListener"); - const session = ArcGISIdentityManager.fromCredential(cred); + const session = new ArcGISIdentityManager(token); + session.disablePostMessageAuth(MockWindow); + expect(removeSpy.calls.count()).toBe( 1, "should call removeEventListener" ); }); + it(".enablePostMessageAuth adds event listener", () => { const addSpy = spyOn(MockWindow, "addEventListener"); - const session = ArcGISIdentityManager.fromCredential(cred); + + const session = new ArcGISIdentityManager(token); + session.enablePostMessageAuth( ["https://storymaps.arcgis.com"], MockWindow ); + expect(addSpy.calls.count()).toBe(1, "should call addEventListener"); }); @@ -1784,7 +1792,8 @@ describe("ArcGISIdentityManager", () => { removeEventListener() {} }; // Create the session - const session = ArcGISIdentityManager.fromCredential(cred); + const session = new ArcGISIdentityManager(token); + // enable postMessageAuth allowing storymaps.arcgis.com to recieve creds session.enablePostMessageAuth(["https://storymaps.arcgis.com"], Win); // create an event object, with a matching origin @@ -1813,14 +1822,10 @@ describe("ArcGISIdentityManager", () => { "arcgis:auth:credential", "should send credential type" ); - expect(args[0].credential.userId).toBe( + expect(args[0].credential.username).toBe( "jsmith", "should send credential" ); - expect(args[0].credential.server).toBe( - "https://www.arcgis.com", - "sends server url without /sharing/rest" - ); // now the case where it's not a valid origin event.origin = "https://evil.com"; Win._fn(event); @@ -1833,11 +1838,10 @@ describe("ArcGISIdentityManager", () => { it(".enablePostMessage handler returns error if session is expired", () => { // ok, this gets kinda gnarly... const expiredCred = { - expires: YESTERDAY.getTime(), - server: "https://www.arcgis.com/sharing/rest", - ssl: false, + tokenExpires: YESTERDAY, + portal: "https://www.arcgis.com/sharing/rest", token: "token", - userId: "jsmith" + username: "jsmith" }; // create a mock window object // that will hold the passed in event handler so we can fire it manually @@ -1849,8 +1853,9 @@ describe("ArcGISIdentityManager", () => { }, removeEventListener() {} }; + // Create the session - const session = ArcGISIdentityManager.fromCredential(expiredCred); + const session = new ArcGISIdentityManager(expiredCred); // enable postMessageAuth allowing storymaps.arcgis.com to recieve creds session.enablePostMessageAuth(["https://storymaps.arcgis.com"], Win); // create an event object, with a matching origin @@ -1895,7 +1900,7 @@ describe("ArcGISIdentityManager", () => { postMessage(msg: any, origin: string) { Win._fn({ origin: "https://origin.com", - data: { type: "arcgis:auth:credential", credential: cred }, + data: { type: "arcgis:auth:credential", credential: token }, source: Win.parent }); } @@ -1931,7 +1936,7 @@ describe("ArcGISIdentityManager", () => { // fire a second we want to intercept Win._fn({ origin: "https://origin.com", - data: { type: "arcgis:auth:credential", credential: cred }, + data: { type: "arcgis:auth:credential", credential: token }, source: Win.parent }); } @@ -2394,6 +2399,13 @@ describe("ArcGISIdentityManager", () => { userId: "jsmith" }; + const MOCK_SERVER_INFO: IServerInfo = { + hasPortal: true, + hasServer: false, + server: "https://www.arcgis.com", + owningSystemUrl: null + }; + const MOCK_USER_SESSION = new ArcGISIdentityManager({ clientId: "clientId", redirectUri: "https://example-app.com/redirect-uri", @@ -2416,22 +2428,77 @@ describe("ArcGISIdentityManager", () => { }); it("should create a ArcGISIdentityManager from a credential", () => { - const session = ArcGISIdentityManager.fromCredential(MOCK_CREDENTIAL); + const session = ArcGISIdentityManager.fromCredential( + MOCK_CREDENTIAL, + MOCK_SERVER_INFO + ); expect(session.username).toEqual("jsmith"); expect(session.portal).toEqual("https://www.arcgis.com/sharing/rest"); + expect(session.server).toBeUndefined(); expect(session.ssl).toEqual(false); expect(session.token).toEqual("token"); expect(session.tokenExpires).toEqual(new Date(TOMORROW)); }); - it("should create a ArcGISIdentityManager from a credential that came from a ArcGISIdentityManager", () => { - const creds = MOCK_USER_SESSION.toCredential(); - const credSession = ArcGISIdentityManager.fromCredential(creds); - expect(credSession.username).toEqual("jsmith"); - expect(credSession.portal).toEqual("https://www.arcgis.com/sharing/rest"); - expect(credSession.ssl).toEqual(false); - expect(credSession.token).toEqual("token"); - expect(credSession.tokenExpires).toEqual(new Date(TOMORROW)); + it("should create a ArcGISIdentityManager from a credential without adding /sharing/rest", () => { + const MOCK_SERVER_INFO: IServerInfo = { + hasPortal: true, + hasServer: false, + server: "https://www.arcgis.com/sharing/rest", + owningSystemUrl: null + }; + + const MOCK_CREDENTIAL: ICredential = { + expires: TOMORROW.getTime(), + server: "https://www.arcgis.com/sharing/rest", + ssl: false, + token: "token", + userId: "jsmith" + }; + + const session = ArcGISIdentityManager.fromCredential( + MOCK_CREDENTIAL, + MOCK_SERVER_INFO + ); + expect(session.username).toEqual("jsmith"); + expect(session.portal).toEqual("https://www.arcgis.com/sharing/rest"); + expect(session.server).toBeUndefined(); + expect(session.ssl).toEqual(false); + expect(session.token).toEqual("token"); + expect(session.tokenExpires).toEqual(new Date(TOMORROW)); + }); + + it("should create a manager for a specific server", () => { + const MOCK_SERVER_CREDENTIAL: ICredential = { + expires: TOMORROW.getTime(), + server: + "https://services.arcgis.com/arcgis/services/test/FeatureServer", + ssl: false, + token: "token", + userId: "jsmith" + }; + + const MOCK_SERVER_INFO_FOR_SERVER: IServerInfo = { + hasPortal: true, + hasServer: true, + server: + "https://services.arcgis.com/arcgis/services/test/FeatureServer", + owningSystemUrl: null + }; + + const session = ArcGISIdentityManager.fromCredential( + MOCK_SERVER_CREDENTIAL, + MOCK_SERVER_INFO_FOR_SERVER + ); + + expect(session.username).toEqual("jsmith"); + expect(session.portal).toEqual("https://www.arcgis.com/sharing/rest"); + expect(session.server).toBe( + "https://services.arcgis.com/arcgis/services/test/FeatureServer" + ); + expect(session.ssl).toEqual(false); + expect(session.token).toEqual("token"); + expect(session.tokenExpires).toEqual(new Date(TOMORROW)); }); }); @@ -2448,7 +2515,17 @@ describe("ArcGISIdentityManager", () => { jasmine.clock().install(); jasmine.clock().mockDate(); - const session = ArcGISIdentityManager.fromCredential(MOCK_CREDENTIAL); + const MOCK_SERVER_INFO: IServerInfo = { + hasPortal: true, + hasServer: true, + server: "https://www.arcgis.com", + owningSystemUrl: null + }; + + const session = ArcGISIdentityManager.fromCredential( + MOCK_CREDENTIAL, + MOCK_SERVER_INFO + ); expect(session.username).toEqual("jsmith"); expect(session.portal).toEqual("https://www.arcgis.com/sharing/rest"); expect(session.ssl).toBeTruthy(); From 143f019535d857789b2c0eb65b7f335de9937b8a Mon Sep 17 00:00:00 2001 From: Patrick Arlt Date: Tue, 22 Mar 2022 08:23:33 -0700 Subject: [PATCH 2/7] chore: Apply suggestions from code review Co-authored-by: Gavin Rehkemper --- demos/jsapi-integration/index.html | 4 ++-- packages/arcgis-rest-request/src/ArcGISIdentityManager.ts | 1 - 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/demos/jsapi-integration/index.html b/demos/jsapi-integration/index.html index ad8bbc553c..8feea08920 100644 --- a/demos/jsapi-integration/index.html +++ b/demos/jsapi-integration/index.html @@ -66,7 +66,7 @@ // JavaScript Identity Manager esriId.registerToken(session.toCredential()); - console.debug(webMapItem); + console.debug('Web map:', webMapItem); // create a map with the item var webmap = new WebMap({ @@ -89,7 +89,7 @@ const credential = esriId.findCredential("https://arcgis.com/sharing/rest/"); const serverInfo = esriId.findServerInfo("https://arcgis.com/sharing/rest/"); const session2 = arcgisRest.ArcGISIdentityManager.fromCredential(credential, serverInfo); - console.log(session2); + console.log('Session from ArcGIS REST JS:', session2); } }); }); diff --git a/packages/arcgis-rest-request/src/ArcGISIdentityManager.ts b/packages/arcgis-rest-request/src/ArcGISIdentityManager.ts index 3debc0cf2a..f838fa2338 100644 --- a/packages/arcgis-rest-request/src/ArcGISIdentityManager.ts +++ b/packages/arcgis-rest-request/src/ArcGISIdentityManager.ts @@ -849,7 +849,6 @@ export class ArcGISIdentityManager implements IAuthenticationManager { tokenExpires: new Date(expires) }); } - console.log(credential.server.includes("sharing/rest")); return new ArcGISIdentityManager({ portal: cleanUrl( credential.server.includes("sharing/rest") From 560e82aecdb18ca17e8e7957a3d83e61beece593 Mon Sep 17 00:00:00 2001 From: Patrick Arlt Date: Tue, 22 Mar 2022 09:27:09 -0700 Subject: [PATCH 3/7] chore: remove old exports --- packages/arcgis-rest-auth/src/index.ts | 2 -- 1 file changed, 2 deletions(-) diff --git a/packages/arcgis-rest-auth/src/index.ts b/packages/arcgis-rest-auth/src/index.ts index 9dbc8d9be6..de3c4a3ed5 100644 --- a/packages/arcgis-rest-auth/src/index.ts +++ b/packages/arcgis-rest-auth/src/index.ts @@ -13,7 +13,6 @@ export { isOnline, normalizeOnlinePortalUrl, fetchToken, - generateToken, validateAppAccess, AuthenticationProvider, IApiKeyOptions, @@ -23,7 +22,6 @@ export { IAuthenticatedRequestOptions, IUserRequestOptions, IFetchTokenResponse, - IGenerateTokenResponse, IAppAccess, IUser } from "@esri/arcgis-rest-request"; From f23cc875ab5b547d55d8bb9d0e6b4332557942bc Mon Sep 17 00:00:00 2001 From: Patrick Arlt Date: Tue, 22 Mar 2022 09:52:13 -0700 Subject: [PATCH 4/7] chore: force latest package versions --- packages/arcgis-rest-feature-service/package.json | 8 ++++---- packages/arcgis-rest-portal/package.json | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/packages/arcgis-rest-feature-service/package.json b/packages/arcgis-rest-feature-service/package.json index 4119246337..3a41494993 100644 --- a/packages/arcgis-rest-feature-service/package.json +++ b/packages/arcgis-rest-feature-service/package.json @@ -46,12 +46,12 @@ "tslib": "^2.3.0" }, "peerDependencies": { - "@esri/arcgis-rest-portal": "4.0.0-beta.3", - "@esri/arcgis-rest-request": "4.0.0-beta.3" + "@esri/arcgis-rest-portal": "4.0.0-beta.4", + "@esri/arcgis-rest-request": "4.0.0-beta.5" }, "devDependencies": { - "@esri/arcgis-rest-portal": "4.0.0-beta.3", - "@esri/arcgis-rest-request": "4.0.0-beta.3" + "@esri/arcgis-rest-portal": "4.0.0-beta.4", + "@esri/arcgis-rest-request": "4.0.0-beta.5" }, "contributors": [ "Mike Tschudi ", diff --git a/packages/arcgis-rest-portal/package.json b/packages/arcgis-rest-portal/package.json index 1c5693ec35..675cfe645a 100644 --- a/packages/arcgis-rest-portal/package.json +++ b/packages/arcgis-rest-portal/package.json @@ -47,10 +47,10 @@ "tslib": "^2.3.0" }, "peerDependencies": { - "@esri/arcgis-rest-request": "4.0.0-beta.4" + "@esri/arcgis-rest-request": "4.0.0-beta.5" }, "devDependencies": { - "@esri/arcgis-rest-request": "4.0.0-beta.4" + "@esri/arcgis-rest-request": "4.0.0-beta.5" }, "contributors": [ "Dave Bouwman (http://blog.davebouwman.com/)" From 6d099aa8ef9fe36de6e9e0bb4c6e7b2edda43b58 Mon Sep 17 00:00:00 2001 From: Patrick Arlt Date: Tue, 22 Mar 2022 10:12:32 -0700 Subject: [PATCH 5/7] chore: force update deps --- package-lock.json | 8 ++++---- packages/arcgis-rest-feature-service/package.json | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/package-lock.json b/package-lock.json index c73722d115..3b9018c74a 100644 --- a/package-lock.json +++ b/package-lock.json @@ -48568,18 +48568,18 @@ "tslib": "^2.3.0" }, "devDependencies": { - "@esri/arcgis-rest-request": "4.0.0-beta.4" + "@esri/arcgis-rest-request": "4.0.0-beta.5" }, "engines": { "node": ">=12.20.0" }, "peerDependencies": { - "@esri/arcgis-rest-request": "4.0.0-beta.4" + "@esri/arcgis-rest-request": "4.0.0-beta.5" } }, "packages/arcgis-rest-request": { "name": "@esri/arcgis-rest-request", - "version": "4.0.0-beta.4", + "version": "4.0.0-beta.5", "license": "Apache-2.0", "dependencies": { "@esri/arcgis-rest-fetch": "4.0.0-beta.1", @@ -50774,7 +50774,7 @@ "@esri/arcgis-rest-portal": { "version": "file:packages/arcgis-rest-portal", "requires": { - "@esri/arcgis-rest-request": "4.0.0-beta.4", + "@esri/arcgis-rest-request": "4.0.0-beta.5", "tslib": "^2.3.0" } }, diff --git a/packages/arcgis-rest-feature-service/package.json b/packages/arcgis-rest-feature-service/package.json index 3a41494993..4119246337 100644 --- a/packages/arcgis-rest-feature-service/package.json +++ b/packages/arcgis-rest-feature-service/package.json @@ -46,12 +46,12 @@ "tslib": "^2.3.0" }, "peerDependencies": { - "@esri/arcgis-rest-portal": "4.0.0-beta.4", - "@esri/arcgis-rest-request": "4.0.0-beta.5" + "@esri/arcgis-rest-portal": "4.0.0-beta.3", + "@esri/arcgis-rest-request": "4.0.0-beta.3" }, "devDependencies": { - "@esri/arcgis-rest-portal": "4.0.0-beta.4", - "@esri/arcgis-rest-request": "4.0.0-beta.5" + "@esri/arcgis-rest-portal": "4.0.0-beta.3", + "@esri/arcgis-rest-request": "4.0.0-beta.3" }, "contributors": [ "Mike Tschudi ", From f8bf1bb7d8e7b0aaf2eb65c84fb0792892307b4a Mon Sep 17 00:00:00 2001 From: Patrick Arlt Date: Tue, 22 Mar 2022 10:18:54 -0700 Subject: [PATCH 6/7] chore: merge latest, fix auth reference --- packages/arcgis-rest-request/test/ArcGISIdentityManager.test.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/packages/arcgis-rest-request/test/ArcGISIdentityManager.test.ts b/packages/arcgis-rest-request/test/ArcGISIdentityManager.test.ts index 85e9b923b1..68686b0b59 100644 --- a/packages/arcgis-rest-request/test/ArcGISIdentityManager.test.ts +++ b/packages/arcgis-rest-request/test/ArcGISIdentityManager.test.ts @@ -23,7 +23,6 @@ import { isBrowser, isNode } from "../../../scripts/test-helpers.js"; -import { IFromTokenOptions } from "../../arcgis-rest-auth/node_modules/@esri/arcgis-rest-request/dist/esm/ArcGISIdentityManager.js"; describe("ArcGISIdentityManager", () => { afterEach(fetchMock.restore); From 2aaeb09b9519e8db55c9ed3731ab05b83e63efd0 Mon Sep 17 00:00:00 2001 From: Patrick Arlt Date: Tue, 22 Mar 2022 11:55:18 -0700 Subject: [PATCH 7/7] chore: doc fix --- demos/jsapi-integration/README.md | 5 ++++- demos/jsapi-integration/index.html | 10 +++++++--- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/demos/jsapi-integration/README.md b/demos/jsapi-integration/README.md index e976515f1a..19047fa853 100644 --- a/demos/jsapi-integration/README.md +++ b/demos/jsapi-integration/README.md @@ -19,7 +19,10 @@ session.getToken("https://www.arcgis.com/sharing/rest").then(() => { // from jsapi esriId.getCredential("https://www.arcgis.com/sharing/rest").then((cred) => { - const session = UserSession.fromCredential(cred); + const serverInfo = esriId.findServerInfo( + "https://www.arcgis.com/sharing/rest" + ); + const session = UserSession.fromCredential(cred, serverInfo); }); ``` diff --git a/demos/jsapi-integration/index.html b/demos/jsapi-integration/index.html index 8feea08920..ea2f7803bc 100644 --- a/demos/jsapi-integration/index.html +++ b/demos/jsapi-integration/index.html @@ -53,7 +53,7 @@ return } - // once we have the private item, we can create a map + // once we have the item, we can create a map // NOTE: this is where you would lazy-load the ArcGIS API for JavaScript require([ "esri/identity/IdentityManager", @@ -69,6 +69,9 @@ console.debug('Web map:', webMapItem); // create a map with the item + // the JS API will automatically discover all portals and severs associated with the webmap. + // this most likly will include https://arcgis.com/sharing/rest/ which is the ArGIS Online portal + // due to the map has a basemap. var webmap = new WebMap({ portalItem: { id: webMapItem.id @@ -81,9 +84,10 @@ container: "viewDiv" }); - // Once the web map loads the JS API should be "aware" of the ArcGIS.com portal. + // Once the web map loads the JS API should be "aware" of the ArcGIS.com portal at https://arcgis.com/sharing/rest/. // Using the findCredential and findServerInfo methods we can create an ArcGISIdentityManager - // for use in REST JS from the JS API + // for use in REST JS from the JS API. You could also call `esriId.getCredential("https://arcgis.com/sharing/rest/")` + // to forece this. webmap.watch("loaded", function (loaded) { if(loaded) { const credential = esriId.findCredential("https://arcgis.com/sharing/rest/");