Using a token to bypass having to sign in to access a hosted feature layer

2527
2
Jump to solution
11-28-2020 08:28 AM
AndrewMurdoch1
Occasional Contributor II

Good Day

I'm trying to bypass the sign-in process to access our host feature layer from the ArcGIS JavaScript API, I tried implementing OAuth, following the guides, and used this:

const info = new OAuthInfo({
    appId: "<blah>",
    popup: false
});

identityManager.registerOAuthInfos([info]);


But every time the feature layer load it kicks me over to a sign-in page, and once I sign-in it kicks me back to our application, but to the wrong page and I enter a non-stop loop,. It is possible to use an ApplicationSession and use the Client ID / Client Secret to generate a token, which I can then register to bypass this issue?

We have this function for queries:

authenticate() {
  this._session = new ApplicationSession({
    clientId: '<blah>',
    clientSecret: '<blah>'
  })
}


But I don't see any option to attach the authentication parameters to the FeatureLayer URL

I looked up this page: https://enterprise.arcgis.com/en/server/latest/administer/windows/about-arcgis-tokens.htm  which doesn't explain how to attach or generate the token, unless I'm meant to use the token from the ArcGIS Developer Portal.

Thanks

0 Kudos
1 Solution

Accepted Solutions
AndrewMurdoch1
Occasional Contributor II

Solved, if you're trying to do the same thing, try this, making sure to fill in username and password:

const tokenURL = 
'https://www.arcgis.com/sharing/generateToken?username=<>&password=<>&client=requestip&f=json'
this.http.httpGet(tokenURL).then((res: any) => {
  identityManager.registerToken({
    server: 'https://www.arcgis.com/sharing/rest',
    token: res.token
  });

  /* Map Init Here */
}).catch((error) => {
  console.log(error);
})

 

View solution in original post

2 Replies
AndrewMurdoch1
Occasional Contributor II

Solved, if you're trying to do the same thing, try this, making sure to fill in username and password:

const tokenURL = 
'https://www.arcgis.com/sharing/generateToken?username=<>&password=<>&client=requestip&f=json'
this.http.httpGet(tokenURL).then((res: any) => {
  identityManager.registerToken({
    server: 'https://www.arcgis.com/sharing/rest',
    token: res.token
  });

  /* Map Init Here */
}).catch((error) => {
  console.log(error);
})

 

prudhvi199
New Contributor

I have integrated Portal with ArcGIS Server , so authentication procedure is taken care by the Portal. We use SAML OKTA users inside the portal, Is there a any API Endpoints to generate token for this usecase?

0 Kudos