If I was to implement a new server-to-server API, what authentication standards are available to make it as easy for others to consume?
Ideally the less I need to document about how the authentication works, the better (hence the standard), and its more likely that developers consuming the service can use a standard library.
Some restrictions though:
I suspect an SSL type setup is a bit too complicated, as it seems most developers don't really know how to implement it properly.
With oAuth 1.0, it seems fairly simple:
http://provider.example.net/profile
Authorization: OAuth realm="http://provider.example.net/",
oauth_consumer_key="dpf43f3p2l4k3l03",
oauth_signature_method="HMAC-SHA1",
oauth_signature="IxyYZfG2BaKh8JyEGuHCOin%2F4bA%3D",
oauth_timestamp="1191242096",
oauth_token="",
oauth_nonce="kllo9940pd9333jh",
oauth_version="1.0"
But developers seem to be focusing on oAuth 2 now, with one possible solution being:
How does 2-legged oauth work in OAuth 2.0?
Which first requires you to call "/oauth/token" to get a token, but there doesn't seem to be much in the form of a specification on how this actually works (see replies):
http://www.ietf.org/mail-archive/web/oauth/current/msg07957.html
However there is some mention of using a MAC in oAuth 2, which might be useful... for example, do the Authorization once to get the MAC (with no login details), keep this semi indefinitely, and re-use for all subsequent requests:
http://blog.facilelogin.com/2013/01/oauth-20-bearer-token-profile-vs-mac.html
There is also an interesting discussion about HMAC, which kind of implies there isn't a standard on how this works either:
http://flascelles.wordpress.com/2010/01/04/standardize-hmac-oauth-restful-authentication-schemes/
Other notes:
Implementation, documentation and discussion for oAuth 1.0:
http://www.ietf.org/mail-archive/web/oauth/current/msg06218.html https://developers.google.com/accounts/docs/OAuth#GoogleAppsOAuth http://oauth.googlecode.com/svn/spec/ext/consumer_request/1.0/drafts/2/spec.html
Unfortunately the more I read about oAuth 2.0, the more I agree with Eran Hammer:
What is now offered is a blueprint for an authorisation protocol, "that is the enterprise way", providing a "whole new frontier to sell consulting services and integration solutions". http://en.wikipedia.org/wiki/OAuth
OAuth 2.0 is much more usable, but much more difficult to build securely. Much more flexible. OAuth 1.0 only handled web workflows, but OAuth 2.0 considers non-web clients as well. Better separation of duties.
You only really need OAuth2 and OpenID Connect if you'd like your users to give consent ("i.e. I want to allow this app access to my personal data"). You do not need OAuth2 to generate a JSON Web Token, a Personal Access Token, a Native Mobile App Session Token.
If you want to provide an API to 3rd party clients, you must use OAuth2 also. OAuth2 is very flexible. JWT implementation is very easy and does not take long to implement. If your application needs this sort of flexibility, you should go with OAuth2.
A typical OAuth flow involves three parties: the end-user (or resource owner), the client (the third-party application), and the server (or authorization server). So a 3-legged flow involves all three. The term 2-legged is used to describe an OAuth-authenticated request without the end-user involved.
Craig, great question. I am no expert, but have thought a lot about this, so a few thoughts.
Assuming we have to code against the lowest-common denominator, and using your requirement list (all 4 items) as my design seed, I would say the following:
?sig=<a mess of chars>&args=<more stuff>&nonce=f81d4fae-7dec-11d0-a765-00a0c91e6bf6
-- the server will record f81d4fae-7dec-11d0-a765-00a0c91e6bf6
as processed and never allow it to be used again. You can probably safely expire these from the DB after a reasonable amount of time (month? depends on velocity/usage/etc). TIP: This is a perfect use-case for using Redis SETs and the SISMEMBER command.Just so you know, the thing that makes secure API design instantly painful is the moment you don't require HTTPS for all communication. As soon as you do that, you have to turn to solutions like HMAC's/signing requests and nonce's. If your communication with the sever is secured over HTTPS and both can trust each other, life gets much better and you can do things like simple basic auth and just give the server an API_KEY with every request to identify who (or what) is making the request.
Hope that helps! It seems you've looked into this quite a bit already, so my apologies if you already knew all this and it didn't help.
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