FirebaseAuthAdmin class

The Firebase Auth admin calls of one FirebaseAdminApp: custom tokens, users, custom claims, revocation and ID token verification. Pure Dart; it talks to the Identity Toolkit REST API.

Get it with FirebaseAuthAdmin(app) or app.auth() (the same object for the same app).

For trusted code only: servers, CLIs, CI jobs and integration tests. Admin calls and service account credentials bypass security rules, and whoever can mint a custom token can sign in as any user. Never put a service account key in an app, a web page, a Flutter asset of a release build or a repository; on Google Cloud prefer Application Default Credentials with AdminCredential.iam, which holds no key.

import 'package:firebase_admin_dart/auth.dart';

Future<String> tokenForTester(FirebaseAdminApp app) async {
  final AdminUser user = await app.auth().createUser(
    customClaims: <String, Object?>{'role': 'tester'},
  );
  return app.auth().createCustomToken(
    user.uid,
    claims: <String, Object?>{'tier': 'pro'},
  );
}

With FirebaseAdminApp.emulator the calls go to the Auth emulator: requests carry Authorization: Bearer owner, custom tokens are unsigned and verifyIdToken accepts the emulator's unsigned ID tokens. Nothing else turns that on.

Constructors

FirebaseAuthAdmin(FirebaseAdminApp app)
The auth admin calls of app: the same object for the same app.
factory

Properties

app → FirebaseAdminApp
The app the calls are made for.
final
hashCode → int
The hash code for this object.
no setterinherited
isEmulator → bool
Whether the calls go to the Auth emulator.
no setter
projectId → String
The project the calls are for (the one of app).
no setter
runtimeType → Type
A representation of the runtime type of the object.
no setterinherited

Methods

createCustomToken(String uid, {Map<String, Object?>? claims, String? tenantId}) → Future<String>
Mints a custom token for uid: the client signs in with it (FirebaseUserAuth.signInWithCustomToken), and claims then appear in the user's ID tokens and in request.auth.token of the security rules.
createUser({String? uid, String? email, String? password, bool emailVerified = false, String? displayName, String? photoUrl, String? phoneNumber, bool disabled = false, Map<String, Object?>? customClaims}) → Future<AdminUser>
Creates a user and returns it as stored.
deleteUser(String uid) → Future<void>
Deletes the user uid. Throws user-not-found if there is none.
deleteUsers(Iterable<String> uids) → Future<DeleteUsersResult>
Deletes the users uids, deleteUsersBatchSize per request, even when they are not disabled.
findUserByEmail(String email) → Future<AdminUser?>
The user with the email address email, or null if there is none.
getUser(String uid) → Future<AdminUser>
The user with uid. Throws a FirebaseAuthAdminException user-not-found if there is none.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
revokeRefreshTokens(String uid) → Future<void>
Revokes the refresh tokens of the user uid: the sessions of the user end at their next token refresh.
setCustomUserClaims(String uid, Map<String, Object?>? claims) → Future<void>
Sets the custom claims of the user uid, which replace the previous ones; null or an empty map clears them.
toString() → String
A string representation of this object.
inherited
updateUser(String uid, {String? email, String? password, bool? emailVerified, String? displayName, String? photoUrl, String? phoneNumber, bool? disabled}) → Future<AdminUser>
Changes the given properties of the user uid and returns the user as stored. A null argument leaves the property as it is. Throws user-not-found and the errors of createUser.
verifyIdToken(String idToken, {bool checkRevoked = false, Duration clockSkew = defaultClockSkew}) → Future<VerifiedIdToken>
Verifies the Firebase ID token idToken of a user and returns its claims.

Operators

operator ==(Object other) → bool
The equality operator.
inherited

Static Properties

idTokenCertificatesUri → Uri
Where Google publishes the certificates of the keys that sign ID tokens (the source the Firebase documentation and the Admin SDKs use).
final

Constants

customTokenAudience → const String
The audience of a custom token.
defaultClockSkew → const Duration
The default clock skew verifyIdToken allows: 10 seconds.
deleteUsersBatchSize → const int
The number of uids deleteUsers sends per request: the limit of the backend.
maxClockSkew → const Duration
The largest clock skew verifyIdToken accepts: 5 minutes.
reservedClaims → const Set<String>
Claim names a custom token or the custom claims of a user may not use: the reserved names of the Firebase documentation and of the Node Admin SDK.