Last active
March 19, 2019 13:08
-
-
Save arielmoraes/bbff8268dd57d9ff53f1b54780e88f3c to your computer and use it in GitHub Desktop.
Jwt Document Retriever
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 authConfig = configuration.GetSection("AuthConfiguration").Get<AuthConfiguration>(); | |
var metadataAddress = authConfig.Authority; | |
if (!metadataAddress.EndsWith("/", StringComparison.Ordinal)) | |
{ | |
metadataAddress += "/"; | |
} | |
metadataAddress += ".well-known/openid-configuration"; | |
var httpClientRetriever = new HttpClient() { Timeout = TimeSpan.FromMinutes(1) }; | |
var configurationRetriever = new OpenIdConnectConfigurationRetriever(); | |
var httpRetriever = new HttpDocumentRetriever(httpClientRetriever) { RequireHttps = false }; | |
var configManager = new ConfigurationManager<OpenIdConnectConfiguration>(metadataAddress, configurationRetriever, httpRetriever); | |
services.AddSingleton<IConfigurationManager<OpenIdConnectConfiguration>>((provider) => configManager); | |
JwtSecurityTokenHandler.DefaultInboundClaimTypeMap.Clear(); | |
services.AddAuthentication(authOptions => | |
{ | |
authOptions.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme; | |
authOptions.DefaultChallengeScheme = JwtBearerDefaults.AuthenticationScheme; | |
}).AddJwtBearer(bearerOptions => | |
{ | |
bearerOptions.Authority = authConfig.Authority; | |
bearerOptions.Audience = authConfig.Audience; | |
bearerOptions.ConfigurationManager = configManager; | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment