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
The auth instance associated with the default Firebase 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.
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.

Public static functions

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

Properties

DefaultInstance

static FirebaseAuth DefaultInstance

The auth instance associated with the default Firebase app.

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

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.

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.
FirebaseException
If the ID token fails to verify.
Parameters
idToken
A Firebase ID token string to parse and verify.
cancellationToken
A cancellation token to monitor the asynchronous operation.
Returns
A task that completes with a FirebaseToken representing the verified and decoded ID token.

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.

发送以下问题的反馈:

此网页
需要帮助?请访问我们的支持页面