Showing a custom domain during sign in

This document shows you how to customize the Identity Platform authentication handler so users see your domain when signing in.

Understanding the default authentication handler

When you enable Identity Platform for your project, a unique subdomain powered by Firebase Hosting is created automatically. The domain takes the form of https://[PROJECT-ID].firebaseapp.com. By default, Identity Platform uses this domain to handle all OAuth, OIDC, and SAML sign-in redirects.

Using the default domain has several benefits:

  • Easier setup

  • Use multiple domains with the same federated providers

  • Share a single callback URL across different services and domains

  • Works with providers that only support one callback URL per app

The downside of the default handler is users will briefly see the https://[PROJECT-ID].firebaseapp.com URL when signing in.

Customizing the authentication handler

To override the default handler and provide your own:

  1. Connect your project to a custom domain. You'll need to complete these steps using the Firebase Console; using the Google Cloud CLI or the Google Cloud console is not supported.

  2. Go to the Identity Providers page in the Google Cloud console, and select your SAML provider. Go to the Identity Providers page

  3. Add the custom domain to the list of Authorized Domains.

  4. Update the Callback URL with your identity provider to use your custom domain instead of the default domain. For example, change https://myproject.firebaseapp.com/__/auth/handler to https://auth.mycustomdomain.com/__/auth/handler.

  5. Click Save.

Updating your client SDK configuration

Web

Normally, you can copy the initialization code for the client SDK from the Google Cloud console. If you customize the authentication handler, you'll need to update the authDomain field to your custom domain:

Web version 9

import { initializeApp } from "firebase/app";

const firebaseConfig = {
  apiKey: "...",
  // By default, authDomain is '[YOUR_APP].firebaseapp.com'.
  // You may replace it with a custom domain.
  authDomain: '[YOUR_CUSTOM_DOMAIN]'
};
const firebaseApp = initializeApp(firebaseConfig);

Web version 8

firebase.initializeApp({
  apiKey: '...',
  // By default, authDomain is '[YOUR_APP].firebaseapp.com'.
  // You may replace it with a custom domain.
  authDomain: '[YOUR_CUSTOM_DOMAIN]'
});

Android and iOS

To customize the authentication handler, use the following code:

Java

FirebaseAuth.getInstance().setCustomAuthDomain("[YOUR_CUSTOM_DOMAIN]");

Kotlin+KTX

Firebase.auth.setCustomAuthDomain("[YOUR_CUSTOM_DOMAIN]")

Swift

let auth = Auth.auth()
auth.customAuthDomain = "[YOUR_CUSTOM_DOMAIN]"

Objective-C

FIRAuth *auth = [FIRAuth auth];
auth.customAuthDomain("[YOUR_CUSTOM_DOMAIN]");