Skip to main content
I have set up a connected app where I set the policy for refresh tokens to no expiration. While I been doing some testing, I receive the error message that my access token is expired. This happens after I have authorized on the same device many times. I have tried revoking all tokens through the Salesforce platform, but when I try to test again, I receive the same error message. I have read online that you may have 5 refresh tokens per user per device? I am curious if this is related to the problem. I only store the most recent authorization tokens and would expect that the most recent refresh token issued would be valid.
1 réponse
  1. 13 janv. 2021, 07:14
    John,

    Sessions expire based on your organization's policy for sessions. As long as the app is in active use, the session won't expire. Once the session is logged out, the timeout has elapsed, or it is otherwise expired (e.g. an administrator expires all sessions for the Connected App).

    There's no way to know how long it will be until your session expires. It's not exactly "trial and error," it is simply a normal process. Even if you were told that your session expired in two hours, it might not last two hours if an administrator revokes the session, the session remains in use, etc.

    If you use refresh tokens, your code should first try the regular API call, and if you get a 4xx result, try using the refresh token to get a new session token, and if that fails, then you've been kicked out, and the user needs to re-authenticate to continue. If you don't use refresh tokens, you can skip the middle step, obviously

     

     

    Please refer to the link below for more information.

    http://salesforce.stackexchange.com/questions/73512/oauth-access-token-expiration

     

    https://developer.salesforce.com/forums/?id=906F00000009CYiIAM 

     

    https://developer.salesforce.com/docs/atlas.en-us.api_rest.meta/api_rest/intro_understanding_refresh_token_oauth.htm

     

    Hope this helps you!

    Let me know if it helps you and close your query by marking it as solved so that it can help others in the future.

    Thanks.