Back

[SOLVED] How get cookie of oauth google session

  • 0
  • Flutter
  • Accounts
hortigado
30 Jul, 2023, 19:11

the same way the sdk does it just for testing but i did it actually i am using the sdk for the oauth

TL;DR
The user was trying to get the cookie of an OAuth Google session but was having trouble with the `android:launchMode`. They were suggested to use the `FlutterWebAuth2` package to simplify the process. It was also suggested to try using deep linking and redirecting to a custom deep link URL instead of the SDK's OAuth2 success page. The solution involved redirecting to `/auth/oauth2/success` and extracting the secret value from the URL.
Drake
30 Jul, 2023, 19:14

The way it works for the SDK is the user is redirected back to an oauth2 success page where the secret for the cookie is in the url. Then, the user is redirected into the app where the app can pull the secret out from the url and save it.

See https://github.com/appwrite/sdk-for-flutter/blob/f8480fdeecfb23782bd5b33d0e2a7db44fc8c391/lib/src/client_io.dart#L332

So, instead, you can redirect to your own deep link and then pull out the value yourself. You just need to redirect to /auth/oauth2/success

hortigado
30 Jul, 2023, 19:23
TypeScript
        provider: 'google',success: "https://appwrite.hordevfree.online/v1/auth/oauth2/success"
        
      );```
hortigado
30 Jul, 2023, 19:23

Thank you, correct, I had read something about it but the truth is that I cannot understand very well how to do it. Should I just put the url? or I also need to create some content in that url

hortigado
30 Jul, 2023, 19:25

I suppose the url must have code that redirects to the app sending this cookie, am I okay?

Drake
30 Jul, 2023, 19:38

Look into deep linking

Drake
30 Jul, 2023, 19:50

The url should link into the app

hortigado
1 Aug, 2023, 20:11

Thanks, it worked for me using deep links. Although it is not a pleasant way for the user because the screen flashes at the end of the login since a new instance of the application is created instead of just closing the browser.

Drake
1 Aug, 2023, 20:29

what do you mean? what flash?

hortigado
1 Aug, 2023, 21:02
hortigado
1 Aug, 2023, 21:03

To this black screen, which is because it only works for me on android:launchMode="standard"

hortigado
1 Aug, 2023, 21:06

Of course this no longer has to do with appwrite, but hey I'm fighting to make it look good. According to what I read, it is solved with the onNewIntent() method, but I still haven't succeeded

Drake
1 Aug, 2023, 21:09

I see...I think we typically do android:launchMode="singleTop". Can you do that?

hortigado
1 Aug, 2023, 21:12

Correct, but it doesn't work for me android:launchMode="singleTop", it keeps loading the google account selection page and doesn't return to the application. I'll keep trying anyway πŸ‘

Drake
1 Aug, 2023, 21:16

Are you still calling this?

hortigado
1 Aug, 2023, 21:19

final data = await account.createOAuth2Session( provider: 'google', success: "https://hordevfree.online/auth/oauth2/success");

hortigado
1 Aug, 2023, 21:20

I had to use another page because appwrite. the assetlinks.json did not work

Drake
1 Aug, 2023, 21:25

I wonder if you need to use something else other than our SDK 🧐

hortigado
1 Aug, 2023, 21:33

πŸ˜… Well, I needed cloud but without the offline mode it doesn't work for me.

Drake
1 Aug, 2023, 21:34

i mean maybe you can just open the browser

hortigado
1 Aug, 2023, 21:38

ooh good but I don't think that generates the problem. Or maybe because when I give the account I want to log in with twice android:launchMode="singleTop" it works

hortigado
1 Aug, 2023, 21:38

I'll try

hortigado
2 Aug, 2023, 03:18

Thanks for everything, I finally did it using the same code from the sdk; with the FlutterWebAuth2 package you save a lot of work because I don't try it before πŸ˜…

Drake
2 Aug, 2023, 03:20

Ah right I guess that's an option

hortigado
2 Aug, 2023, 03:22

[SOLVED] How get cookie of oauth google session

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