createSessionCookie method

  1. @override
Future<String> createSessionCookie(
  1. String idToken,
  2. SessionCookieOptions sessionCookieOptions
)

Creates a new Firebase session cookie with the specified options that can be used for session management (set as a server side session cookie with custom cookie policy). The session cookie JWT will have the same payload claims as the provided ID token.

idToken - The Firebase ID token to exchange for a session cookie. sessionCookieOptions - The session cookie options which includes custom expiration in milliseconds. The minimum allowed is 5 minutes and the maxium allowed is 2 weeks.

Returns a Future that resolves with the created session cookie.

Implementation

@override
Future<String> createSessionCookie(
  String idToken,
  SessionCookieOptions sessionCookieOptions,
) async {
  // Validate idToken is not empty before verification.
  if (idToken.isEmpty) {
    throw FirebaseAuthAdminException(AuthClientErrorCode.invalidIdToken);
  }

  // Verify the ID token and check tenant ID before creating session cookie.
  await verifyIdToken(idToken);

  return super.createSessionCookie(idToken, sessionCookieOptions);
}