The Scenario
I've recently built an API, and have protected its resources using OAuth
Bearer Access Tokens.
I've used the Client_Credentials
Flow, as it will be accessed by clients as opposed to users.
Here's the thing, when a client has successfully provided the client_id
and the client_secret
they receive a response like the following :-
{
"access_token": "<Access Token>",
"token_type": "bearer",
"expires_in": 1199,
"refresh_token": "<Refresh Token>"
}
Refresh Tokens.
Not knowing much about refresh tokens, i immediately assumed that a client would be able to provide the OAuth Server the refresh_token
to retrieve a fresh Access_Token
.
This is 'kind of' correct.
In order to use the refresh_token
the client still needs to pass the client_id
and client_secret
along with the refresh_token
to get a new access token.
The grant_type
also needs to be changed to refresh_token
.
Where is the benefit of a refresh_token using this flow? If I need to pass the client_id and client_secret each time, surely you would just avoid using a refresh token altogether?
In order to use the refresh_token the client still needs to pass the client_id and client_secret along with the refresh_token to get a new access token. The grant_type also needs to be changed to refresh_token .
The token endpoint does not issue a refresh token as refresh tokens are not supported by the client credentials grant.
Typically, refresh tokens are only used with confidential clients. However, since it is possible to use the authorization code flow without a client secret, the refresh grant may also be used by clients that don't have a secret. If the client was issued a secret, then the client must authenticate this request.
In the client credentials flow, permissions are granted directly to the application itself by an administrator. When the app presents a token to a resource, the resource enforces that the app itself has authorization to perform an action since there is no user involved in the authentication.
The issuance of a refresh token with the client credential grant has no benefit.
That is why the RFC6749 section 4.4.3 indicates A refresh token SHOULD NOT be included
. Thus its issuance is at the discretion of the authorization server.
From my point of view an authorization server should never issue a refresh token with the client credentials grant as the access token issuance process will take an additional and unnecessary step:
Issuance with the client_credentials grant type:
Issuance with the refresh_token grant type:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With