Back

How does authentication with oauth2 sessions work?

  • 0
  • Web
Kuro
12 May, 2023, 22:00

After reading over the documentation and tinkering a bit myself I'm still a bit confused on how I should be able to login using oauth2. I wanted to try to log in into an vue application but discord OAuth2 and I've gotten as far as that an user is being generated when I allow my application access. Now I'm stuck after this where I don't know how the system works because I can't seem to really find any authentication for the user.

TL;DR
User is seeking clarification on how authentication with oauth2 sessions works in Appwrite. They set up a web project and activated Discord as an OAuth2 provider. When trying the example code from the documentation, a user is created in Appwrite but the user is unsure how to authenticate themselves on the web application. The user has read the documentation but is still confused about the authentication process. Solution: After the OAuth2 session flow is complete, the user should be logged in. The user should provide success and failure URLs to redirect them back to the app after authentication. Further information and guidance on OAuth2 authentication can be found in the Appwrite
Drake
12 May, 2023, 22:05
Kuro
12 May, 2023, 22:06

ye I did

Drake
12 May, 2023, 22:07

So after the create oauth2 session API flow is complete, you should be logged in. What's going on for you? And is your client app running on localhost?

Kuro
12 May, 2023, 22:14

no the app is not running on localhost right now and as for the point on what's going on or me I am really confused about the further authentication because I don't see any clues on that

Drake
12 May, 2023, 22:28

Clues on what? What further authentication? Would you please describe what's going on? Maybe with a screen recording?

Kuro
12 May, 2023, 22:39

I'm sorry for all the confusion I'll start from the beginning. So I choose to create a web app where I want users to be able to authenticate themselves using discord through appwrite. I set up a new web project and in authentication I activate Discord as OAuth2 Provider with the correct settings. Meaning when I try out the example code from the docs on OAuth, I fill it with my project ID and createOAuth2Session with some other params I'll get an authentication link. when using the link and allowing my app through discord to access my data nothing happened except an user got created in appwrite with my username and email. that's the only thing I've seen so far what happends but I don't know how I should let the user authenticate himself on the web application with anthingof this now

Drake
12 May, 2023, 22:42

Did you provide success and failure URLs to redirect the user back to your app after authentication? https://appwrite.io/docs/client/account?sdk=web-default#accountCreateOAuth2Session

Kuro
12 May, 2023, 22:43

yes I provided discord as provider, an redirect url for success and failure as well as some scopes

Drake
12 May, 2023, 22:44

so they should be redirected back to your app and authenticated...

Kuro
12 May, 2023, 22:48

ye I know that the redirection works but how do I know that the authentication does? do I somehow obtain a session id or a jwt? I can't see anything that would tell me about the authentication

Drake
12 May, 2023, 22:54

if you're redirected back to your success url, the session should be created. you can then call, account.get() to confirm you have a session.

This works because Appwrite sessions are stored in cookies. Right before the user is redirected to your app, a cookie is set in the browser: https://github.com/appwrite/appwrite/blob/953485299a2a4040406cfec290a68f69187ec5e8/app/controllers/api/account.php#L622. You can open your browser's dev tools and look at the network logs to verify the response header that sets the cookie.

Kuro
12 May, 2023, 22:57

hey is the cookie called a_session_console_legacy?

Drake
12 May, 2023, 22:57

that's not for your app. that's for the console

there are 2 cookies and they have the format of:

TypeScript
a_session_[PROJECT ID]_legacy
a_session_[PROJECT ID]
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