Back

Dynamic state in OAuth2

  • 0
  • Self Hosted
Guille
9 May, 2023, 21:48

Yes they are using OIDC, the implementation is working except for that little detail

TL;DR
The user is discussing an issue related to dynamic state in OAuth2. They're trying to determine the identity management product being used and are exploring options such as passing `prompt=login` in the initial request to the auth provider. The user suggests generating and validating a token with the appwrite secret to avoid storing the state in the database. They plan to make changes and create an issue on GitHub. The user mentions difficulty in maintaining and validating the state in Appwrite. They mention a related issue on GitHub and discuss the use of success and failure URLs. The user notes that their API is stateless and considers creating a GitHub issue for the
Guille
9 May, 2023, 21:51

Yes in most cases it's, but in this one all sites using their authentication method must have dynamic state (it's a governmental provider) to be certificated

Drake
9 May, 2023, 21:56

Can you explain more about what this dynamic state requirement is?

Guille
9 May, 2023, 22:06

In the their docs says:

TypeScript
Step 1

The integrator must protect the security of its citizens by preventing request forgery attacks, for this the first step is to create a unique session token, which maintains the state between the citizen and the integrated application.
You must then match this unique session token with the authentication response returned by the service. Thus, both, our service and the integrated service can ensure that it is the user who is making the request and that it is not a malicious attacker. This type of attack is called Cross-Site Request Forgery (CSRF).

A good option to implement this unique session token is to generate a random string of 30 or more characters through some library or to generate a hash through a secret.

Step 2

Make the HTTP request (...)

State: The same unique session token that was indicated in Step 1 must go in this parameter.
Drake
9 May, 2023, 22:09

I see. So this sounds like the standard oauth flow. We actually have trouble with this because our API is stateless.

Maybe you can create a GitHub issue for this?

Guille
9 May, 2023, 22:17

Sure I will So what is used to create the state in this moment?

Guille
9 May, 2023, 22:20

I see so, wouldn't be so hard to change to a dynamic state... I'll test it, and create the issue as well

Drake
9 May, 2023, 22:23

The hard part is getting Appwrite to maintain the state and validate it

Guille
10 May, 2023, 13:13

I'm planing to work in the changes now and I see where is the problem, I don't see any other solution than store the state in the database 🤔

Guille
10 May, 2023, 13:26
Guille
10 May, 2023, 13:33

I'm thinking something to avoid store the state in the database:

  1. Generate a token with the appwrite secret and send it
  2. The token is returned by the OAuth2 entity
  3. Validate the token with the appwrite secret

If there is no problem with the validation, means no CSRF attak is made

What you think?

Drake
10 May, 2023, 16:53

How would step 3 actually work? How would Appwrite validate it?

Guille
10 May, 2023, 16:58

You generate a payload and sign it (with the secret), and send it when it returns you validate it with the same secret, the payload can have the success and failed url too, and also this token can have an expiration time, you check the signature and the expiration time, that way you only need the secret

Drake
10 May, 2023, 17:15

Currently if you close your session and log in again the session will be create again without ask for any credentials

btw, i thing this state stuff is unrelated to your problem

Guille
10 May, 2023, 17:18

What would be that issue related to? 🤔

Drake
10 May, 2023, 17:18

it's just some configuration in your provider

Guille
10 May, 2023, 17:22

I'm not sure but maybe, in this case is relate, I'll keep investigating, I'm not 100% familiar with their implementation

Drake
10 May, 2023, 17:22

who's the provider?

Guille
10 May, 2023, 17:23

Chilean Government

Drake
10 May, 2023, 17:23

no the authorization provider. what product are they using?

Drake
10 May, 2023, 17:25

also, you can try passing prompt=login in the first request to the auth provider

Guille
10 May, 2023, 17:25

what you mean with product?

Drake
10 May, 2023, 17:26

they're probably using some sort of identity management product. do you have any documentation from them that you can share?

Guille
10 May, 2023, 17:27

Sure can I send to you in a PM?

Reply

Reply to this thread by joining our Discord

Reply on Discord

Need support?

Join our Discord

Get community support by joining our Discord server.

Join Discord

Get premium support

Join Appwrite Pro and get email support from our team.

Learn more