Go to console

FirebaseAdmin.Auth.FirebaseAuth

This is the entry point to all server-side Firebase Authentication operations.

Summary

You can get an instance of this class via FirebaseAuth.DefaultInstance.

Inheritance

Inherits from: FirebaseAdmin.IFirebaseService

Properties

DefaultInstance
static FirebaseAuth
Gets the auth instance associated with the default Firebase app.

Public static functions

GetAuth(FirebaseApp app)
Returns the auth instance for the specified app.

Public functions

CreateCustomTokenAsync(string uid)
async Task< string >
Creates a Firebase custom token for the given user ID.
CreateCustomTokenAsync(string uid, CancellationToken cancellationToken)
async Task< string >
Creates a Firebase custom token for the given user ID.
CreateCustomTokenAsync(string uid, IDictionary< string, object > developerClaims)
async Task< string >
Creates a Firebase custom token for the given user ID containing the specified additional claims.
CreateCustomTokenAsync(string uid, IDictionary< string, object > developerClaims, CancellationToken cancellationToken)
async Task< string >
Creates a Firebase custom token for the given user ID containing the specified additional claims.
DeleteUserAsync(string uid)
async Task
Deletes the user identified by the specified uid .
DeleteUserAsync(string uid, CancellationToken cancellationToken)
async Task
Deletes the user identified by the specified uid .
GetUserAsync(string uid)
async Task< UserRecord >
Gets a UserRecord object containing information about the user who's user ID was specified in uid .
GetUserAsync(string uid, CancellationToken cancellationToken)
async Task< UserRecord >
Gets a UserRecord object containing information about the user who's user ID was specified in uid .
GetUserByEmailAsync(string email)
async Task< UserRecord >
Gets a UserRecord object containing information about the user identified by email .
GetUserByEmailAsync(string email, CancellationToken cancellationToken)
async Task< UserRecord >
Gets a UserRecord object containing information about the user identified by email .
GetUserByPhoneNumberAsync(string phoneNumber)
async Task< UserRecord >
Gets a UserRecord object containing information about the user identified by phoneNumber .
GetUserByPhoneNumberAsync(string phoneNumber, CancellationToken cancellationToken)
async Task< UserRecord >
Gets a UserRecord object containing information about the user identified by phoneNumber .
SetCustomUserClaimsAsync(string uid, IReadOnlyDictionary< string, object > claims)
async Task
Sets the specified custom claims on an existing user account.
SetCustomUserClaimsAsync(string uid, IReadOnlyDictionary< string, object > claims, CancellationToken cancellationToken)
async Task
Sets the specified custom claims on an existing user account.
VerifyIdTokenAsync(string idToken)
async Task< FirebaseToken >
Parses and verifies a Firebase ID token.
VerifyIdTokenAsync(string idToken, CancellationToken cancellationToken)
async Task< FirebaseToken >
Parses and verifies a Firebase ID token.

Properties

DefaultInstance

static FirebaseAuth DefaultInstance

Gets the auth instance associated with the default Firebase app.

This property is null if the default app doesn't yet exist.

Public static functions

GetAuth

FirebaseAuth GetAuth(
  FirebaseApp app
)

Returns the auth instance for the specified app.

Details
Exceptions
System.ArgumentNullException
If the app argument is null.
Parameters
app
An app instance.
Returns
The FirebaseAuth instance associated with the specified app.

Public functions

CreateCustomTokenAsync

async Task< string > CreateCustomTokenAsync(
  string uid
)

Creates a Firebase custom token for the given user ID.

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 accound ID was specified via AppOptions
  3. the local metadata server if the code is deployed in a GCP-managed environment.

Details
Exceptions
ArgumentException
If uid is null, empty or longer than 128 characters.
FirebaseException
If an error occurs while creating a custom token.
Parameters
uid
The UID to store in the token. This identifies the user to other Firebase services (Realtime Database, Firebase Auth, etc.). Must not be longer than 128 characters.
Returns
A task that completes with a Firebase custom token.

CreateCustomTokenAsync

async Task< string > CreateCustomTokenAsync(
  string uid,
  CancellationToken cancellationToken
)

Creates a Firebase custom token for the given user ID.

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 accound ID was specified via AppOptions
  3. the local metadata server if the code is deployed in a GCP-managed environment.

Details
Exceptions
ArgumentException
If uid is null, empty or longer than 128 characters.
FirebaseException
If an error occurs while creating a custom token.
Parameters
uid
The UID to store in the token. This identifies the user to other Firebase services (Realtime Database, Firebase Auth, etc.). Must not be longer than 128 characters.
cancellationToken
A cancellation token to monitor the asynchronous operation.
Returns
A task that completes with a Firebase custom token.

CreateCustomTokenAsync

async Task< string > CreateCustomTokenAsync(
  string uid,
  IDictionary< string, object > developerClaims
)

Creates a Firebase custom token for the given user ID 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 uses the same mechanisms as CreateCustomTokenAsync(string) to sign custom tokens.

Details
Exceptions
ArgumentException
If uid is null, empty or longer than 128 characters. Or, if developerClaims contains any standard JWT claims.
FirebaseException
If an error occurs while creating a custom token.
Parameters
uid
The UID to store in the token. This identifies the user to other Firebase services (Realtime Database, Firebase Auth, etc.). Must not be longer than 128 characters.
developerClaims
Additional claims to be stored in the token, and made available to Firebase security rules. These must be serializable to JSON, and must not contain any standard JWT claims.
Returns
A task that completes with a Firebase custom token.

CreateCustomTokenAsync

async Task< string > CreateCustomTokenAsync(
  string uid,
  IDictionary< string, object > developerClaims,
  CancellationToken cancellationToken
)

Creates a Firebase custom token for the given user ID 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 uses the same mechanisms as CreateCustomTokenAsync(string) to sign custom tokens.

Details
Exceptions
ArgumentException
If uid is null, empty or longer than 128 characters. Or, if developerClaims contains any standard JWT claims.
FirebaseException
If an error occurs while creating a custom token.
Parameters
uid
The UID to store in the token. This identifies the user to other Firebase services (Realtime Database, Firebase Auth, etc.). Must not be longer than 128 characters.
developerClaims
Additional claims to be stored in the token, and made available to Firebase security rules. These must be serializable to JSON, and must not contain any standard JWT claims.
cancellationToken
A cancellation token to monitor the asynchronous operation.
Returns
A task that completes with a Firebase custom token.

DeleteUserAsync

async Task DeleteUserAsync(
  string uid
)

Deletes the user identified by the specified uid .

Details
Parameters
uid
A user ID string.
Exceptions
ArgumentException
If the user ID argument is null or empty.
FirebaseException
If an error occurs while deleting the user.
Returns
A task that completes when the user account has been deleted.

DeleteUserAsync

async Task DeleteUserAsync(
  string uid,
  CancellationToken cancellationToken
)

Deletes the user identified by the specified uid .

Details
Parameters
uid
A user ID string.
cancellationToken
A cancellation token to monitor the asynchronous operation.
Exceptions
ArgumentException
If the user ID argument is null or empty.
FirebaseException
If an error occurs while deleting the user.
Returns
A task that completes when the user account has been deleted.

GetUserAsync

async Task< UserRecord > GetUserAsync(
  string uid
)

Gets a UserRecord object containing information about the user who's user ID was specified in uid .

Details
Parameters
uid
The user ID for the user who's data is to be retrieved.
Exceptions
ArgumentException
If user ID argument is null or empty.
FirebaseException
If a user cannot be found with the specified user ID.
Returns
A task that completes with a UserRecord representing a user with the specified user ID.

GetUserAsync

async Task< UserRecord > GetUserAsync(
  string uid,
  CancellationToken cancellationToken
)

Gets a UserRecord object containing information about the user who's user ID was specified in uid .

Details
Parameters
uid
The user ID for the user who's data is to be retrieved.
cancellationToken
A cancellation token to monitor the asynchronous operation.
Exceptions
ArgumentException
If user ID argument is null or empty.
FirebaseException
If a user cannot be found with the specified user ID.
Returns
A task that completes with a UserRecord representing a user with the specified user ID.

GetUserByEmailAsync

async Task< UserRecord > GetUserByEmailAsync(
  string email
)

Gets a UserRecord object containing information about the user identified by email .

Details
Parameters
email
The email of the user who's data is to be retrieved.
Exceptions
ArgumentException
If the email argument is null or empty.
FirebaseException
If a user cannot be found with the specified email.
Returns
A task that completes with a UserRecord representing a user with the specified email.

GetUserByEmailAsync

async Task< UserRecord > GetUserByEmailAsync(
  string email,
  CancellationToken cancellationToken
)

Gets a UserRecord object containing information about the user identified by email .

Details
Parameters
email
The email of the user who's data is to be retrieved.
cancellationToken
A cancellation token to monitor the asynchronous operation.
Exceptions
ArgumentException
If the email argument is null or empty.
FirebaseException
If a user cannot be found with the specified email.
Returns
A task that completes with a UserRecord representing a user with the specified email.

GetUserByPhoneNumberAsync

async Task< UserRecord > GetUserByPhoneNumberAsync(
  string phoneNumber
)

Gets a UserRecord object containing information about the user identified by phoneNumber .

Details
Parameters
phoneNumber
The phone number of the user who's data is to be retrieved.
Exceptions
ArgumentException
If the phone number argument is null or empty.
FirebaseException
If a user cannot be found with the specified phone number.
Returns
A task that completes with a UserRecord representing a user with the specified phone number.

GetUserByPhoneNumberAsync

async Task< UserRecord > GetUserByPhoneNumberAsync(
  string phoneNumber,
  CancellationToken cancellationToken
)

Gets a UserRecord object containing information about the user identified by phoneNumber .

Details
Parameters
phoneNumber
The phone number of the user who's data is to be retrieved.
cancellationToken
A cancellation token to monitor the asynchronous operation.
Exceptions
ArgumentException
If the phone number argument is null or empty.
FirebaseException
If a user cannot be found with the specified phone number.
Returns
A task that completes with a UserRecord representing a user with the specified phone number.

SetCustomUserClaimsAsync

async Task SetCustomUserClaimsAsync(
  string uid,
  IReadOnlyDictionary< string, object > claims
)

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 must serialize into a valid JSON string. The serialized claims must not be larger than 1000 characters.

Details
Exceptions
ArgumentException
If uid is null, empty or longer than 128 characters. Or, if the serialized claims is larger than 1000 characters.
Parameters
uid
The user ID string for the custom claims will be set. Must not be null or longer than 128 characters.
claims
The claims to be stored on the user account, and made available to Firebase security rules. These must be serializable to JSON, and the serialized claims should not be larger than 1000 characters.
Returns
A task that completes when the claims have been set.

SetCustomUserClaimsAsync

async Task SetCustomUserClaimsAsync(
  string uid,
  IReadOnlyDictionary< string, object > claims,
  CancellationToken cancellationToken
)

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.

Details
Exceptions
ArgumentException
If uid is null, empty or longer than 128 characters. Or, if the serialized claims is larger than 1000 characters.
Parameters
uid
The user ID string for the custom claims will be set. Must not be null or longer than 128 characters.
claims
The claims to be stored on the user account, and made available to Firebase security rules. These must be serializable to JSON, and after serialization it should not be larger than 1000 characters.
cancellationToken
A cancellation token to monitor the asynchronous operation.
Returns
A task that completes when the claims have been set.

VerifyIdTokenAsync

async Task< FirebaseToken > VerifyIdTokenAsync(
  string idToken
)

Parses and verifies a Firebase ID token.

A Firebase client app can identify itself to a trusted back-end server by sending its Firebase ID Token (accessible via the getIdToken() API in the Firebase client SDK) with its requests. The back-end server can then use this method to verify that the token is valid. This method ensures that the token is correctly signed, has not expired, and it was issued against the Firebase project associated with this FirebaseAuth instance.

See Verify ID Tokens for code samples and detailed documentation.

Details
Exceptions
ArgumentException
If ID token argument is null or empty.
FirebaseException
If the ID token fails to verify.
Parameters
idToken
A Firebase ID token string to parse and verify.
Returns
A task that completes with a FirebaseToken representing the verified and decoded ID token.

VerifyIdTokenAsync

async Task< FirebaseToken > VerifyIdTokenAsync(
  string idToken,
  CancellationToken cancellationToken
)

Parses and verifies a Firebase ID token.

A Firebase client app can identify itself to a trusted back-end server by sending its Firebase ID Token (accessible via the getIdToken() API in the Firebase client SDK) with its requests. The back-end server can then use this method to verify that the token is valid. This method ensures that the token is correctly signed, has not expired, and it was issued against the Firebase project associated with this FirebaseAuth instance.

See Verify ID Tokens for code samples and detailed documentation.

Details
Exceptions
ArgumentException
If ID token argument is null or empty.