News for hackers. Stuff that matters.
Re:Understanding OAuth2 and OpenID Connect by mooreds on Sunday September 06, 2020 @06:38PM (#24395200)
This was a good article. The first section, explaining the reason why OAuth2 is a fit for certain data flow needs, was really strong. I liked the diagram of the flow as that made it clear what all the pieces were.

I think that if you need that separation between your resource servers and authorization server, the OAuth dance can be a bit complicated, you can just use a simple api key. But as soon as you start to allow outside access to your systems, I'd suggest using an OAuth server (disclosure, I work for FusionAuth, a free as in beer competitor to Keycloak, Gluu, etc).

Additional things that I wish had been in the article:

* Don't use implicit flow, use the authorization code grant with PKCE.

* Don't use resource owner password flow; it was designed to allow existing systems to bridge into OAuth and shouldn't be used in new systems today.

Both the implicit flow and the resource owner password flow are not part of OAuth 2.1--here's a post I wrote about it: https://fusionauth.io/blog/2020/04/15/whats-new-in-oauth-2-1

* Also, storing access tokens should be done carefully in the browser (httponly, secure cookies is the best way). If you can't do that, then use a server side proxy to store the access tokens. Otherwise your access tokens might get stolen by code executing in the browser.

* OIDC is built on top of OAuth and has a standard set of claims. If you can get by on what OIDC defines, you can switch between identity provider implementations fairly easily.

Re:Understanding OAuth2 and OpenID Connect by different_sort on Monday September 07, 2020 @12:45AM (#24396679)
Storing tokens in cookies would be against the spec wouldn’t it? I’m not putting rfc6749 on some sort of pedestal, but it clearly states that the tokens are in the response body and not set in cookies.

Do you have any examples of Authorization servers in the wild doing this or front end SDKs that work with that?

I’m very curious, I’m doing an SPA security research project at work and I’m very interested in these stories and learning more.

I’ve seen some folks do refresh in an httponly cookie, and Access in the js space. I’ve seen another example (auth0) put the refresh token in a web worker and access token accessible in js.

And I’ve seen things like msal.js just say F it and make them all accessible to js.

Re:Understanding OAuth2 and OpenID Connect by mooreds on Monday September 07, 2020 @10:41AM (#24399720)
Hiya,

Sorry, I was wrong. According to the spec you definitely have to send the access token back in the response body[0].

However, a client can store them as cookies (or, as you mention, other places, such as a service worker[1]). This is useful if the client is a single page application (SPA), which may need to present the access token to other resource servers.

RFC 6750 has something to say about how to store the bearer token [2]:

> Don't store bearer tokens in cookies: Implementations MUST NOT store bearer tokens within cookies that can be sent in the clear (which is the default transmission mode for cookies). Implementations that do store bearer tokens in cookies MUST take precautions against cross-site request forgery.

So, I apologize. The authorization server wouldn't send the access token as a cookie. Instead, there'd be a server side proxy which would request the token and then send it down as a secure cookie. Again, best practice would be to keep the access token on the server side proxy and just send a session id down to the client, but that sometimes doesn't work. Here is a diagram illustrating that path (with the 'store' entity acting as the proxy mentioned above)[3].

0: https://tools.ietf.org/html/rfc6749#section-5.1

1: https://gitlab.com/jimdigriz/oauth2-worker

2: https://tools.ietf.org/html/rfc6750#page-13

3: https://fusionauth.io/learn/expert-advice/authentication/web...

Re:Understanding OAuth2 and OpenID Connect by different_sort on Monday September 07, 2020 @08:55PM (#24404230)
Thank you for your replies and insight, it's really appreciated.

The way I see it with SPA and tokens in JS accessible space is that you're exposing your users to the possibility of token theft and user impersonation if someone is able pull off an XSS. This is not so different than using a session cookie that is not marked as 'httponly'. What's old is new again :)

I have also heard the argument that we shouldn't worry about token theft, because it's already too late if you're XSS'd, but I don't buy into that rhetoric(not saying XSS isn't incredibly bad).

Unfortunately I work in financial services, so we can't just skate by and assume that we're so uninteresting that an adversary with advanced capabilities wouldn't look to exploit our external or internal users somehow.

One another thing we're looking into is access tokens, like having the user re-authenticate or use a stronger factor(or multiple) to get the AS to grant them a very short lived, non-refreshable token to do their sensitive operation.

I'm going to check out the fusionauth blog for a bit more inspiration, if you're interested in continuing this discussion I would be interested in carrying it on.

Re:Understanding OAuth2 and OpenID Connect by mooreds on Monday September 07, 2020 @10:24PM (#24404701)
> This is not so different than using a session cookie that is not marked as 'httponly'.

The difference is a session cookie is tied to one server, but an access token could be used with many different APIs or other services. That said, an access token may expire more quickly, so the devil is definitely in the details.

> One another thing we're looking into is access tokens, like having the user re-authenticate or use a stronger factor(or multiple) to get the AS to grant them a very short lived, non-refreshable token to do their sensitive operation.

That makes sense, for sure. You could definitely require MFA to get an access token and have it be short lived. At that point it gets to a question of UX and how much impact you want on your users, but I'm not familiar with all the requirements you have.

> I'm going to check out the fusionauth blog for a bit more inspiration, if you're interested in continuing this discussion I would be interested in carrying it on.

Please do! Happy to respond here or if you want to check out the FusionAuth forum (which I monitor), you can find it on the the website under the resources tab.

Re:Understanding OAuth2 and OpenID Connect by bswamina on Sunday September 06, 2020 @08:56PM (#24395882)
Thank you very much for the valuable feedback ... very much appreciate and pointers ... this why love to share so can get feedback and pointers for other information may have missed.
Re:Understanding OAuth2 and OpenID Connect by mooreds on Sunday September 06, 2020 @08:58PM (#24395888)
Thanks for writing the post and helping people understand the standards better!
Re:Understanding OAuth2 and OpenID Connect by mooreds on Sunday September 06, 2020 @10:59PM (#24396270)
> I think that if you need that separation between your resource servers and authorization server, ...

Ack, this should have been

I think that if you do not need that separation between your resource servers and authorization server, ...