Select to view content in your preferred language

Oauth 2.0 Sign in

374
0
06-01-2023 12:59 PM
tad
by
New Contributor

Hello,

I have an old web map, created in C#, that utilizes the ArcGIS API for JavaScript 3. Currently, there is a proxy used to log into the organizational account to utilize the web map. I am attempting to update the code to use Oauth to sign into the ArcGIS Enterprise account instead.

Things work until it checks if the user is signed in, which is false. I'm currently getting an error with the domStyle panels (Cannot read properties of null (reading 'style')).

Any help would be appreciated.

Thanks, tad

Here is the code (apologies for non-formatted):

require([
"dojo/dom",
"dojo/parser",
"esri/arcgis/Portal",
"esri/arcgis/OAuthInfo",
"esri/IdentityManager",
"dojo/dom-style"
],
function (
dom,
parser,
Portal,
OAuthInfo,
esriId,
domStyle) {
parser.parse();

arcgisLogin();

function arcgisLogin() {
var info = new OAuthInfo({
appId: "[Id from the app I created]",
portalUrl: "[URL to organization portal]",
popup: false
});
esriId.registerOAuthInfos([info]);

esriId
.checkSignInStatus(info.portalUrl + "/sharing/rest")
.then(function () {
handleSignedIn();
})
.otherwise(function () {
domStyle.set("anonymousPanel", "display", "block");
domStyle.set("personalizedPanel", "display", "none");
});

document.getElementById("sign-in").addEventListener("click", function () {
esriId.getCredential(info.portalUrl + "/sharing/rest");
});

document.getElementById("sign-out").addEventListener("click", function () {
esriId.destroyCredentials();
window.location.reload();
});

function handleSignedIn() {

var portal = new Portal();

portal.load().then(function () {
const results = { name: portal.user.fullName, username: portal.user.username };
otherMapFeatures();
});

}

}

0 Kudos
0 Replies