Class FirebaseAuth
Firebase Authentication client backed by the Identity Toolkit REST API.
Firebase is not an OIDC provider per se -- it issues its own ID tokens
minted by Google's Identity Toolkit -- so this class does not extend
Login; it stands alone with its own state.
Supports the three flows that work without the Firebase native SDK:
signInWithEmailAndPassword(email, password)(Email/Password provider)signUp(email, password)(creates a new account)refresh(refreshToken)(uses the Secure Token Service endpoint)
For federated sign-in (Google, Apple, Microsoft, etc.) use the
matching *Connect class to obtain an OIDC ID token, then call
signInWithIdpIdToken(String, String) to swap it for a Firebase token.
Tokens are persisted to Preferences under a cn1.firebase.* namespace.
They are not encrypted-at-rest by default -- bring your own
TokenStore strategy if that matters to you.
- Since:
- 7.0.245
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final classSuccessfully-resolved Firebase session: ID token, refresh token, the stablelocalId, the user's email when present, and the absolute expiry computed fromexpiresIn. -
Method Summary
Modifier and TypeMethodDescriptionCurrently-stored Firebase ID token.static FirebaseAuthgetUid()Last-known Firebase user identifier (localIdfrom Firebase's REST API), ornullif no one is signed in.booleantrueif a token is stored and not past its expiry.refresh()Refreshes the stored session using the saved refresh token.Same asrefresh()but takes an explicit refresh token.static StringrequireFirebaseToken(String token) Sanitiser for refresh-token-shaped strings.signInWithEmailAndPassword(String email, String password) Email + password sign-in via Identity Toolkit'saccounts:signInWithPasswordendpoint.signInWithIdpIdToken(String idToken, String providerId) Exchanges an OIDC ID token obtained viaGoogleConnect,AppleSignIn,MicrosoftConnector similar for a Firebase session.voidsignOut()Clears the locally stored Firebase session.Creates a new account viaaccounts:signUp.withApiKey(String apiKey) The Web API key from the Firebase console (Project Settings -> General -> Your apps -> Web API key).
-
Method Details
-
getInstance
-
withApiKey
The Web API key from the Firebase console (Project Settings -> General -> Your apps -> Web API key). Required before any of the sign-in methods will work. -
getUid
Last-known Firebase user identifier (localIdfrom Firebase's REST API), ornullif no one is signed in. -
getIdToken
Currently-stored Firebase ID token. Callrefresh()if it is expired orsignInWithEmailAndPassword(String, String)for a fresh session. -
isSignedIn
public boolean isSignedIn()trueif a token is stored and not past its expiry. -
signOut
public void signOut()Clears the locally stored Firebase session. Does not revoke the refresh token on Google's side. -
signInWithEmailAndPassword
public AsyncResource<FirebaseAuth.FirebaseUser> signInWithEmailAndPassword(String email, String password) Email + password sign-in via Identity Toolkit'saccounts:signInWithPasswordendpoint. -
signUp
Creates a new account viaaccounts:signUp. Returns the newFirebaseAuth.FirebaseUserjust likesignInWithEmailAndPassword(String, String). -
signInWithIdpIdToken
public AsyncResource<FirebaseAuth.FirebaseUser> signInWithIdpIdToken(String idToken, String providerId) Exchanges an OIDC ID token obtained viaGoogleConnect,AppleSignIn,MicrosoftConnector similar for a Firebase session.providerIdmust be a Firebase-recognised identifier such as"google.com","apple.com","microsoft.com","facebook.com","twitter.com". -
refresh
Refreshes the stored session using the saved refresh token. Falls through with the currently-cachedFirebaseAuth.FirebaseUserwhen no refresh token is on file. -
refresh
Same asrefresh()but takes an explicit refresh token. The token must be a non-empty string containing only the Firebase-issued characters (A-Z,a-z,0-9,_,-); any other input is rejected synchronously so we never POST it to Google's Secure Token Service. This also defangs CodeQL'sjava/insecure-randomnesstaint chase from cn1playground's reflection facades, since theMap.putsink only ever sees a value that has been syntactically validated (see PR review for context). -
requireFirebaseToken
Sanitiser for refresh-token-shaped strings. Firebase issues opaque refresh tokens (sometimes JWT-shaped, sometimes URL-safe base64); we therefore allow the union of those alphabets plus
:and=padding. Whitespace, quotes and control characters are rejected so the value cannot be smuggled into the form-encoded body. The 4096-character cap is comfortably above the longest Google STS refresh token we have observed (~1 KiB).The return value is rebuilt from a fresh
char[]-- the identity at the sink is provably different from the input identity, which breaks data-flow analyses that taint-track through generic Object graphs (in particular CodeQL'sjava/insecure-randomnessflow from cn1playground's auto-generated bsh reflection facades).Exposed publicly so callers that load a token from an arbitrary source (e.g. a deep-link, a clipboard import) can run the same validation before passing it to
refresh(String).
-