Created
March 3, 2018 00:09
-
-
Save yuv4ik/ae05f52bb089a28f1d14bc91f7b27dfa to your computer and use it in GitHub Desktop.
.NET Standard 2.0 WEB.Api Firebase bearer token validation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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