Select to view content in your preferred language

Generate Token for hosted ArcGIS

7260
5
11-02-2017 05:47 AM
YashvitNaik
Occasional Contributor

One of our client uses the hosted ArcGIS service. I am trying to use one of their feature services via the JS API.

The URL of this feature server is something like this:

https://services8.arcgis.com/<some code>/ArcGIS/rest/services/<service name>/FeatureServer 

As this service is not public, I understand that we need to generate a token to access this resource. This is something we do with our hosted GIS Servers. 

For our hosted GIS server we use the token generation api at :

https://<local server name>/ArCGIS/tokens

But when we are not able to access this same API on the hosted server. 

Have done quite a bit of googling and am seeing docs that mention a URL like /arcgis/tokens/generateToken 

http://resources.arcgis.com/en/help/arcgis-rest-api/#/Generate_Token/02r3000000ts000000/  

http://server.arcgisonline.com/arcgis/sdk/rest/index.html#/Generate_Token/02ss00000059000000/

But this does not work.

This help doc shows the various options for security out of which one is Token based and it says it works with ArcGIS Online. So what are we doing wrong?

ArcGIS Security and Authentication | ArcGIS for Developers 

Is there something that needs to be enabled on the account?

5 Replies
ThomasSolow
Frequent Contributor

When you say generateToken doesn't work, what do you mean exactly?

I'm not completely sure how you're supposed to handle this for logging into ArcGIS Online but my expectation is that you could generate a token from a URL like: Generate Token.

Also I've actually never done this manually (but I don't see any reason that you couldn't).  I've always used some combination of OAuthInfo and the Identity Manager, which are documented in the JS SDK.

YashvitNaik
Occasional Contributor

With doesnt work I mean the URL https://services8.arcgis.com/ArcGIS/tokens/generateToken  doesnt exist at all.

The sample arcgisonline servers seems to have that api but not the production hosted ones.

Dont want to get into OAuth at the moment as that would involve quite some change and there are quite a few other clients that are happy with the token based login for their locally hosted GIS servers.

Just to clarify, I am trying to generate the token with a username and password.

ThomasSolow
Frequent Contributor

Does this URL work? ArcGIS Portal Directory 

There's no HTML interface, but you should be able to POST user info to that URL with the parameters listed here: ArcGIS REST API 

I found some old code that seems to work:

esriRequest("https://www.arcgis.com/sharing/generateToken",{
  method: "post",
  query:{
    f:"json",
    username: '<name>',
    password: '<password>',
    // I guess this would be sampleserver8 for you
    referer: '<http://analysis7.arcgis.com/>'
  }
}).then(response => {
  return r.data.token;
});‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍
by Anonymous User
Not applicable

I may have the same issue. I have a script that works on one ArcGIS Online organizational account to generate a token, however if I use that same script on another account it fails to generate the token. We manage multiple accounts so I have tried it with several and currently only one returns a token. Is there an org setting that needs to be changed? Everything else is the exact same. Running the same script from the same machine etc. 

by Anonymous User
Not applicable

An update:

Not sure what the exact problem ended up being for the original poster on this thread, however I found this useful tidbit:

When using the REST API to generate a token the username is case sensitive. It's not case sensitive when manually signing into ArcGIS Online so in my case I didn't even realize that would be an issue in my script.

ArcGIS Online generateToken does not work?