Created
June 8, 2020 13:10
-
-
Save Odonno/f8eb8e6588b7153f462971d14e9995b3 to your computer and use it in GitHub Desktop.
.NET Core Azure Templates - AzureAd
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
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