In my case, I'm providing services for subscribing tenants
(applications/developers/consumers). These services are based on our
own content, plus tenant content that is uploaded and associated with
our content. There is no end user data within our application, and
thus there is no need for user delegated authorization.
But, we still need to support both tenant access (updates and
queries), as well as end user access (queries only). To facilitate end
user access, we provide Flash and JavaScript based 'widgets' which can
be easily embedded within the tenant's web application. Or, a tenant
can create their own JavaScript, mobile application etc., and invoke
the APIs directly w/o using our widgets.
So, we have both tenant and end user clients accessing our APIs. And,
the end users are accessing the APIs using something as transparent as
JavaScript. User agents don't run through some tenant proxy, they
directly invoke our APIs via JSONP. Providing a user agent with
credentials to do signing (like OAuth 1.0a), or for HTTP basic
authentication etc., was not something we wanted to do. Granted,
temporary credentials could be generated for this purpose. But, the
OAuth 2.0 bearer token made more sense for us.
Not only does the bearer have access to the APIs (within limits), the
token also identifies the tenant that issued the token. That way, we
know both which tenant to attribute usage, as well as which tenant's
data to incorporate into the API response. This works well. But, from
where does the user agent get this token? In our case, the tenant
application acquires the token on behalf of the user agent, and then
conveys it when the page is loaded. OAuth 2.0 specifies a client
credentials mechanism by which the tenant application invokes our
OAuth Authorization Server (AS) and provides its client ID and secret
(issued by us), to obtain a bearer token. This token is then passed on
to the user agent.
I believe client credentials has been superseded by HTTP basic
authentication (both over HTTPS), though the former is still
supported. Either way, the tenant in possession of the API key (client
ID) and secret can obtain tokens, either for their own use (server-to-
server) or to hand off to user agents (site visitors/customers).
For us, OAuth 2.0 handles this nicely. Could we instead have just
created our own authorization API, whereby the tenant uses HTTP basic
authentication to obtain some magic token (UUID say) that we generate
and maintain? Sure thing, that would have worked, but it would also
have been non-standard; in terms of defining this endpoint, the format
and meaning of the token, how the token is conveyed when making API
calls (Authorization header, request parameter) etc. I think when
selling your services, keeping with standards is very helpful. And,
one day we may have end user data, and OAuth has a solution for that
was well. :)
Also, not using cookies and HTTP sessions pertains to more than just
following a standard. I believe one of the tenants of a RESTful API is
that it is stateless. The client provides everything in the request
the server needs. Sure, a cookie is just another thing in some
respects, but if it is used to identify a chunk of server-side state
(session), then it's going to matter which instance of the service
handles the requests, or forces you to maintain distributed sessions
among your servers, implement sticky load balancing etc. That's just
mechanical though. If the API is dependent on building up some kind of
session state by invoking some sequence of methods etc., then that
adds complexity to the API.
But, even though OAuth itself stands outside of (in front of) your
API, an OAuth bearer token actually is state. Is it a valid token or
just some random characters provided by the client? Is the token
expired? How does the server handling this request know this? In my
case I need to make sure the token is always used by the same source
IP address (not hijacked), as well as count its usage, and perhaps
invalidate the token due to malicious usage detection etc. That's all
state associated with the token. Whichever instance of my API server
receives the request, it must have equal (well, eventually consistent)
access to the token state. That is all security related though, and at
least the APIs themselves do not also have to deal with session state
etc. A homebrew (non-OAuth) security scheme would have the same
problem, so this not a detraction of OAuth per se.
The OAuth dance is not difficult. There are implementations out there
for both Authorization Server and Provider functionality. Or you can
basically outsource it to our friends at Apigee, Mashery etc. I work
in a Java shop, so we're making use of Spring Security OAuth. By
setting up some filters, and providing some persistence for token
data, it's easy to get up and running. I've had to add more to that
given the other restrictions we apply to token usage, but again, I'm
not writing OAuth 2.0 code form scratch. :)
Cheers,
Jeff
On May 26, 3:41 pm, Richard Berger <
richardlan...@gmail.com> wrote:
> First, thanks for the link to the "oauth-demystified-hopefully<
http://www.slideshare.net/coldfumonkeh/oauth-demystified-hopefully>"