Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

OAuth REST access_token and instance_url expiry time?

I am working with Oauth2.0. In that i could able get the access_token and instance_url. Is there any expiry time for these two.

Can I store them and use it for all my REST calls without getting the new access_token and the instance_url. Is it possible for me to use it for long hours or even days.

like image 817
Easwaramoorthy K Avatar asked Feb 13 '12 13:02

Easwaramoorthy K


People also ask

How long is an OAuth token valid?

By default, access tokens are valid for 60 days and programmatic refresh tokens are valid for a year. The member must reauthorize your application when refresh tokens expire.

How long should access and refresh tokens last?

The Refresh token has a sliding window that is valid for 14 days and refresh token's validity is for 90 days.

How long are bearer tokens valid?

Renew tokens A valid bearer token (with active access_token or refresh_token properties) keeps the user's authentication alive without requiring him or her to re-enter their credentials frequently. The access_token can be used for as long as it's active, which is up to one hour after login or renewal.

Is there any way to check if OAuth token is expired or not?

The easiest way is to just try to call the service with it. It will reject it if it is expired and then you can request a new one. You can also keep the time you received the token and use the expires_in to calculate when it will approximately expire.


1 Answers

The access token is only valid for the length of a session (as defined in the Salesforce Org's settings — I believe the longest this can be is 8 hours without activity), as it's actually a session ID, that said, you should also be given a refresh token. The refresh token has a much longer lifetime and can be used to authenticate the user once the session has expired, without them having to enter any credentials — this allows you to do it in the background without them even having to concern themselves with the login process.

model metrics do a good job of explaining the token flow here.

like image 177
Matt Lacey Avatar answered Nov 03 '22 01:11

Matt Lacey