Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Advantages of using OAuth Password Credentials Grant over Token Access Authentication

I am creating an API for a mobile application using Rails 5. At the moment, I don't need three-legged authorization, as the API will only be consumed by our own mobile apps.

I'm thinking of choosing one of these two options:

  1. Doorkeeper + Devise: I can implement OAuth 2.0 using Doorkeeper, but I will only be using the Password Credentials Grant, at least for now.
  2. Rails' own ActionController::HttpAuthentication::Token module + Devise: This seems like the simpler way to go.

Honestly, I can't see the difference between the Token Access Authentication method and OAuth 2.0's Password Credentials Grant.

How would one choose one over the other? Is there any other option that needs to be considered?

like image 337
hattenn Avatar asked Apr 05 '17 10:04

hattenn


2 Answers

If all you'll ever have is the "single purpose API" (only for mobile application), there is no big difference in terms of security.

But if you'd like to extend this API to be used by the external services, then, you'll be in a much better position with implemented OAuth 2.0 using Doorkeeper, because you can easily configure, for example, a Authorization Code Grant for them. So, I'd say that "Doorkeeper + Devise" option is more future-proof, because it provides more options, while HTTP Token authentication is much simpler for implementation.

like image 114
Zoran Majstorovic Avatar answered Nov 04 '22 03:11

Zoran Majstorovic


The two are conceptually different things:

  • "Token Access Authentication" specifies a protocol describing how a (possibly long-lived) token should be presented to the server securely. It says nothing about where the token came from or how it should be interpreted.
  • "Password Credentials Grant" is a part of the fully-fledged OAuth flow, describing the means of obtaining a (usually short-lived) token.

In a sense, you could use Password Credentials Grant to obtain a token using OAuth and then use this token in the Token authorization header to gain access.

The question then becomes - is it useful to do the extra roundtrip for exchanging the (permanent and secret) credentials for a (temporary) token, when we could instead use the (permanent and secret) token stored in the app to authorize immediately anyway.

As I see it, there are two potential benefits of using the full OAuth flow. Firstly, it lets you add other means of authorization for third parties naturally. Secondly, it lets you revoke the token at any moment and force a re-authorization using these other means (if you implement them, of course) without having to invent any wheels.

On the other hand, you can always add any additional "token generation" parts later, when they are needed. Thus, if your current plan is to hard-code credentials in code anyway, I'd suspect you are probably better off relying on Token authorization.

Not only is it one request shorter, it may also be slightly more secure than the Bearer authentication used in OAuth: if an attacker sniffs a Bearer token, they would (usually) get full token access to the server until its expiration. It is not the case with Token tokens (normally). Not that it all matters too much of course if the attacker could extract the shared secret from your app anyway.

like image 34
KT. Avatar answered Nov 04 '22 05:11

KT.