Back

[SOLVED] How to implement Google/OAuth Login in the server side?

  • 0
  • Accounts
  • Web
manazo
18 Sep, 2023, 16:04

As the title suggests, i'm trying to implement Google/OAuth login, but in the server side. To implement other logins in the server side, the suggested way is to hit the login endpoint manually, get the cookies and set those in the server. But in case of OAuth login, the cookies are set in the redirect link that we pass in the OAuth console (i think). So how can i manually control that? I also need to extract the authorization code that's passed by google

Tech Stack: Next.js@13 Version: Appwrite@latest (local)

TL;DR
The user successfully implemented Google/OAuth Login with Appwrite on the server side. They had a few questions and concerns including the redirect path, creating extra endpoints, and extracting the authorization code. There was a discussion about setting cookies and a link to a JavaScript example. The solution provided was to set cookies in the redirect URL and extract the code to further authorize with Google services. The user's tech stack was Next.js@13 and Appwrite@latest (local).
manazo
18 Sep, 2023, 17:37

Hi. I'm getting a project, key, and secret in the URL. but I'm a bit confused what should I do with these? Can you please show/redirect me to a JS example?

Drake
18 Sep, 2023, 18:06

Have you looked into how to set a cookie?

manazo
18 Sep, 2023, 19:06

u mean the "almost-ssr" code?

Drake
18 Sep, 2023, 19:39

No just in general with nextjs

manazo
18 Sep, 2023, 20:05

yeah i know that

Drake
18 Sep, 2023, 20:20

What are you stuck with for how to set the cookie from the oauth data?

manazo
18 Sep, 2023, 21:04

I've implemented it and it works fine. I've got a few things roaming around my head at this moment

  1. why auth/oauth2/success is the only path that works
  2. it's creating an extra endpoint in my app, which is an overhead and it is something that should be worked on imo
  3. after the OAuth flow completes, google provides a code param in the redirect URL ( http://localhost/v1/account/sessions/oauth2/callback/google/{PROJECT_ID} ) and I think I'll need that value for further authorization with google services. is there any way to extract that?
Drake
18 Sep, 2023, 22:41

auth/oauth2/success is the default redirect path Appwrite uses to redirect into a mobile app (passing the secret). This is sort of a hack that leverages the oauth2 flow for mobile

Drake
18 Sep, 2023, 22:43

I think I'll need that value for further authorization with google services

No. Appwrite uses that code to create the session. Are you looking to make API calls to the oauth provider? If so, call the Appwrite get current session API and look at the providerAccessToken in the reponse. that's an access token from the provider

manazo
19 Sep, 2023, 06:23

okay, now i get it. thanks

manazo
19 Sep, 2023, 13:03

[SOLVED] How to implement Google/OAuth Login in the server side?

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