-
Notifications
You must be signed in to change notification settings - Fork 128
Description
Describe the bug
This comes up on Enterprise 12 dev when attempting to make a GET call that requires a token in the search params.
After getting a credential from JSAPI's IdentityManager.checkSignInStatus on Enterprise, a call to ArcGISIdentityManager.fromCredential produces an object whose portal property is "https://www.arcgis.com/sharing/rest". If this object is used in a request call, its token setup switches to "same-origin" and the token is omitted from the GET URL, thus causing the request to fail.
If the portal property is manually changed to the Enterprise portal, the request call adds the token and succeeds.
Reproduction
This sample needs to be run on an Enterprise server in which one has already signed in in another tab. Note that the portalUrl and appId constants need to be set.
<!doctype html>
<html lang="en" dir="ltr">
<head>
<meta charset="utf-8"/>
<script src="https://js.arcgis.com/4.33/"></script>
</head>
<body>
<script type="module">
const [IdentityManager, OAuthInfo] = await $arcgis.import([
"@arcgis/core/identity/IdentityManager.js",
"@arcgis/core/identity/OAuthInfo.js",
]);
import { ArcGISIdentityManager, request } from "https://esm.run/@esri/[email protected]";
// Set these constants
const portalUrl = "ENTERPRISE_PORTAL";
const appId = "APPID";
const info = new OAuthInfo({
appId,
locale: "en-us",
popup: false,
portalUrl: portalUrl,
preserveUrlHash: true
});
IdentityManager.registerOAuthInfos([info]);
const credential = await IdentityManager.checkSignInStatus(portalUrl + "/sharing");
const serverInfo = {
server: portalUrl,
hasPortal: true,
hasServer: true
}
const authentication = ArcGISIdentityManager.fromCredential(credential, serverInfo);
console.log(authentication.portal);
const portalRestURL = `${portalUrl}/sharing/rest`;
const getServersURL = `${portalRestURL}/portals/self/servers`;
// Attempt server call with created authentication
try {
const serversJSON = await request(getServersURL, {
authentication,
httpMethod: "GET",
params: {
f: "json",
},
});
} catch (err) {
console.log(err);
// Retry server call with modified authentication
authentication.portal = portalRestURL;
const serversJSON = await request(getServersURL, {
authentication,
httpMethod: "GET",
params: {
f: "json",
},
});
console.log(serversJSON.servers);
}
</script>
</body>
</html>Logs
Using ArcGIS Maps SDK for JavaScript 4.33.4 [Date: 20250626, Revision: a8d23c72]
Using Calcite Components 3.2.1 [Date: 2025-05-29, Revision: 618973fec]
https://www.arcgis.com/sharing/rest
ArcGISRequestError: GWM_0003: You do not have permissions to access this resource or perform this operation.
at m (request.ts:185:11)
at request.ts:479:26
at async im.html:40:27
(5) [{…}, {…}, {…}, {…}, {…}]System Info
ArcGIS Rest JS version: `v4.5.1`
The HTML example stands alone with no npm or build needed.Additional Information
ArcGIS Rest JS version v3.6.0's UserSession did not need the manual override.