Skip to content

Instantly share code, notes, and snippets.

@yuv4ik
Created March 3, 2018 00:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yuv4ik/ae05f52bb089a28f1d14bc91f7b27dfa to your computer and use it in GitHub Desktop.
Save yuv4ik/ae05f52bb089a28f1d14bc91f7b27dfa to your computer and use it in GitHub Desktop.
.NET Standard 2.0 WEB.Api Firebase bearer token validation
public class Startup
{
public Startup(IConfiguration configuration)
{
Configuration = configuration;
}
public IConfiguration Configuration { get; }
// This method gets called by the runtime. Use this method to add services to the container.
public void ConfigureServices(IServiceCollection services)
{
var firebaseProjectId = "xxxxxx";
services
.AddAuthentication(JwtBearerDefaults.AuthenticationScheme)
.AddJwtBearer(options =>
{
options.Authority = $"https://securetoken.google.com/{firebaseProjectId}";
options.TokenValidationParameters = new TokenValidationParameters
{
ValidateIssuer = true,
ValidIssuer = $"https://securetoken.google.com/{firebaseProjectId}",
ValidateAudience = true,
ValidAudience = firebaseProjectId,
ValidateLifetime = true
};
});
services.AddMvc();
}
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
app.UseAuthentication();
app.UseMvc();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment