Capacitorjs Deep Link configured, in ios/android, How to deal with OAuth2 ?
- 0
- Android
- Accounts
- Web
- Apple
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
Capacitorjs Deep Link configured, in ios/android, OAuth2 cookies are not extracted!
How are you deep linking?
I just followed this instructions and it works well as i recorded in second video.
Interesting...sooo how do you set cookies in capacitor?
Actually appwrite response after createEmailSession
/ createOauthSession
sets automatically in PWA. I did not do anything extra.
However deeplinking is just split url and navigate..
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);
}
});
});
}
Copilot feedback.
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
In this example it handles incoming cookies in AppDelegate.swift
Does it work with only apple-sdk
yeah ?
image ref: appwrite-docs
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.
You didn't redirect to this path
it is regular path of GET /account/sessions/oauth2/{provider}
1- https://db.languagexchange.net/v1/account/sessions/oauth2/google?success=https...
2- https://accounts.google.com/o/oauth2/v2/auth?client_id=10893...
3- https://db.languagexchange.net/v1/account/sessions/oauth2/callback/google/650750d...
4- THIS ONE HAS COOKIES https://db.languagexchange.net/v1/account/sessions/oauth2/google/redirect?project=6507...
5- my success url
https://app.languagexchange.net/login/oau...
i do 1st request and get 5th request, 2nd 3rd and 4th browser executes.
Your success url...make the path what I sent
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
What are you passing for the success url when calling the create oauth2 session method?
this.api.account.createOAuth2Session(
'facebook',
environment.url.SUCCESS_OAUTH2,
environment.url.FAILURE_OAUTH2
);
environment.url.SUCCESS_OAUTH2 = "https://app.languagexchange.net/login/oauth2-callback"
The path you have is /login/oauth2-callback
. Change it to what I sent you earlier
That's not what I sent you. Remove the v1
wow
but where did i know this url ? any link from the Docs or somewhere?
This is used for mobile apps. Hence why I shared you the code for the flutter sdk
i really thank you to solve that one, i am really appreciate! It consumed pretty much of my time !!
Happy New Year 🎄
Recommended threads
- How to Avoid Double Requests in function...
I'm currently using Appwrite's `functions.createExecution` in my project. I want to avoid double requests when multiple actions (like searching or pagination) a...
- Send Email Verification With REST
I am using REST to create a user on the server side after receiving form data from the client. After the account is successfully created i wanted to send the v...
- Use different email hosts for different ...
Hello, I have 2 projects and i want to be able to set up email templates in the projects. Both projects will have different email host configurations. I see ...