Repository navigation
Add GoogleAuthProvider.credential(withIDToken:accessToken:) - #104
Open
vincentborko wants to merge 1 commit into
Open
vincentborko wants to merge 1 commit into
vincentborko wants to merge 1 commit into
Conversation
Signing in to Firebase with a Google ID token is the documented path on both platforms, but the Android side of SkipFirebaseAuth had no `GoogleAuthProvider` at all: only `EmailAuthProvider` and the generic `OAuthProvider`. A Skip app that gets an ID token from Credential Manager had nothing to hand it to. `AuthCredential.provider` comes along because it is the only way to assert the result without a network call, and it matches the iOS property of the same name. An empty `accessToken` maps to `null`, which is what Credential Manager callers need: it returns an ID token and no access token. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
SkipFirebaseAuthhas noGoogleAuthProvideron the Android side. OnlyEmailAuthProviderand the genericOAuthProviderare wrapped, so an app that already holds a Google ID token, which is what Credential Manager and Google Identity Services hand out, has nothing to turn it into anAuthCredential. The only route left isAuth.signIn(with: OAuthProvider(providerID: "google.com")), which isstartActivityForSignInWithProvider: a browser redirect that takes the user out of the app.This adds
GoogleAuthProvider.credential(withIDToken:accessToken:)andGoogleAuthProvider.id, plusAuthCredential.provider. All three match the iOS API of the same name.How
credential(withIDToken:accessToken:)wrapscom.google.firebase.auth.GoogleAuthProvider.getCredential. An emptyaccessTokenmaps tonull, because Credential Manager returns an ID token and no access token, and the Android API takesnullthere.AuthCredential.providerwrapsgetProvider(). It earns its place beyond parity: it is the only way to assert the result of a credential builder without a network call, which is what the new test does.idis spelled out as"google.com"rather than read fromGoogleAuthProvider.PROVIDER_ID. The Java constant arrives with an implicitly unwrapped type, and a native SkipFuse consumer then fails to build with'?' does not appear to be a bridged type. The iOS SDK spells the same constant out.Verification
swift test --filter SkipFirebaseAuthTests, which runs the transpiled tests under Robolectric as well as the Swift ones:The new test is not a shape test under
if false. Building a Google credential needs no network and no Firebase app, so it runs and asserts on both platforms.It has been red. With
idmutated to"apple.com":Reverted, green again. A counter-mutation outside the change (swapping the two arguments in
EmailAuthProvider.credential(withEmail:password:)) stays green, so the test measures the new code rather than the file.Consumed for real in an app on an Android emulator: tapping the Google button no longer starts a browser.
GenericIdpActivitygoes from 21 log lines to 0 and Chrome from 6 starts to 0, with a positive control line that stays at 2 in both runs.Redeeming the ID token against the Firebase backend is verified too, on an emulator with a real Google account signed in:
Credential Manager status=ok idTokenLength=1108, and Firebase returns the same UID for that account as the browser-redirect path returns. It was an existing user, not a fresh one: both runs land on identical app data, so the credential built here resolves to the same identity rather than creating a second account. Before each install, the APK was checked for a marker string from the branch under test, with a control string present in both, so each run is known to carry the code it claims.Not verified
Whether the same holds for an account whose Firebase user was originally created on iOS or on the web. Measured on one account.
Skip Pull Request Checklist:
swift test