Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Best practices for handling access tokens and scopes for OAuth2 implementation?

Tags:

oauth-2.0

Assume we have an OAuth2 implementation that supports "read" and "write" scope.

I retrieve an access token "f482c829" with "read" scope. If I then change my mind and now want read+write permission and authorize again with "read" and "write" scope do you:

  • Update scopes for existing access token and return same token "f482c829"?
  • If using same token, require that the access token is reclaimed if using response_type=code before updating scopes? (I think yes)
  • Update scopes for existing access token and return a refreshed token "zf382nL"?
  • Create an entirely new token leaving "f482c829" and its scopes intact?

If you create a new token every time per scope, you end up having to store multiple access tokens per authorization and different permissions everywhere. I've been hesitant to implement it that way.

The OAuth2 spec (as of draft-12) unfortunately does not address any of this.

like image 970
dschn Avatar asked Feb 16 '11 21:02

dschn


People also ask

Is scope required for OAuth2?

You don't necessarily need OAuth2 scopes, and you can handle authentication and authorization however you want. But OAuth2 with scopes can be nicely integrated into your API (with OpenAPI) and your API docs.

What is the request scope for write access to the API while using OAuth?

OAuth 2.0 scopes provide a way to limit the amount of access that is granted to an access token. For example, an access token issued to a client app may be granted READ and WRITE access to protected resources, or just READ access. You can implement your APIs to enforce any scope or combination of scopes you wish.

Which format does OAuth 2.0 require tokens to use?

Bearer Tokens are the predominant type of access token used with OAuth 2.0. A Bearer Token is an opaque string, not intended to have any meaning to clients using it. Some servers will issue tokens that are a short string of hexadecimal characters, while others may use structured tokens such as JSON Web Tokens.


1 Answers

In facebook's case, resource server is basically same with authorization server. So they do "use existing token" way. And it enable to allow users to disable each scopes on facebook.com site. About refresh token, you don't need to establish new refresh token. (Of course you can do it though.) Existing refresh token will also be connected with all scopes.

In Google's case (maybe Yahoo! too), resource server is totally different from authorization server. Many resource server (Docs, Buzz etc) accept access tokens established single authorization server. In this case, "establish new token" way seems better.

In Twitter's case (maybe your case too), both seems OK.

Plus, in any way, when user revoked client access you need to revoke all tokens for the client. User is not revoking "token" but "client".

Since developer should pre-register redirect_uri, using same client credentials both on website and on mobile all seems tricky. So I recommend asking developers to use different client credentials in that case.

like image 63
nov matake Avatar answered Sep 29 '22 03:09

nov matake