Using Firebase Authentication JWT Tokens in ASP.NET Core (.NET 5)

Enabling your secured AspNetCore Web API to accept Firebase tokens is quite simple actually. All you have to do is register the JWTBearer and add the firebase issuer information, detailed steps are below.

This tutorial assumes that you already have an AspNetCore API and a corresponding Frontend that uses Firebase for authentication.

services
.AddAuthentication(JwtBearerDefaults.AuthenticationScheme)
.AddJwtBearer(options =>
{
options.Authority = "https://securetoken.google.com/FIREBASE-APP-ID";
options.TokenValidationParameters = new TokenValidationParameters
{
ValidateIssuer = true,
ValidIssuer = "https://securetoken.google.com/FIREBASE-APP-ID",
ValidateAudience = true,
ValidAudience = "FIREBASE-APP-ID",
ValidateLifetime = true
};
});

Enable Authorization & Authentication in Startup.cs

app.UseAuthentication();
app.UseAuthorization();

3 Add the [Authorize] Annotation to your endpoints.

The above example also shows you how you can get the user UUID from the token by using token Claims.

And that’s all there is to it. You’ve now successfully secured your AspNetCore Web API with Firebase.

Thanks for reading.

Short Coding Tutorials for .NET & NodeJS

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store