| java.lang.Object | |
| ↳ | com.google.firebase.auth.FirebaseAuth |
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 Methods | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|
| 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. | ||||||||||
| static FirebaseAuth |
getInstance()
Gets the FirebaseAuth instance for the default
FirebaseApp. | ||||||||||
| synchronized static FirebaseAuth |
getInstance(FirebaseApp app)
Gets an instance of FirebaseAuth for a specific
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.
| ||||||||||
| ListUsersPage |
listUsers(String pageToken)
Gets a page of users starting from the specified
pageToken. | ||||||||||
| ListUsersPage |
listUsers(String pageToken, int maxResults)
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)
Parses and verifies a Firebase ID Token.
| ||||||||||
| FirebaseToken |
verifyIdToken(String token, boolean checkRevoked)
Parses and verifies a Firebase ID Token.
| ||||||||||
| ApiFuture<FirebaseToken> |
verifyIdTokenAsync(String token, boolean checkRevoked)
Similar to
verifyIdToken(String, boolean) but performs the operation asynchronously. | ||||||||||
| ApiFuture<FirebaseToken> |
verifyIdTokenAsync(String token)
Similar to
verifyIdToken(String) but performs the operation asynchronously. | ||||||||||
| FirebaseToken |
verifySessionCookie(String cookie)
Parses and verifies a Firebase session cookie.
| ||||||||||
| FirebaseToken |
verifySessionCookie(String cookie, boolean checkRevoked)
Parses and verifies a Firebase session cookie.
| ||||||||||
| ApiFuture<FirebaseToken> |
verifySessionCookieAsync(String cookie)
Similar to
verifySessionCookie(String) but performs the operation asynchronously. | ||||||||||
| ApiFuture<FirebaseToken> |
verifySessionCookieAsync(String cookie, boolean checkRevoked)
Similar to
verifySessionCookie(String, boolean) but performs the operation
asynchronously. | ||||||||||
|
[Expand]
Inherited Methods | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|
From class
java.lang.Object
| |||||||||||
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.
| 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. |
|---|
| 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. |
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.
FirebaseApp must have been initialized with service account credentials to use
call this method.
| 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.) |
| 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. |
Similar to createCustomToken(String, Map) but performs the operation
asynchronously.
| 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.) |
ApiFuture which will complete successfully with the created Firebase custom
token, or unsuccessfully with the failure Exception.| IllegalArgumentException | If the specified uid is null or empty, or if the app has not been initialized with service account credentials. |
|---|
Similar to createCustomToken(String) but performs the operation asynchronously.
| 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. |
|---|
ApiFuture which will complete successfully with the created Firebase custom
token, or unsuccessfully with the failure Exception.| IllegalArgumentException | If the specified uid is null or empty, or if the app has not been initialized with service account credentials. |
|---|
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.
| idToken | The Firebase ID token to exchange for a session cookie. |
|---|---|
| options | Additional options required to create the cookie. |
| IllegalArgumentException | If the ID token is null or empty, or if options is null. |
|---|---|
| FirebaseAuthException | If an error occurs while generating the session cookie. |
Similar to createSessionCookie(String, SessionCookieOptions) but performs the
operation asynchronously.
| idToken | The Firebase ID token to exchange for a session cookie. |
|---|---|
| options | Additional options required to create the cookie. |
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.| IllegalArgumentException | If the ID token is null or empty, or if options is null. |
|---|
Creates a new user account with the attributes contained in the specified
UserRecord.CreateRequest.
| request | A non-null UserRecord.CreateRequest instance. |
|---|
UserRecord instance corresponding to the newly created account.| NullPointerException | if the provided request is null. |
|---|---|
| FirebaseAuthException | if an error occurs while creating the user account. |
Similar to createUser(CreateRequest) but performs the operation asynchronously.
| request | A non-null UserRecord.CreateRequest instance. |
|---|
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.| NullPointerException | if the provided request is null. |
|---|
Deletes the user identified by the specified user ID.
| uid | A user ID string. |
|---|
| IllegalArgumentException | If the user ID string is null or empty. |
|---|---|
| FirebaseAuthException | If an error occurs while deleting the user. |
Similar to deleteUser(String) but performs the operation asynchronously.
| uid | A user ID string. |
|---|
ApiFuture which will complete successfully when the specified user account
has been deleted. If an error occurs while deleting the user account, the future throws a
FirebaseAuthException.| IllegalArgumentException | If the user ID string is null or empty. |
|---|
Gets the FirebaseAuth instance for the default FirebaseApp.
FirebaseApp.
Gets an instance of FirebaseAuth for a specific FirebaseApp.
| app | The FirebaseApp to get a FirebaseAuth instance for. |
|---|
Gets the user data corresponding to the specified user ID.
| uid | A user ID string. |
|---|
UserRecord instance.| IllegalArgumentException | If the user ID string is null or empty. |
|---|---|
| FirebaseAuthException | If an error occurs while retrieving user data. |
Similar to getUser(String) but performs the operation asynchronously.
| uid | A user ID string. |
|---|
ApiFuture which will complete successfully with a UserRecord
instance. If an error occurs while retrieving user data or if the specified user ID does
not exist, the future throws a FirebaseAuthException.| IllegalArgumentException | If the user ID string is null or empty. |
|---|
Gets the user data corresponding to the specified user email.
| A user email address string. |
UserRecord instance.| IllegalArgumentException | If the email is null or empty. |
|---|---|
| FirebaseAuthException | If an error occurs while retrieving user data. |
Similar to getUserByEmail(String) but performs the operation asynchronously.
| A user email address string. |
ApiFuture which will complete successfully with a UserRecord
instance. If an error occurs while retrieving user data or if the email address does not
correspond to a user, the future throws a FirebaseAuthException.| IllegalArgumentException | If the email is null or empty. |
|---|
Gets the user data corresponding to the specified user phone number.
| phoneNumber | A user phone number string. |
|---|
UserRecord instance.| IllegalArgumentException | If the phone number is null or empty. |
|---|---|
| FirebaseAuthException | If an error occurs while retrieving user data. |
Gets the user data corresponding to the specified user phone number.
| phoneNumber | A user phone number string. |
|---|
ApiFuture which will complete successfully with a UserRecord
instance. If an error occurs while retrieving user data or if the phone number does not
correspond to a user, the future throws a FirebaseAuthException.| IllegalArgumentException | If the phone number is null or empty. |
|---|
Gets a page of users starting from the specified pageToken. Page size will be
limited to 1000 users.
| pageToken | A non-empty page token string, or null to retrieve the first page of users. |
|---|
ListUsersPage instance.| IllegalArgumentException | If the specified page token is empty. |
|---|---|
| FirebaseAuthException | If an error occurs while retrieving user data. |
Gets a page of users starting from the specified pageToken.
| pageToken | A non-empty page token string, or null to retrieve the first page of users. |
|---|---|
| maxResults | Maximum number of users to include in the returned page. This may not exceed 1000. |
ListUsersPage instance.| IllegalArgumentException | If the specified page token is empty, or max results value is invalid. |
|---|---|
| FirebaseAuthException | If an error occurs while retrieving user data. |
Similar to listUsers(String, int) but performs the operation asynchronously.
| pageToken | A non-empty page token string, or null to retrieve the first page of users. |
|---|---|
| maxResults | Maximum number of users to include in the returned page. This may not exceed 1000. |
ApiFuture which will complete successfully with a ListUsersPage
instance. If an error occurs while retrieving user data, the future throws an exception.| IllegalArgumentException | If the specified page token is empty, or max results value is invalid. |
|---|
Similar to listUsers(String) but performs the operation asynchronously.
| pageToken | A non-empty page token string, or null to retrieve the first page of users. |
|---|
ApiFuture which will complete successfully with a ListUsersPage
instance. If an error occurs while retrieving user data, the future throws an exception.| IllegalArgumentException | If the specified page token is empty. |
|---|
Revokes all refresh tokens for the specified user.
Updates the user's tokensValidAfterTimestamp to the current UTC time expressed in milliseconds since the epoch and truncated to 1 second accuracy. It is important that the server on which this is called has its clock set correctly and synchronized.
While this will revoke all sessions for a specified user and disable any new ID tokens for
existing sessions from getting minted, existing ID tokens may remain active until their
natural expiration (one hour).
To verify that ID tokens are revoked, use verifyIdTokenAsync(String, boolean).
| uid | The user id for which tokens are revoked. |
|---|
| IllegalArgumentException | If the user ID is null or empty. |
|---|---|
| FirebaseAuthException | If an error occurs while revoking tokens. |
Similar to revokeRefreshTokens(String) but performs the operation asynchronously.
| uid | The user id for which tokens are revoked. |
|---|
ApiFuture which will complete successfully or fail with a
FirebaseAuthException in the event of an error.| IllegalArgumentException | If the user ID is null or empty. |
|---|
This method is deprecated.
Use setCustomUserClaims(String, Map) instead.
| FirebaseAuthException |
|---|
Sets the specified custom claims on an existing user account. A null claims value removes any claims currently set on the user account. The claims should serialize into a valid JSON string. The serialized claims must not be larger than 1000 characters.
| uid | A user ID string. |
|---|---|
| claims | A map of custom claims or null. |
| FirebaseAuthException | If an error occurs while updating custom claims. |
|---|---|
| IllegalArgumentException | If the user ID string is null or empty, or the claims payload is invalid or too large. |
Similar to setCustomUserClaims(String, Map) but performs the operation asynchronously.
| uid | A user ID string. |
|---|---|
| claims | A map of custom claims or null. |
ApiFuture which will complete successfully when the user account has been
updated. If an error occurs while deleting the user account, the future throws a
FirebaseAuthException.| IllegalArgumentException | If the user ID string is null or empty. |
|---|
Updates an existing user account with the attributes contained in the specified
UserRecord.UpdateRequest.
| request | A non-null UserRecord.UpdateRequest instance. |
|---|
UserRecord instance corresponding to the updated user account.
account, the task fails with a FirebaseAuthException.| NullPointerException | if the provided update request is null. |
|---|---|
| FirebaseAuthException | if an error occurs while updating the user account. |
Similar to updateUser(UpdateRequest) but performs the operation asynchronously.
| request | A non-null UserRecord.UpdateRequest instance. |
|---|
ApiFuture which will complete successfully with a UserRecord
instance corresponding to the updated user account. If an error occurs while updating the
user account, the future throws a FirebaseAuthException.
Parses and verifies a Firebase ID Token.
A Firebase application can identify itself to a trusted backend server by sending its
Firebase ID Token (accessible via the getToken API in the Firebase Authentication
client) with its requests. The backend server can then use the verifyIdToken() method
to verify that the token is valid. This method ensures that the token is correctly signed,
has not expired, and it was issued to the Firebase project associated with this
FirebaseAuth instance.
This method does not check whether a token has been revoked. Use
verifyIdToken(String, boolean) to perform an additional revocation check.
| token | A Firebase ID token string to parse and verify. |
|---|
FirebaseToken representing the verified and decoded token.| IllegalArgumentException | If the token is null, empty, or if the FirebaseApp
instance does not have a project ID associated with it. |
|---|---|
| FirebaseAuthException | If an error occurs while parsing or validating the token. |
Parses and verifies a Firebase ID Token.
A Firebase application can identify itself to a trusted backend server by sending its
Firebase ID Token (accessible via the getToken API in the Firebase Authentication
client) with its requests. The backend server can then use the verifyIdToken() method
to verify that the token is valid. This method ensures that the token is correctly signed,
has not expired, and it was issued to the Firebase project associated with this
FirebaseAuth instance.
If checkRevoked is set to true, this method performs an additional check to see
if the ID token has been revoked since it was issues. This requires making an additional
remote API call.
| token | A Firebase ID token string to parse and verify. |
|---|---|
| checkRevoked | A boolean denoting whether to check if the tokens were revoked. |
FirebaseToken representing the verified and decoded token.| IllegalArgumentException | If the token is null, empty, or if the FirebaseApp
instance does not have a project ID associated with it. |
|---|---|
| FirebaseAuthException | If an error occurs while parsing or validating the token. |
Similar to verifyIdToken(String, boolean) but performs the operation asynchronously.
| token | A Firebase ID Token to verify and parse. |
|---|---|
| checkRevoked | A boolean denoting whether to check if the tokens were revoked. |
ApiFuture which will complete successfully with the parsed token, or
unsuccessfully with a FirebaseAuthException.| IllegalArgumentException | If the token is null, empty, or if the FirebaseApp
instance does not have a project ID associated with it.
|
|---|
Similar to verifyIdToken(String) but performs the operation asynchronously.
| token | A Firebase ID Token to verify and parse. |
|---|
ApiFuture which will complete successfully with the parsed token, or
unsuccessfully with a FirebaseAuthException.| IllegalArgumentException | If the token is null, empty, or if the FirebaseApp
instance does not have a project ID associated with it.
|
|---|
Parses and verifies a Firebase session cookie.
If verified successfully, returns a parsed version of the cookie from which the UID and the
other claims can be read. If the cookie is invalid, throws a FirebaseAuthException.
This method does not check whether the cookie has been revoked. See
verifySessionCookie(String, boolean).
| cookie | A Firebase session cookie string to verify and parse. |
|---|
FirebaseToken representing the verified and decoded cookie.
| FirebaseAuthException |
|---|
Parses and verifies a Firebase session cookie.
If checkRevoked is true, additionally verifies that the cookie has not been
revoked.
If verified successfully, returns a parsed version of the cookie from which the UID and the
other claims can be read. If the cookie is invalid or has been revoked while
checkRevoked is true, throws a FirebaseAuthException.
| cookie | A Firebase session cookie string to verify and parse. |
|---|---|
| checkRevoked | A boolean indicating whether to check if the cookie was explicitly revoked. |
FirebaseToken representing the verified and decoded cookie.
| FirebaseAuthException |
|---|
Similar to verifySessionCookie(String) but performs the operation asynchronously.
| cookie | A Firebase session cookie string to verify and parse. |
|---|
ApiFuture which will complete successfully with the parsed cookie, or
unsuccessfully with the failure Exception.
Similar to verifySessionCookie(String, boolean) but performs the operation
asynchronously.
| cookie | A Firebase session cookie string to verify and parse. |
|---|---|
| checkRevoked | A boolean indicating whether to check if the cookie was explicitly revoked. |
ApiFuture which will complete successfully with the parsed cookie, or
unsuccessfully with the failure Exception.