Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

OpenId Connect Questions -Authorization Code Flow (OAuth 2.0)

I am facing a custom implementation of OpenId Connect. But (there is always a but) I have some doubts:

I understand the process of obtainning an acces_token an a id_token, except the step when the OP provides an authorization_code to the client. If it is done by a redirect (using the redirect uri)

HTTP/1.1 302 Found
Location: https://client.example.org/cb?
code=SplxlOBeZQQYbYS6WxSbIA
&state=af0ifjsldkj
  • The end-user is able to see that authorization code? It does not expire? Imagine we catch it and we use later (some days later) Is it a security hole? Should the state be expired in the Token Endpoint?

The flow continues and we got at the client the Access_token and the id_token in the client.

  • How the Access_token should be used on the OP side ? It should be stored in a database? Or be self containing of the information required to validate it ?What would you recommend?
  • And in the client-side , both tokens should be sent in every request?

And the last doubt, if we have an Access_token the existence of an id_token is for representing authorization and authentication in separated tokens?

Extra doubts: I know the process to obtain an access token but I have doubts of how the OP ,once generated and sent, it validates the access_token that comes with every request

  • How the OP knows an access token is valid? As far as I know, the OP should say that an access_token is valid/invalid. There should be some way to check it right? How it gets to know that a token represents a valid authenticated user if it is not stored in DB?
  • Is it a bad idea to store access_token in a cookie? Because sometimes we call to some webservices and we want to send access_token as parameter. Or there is another workaroundsolution?
  • How the access token should be stored in the Client , for example, in ASP.NET, in the session?

Thanks very much to all of you, I will give upvote and mark as answer as soon as you give me the explanations. Thanks!

like image 252
X.Otano Avatar asked Feb 09 '23 01:02

X.Otano


1 Answers

The end-user is able to see that authorization code?

Yes. Although, even if the authorization code can be seen, the token request requires that the client's secret be sent as well (which the browser does not see)

it does not expires? Imagine we catch it and we use later (some days later) It is a security hole? Should the state be expired in the Token Endpoint?

The spec says that the authorization code should expire. See https://www.rfc-editor.org/rfc/rfc6749#section-4.1.2.

How the Access_token should be used on the OP side ? It should be stored in a database? Or be self containing of the information required to validate it ?What would you recommend?

The access token should be stored on the OP if you want to be able to revoke the tokens. If you don't, the token will be in JWT format (self-contained)...but you should store it if you want to be able to revoke it whether it's a JWT or not.

And in the client-side , both tokens should be sent in every request?

No, just the access token.

And the last doubt, if we have an Access_token the existance of an id_token is for representing authorization and authentication in separeted tokens?

Yes, they are separate tokens for different purposes. Access token is for authorization and Id token is self contained and used to communicate to the client that the user is authenticated.

How the OP knows an access token is valid? As far as i know, the OP should say that an access_token is valid/invalid. There should be some way to check it right? How it gets to know that a token represents a valid authenticated user if it is not stored in DB?

see How to validate an OAuth 2.0 access token for a resource server? about thoughts on how the resource server should validate the access token before letting the request from the client go through.

It´s a bad idea to store access_token in a cookie? because sometimes we call to some webservices and we want to send access_token as parameter. Or there is another workaroundsolution?

I'm assuming you're using the authorization code grant flow (...from your questions). If that's the case, the reason why an authorization code is, first of all, passed back from the OP rather than the access token is so that the access token can stay hidden on the server side--away from the browser itself. With the authorization code grant flow, the access token should stay out of the browser. If you're wanting to send api requests to the resource server directly from the browser, then look into the oauth2 implicit flow (https://www.rfc-editor.org/rfc/rfc6749#section-4.2).

How the access token should be stored in the Client , for example, in ASP.NET, in the session?

In the OpenID Connect flavour of OAuth2, the access token is for offline_access (i.e. outside of an authenticated "session"). The access token could be used during the session of the user but it might be better to store the refresh token in the database so that your client app can request new access tokens whenever it needs to and as long as the refresh token is valid...even when the user's authentication is expired. The access token should be short-lived so storing it in the database is an option but not necessary.

like image 179
sdoxsee Avatar answered Feb 11 '23 13:02

sdoxsee