前往主控台

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.
CreateUserAsync(UserRecordArgs args)
async Task< UserRecord >
Creates a new user account with the attributes contained in the specified UserRecordArgs.
CreateUserAsync(UserRecordArgs args, CancellationToken cancellationToken)
async Task< UserRecord >
Creates a new user account with the attributes contained in the specified UserRecordArgs.
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 .
ListUsersAsync(ListUsersOptions options)
PagedAsyncEnumerable< ExportedUserRecords, ExportedUserRecord >
Gets an async enumerable to iterate or page through users starting from the specified page token.
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.
UpdateUserAsync(UserRecordArgs args)
async Task< UserRecord >
Updates an existing user account with the attributes contained in the specified UserRecordArgs.
UpdateUserAsync(UserRecordArgs args, CancellationToken cancellationToken)
async Task< UserRecord >
Updates an existing user account with the attributes contained in the specified UserRecordArgs.
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.
InvalidOperationException
If no service account can be discovered from either the AppOptions or the deployment environment.
FirebaseAuthException
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.
InvalidOperationException
If no service account can be discovered from either the AppOptions or the deployment environment.
FirebaseAuthException
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.
InvalidOperationException
If no service account can be discovered from either the AppOptions or the deployment environment.
FirebaseAuthException
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.