From a135960d15a9f5b03d13cf4621f6933bc17893b4 Mon Sep 17 00:00:00 2001 From: Hans van Bakel Date: Fri, 19 Oct 2018 11:38:32 -0700 Subject: [PATCH] Expose configuration to deriving types --- .../OpenIdConnectHandler.cs | 34 +++++++++---------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/src/Microsoft.AspNetCore.Authentication.OpenIdConnect/OpenIdConnectHandler.cs b/src/Microsoft.AspNetCore.Authentication.OpenIdConnect/OpenIdConnectHandler.cs index 029cf541b..69e65ede9 100644 --- a/src/Microsoft.AspNetCore.Authentication.OpenIdConnect/OpenIdConnectHandler.cs +++ b/src/Microsoft.AspNetCore.Authentication.OpenIdConnect/OpenIdConnectHandler.cs @@ -34,7 +34,7 @@ public class OpenIdConnectHandler : RemoteAuthenticationHandler Options.Backchannel; @@ -166,15 +166,15 @@ public async virtual Task SignOutAsync(AuthenticationProperties properties) Logger.EnteringOpenIdAuthenticationHandlerHandleSignOutAsync(GetType().FullName); - if (_configuration == null && Options.ConfigurationManager != null) + if (Configuration == null && Options.ConfigurationManager != null) { - _configuration = await Options.ConfigurationManager.GetConfigurationAsync(Context.RequestAborted); + Configuration = await Options.ConfigurationManager.GetConfigurationAsync(Context.RequestAborted); } var message = new OpenIdConnectMessage() { EnableTelemetryParameters = !Options.DisableTelemetry, - IssuerAddress = _configuration?.EndSessionEndpoint ?? string.Empty, + IssuerAddress = Configuration?.EndSessionEndpoint ?? string.Empty, // Redirect back to SigneOutCallbackPath first before user agent is redirected to actual post logout redirect uri PostLogoutRedirectUri = BuildRedirectUriIfRelative(Options.SignedOutCallbackPath) @@ -316,16 +316,16 @@ protected override async Task HandleChallengeAsync(AuthenticationProperties prop } Logger.PostAuthenticationLocalRedirect(properties.RedirectUri); - if (_configuration == null && Options.ConfigurationManager != null) + if (Configuration == null && Options.ConfigurationManager != null) { - _configuration = await Options.ConfigurationManager.GetConfigurationAsync(Context.RequestAborted); + Configuration = await Options.ConfigurationManager.GetConfigurationAsync(Context.RequestAborted); } var message = new OpenIdConnectMessage { ClientId = Options.ClientId, EnableTelemetryParameters = !Options.DisableTelemetry, - IssuerAddress = _configuration?.AuthorizationEndpoint ?? string.Empty, + IssuerAddress = Configuration?.AuthorizationEndpoint ?? string.Empty, RedirectUri = BuildRedirectUri(Options.CallbackPath), Resource = Options.Resource, ResponseType = Options.ResponseType, @@ -523,10 +523,10 @@ protected override async Task HandleRemoteAuthenticateAsync return HandleRequestResult.Fail(CreateOpenIdConnectProtocolException(authorizationResponse, response: null), properties); } - if (_configuration == null && Options.ConfigurationManager != null) + if (Configuration == null && Options.ConfigurationManager != null) { Logger.UpdatingConfiguration(); - _configuration = await Options.ConfigurationManager.GetConfigurationAsync(Context.RequestAborted); + Configuration = await Options.ConfigurationManager.GetConfigurationAsync(Context.RequestAborted); } PopulateSessionProperties(authorizationResponse, properties); @@ -722,9 +722,9 @@ private void PopulateSessionProperties(OpenIdConnectMessage message, Authenticat properties.Items[OpenIdConnectSessionProperties.SessionState] = message.SessionState; } - if (!string.IsNullOrEmpty(_configuration.CheckSessionIframe)) + if (!string.IsNullOrEmpty(Configuration.CheckSessionIframe)) { - properties.Items[OpenIdConnectSessionProperties.CheckSessionIFrame] = _configuration.CheckSessionIframe; + properties.Items[OpenIdConnectSessionProperties.CheckSessionIFrame] = Configuration.CheckSessionIframe; } } @@ -737,7 +737,7 @@ protected virtual async Task RedeemAuthorizationCodeAsync( { Logger.RedeemingCodeForTokens(); - var requestMessage = new HttpRequestMessage(HttpMethod.Post, _configuration.TokenEndpoint); + var requestMessage = new HttpRequestMessage(HttpMethod.Post, Configuration.TokenEndpoint); requestMessage.Content = new FormUrlEncodedContent(tokenEndpointRequest.Parameters); var responseMessage = await Backchannel.SendAsync(requestMessage); @@ -787,7 +787,7 @@ protected virtual async Task GetUserInformationAsync( OpenIdConnectMessage message, JwtSecurityToken jwt, ClaimsPrincipal principal, AuthenticationProperties properties) { - var userInfoEndpoint = _configuration?.UserInfoEndpoint; + var userInfoEndpoint = Configuration?.UserInfoEndpoint; if (string.IsNullOrEmpty(userInfoEndpoint)) { @@ -1156,13 +1156,13 @@ private ClaimsPrincipal ValidateToken(string idToken, AuthenticationProperties p throw new SecurityTokenException(string.Format(CultureInfo.InvariantCulture, Resources.UnableToValidateToken, idToken)); } - if (_configuration != null) + if (Configuration != null) { - var issuer = new[] { _configuration.Issuer }; + var issuer = new[] { Configuration.Issuer }; validationParameters.ValidIssuers = validationParameters.ValidIssuers?.Concat(issuer) ?? issuer; - validationParameters.IssuerSigningKeys = validationParameters.IssuerSigningKeys?.Concat(_configuration.SigningKeys) - ?? _configuration.SigningKeys; + validationParameters.IssuerSigningKeys = validationParameters.IssuerSigningKeys?.Concat(Configuration.SigningKeys) + ?? Configuration.SigningKeys; } var principal = Options.SecurityTokenValidator.ValidateToken(idToken, validationParameters, out SecurityToken validatedToken);