The accepted answer here as to why OAuth2 access tokens expire:
Assuming that we don't support non-encrypted transmission of the access token takes care of the first bullet point.
Assuming that we are fine with doing a database lookup against a revokable, completely random access token takes care of the second one.
For mobile apps, client authentication cannot be stronger, because "the client_id and client_secret obtained during registration are embedded in the source code of your application. In this context, the client_secret is obviously not treated as a secret." (Google). That eliminates the third concern.
So what is the benefit of separating short-lived access tokens and long-lived refresh tokens in this scenario? Is it "okay" to just issue non-expiring access tokens and ignore the whole refresh token part?
By default, access tokens are valid for 60 days and programmatic refresh tokens are valid for a year.
The access token is set with a reasonably lower expiration time of 30 mins. The refresh token is set with a very long expiration time of 200 days. If the traffic to this API is 10 requests/second, then it can generate as many as 864,000 tokens in a day.
Developers strongly prefer access tokens that don't expire, since it's much less code to deal with. In order to help mitigate these concerns, services will often build the token refreshing logic into their SDK, so that the process is transparent to developers.
Mobile applications do not require a client secret, but they should still be sure to store refresh tokens somewhere only the client application can access.
The difference between a refresh token and a non-expiring access token in means of security is one additional call to the authorization server.
If an attacker gains access to your non-expiring access token, he can directly call your resource server and get confidential data as response.
Now if he steals your refresh token, he first has to call the authorization server and receive an access token in response. Then he can query the resource server for confidential data.
Each time an access token is requested from your authorization server using a refresh token, the OAuth 2 specification (at least the latest draft for now) requires the server to check the client identity and if it is bound to the token, if possible.
As the normal approach with a client secret does not work to definitly identify an installed application on an open platform, the platform running the application has to provide methods to do this. Google e.g. requires Android applications to be signed by the developer. When requesting credentials for an Android application using the Google API Console, you therefore have to specify the fingerprint of the certificate you used for signing the application and only get a client ID, but no secret in response. On issuing tokens, Google can then decide if the application was authorized by the developer to request tokens in his name.
If you definitly can't verify the client identity, it is at least possible in some cases to recognize that a refresh token was stolen. The specification has an example for this:
When client authentication is not possible, the authorization server SHOULD deploy other means to detect refresh token abuse.
For example, the authorization server could employ refresh token rotation in which a new refresh token is issued with every access token refresh response. The previous refresh token is invalidated but retained by the authorization server. If a refresh token is compromised and subsequently used by both the attacker and the legitimate client, one of them will present an invalidated refresh token, which will inform the authorization server of the breach.
The biggest issue with a non-expiring access token is that there is no mechanism to replace a token that is stolen. If I get access to your non-expiring access token, then I am effectively you for that system. If the token is short-lived and expires, then there is a mechanism to replace the stolen token and a limit on the window I have to crack your token.
Let's assume it takes me 3 hours to crack a packet and get the token, but the access token is only good for two hours. Then, by the time I am able to break into your account, the token has changed and I have to start over. If the token is non-expiring, then I have complete access to your account and you have no way to replace it short of removing the token and forcing a re-authorization.
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