How to refresh or obtain a new token from Portal?

4195
7
09-27-2015 07:25 AM
by Anonymous User
Not applicable

What would be the correct process for detecting when and then obtaining a new token from Portal when the existing one expires?

One way would be to catch the error message and obtain a new token.

The Portal object in the API has a 'token' property, and an 'expires' property. I guess another method would be to check periodically whether the "expires" property is older than the current datetime.

But how to actually go about obtaining a new token? I expected there might be a method called 'refreshToken' or similar but not that I can find.

Cheers,

-Paul

0 Kudos
7 Replies
NeilAyres
MVP Alum

I think that there is only the "generateToken" call to the server.

You can also generate a token with a long expiry by specifying "expiration" : 1000 or something for a large number of seconds validity. Otherwise check the expires property against the system time as you suggest.

by Anonymous User
Not applicable

Hi Neil

Where is the 'generateToken' method within the qml API?

Thanks,

-Paul

0 Kudos
NeilAyres
MVP Alum

ArcGIS Rest api :

ArcGIS REST API

0 Kudos
NeilAyres
MVP Alum

But I also see that there is this under the OAuth 2.0 section...

ArcGIS REST API

0 Kudos
AlexanderNohe1
Occasional Contributor III

Hey Paul Haakma​,

I believe that you are looking for the expires property in the Portal class.  What you can do is compare this to the current time and if the current time is less than the expires time, generate a new token.  Having said that, I do not believe that you would need to run this as ArcGIS Online tokens generally last for about 2 weeks straight before they expire.

Date QML Type | Qt QML 5.5

ArcGIS Runtime SDK for Qt QML API: Portal Class Reference

I hope this helps!

NeilAyres
MVP Alum

Default token expiry is 60mins

0 Kudos
AlexanderNohe1
Occasional Contributor III

My mistake.  I must be thinking of another service I use.

0 Kudos