Skip to content

Instantly share code, notes, and snippets.

@Odonno
Created June 8, 2020 13:10
Show Gist options
  • Save Odonno/f8eb8e6588b7153f462971d14e9995b3 to your computer and use it in GitHub Desktop.
Save Odonno/f8eb8e6588b7153f462971d14e9995b3 to your computer and use it in GitHub Desktop.
.NET Core Azure Templates - AzureAd
var authSettings = configuration.GetSection("AzureAd").Get<AzureAdOptions>();
services
.AddAuthentication(sharedOptions =>
{
sharedOptions.DefaultScheme = JwtBearerDefaults.AuthenticationScheme;
})
.AddJwtBearer(options =>
{
options.Audience = authSettings.ClientId;
options.Authority = authSettings.Authority;
options.Events = new JwtBearerEvents
{
OnMessageReceived = context =>
{
if (context.Request.Path.StartsWithSegments("/hub"))
{
string? accessToken = context.Request.Query["access_token"];
if (!string.IsNullOrEmpty(accessToken))
{
context.Token = accessToken;
}
}
return Task.CompletedTask;
}
};
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment