Skip to content

Align the Auth API with the Firebase Android SDK - #82

Merged
nbransby merged 4 commits into
masterfrom
auth-android-api
Oct 31, 2026
Merged

nbransby merged 4 commits into
masterfrom
auth-android-api

Conversation

@nbransby

@nbransby nbransby commented Oct 31, 2026 •

Copy link
Copy Markdown
Member

Adds every public Auth class and member the Firebase Android SDK declares and this port lacked, and aligns the four places where the port's shape differed, so that code written against the Android SDK compiles and links against this one. The motivation is firebase-kotlin-sdk's com.google.firebase.auth compatibility layer (GitLiveApp/firebase-kotlin-sdk#890), whose header stubs are verified against this port on the JVM: against 0.7.0 that verification tolerates 91 missing members and the layer reaches four members by reflection; against this branch it passes with an empty exclusion list and the reflection can go.

Shape changes (breaking for callers of the old shapes)

  • FirebaseUser.getPhotoUrl() returns an android.net.Uri rather than a String, as on Android (photoUrl.toString() gives the old value).
  • UserInfo is the Android interface (with isEmailVerified) and FirebaseUser implements it; providerData holds an internal implementation.
  • ActionCodeInfo is a class with a protected email, ActionCodeEmailInfo and ActionCodeMultiFactorInfo abstract classes, as on Android, instead of interfaces.
  • OAuthCredential is the Android abstract class (getAccessToken, getIdToken, getSecret) over a package-private implementation; OAuthProvider extends the new FederatedAuthProvider.
  • AuthResult gains getAdditionalUserInfo() and getCredential(), so it is no longer a single-method interface; both are filled from the sign-in response (isNewUser, providerId, rawUserInfo, screenName or the profile's login/screen_name, the returned OAuth tokens).
  • MultiFactorInfo, MultiFactorAssertion, MultiFactor and MultiFactorResolver are abstract, as on Android; FirebaseAuthMultiFactorException takes its resolver; PhoneAuthProvider is Kotlin with the same Java-visible API plus the static verifyPhoneNumber(PhoneAuthOptions).
  • UserProfileChangeRequest exposes getDisplayName() and getPhotoUri(), and its Builder the same getters.
  • FirebaseUser.verifyBeforeUpdateEmail and the new operations return Task<Void> completing with null, as on Android (updateEmail, updateProfile and updatePassword keep their Task<Unit>).
  • FirebaseUser.reload() refreshes the profile as well as the token, so a verified or changed email shows on the current user; the account lookup also refreshes the phone number, verification state and providers.
  • Invalid and expired action codes arrive as FirebaseAuthActionCodeException and a weak password as FirebaseAuthWeakPasswordException carrying the server's reason; the server's error codes are kept as before.

Additions

  • Providers: PROVIDER_ID and sign-in method constants on EmailAuthProvider, FacebookAuthProvider, GithubAuthProvider, TwitterAuthProvider, PhoneAuthProvider; FirebaseAuthProvider; the credential classes EmailAuthCredential (a password or a sign-in link), FacebookAuthCredential, GithubAuthCredential, TwitterAuthCredential (with its token secret); AuthCredential keeps its Identity Toolkit post body behind package-private accessors. signInWithCredential and linkWithCredential accept an email credential: a password signs in with verifyPassword or links through accounts:update (refused with ERROR_PROVIDER_ALREADY_LINKED when the account has a password already), a link through accounts:signInWithEmailLink; an email-link credential is only created from a sign-in link.
  • ActionCodeSettings is implemented (builder, Kotlin properties behind the Android getter names, setLinkDomain, the deprecated dynamic link domain) and its fields travel with every action email; ActionCodeUrl.parseLink reads an action link with an apiKey, oobCode and mode, as on Android, unwrapping a Dynamic Link; ActionCodeResult gains the deprecated getData and its annotation types, checkActionCode returns one, and a reverted second factor reports its factor through ActionCodeMultiFactorInfo.
  • FirebaseAuth: sendPasswordResetEmail (both forms), sendSignInLinkToEmail, signInWithEmailLink, isSignInWithEmailLink, checkActionCode, verifyPasswordResetCode (rejects codes of other actions), confirmPasswordReset, applyActionCode, fetchSignInMethodsForEmail, updateCurrentUser (rejects a user of another project), revokeAccessToken (Apple tokens, accounts:revokeToken), getLanguageCode/setLanguageCode (sent as X-Firebase-Locale with every action email), useAppLanguage, getTenantId/setTenantId (setting a tenant throws: the port signs in to the default tenant only), getCustomAuthDomain/setCustomAuthDomain, getFirebaseAuthSettings, getPendingAuthResult (always null), initializeRecaptchaConfig (a completed task), startActivityForSignInWithProvider (fails: no Activity on the JVM). An action sent for a signed-in user, a credential link and a token revocation refresh the user's ID token first when it has expired; signInWithCustomToken keeps the sign-in's additional user info through the account lookup.
  • FirebaseUser: sendEmailVerification (both forms), updatePhoneNumber(PhoneAuthCredential) (links the verified number), verifyBeforeUpdateEmail(String), getTenantId, getMultiFactor, the two startActivityFor… members (fail).
  • PhoneAuthOptions and its Builder; PhoneAuthProvider.verifyPhoneNumber(PhoneAuthOptions) reports to the callbacks that the JVM cannot verify a number; PhoneAuthCredential.getSmsCode.
  • Multi-factor types: PhoneMultiFactorInfo, TotpMultiFactorInfo, PhoneMultiFactorAssertion, TotpMultiFactorAssertion, PhoneMultiFactorGenerator, TotpMultiFactorGenerator, TotpSecret, MultiFactorInfo.FACTOR_ID_KEY; enrolment fails with UnsupportedOperationException. MultiFactorInfo.toJson() is not mirrored: it returns org.json.JSONObject, an Android type the compatibility layer treats as platform-only.
  • FirebaseAuthSettings, FirebaseAuthMissingActivityForRecaptchaException, FirebaseAuthUserCollisionException.email/updatedCredential, FirebaseAuthWeakPasswordException(code, message, reason) and reason, FirebaseAuthMultiFactorException.resolver, all Kotlin properties behind the Android getters. AuthResult's string form names the user rather than rendering it, since the user's carries its tokens.

Verification

  • FirebaseAuthApiTest covers the shapes, constants, builders and credential types without a server; FirebaseAuthEmailFlowsTest runs password reset, email-link sign-in, email verification observed through reload(), email-credential linking (including the already-linked refusal), updateCurrentUser and the exception types for an invalid code and a weak password against the Auth emulator, reading the codes it would have emailed from its REST API. The existing Auth and credential tests pass (one assertion now compares photoUrl.toString()). The CI emulator now runs as the tests' project, fir-java-sdk, so the tokens and codes it issues belong to the project the tests use.
  • firebase-kotlin-sdk's firebase-auth module (Add com.google.firebase.auth source-compatibility layer firebase-kotlin-sdk#890) compiles and verifies its JVM header stubs against a local build of this branch with api/jvm/firebase-java-sdk-missing.txt emptied.
  • The README's Auth limitations describe what the port supports and what still needs a device or browser; reauthenticate, unlink and updatePassword remain unimplemented.

Every public Auth class and member the Android SDK declares and this port
lacked is added, and the four places where the port's shape differed are
aligned, so that code written against the Android SDK compiles and links
against this one: FirebaseUser.getPhotoUrl returns a Uri, FirebaseUser
implements the UserInfo interface (which gains isEmailVerified), the
ActionCodeInfo types are classes, and the profile change request exposes its
display name and photo URI. AuthResult gains getAdditionalUserInfo and
getCredential, filled from the sign-in response. The providers expose their
PROVIDER_ID and sign-in method constants and create the Android credential
types, including EmailAuthCredential for a password or a sign-in link, which
signInWithCredential and linkWithCredential accept. OAuthCredential is the
Android abstract class over a package-private implementation, OAuthProvider
extends FederatedAuthProvider and its builders expose their state.

ActionCodeSettings is implemented and travels with every action email, and
ActionCodeUrl parses an action link, unwrapping a Dynamic Link. FirebaseAuth
gains sendPasswordResetEmail, sendSignInLinkToEmail, signInWithEmailLink,
isSignInWithEmailLink, checkActionCode, verifyPasswordResetCode,
confirmPasswordReset, applyActionCode, fetchSignInMethodsForEmail,
updateCurrentUser, revokeAccessToken, the language code (sent as
X-Firebase-Locale), useAppLanguage, the tenant id, the custom auth domain,
getFirebaseAuthSettings, getPendingAuthResult and initializeRecaptchaConfig;
FirebaseUser gains sendEmailVerification, updatePhoneNumber(PhoneAuthCredential),
verifyBeforeUpdateEmail(String) and getTenantId. PhoneAuthOptions, the
multi-factor info, assertion and generator types, TotpSecret,
FirebaseAuthSettings, FirebaseAuthProvider and the exception members
(FirebaseAuthUserCollisionException's email and credential,
FirebaseAuthWeakPasswordException's reason, FirebaseAuthMultiFactorException's
resolver, FirebaseAuthMissingActivityForRecaptchaException) complete the
surface; what needs a device or a browser (phone verification, multi-factor,
Activity flows) is present and fails with a clear message.

FirebaseAuthApiTest covers the shapes without a server and
FirebaseAuthEmailFlowsTest runs the action-code flows against the Auth
emulator; the README describes what the port now supports.
Copilot AI balanced review requested due to automatic review settings October 31, 2026 04:34

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Critical authentication flaws remain, including cross-project token acceptance, session-credential exposure in logs, and unintended password changes when linking an already-linked provider.

10 open issues
What changed in this PR

Expands the JVM Auth port toward Firebase Android SDK compatibility, supporting firebase-kotlin-sdk’s compatibility layer while documenting flows that still require a device or browser.

Changes:

  • Aligns public Auth types, credentials, builders, constants, and result metadata with Android.
  • Implements email action flows, email-credential linking, user restoration, and Apple token revocation.
  • Adds API and emulator tests and updates the documented Auth limitations.
File Description
src/​test/​kotlin/​FirebaseAuthTest.kt Updates the photo URL assertion for Uri.
src/​test/​kotlin/​FirebaseAuthEmailFlowsTest.kt Adds emulator coverage for email and account flows.
src/​test/​kotlin/​FirebaseAuthApiTest.kt Tests API shapes, builders, and unsupported flows.
src/​main/​java/​com/​google/​firebase/​auth/​UserProfileChangeRequest.kt Exposes profile request and builder getters.
src/​main/​java/​com/​google/​firebase/​auth/​UserInfo.kt Adds the Android-style interface and provider implementation.
src/​main/​java/​com/​google/​firebase/​auth/​TwitterAuthProvider.java Implements credential creation and provider constants.
src/​main/​java/​com/​google/​firebase/​auth/​TwitterAuthCredential.java Adds Twitter token and secret handling.
src/​main/​java/​com/​google/​firebase/​auth/​Stubs.kt Replaces moved stubs with settings and query implementations.
src/​main/​java/​com/​google/​firebase/​auth/​PhoneAuthProvider.kt Adds Kotlin replacement and verification failure callbacks.
src/​main/​java/​com/​google/​firebase/​auth/​PhoneAuthProvider.java Removes the replaced Java implementation.
src/​main/​java/​com/​google/​firebase/​auth/​PhoneAuthOptions.kt Adds phone verification options and builder.
src/​main/​java/​com/​google/​firebase/​auth/​PhoneAuthCredential.kt Extracts phone credentials and exposes the SMS code.
src/​main/​java/​com/​google/​firebase/​auth/​OAuthProvider.java Aligns inheritance and adds builder accessors.
src/​main/​java/​com/​google/​firebase/​auth/​OAuthCredentialImpl.java Adds the package-private OAuth implementation.
src/​main/​java/​com/​google/​firebase/​auth/​OAuthCredential.java Converts OAuth credentials to an abstract API.
src/​main/​java/​com/​google/​firebase/​auth/​MultiFactor.kt Adds multi-factor types and unsupported-operation results.
src/​main/​java/​com/​google/​firebase/​auth/​GoogleAuthCredential.java Adapts Google credentials to the revised base class.
src/​main/​java/​com/​google/​firebase/​auth/​GithubAuthProvider.java Implements GitHub credential creation and constants.
src/​main/​java/​com/​google/​firebase/​auth/​GithubAuthCredential.java Adds GitHub access-token credentials.
src/​main/​java/​com/​google/​firebase/​auth/​FirebaseUser.kt Aligns user properties and adds account operations.
src/​main/​java/​com/​google/​firebase/​auth/​FirebaseAuthWeakPasswordException.kt Exposes the password rejection reason.
src/​main/​java/​com/​google/​firebase/​auth/​FirebaseAuthUserCollisionException.kt Adds collision email and credential details.
src/​main/​java/​com/​google/​firebase/​auth/​FirebaseAuthSettings.java Defines Android-compatible test settings.
src/​main/​java/​com/​google/​firebase/​auth/​FirebaseAuthProvider.java Adds the Firebase provider identifier.
src/​main/​java/​com/​google/​firebase/​auth/​FirebaseAuthMultiFactorException.kt Adds resolver-bearing exceptions.
src/​main/​java/​com/​google/​firebase/​auth/​FirebaseAuthMissingActivityForRecaptchaException.kt Adds the missing-Activity exception type.
src/​main/​java/​com/​google/​firebase/​auth/​FirebaseAuth.kt Implements Auth flows, settings, and result handling.
src/​main/​java/​com/​google/​firebase/​auth/​FederatedAuthProvider.java Adds the federated provider base class.
src/​main/​java/​com/​google/​firebase/​auth/​FacebookAuthProvider.java Implements Facebook credential creation and constants.
src/​main/​java/​com/​google/​firebase/​auth/​FacebookAuthCredential.java Adds Facebook access-token credentials.
src/​main/​java/​com/​google/​firebase/​auth/​EmailAuthProvider.java Implements password and email-link credential factories.
src/​main/​java/​com/​google/​firebase/​auth/​EmailAuthCredential.java Represents password and email-link credentials.
src/​main/​java/​com/​google/​firebase/​auth/​AuthResultImpl.kt Parses additional user information and OAuth credentials.
src/​main/​java/​com/​google/​firebase/​auth/​AuthResult.java Adds additional information and credential accessors.
src/​main/​java/​com/​google/​firebase/​auth/​AuthCredential.java Refactors credential accessors and request serialization.
src/​main/​java/​com/​google/​firebase/​auth/​AdditionalUserInfo.java Defines supplementary sign-in metadata.
src/​main/​java/​com/​google/​firebase/​auth/​ActionCodeUrl.kt Parses action URLs and wrapped links.
src/​main/​java/​com/​google/​firebase/​auth/​ActionCodeSettings.kt Implements action-email settings and request fields.
src/​main/​java/​com/​google/​firebase/​auth/​ActionCodeResultImpl.kt Maps action-code responses into result objects.
src/​main/​java/​com/​google/​firebase/​auth/​ActionCodeResult.java Adds annotations and the deprecated data accessor.
src/​main/​java/​com/​google/​firebase/​auth/​ActionCodeMultiFactorInfo.java Aligns the multi-factor action-info class shape.
src/​main/​java/​com/​google/​firebase/​auth/​ActionCodeInfo.java Converts action information into a class.
src/​main/​java/​com/​google/​firebase/​auth/​ActionCodeEmailInfo.java Aligns email-change action information.
README.md Updates supported Auth flows and remaining limitations.
firebase-debug.log Adds an emulator execution log.

Review effort: Balanced

The new operations complete with null as Task<Void>, as the Android SDK's do,
and verifyBeforeUpdateEmail joins them through sendOobCode, so the locale
header reaches every action email. An action sent for a user, a phone number
link and an Apple token revocation first refresh the user's ID token when it
has expired. Linking a password credential to an account that already has a
password provider fails with ERROR_PROVIDER_ALREADY_LINKED instead of
replacing the password, an email-link credential is only created from a
sign-in link, verifyPasswordResetCode rejects codes of other actions,
updateCurrentUser rejects a user whose token was issued for another project,
signInWithCustomToken keeps the sign-in's additional user info, and
AuthResult no longer renders the user, whose string form carries its tokens.
The tests initialise their app as fir-java-sdk while the emulator ran as
my-firebase-project, which it warned about on every request. The ID tokens it
issued carried its own project as audience, so updateCurrentUser's project
check rejected them, and the action codes it recorded were listed under its
own project, so the email-flow tests found none. The emulator now runs as the
tests' project, as it does locally.
Comment thread firebase-debug.log Outdated

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what this file?

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.


internal fun <T> unsupportedTask(message: String): Task<T> = Tasks.forException(UnsupportedOperationException(message))

abstract class MultiFactorInfo {
reload refreshes the profile after the token, so a verified or changed email
shows on the current user, and the account lookup also refreshes the phone
number, verification state and providers. Linking refreshes the user's ID
token first, as the other user actions do, which a token that is not a JWT
(a test double's) now survives. Invalid and expired action codes arrive as
FirebaseAuthActionCodeException and a weak password as
FirebaseAuthWeakPasswordException with the server's reason, keeping the
server's codes. An action link needs its apiKey to parse, as on Android, a
reverted second factor reports the factor through ActionCodeMultiFactorInfo,
and the username falls back to the provider profile's login or screen_name.
ActionCodeSettings and the exception details are Kotlin properties behind the
Android getter names, so Kotlin written for Android reads them the same way.
Setting a tenant throws, since the port signs in to the default tenant only.
The emulator's debug log left in the tree is removed and ignored.
@nbransby
nbransby merged commit d32e197 into master Oct 31, 2026
1 check passed
@nbransby
nbransby deleted the auth-android-api branch October 31, 2026 05:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants