Go to console

FirebaseAuth

public class FirebaseAuth extends Object

This class is the entry point for all server-side Firebase Authentication actions.

You can get an instance of FirebaseAuth via getInstance(FirebaseApp) and then use it to perform a variety of authentication-related operations, including generating custom tokens for use by client-side code, verifying Firebase ID Tokens received from clients, or creating new FirebaseApp instances that are scoped to a particular authentication UID.

Public Method Summary

String
createCustomToken(String uid)
Creates a Firebase custom token for the given UID.
String
createCustomToken(String uid, Map<String, Object> developerClaims)
Creates a Firebase custom token for the given UID, containing the specified additional claims.
ApiFuture<String>
createCustomTokenAsync(String uid, Map<String, Object> developerClaims)
Similar to createCustomToken(String, Map) but performs the operation asynchronously.
ApiFuture<String>
createCustomTokenAsync(String uid)
Similar to createCustomToken(String) but performs the operation asynchronously.
String
createSessionCookie(String idToken, SessionCookieOptions options)
Creates a new Firebase session cookie from the given ID token and options.
ApiFuture<String>
createSessionCookieAsync(String idToken, SessionCookieOptions options)
Similar to createSessionCookie(String, SessionCookieOptions) but performs the operation asynchronously.
UserRecord
createUser(UserRecord.CreateRequest request)
Creates a new user account with the attributes contained in the specified UserRecord.CreateRequest.
ApiFuture<UserRecord>
createUserAsync(UserRecord.CreateRequest request)
Similar to createUser(CreateRequest) but performs the operation asynchronously.
void
deleteUser(String uid)
Deletes the user identified by the specified user ID.
ApiFuture<Void>
deleteUserAsync(String uid)
Similar to deleteUser(String) but performs the operation asynchronously.
String
generateEmailVerificationLink(String email, ActionCodeSettings settings)
Generates the out-of-band email action link for email verification flows for the specified email address, using the action code settings provided.
String
generateEmailVerificationLink(String email)
Generates the out-of-band email action link for email verification flows for the specified email address.
ApiFuture<String>
generateEmailVerificationLinkAsync(String email, ActionCodeSettings settings)
Similar to generateEmailVerificationLink(String, ActionCodeSettings) but performs the operation asynchronously.
ApiFuture<String>
generateEmailVerificationLinkAsync(String email)
Similar to generateEmailVerificationLink(String) but performs the operation asynchronously.
String
generatePasswordResetLink(String email, ActionCodeSettings settings)
Generates the out-of-band email action link for password reset flows for the specified email address.
String
generatePasswordResetLink(String email)
Generates the out-of-band email action link for password reset flows for the specified email address.
ApiFuture<String>
generatePasswordResetLinkAsync(String email, ActionCodeSettings settings)
Similar to generatePasswordResetLink(String, ActionCodeSettings) but performs the operation asynchronously.
ApiFuture<String>
generatePasswordResetLinkAsync(String email)
Similar to generatePasswordResetLink(String) but performs the operation asynchronously.
String
generateSignInWithEmailLink(String email, ActionCodeSettings settings)
Generates the out-of-band email action link for email link sign-in flows, using the action code settings provided.
ApiFuture<String>
generateSignInWithEmailLinkAsync(String email, ActionCodeSettings settings)
Similar to generateSignInWithEmailLink(String, ActionCodeSettings) but performs the operation asynchronously.
synchronized static FirebaseAuth
getInstance(FirebaseApp app)
Gets an instance of FirebaseAuth for a specific FirebaseApp.
static FirebaseAuth
getInstance()
Gets the FirebaseAuth instance for the default FirebaseApp.
UserRecord
getUser(String uid)
Gets the user data corresponding to the specified user ID.
ApiFuture<UserRecord>
getUserAsync(String uid)
Similar to getUser(String) but performs the operation asynchronously.
UserRecord
getUserByEmail(String email)
Gets the user data corresponding to the specified user email.
ApiFuture<UserRecord>
getUserByEmailAsync(String email)
Similar to getUserByEmail(String) but performs the operation asynchronously.
UserRecord
getUserByPhoneNumber(String phoneNumber)
Gets the user data corresponding to the specified user phone number.
ApiFuture<UserRecord>
getUserByPhoneNumberAsync(String phoneNumber)
Gets the user data corresponding to the specified user phone number.
UserImportResult
importUsers(List<ImportUserRecord> users)
Imports the provided list of users into Firebase Auth.
UserImportResult
importUsers(List<ImportUserRecord> users, UserImportOptions options)
Imports the provided list of users into Firebase Auth.
ApiFuture<UserImportResult>
importUsersAsync(List<ImportUserRecord> users)
Similar to importUsers(List) but performs the operation asynchronously.
ApiFuture<UserImportResult>
importUsersAsync(List<ImportUserRecord> users, UserImportOptions options)
Similar to importUsers(List, UserImportOptions) but performs the operation asynchronously.
ListUsersPage
listUsers(String pageToken, int maxResults)
Gets a page of users starting from the specified pageToken.
ListUsersPage
listUsers(String pageToken)
Gets a page of users starting from the specified pageToken.
ApiFuture<ListUsersPage>
listUsersAsync(String pageToken, int maxResults)
Similar to listUsers(String, int) but performs the operation asynchronously.
ApiFuture<ListUsersPage>
listUsersAsync(String pageToken)
Similar to listUsers(String) but performs the operation asynchronously.
void
revokeRefreshTokens(String uid)
Revokes all refresh tokens for the specified user.
ApiFuture<Void>
revokeRefreshTokensAsync(String uid)
Similar to revokeRefreshTokens(String) but performs the operation asynchronously.
void
setCustomClaims(String uid, Map<String, Object> claims)
This method is deprecated. Use setCustomUserClaims(String, Map) instead.
void
setCustomUserClaims(String uid, Map<String, Object> claims)
Sets the specified custom claims on an existing user account.
ApiFuture<Void>
setCustomUserClaimsAsync(String uid, Map<String, Object> claims)
Similar to setCustomUserClaims(String, Map) but performs the operation asynchronously.
UserRecord
updateUser(UserRecord.UpdateRequest request)
Updates an existing user account with the attributes contained in the specified UserRecord.UpdateRequest.
ApiFuture<UserRecord>
updateUserAsync(UserRecord.UpdateRequest request)
Similar to updateUser(UpdateRequest) but performs the operation asynchronously.
FirebaseToken
verifyIdToken(String token, boolean checkRevoked)
Parses and verifies a Firebase ID Token.
FirebaseToken
verifyIdToken(String token)
Parses and verifies a Firebase ID Token.
ApiFuture<FirebaseToken>
verifyIdTokenAsync(String token)
Similar to verifyIdToken(String) but performs the operation asynchronously.
ApiFuture<FirebaseToken>
verifyIdTokenAsync(String token, boolean checkRevoked)
Similar to verifyIdToken(String, boolean) but performs the operation asynchronously.
FirebaseToken
verifySessionCookie(String cookie, boolean checkRevoked)
Parses and verifies a Firebase session cookie.
FirebaseToken
verifySessionCookie(String cookie)
Parses and verifies a Firebase session cookie.
ApiFuture<FirebaseToken>
verifySessionCookieAsync(String cookie, boolean checkRevoked)
Similar to verifySessionCookie(String, boolean) but performs the operation asynchronously.
ApiFuture<FirebaseToken>
verifySessionCookieAsync(String cookie)
Similar to verifySessionCookie(String) but performs the operation asynchronously.

Inherited Method Summary

Public Methods

public String createCustomToken (String uid)

Creates a Firebase custom token for the given UID. This token can then be sent back to a client application to be used with the signInWithCustomToken authentication API.

FirebaseApp must have been initialized with service account credentials to use call this method.

Parameters
uid The UID to store in the token. This identifies the user to other Firebase services (Realtime Database, Firebase Auth, etc.). Should be less than 128 characters.
Returns
  • A Firebase custom token string.
Throws
IllegalArgumentException If the specified uid is null or empty, or if the app has not been initialized with service account credentials.
FirebaseAuthException If an error occurs while generating the custom token.

public String createCustomToken (String uid, Map<String, Object> developerClaims)

Creates a Firebase custom token for the given UID, containing the specified additional claims. This token can then be sent back to a client application to be used with the signInWithCustomToken authentication API.

This method attempts to generate a token using:

  1. the private key of FirebaseApp's service account credentials, if provided at initialization.
  2. the IAM service if a service account email was specified via setServiceAccountId(String).
  3. the App Identity service if the code is deployed in the Google App Engine standard environment.
  4. the local Metadata server if the code is deployed in a different GCP-managed environment like Google Compute Engine.

This method throws an exception when all the above fail.

Parameters
uid The UID to store in the token. This identifies the user to other Firebase services (Realtime Database, Firebase Auth, etc.). Should be less than 128 characters.
developerClaims Additional claims to be stored in the token (and made available to security rules in Database, Storage, etc.). These must be able to be serialized to JSON (e.g. contain only Maps, Arrays, Strings, Booleans, Numbers, etc.)
Returns
  • A Firebase custom token string.
Throws
IllegalArgumentException If the specified uid is null or empty.
IllegalStateException If the SDK fails to discover a viable approach for signing tokens.
FirebaseAuthException If an error occurs while generating the custom token.

public ApiFuture<String> createCustomTokenAsync (String uid, Map<String, Object> developerClaims)

Similar to createCustomToken(String, Map) but performs the operation asynchronously.

Parameters
uid The UID to store in the token. This identifies the user to other Firebase services (Realtime Database, Storage, etc.). Should be less than 128 characters.
developerClaims Additional claims to be stored in the token (and made available to security rules in Database, Storage, etc.). These must be able to be serialized to JSON (e.g. contain only Maps, Arrays, Strings, Booleans, Numbers, etc.)
Returns
  • An ApiFuture which will complete successfully with the created Firebase custom token, or unsuccessfully with the failure Exception.
Throws
IllegalArgumentException If the specified uid is null or empty, or if the app has not been initialized with service account credentials.

public ApiFuture<String> createCustomTokenAsync (String uid)

Similar to createCustomToken(String) but performs the operation asynchronously.

Parameters
uid The UID to store in the token. This identifies the user to other Firebase services (Realtime Database, Firebase Auth, etc.). Should be less than 128 characters.
Returns
  • An ApiFuture which will complete successfully with the created Firebase custom token, or unsuccessfully with the failure Exception.
Throws
IllegalArgumentException If the specified uid is null or empty, or if the app has not been initialized with service account credentials.

public String createSessionCookie (String idToken, SessionCookieOptions options)

Creates a new Firebase session cookie from the given ID token and options. The returned JWT can be set as a server-side session cookie with a custom cookie policy.

Parameters
idToken The Firebase ID token to exchange for a session cookie.
options Additional options required to create the cookie.
Returns
  • A Firebase session cookie string.
Throws
IllegalArgumentException If the ID token is null or empty, or if options is null.
FirebaseAuthException If an error occurs while generating the session cookie.

public ApiFuture<String> createSessionCookieAsync (String idToken, SessionCookieOptions options)

Similar to createSessionCookie(String, SessionCookieOptions) but performs the operation asynchronously.

Parameters
idToken The Firebase ID token to exchange for a session cookie.
options Additional options required to create the cookie.
Returns
  • An ApiFuture which will complete successfully with a session cookie string. If an error occurs while generating the cookie or if the specified ID token is invalid, the future throws a FirebaseAuthException.
Throws
IllegalArgumentException If the ID token is null or empty, or if options is null.

public UserRecord createUser (UserRecord.CreateRequest request)

Creates a new user account with the attributes contained in the specified UserRecord.CreateRequest.

Parameters
request A non-null UserRecord.CreateRequest instance.
Returns
  • A UserRecord instance corresponding to the newly created account.
Throws
NullPointerException if the provided request is null.
FirebaseAuthException if an error occurs while creating the user account.

public ApiFuture<UserRecord> createUserAsync (UserRecord.CreateRequest request)

Similar to createUser(CreateRequest) but performs the operation asynchronously.

Parameters
request A non-null UserRecord.CreateRequest instance.
Returns
  • An ApiFuture which will complete successfully with a UserRecord instance corresponding to the newly created account. If an error occurs while creating the user account, the future throws a FirebaseAuthException.
Throws
NullPointerException if the provided request is null.

public void deleteUser (String uid)

Deletes the user identified by the specified user ID.

Parameters
uid A user ID string.
Throws
IllegalArgumentException If the user ID string is null or empty.
FirebaseAuthException If an error occurs while deleting the user.

public ApiFuture<Void> deleteUser