Skip to content
This repository has been archived by the owner. It is now read-only.

Attempt at making Apple login work on the web #47

Closed
wants to merge 2 commits into from

Conversation

vojto
Copy link
Contributor

@vojto vojto commented Jul 22, 2021

This PR is just a proof of concept which makes auth on web-layer functional.

In FirebaseAuthentication.swift we're hard-wiring skipNativeLogin = true, which completely skips logging in in the native app, and just forwards the needed data to the web layer. Do we have to skip on native side? Yeah. You can't use the same tokens to login twice. See more here: #41 (comment)

We're collecting and forwarding idToken, rawNonce and accessToken, which is all that the web layer needs to sign in.

For Google, idToken and accessToken is used:

const {idToken, accessToken} = await FirebaseAuthentication.signInWithGoogle()
const credential = firebase.auth.GoogleAuthProvider.credential(idToken, accessToken)

await firebase.auth().signInWithCredential(credential)

For Apple, idToken and rawNonce is used:

const {idToken, rawNonce} = await FirebaseAuthentication.signInWithApple()

if (!idToken || !rawNonce) {
  return
}

const provider = new firebase.auth.OAuthProvider('apple.com')
const credential = provider.credential({idToken, rawNonce})

firebase.auth().signInWithCredential(credential)

Why can't we just forward the entire credential object? For Google, it's going to be AuthCredential, and it's impossible to read idToken or accessToken from that object. For Apple, it's going to be OAuthCredential, and it's impossible to read rawNonce from that. (Well unless we used some private APIs.)

So it's just send these to web layer, and we allow web layer to take over and log in there.

@robingenz
Copy link
Owner

Thanks, I will have a look at it this weekend.

@robingenz
Copy link
Owner

Thank you @vojto! Your draft PR has helped me a lot. I have implemented this now and will publish it with the next update. For this reason I am closing this PR.

@robingenz robingenz closed this Jul 30, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants