Back

Capacitorjs Deep Link configured, in ios/android, How to deal with OAuth2 ?

  • 0
  • Android
  • Accounts
  • Web
  • Apple
xue
27 Dec, 2023, 05:07

Before i start , i use only web-sdk with capacitorjs. It builds, PWA, iOS and Android clients. createEmailSession works fine with custom domain in PWA and also iOS and android clients. It sets cookies and session works without any error. - --demo video 1--

createOAuth2Session works fine with only custom domain in PWA. Not in iOS/android clients. Success link is going to app by deep linking configuration. (shown in demo video).

But the problem is in ios app, session is not started (cookies are not set) thats why i cant move further. In the same time, it sets cookies into PWA, when i try to open PWA in browser in simulator, user logged in, but user not logged in ios app. --demo video 2--

How can i handle or transfer/copy cookies from web app to mobile app ? Is there any way to transfer it? Any idea?

Related thread: 1145408157343039498

TL;DR
The user has configured Capacitorjs Deep Link in iOS and Android but is having trouble extracting OAuth2 cookies. There is no further information provided in the support thread. Unfortunately, without more details, it is difficult to provide a solution to this issue.
xue
27 Dec, 2023, 05:07

Capacitorjs Deep Link configured, in ios/android, OAuth2 cookies are not extracted!

Drake
27 Dec, 2023, 05:14

How are you deep linking?

xue
27 Dec, 2023, 05:22

I just followed this instructions and it works well as i recorded in second video.

Drake
27 Dec, 2023, 05:24

Interesting...sooo how do you set cookies in capacitor?

xue
27 Dec, 2023, 05:25

Actually appwrite response after createEmailSession / createOauthSession sets automatically in PWA. I did not do anything extra.

xue
27 Dec, 2023, 05:28

However deeplinking is just split url and navigate..

TypeScript
  async ngOnInit() {
    // Init Deep Link
    this.initDeepLink();
  }
  // Deep Link
  initDeepLink() {
    App.addListener('appUrlOpen', (event: URLOpenListenerEvent) => {
      this.zone.run(() => {
        const slug = event.url.split('app.languagexchange.net').pop();
        if (slug) {
          this.router.navigateByUrl(slug);
        }
      });
    });
  }
xue
27 Dec, 2023, 05:28

Copilot feedback.

Drake
27 Dec, 2023, 05:32

So either you need to open the oauth url in the capacitor app context or you need to figure out how to set the cookie

xue
27 Dec, 2023, 05:36

In this example it handles incoming cookies in AppDelegate.swift Does it work with only apple-sdk yeah ?

image ref: appwrite-docs

xue
29 Dec, 2023, 04:37

only this url has cookie but browser triggers this request. So after that request executed then it redirects to my success URL in location part which there is no cookies in headers. I can listen success url but not the first request.

Drake
29 Dec, 2023, 04:43

You didn't redirect to this path

Drake
29 Dec, 2023, 04:52

Your success url...make the path what I sent

xue
29 Dec, 2023, 05:28

as i understand, i use web-sdk so i dont redirect back to my app at this path of /auth/oauth2/success

The response with cookies comes from account/sessions/oauth2/google/redirect

it is set here: https://github.com/appwrite/appwrite/blob/86ce7a30040618c7b716cfc6611af078ecd3ee93/app/controllers/api/account.php#L796

Drake
29 Dec, 2023, 05:30

What are you passing for the success url when calling the create oauth2 session method?

xue
29 Dec, 2023, 05:32
TypeScript
    this.api.account.createOAuth2Session(
      'facebook',
      environment.url.SUCCESS_OAUTH2,
      environment.url.FAILURE_OAUTH2
    );

environment.url.SUCCESS_OAUTH2 = "https://app.languagexchange.net/login/oauth2-callback"

Drake
29 Dec, 2023, 05:33

The path you have is /login/oauth2-callback. Change it to what I sent you earlier

xue
29 Dec, 2023, 05:35
Drake
29 Dec, 2023, 05:36

That's not what I sent you. Remove the v1

xue
29 Dec, 2023, 05:38

wow

xue
29 Dec, 2023, 05:39

but where did i know this url ? any link from the Docs or somewhere?

Drake
29 Dec, 2023, 05:41

https://github.com/appwrite/appwrite/blob/86ce7a30040618c7b716cfc6611af078ecd3ee93/app/controllers/api/account.php#L781

This is used for mobile apps. Hence why I shared you the code for the flutter sdk

xue
29 Dec, 2023, 05:44

i really thank you to solve that one, i am really appreciate! It consumed pretty much of my time !!

xue
29 Dec, 2023, 05:45

Happy New Year 🎄

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