Should I explicitly send the Refresh Token to get a new Access Token - JWT

前端 未结 1 913
耶瑟儿~
耶瑟儿~ 2020-11-29 07:00

In my application, I return an access token and a refresh token when a user logs in successfully. The expiration times for access and refresh token have been set to 10 and 4

相关标签:
1条回答
  • 2020-11-29 07:22

    Yes, the refresh token is used to obtain a new access token.

    When you request the access token for the first time, you usually start by sending a token request to the token endpoint, in case of the so called Resource Owner Password Credentials Grant with user credentials in the request header, e.g.

    grant_type=password&username=user1&passowrd=very_secret
    

    when the access token is expired, you have to request a new access token. This time, with a refresh token which is still valid, you don't need the user credentials again but send

    grant_type=refresh_token&refresh_token=<your refresh token>
    

    instead. This way you don't need to store the user credential on client side and don't need to bother the user again with a login procedure. As you know the expiry time, you can also implement a mechanism to refresh your token before the access_token is expired.

    Additionally you can read this for further information about the topic: https://auth0.com/learn/refresh-tokens/

    In the following tutorial is also a screenshot of how to use refresh token in postman: http://bitoftech.net/2014/07/16/enable-oauth-refresh-tokens-angularjs-app-using-asp-net-web-api-2-owin/ (scroll down to step 6) Generally I can recommend reading Taiseer Joudeh's tutorial, esp. for C#, ASP.NET uand Angular programmers.

    0 讨论(0)
提交回复
热议问题