Firebase Authentication
Integrate Firebase Authentication with your Xams application for secure user management.
Xams provides built-in Firebase authentication support with a customizable login page and comprehensive auth flows including multi-factor authentication (MFA).
The fastest way to get started is to use the Xams Firebase template which includes a complete example with React frontend.

Install Required Packages
Install the FirebaseAdmin SDK and Xams.Firebase NuGet packages.
Download Service Account Key
Generate and configure your Firebase service account private key:
- Navigate to your Firebase project in the Firebase console
- Open Project settings
- Select the Service accounts tab
- Click Generate new private key in the Firebase Admin SDK section
- Confirm to download the JSON key file
- Add the JSON file to your project (e.g., in a
keys
folder) - Configure the file to copy to output directory in your project settings
Configure User Entity
Add the required Firebase fields to your User entity:
Project / Entities / AppUser.cs
Register AppUser in your DbContext:
Project / DataContext.cs
Configure Authentication
Add Firebase authentication to Program.cs:
Project / Program.cs
Configure API Endpoints
Configure the Xams API with Firebase support in Program.cs:
Project / Program.cs
User Authentication Helper
Create a UserUtil class to handle user authentication, automatically creating Xams users from Firebase claims:
Project / UserUtil.cs
Firebase Configuration
Add your Firebase configuration to appsettings.json:
Google Provider
To configure Google as an authentication provider and enable custom domain redirects:
-
Go to Google Cloud Console
- Open the Google Cloud Console and select your project linked to your Firebase app.
-
Navigate to OAuth 2.0 Credentials
- In the left sidebar, click on "APIs & Services," then choose "Credentials."
- Under "OAuth 2.0 Client IDs," find the web client associated with your Firebase project and click the pencil/edit icon.
-
Add Your Redirect URL (Required for Custom Domains)
- The default redirect URL for Firebase Authentication will look like:
- For custom domains (required when using Google authentication with your own domain), add your Xams ASP.NET project URL:
The
/__/auth/handler
endpoint is automatically provided by the Xams framework when you configure Firebase authentication withapp.AddFirebaseAuthProxy()
. This implements Option 3 from Firebase's redirect best practices - proxying the auth handler through your application backend. This configuration is essential for Google OAuth to properly redirect users back to your custom domain after authentication. - For local development, use:
- Replace
YOUR_PROJECT_ID
with your Firebase project ID,YOUR_CUSTOM_DOMAIN
with your production domain hosting the Xams API, andPORT
with your local development port.
- The default redirect URL for Firebase Authentication will look like:
-
Add the Redirect URL to Authorized Redirect URIs
- In the OAuth client settings, scroll to the "Authorized redirect URIs" section.
- Click "Add URI" and paste in your Firebase project's handler URL(s).
- Add both your production and localhost URLs for development convenience.
-
Save Changes
- After adding your URLs, click "Save" at the bottom of the OAuth client configuration page.
-
Use Your Redirect URL in Code (Optional)
- In most setups, Firebase Authentication manages the redirect internally, so you don't need to specify it in your frontend code.
- If you are configuring the
authDomain
in your Firebase initialization, match it to your custom domain if used.
Test Your Configuration
Navigate to the admin dashboard to verify Firebase authentication is working:
Example: https://localhost:8000/x
You should see the Firebase login page with your configured authentication providers.
React Setup
Install the required npm packages:
Configure your React application environment variables:
In your _app.tsx
file, import the Firebase styles and wrap your application with the XamsFirebaseAuthProvider
. The auth-recaptcha
div element is required for phone authentication functionality.
Create the authentication pages for login, user profile management, password reset, and Firebase action handling:
src/pages/login.tsx
src/pages/profile.tsx
src/pages/reset-password.tsx
src/pages/__/auth/action.tsx
Configure the Firebase email template action URL to redirect to your Xams application:
- Navigate to Authentication → Templates in the Firebase console
- Select an email template and click Edit Template
- Click Customize action URL
- Set the URL to your application's action handler (e.g.,
https://localhost:3000/__/auth/action
)
This URL handles email verification, password reset, and other Firebase authentication actions.