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
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 17 additions & 8 deletions ios/Plugin/FirebaseAuthentication.swift
Original file line number Diff line number Diff line change
Expand Up @@ -84,20 +84,29 @@ import FirebaseAuth
Auth.auth().useAppLanguage()
}

func handleSuccessfulSignIn(credential: AuthCredential) {
func handleSuccessfulSignIn(credential: AuthCredential, idToken: String? = nil, rawNonce: String? = nil, accessToken: String? = nil) {
let skipNativeLogin = true
var result = JSObject()

result["idToken"] = idToken
result["rawNonce"] = rawNonce
result["accessToken"] = accessToken

if (skipNativeLogin) {
savedCall?.resolve(result)
return
}

Auth.auth().signIn(with: credential) { (_, error) in
if let error = error {
self.handleFailedSignIn(error: error)
return
}
guard let savedCall = self.savedCall else {
return
}

let user = self.getCurrentUser()
let userResult = FirebaseAuthenticationHelper.createUserResultFromFirebaseUser(user)
var result = JSObject()
result["user"] = userResult
savedCall.resolve(result)
result["user"] = FirebaseAuthenticationHelper.createUserResultFromFirebaseUser(user)

self.savedCall?.resolve(result)
}
}

Expand Down
8 changes: 7 additions & 1 deletion ios/Plugin/Handlers/AppleAuthProviderHandler.swift
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ extension AppleAuthProviderHandler: ASAuthorizationControllerDelegate, ASAuthori
guard let appleIDCredential = authorization.credential as? ASAuthorizationAppleIDCredential else {
return
}

guard let nonce = currentNonce else {
fatalError("Invalid state: A login callback was received, but no login request was sent.")
}
Expand All @@ -104,7 +105,12 @@ extension AppleAuthProviderHandler: ASAuthorizationControllerDelegate, ASAuthori
return
}
let credential = OAuthProvider.credential(withProviderID: "apple.com", idToken: idTokenString, rawNonce: nonce)
self.pluginImplementation.handleSuccessfulSignIn(credential: credential)

self.pluginImplementation.handleSuccessfulSignIn(
credential: credential,
idToken: idTokenString,
rawNonce: nonce
)
}

func authorizationController(controller: ASAuthorizationController, didCompleteWithError error: Error) {
Expand Down
6 changes: 5 additions & 1 deletion ios/Plugin/Handlers/GoogleAuthProviderHandler.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,11 @@ class GoogleAuthProviderHandler: NSObject {
guard let idToken = authentication.idToken else { return }
let credential = GoogleAuthProvider.credential(withIDToken: idToken, accessToken: authentication.accessToken)

self.pluginImplementation.handleSuccessfulSignIn(credential: credential)
self.pluginImplementation.handleSuccessfulSignIn(
credential: credential,
idToken: idToken,
accessToken: authentication.accessToken
)
}
}
}
Expand Down
3 changes: 3 additions & 0 deletions src/definitions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,9 @@ export interface SignInResult {
* The currently signed-in user, or null if there isn't any.
*/
user: User | null;
idToken: string | null;
rawNonce: string | null;
accessToken: string | null;
}

export interface User {
Expand Down