Why Does OAuth v2 Have Both Access and Refresh Tokens?

后端 未结 14 2557
情话喂你
情话喂你 2020-11-22 12:36

Section 4.2 of the draft OAuth 2.0 protocol indicates that an authorization server can return both an access_token (which is used to authenticate oneself with a

14条回答
  •  Happy的楠姐
    2020-11-22 13:07

    To clear up some confusion you have to understand the roles of the client secret and the user password, which are very different.

    The client is an app/website/program/..., backed by a server, that wants to authenticate a user by using a third-party authentication service. The client secret is a (random) string that is known to both this client and the authentication server. Using this secret the client can identify itself with the authentication server, receiving authorization to request access tokens.

    To get the initial access token and refresh token, what is required is:

    • The user ID
    • The user password
    • The client ID
    • The client secret

    To get a refreshed access token however the client uses the following information:

    • The client ID
    • The client secret
    • The refresh token

    This clearly shows the difference: when refreshing, the client receives authorization to refresh access tokens by using its client secret, and can thus re-authenticate the user using the refresh token instead of the user ID + password. This effectively prevents the user from having to re-enter his/her password.

    This also shows that losing a refresh token is no problem because the client ID and secret are not known. It also shows that keeping the client ID and client secret secret is vital.

提交回复
热议问题