How to make JavaScript API show company specific portal login screen when trying to access secure layer

1241
1
01-20-2023 01:37 PM
IvoSturm
New Contributor

Dear fellow developers,

I have written a webapp with the ArcGIS JavaScript API and all is working fine. Now I am trying to add secured layers to the web app and the app starts asking for credentials via a default login screen. I could use that, just entering username and password, but most users don't know their user name and password for ArcGIS. 

IvoSturm_0-1674250696920.png

 

The company has implemented SSO with ArcGIS so users don't have to fill in their credentials. Users typically go to the main company.maps.arcgis.com site and get to a company specific login screen where they have the option to click this SSO button.

IvoSturm_1-1674250706028.png

 

My question; how can I make the JavaScript API show this company specific login page with SSO button instead of the default one?

I tried registering oauthInfo and serverInfo setting but without success....

Did anybody else ever built this?

Tags (3)
0 Kudos
1 Reply
MichaelSnook
Occasional Contributor III

Hello
This does require oAuth and you need to register your app with your Portal/AGO instance. Once you register it you get the app id and add it to your oAuth configuration in your app.

 

var oauthInfo;
//get oauthInfo
oauthInfo = new OAuthInfo({
appId: <app id here>,
portalUrl: <portal url here>,
popup: true
});

esriId.registerOAuthInfos([oauthInfo]);

 


Then, when you load your secure layer you pass in the portal you are accessing it from...if it's a secured layer the login dialog will popup for that portal:

 

Layer.fromPortalItem({
portalItem: {
// autocasts as new PortalItem()
id: <item id here>,
portal: new.Portal({ url: <portal or ago url here> });

}
})
.then(function (layer) {

})
.catch(rejection);
});

 

Hope that helps!