Authentication Using Token No Longer Works

485
5
Jump to solution
08-04-2020 11:29 PM
WengNg1
New Contributor III

Hi All,

I've been accessing our ArcGIS Online site via token in ArcGIS Python API without any issues for the past couple of months.

I seem to be having issues authenticating via an access token now. 

from arcgis.gis import GIS
gis = GIS(url=portal, token=accessToken)

In the API references , I also realised that it mentions the below:

token

Optional string. This is the Enterprise token for built-in logins. This parameter is only honored if the username/password is None and the security for the site uses BUILT-IN security.

Our AGOL site is configured with Enterprise Login and I use the token authentication to login with my Enterprise login.

Did something change recently and is this still a supported method of authentication? It has significant ramifications to our org if it is no longer supported.

Regards,

Weng

Tags (1)
0 Kudos
1 Solution

Accepted Solutions
WengNg1
New Contributor III

Finally found the issue, the solution was actually pretty simple:

gis = GIS(url=portal, token=accessToken)

only supports portal = https://www.arcgis.com as documented in the API reference.

If you set it to your own portal's URL, it will not work. So the solution was to set it to the default https://www.arcgis.com .

View solution in original post

0 Kudos
5 Replies
GeoJosh
Esri Contributor

Hello,

I'm not familiar with method of authentication but would be happy to take a look. Can you share where you normally get the token from?

Thanks,

Josh

0 Kudos
WengNg1
New Contributor III

I use the following method( grant type = authorization code) to get an access token : 

Token—ArcGIS REST API | ArcGIS for Developers 

Then , I use the access token generated to authenticate using ArcGIS Python API as mentioned above . 

0 Kudos
JoshuaBixby
MVP Esteemed Contributor

Tokens expire, are you sure yours didn't?

0 Kudos
WengNg1
New Contributor III

I realise it is short lived for AGOL (30 mins), but pretty sure the token worked as I can append it to the end of my site's URL to access REST .

0 Kudos
WengNg1
New Contributor III

Finally found the issue, the solution was actually pretty simple:

gis = GIS(url=portal, token=accessToken)

only supports portal = https://www.arcgis.com as documented in the API reference.

If you set it to your own portal's URL, it will not work. So the solution was to set it to the default https://www.arcgis.com .

0 Kudos