Hi guys,
I'd like to generate token for arcgisonline hosted service but I can figure out the endpoint and how to construct the request.
Is ithttps://www.arcgis.com/sharing/rest/generateToken?username=username&password=password&expiration=60 or https://services2.arcgis.com/xyz/arcgis/tokens/generateToken?username=username&password=password&expiration=60 or ...../arcgis/tokens?request=getToken&username=<usr>&password=<usr>&expiration=<token_lifespan
What is the endpoint and how would I construct the parameters. I'm using Java HttpUrlConnection? #ArcGISREST
Request:
POST https://www.arcgis.com/sharing/generateToken HTTP/1.1 Host: www.arcgis.com Content-Type: application/x-www-form-urlencoded f=json&username=USERNAME&password=PASSWORD&client=requestip
Response:
HTTP/1.1 200 OK Date: Thu, 01 Mar 2018 09:53:04 GMT Content-Type: text/plain;charset=utf-8 Transfer-Encoding: chunked Connection: keep-alive Vary: Origin Cache-Control: no-cache Pragma: no-cache Expires: -1 Vary: Accept-Encoding, User-Agent X-Robots-Tag: noindex {"token":"TOKEN","expires":1519905184244,"ssl":false}
Steve,
Please refer:
Acquiring ArcGIS tokens—ArcGIS Server Administration (Windows) | ArcGIS Enterprise
Generate Token
~Shan
I have seen this, and for ArcGIS Server this is okay. However, I'd like to know which endpoint does ArcGIS Online use to generate tokens for username and password based authentication.
I know there is this option Get an access token | ArcGIS for Developers which is based on CLIENT_ID and CLIENT_SECRET. But I want to use my password and username to get the token from ArcGIS online.
Use POST instead of GET.
Yes I need to use POST. But what is the right endpoint?
Thank you ramunask I just tried in Postman and it works.
How do you include the post conditions into the URL? I keep getting the following error:
{"error":{"code":400,"messageCode":"GWM_0002","message":"Invalid URL","details":[]}} My URL looks like this: https://www.arcgis.com/sharing/generateToken HTTP/1.1?f=json&username=USERNAME&password=PASSWORD&client=requestip
Hi dear all,
I been trying to do that request too, using postman but I get an error: {"error":{"code":400,"message":"Unable to generate token.","details":["POST request should not contain username and password in the query string."]}
Can anybody help me to solve this, please?
Best regards,
I can get the token, but when I try to use it for actions like adding to a feature layer (applyedits) it keeps saying,
{"error":{"code":498,"message":"Invalid token.","details":["Invalid token."]}}
@ArthurXiaoif you generated your token from one IP address and trying to use from different IP address, then it's normal, that you get "Invalid token" error. Also, there is no problem with "." (dot) at the end of token.
Please see documentation at https://developers.arcgis.com/rest/users-groups-and-items/generate-token.htm and check other options when generating token.
Thank you for your response.
I used "requestip" for parameter "client", so looks is not the problem of client IP. Do you mean I requested token from "https://www.arcgis.com/sharing/rest/generateToken?" but used to query service on "https://services3.arcgis.com/ViXXHj2TcfxwEXHV/arcgis/rest/services/"?If that's the case, then how to request token from "https://services3.arcgis.com"? I tried
https://services3.arcgis.com/sharing/rest/generateToken?https://services3.arcgis.com/generateToken?https://services3.arcgis.com/sharing/generateToken?
But none of them works.
The link you pointed to is for portal, but we tried to get token from ArcGIS online.
Any idea will be appreciated.
"/rest/info?f=json" (in your case - https://services3.arcgis.com/ViXXHj2TcfxwEXHV/arcgis/rest/info?f=pjson ) gives information where tokens should be generated (https://www.arcgis.com/sharing/generateToken).
Thanks again for the explanation. So now goes back to the beginning question:
Generated token with https://www.arcgis.com/sharing/generateToken, then query service hosed by https://services3.arcgis.com/ViXXHj2TcfxwEXHV/arcgis/rest but got failed message "Invalid Token".
So I think it's the problem of AGOL.
@AppmartIntegrated
I'm not sure if this will help you; but, I had a similar issue that was resolved by setting the client parameter to referer; and setting the referer parameter to my feature service's base URL, which in your case may be https://services3.arcgis.com/ViXXHj2TcfxwEXHV.
This reference was useful for me:
https://developers.arcgis.com/rest/users-groups-and-items/generate-token.htm
@ArthurXiao
Hello @ArthurXiao ,
Have you been able to resolve this issue? I'm having a similar, if not the same, issue.
Do you think the ArcGIS Online security settings for the user whose credentials are being used to generate the token have anything to do with this. For example, do they need to be an administrator?
This worked for me. Thank you
In case anyone runs into this, here's how I solved generating a token. Our enterprise system means the same user account is used for ArcPro and ArcGIS Online.
Open a new python notebook in ArcPro (tested in 3.7.0), paste the following code into a single cell and run it:
import arcpy, time oldURL = input("What URL are you trying to access?\n\t") # <base of URL>/arcgis/rest/services/Generic_Data_Collection/FeatureServer token_info = arcpy.GetSigninToken() print(f"\nYour new url:\n{oldURL}?token={token_info['token']}") remainingTime = token_info['expires'] - int(time.time()) print(f'\n\t{remainingTime/60} minutes left')
Los miembros registrados pueden publicar, seguir actualizaciones y más. ¿Nuevo aquí? Regístrate gratis.
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.