@@ -78,22 +78,12 @@ internal class TokenValidationHandler : DelegatingHandler
7878 //
7979 protected async override Task < HttpResponseMessage > SendAsync ( HttpRequestMessage request , CancellationToken cancellationToken )
8080 {
81- string authHeader = null ;
81+ // Get the jwt bearer token from the authorization header
8282 string jwtToken = null ;
83- string issuer ;
84- string stsDiscoveryEndpoint = string . Format ( "{0}/.well-known/openid-configuration" , authority ) ;
85-
86- List < SecurityToken > signingTokens ;
87-
88- // The header is of the form "bearer <accesstoken>", so extract to the right of the whitespace to find the access token.
89- authHeader = HttpContext . Current . Request . Headers [ "Authorization" ] ;
83+ AuthenticationHeaderValue authHeader = request . Headers . Authorization ;
9084 if ( authHeader != null )
9185 {
92- int startIndex = authHeader . LastIndexOf ( ' ' ) ;
93- if ( startIndex > 0 )
94- {
95- jwtToken = authHeader . Substring ( startIndex ) . Trim ( ) ;
96- }
86+ jwtToken = authHeader . Parameter ;
9787 }
9888
9989 if ( jwtToken == null )
@@ -102,6 +92,9 @@ protected async override Task<HttpResponseMessage> SendAsync(HttpRequestMessage
10292 return response ;
10393 }
10494
95+ string issuer ;
96+ List < SecurityToken > signingTokens ;
97+
10598 try
10699 {
107100 // The issuer and signingTokens are cached for 24 hours. They are updated if any of the conditions in the if condition is true.
@@ -110,6 +103,7 @@ protected async override Task<HttpResponseMessage> SendAsync(HttpRequestMessage
110103 || _signingTokens == null )
111104 {
112105 // Get tenant information that's used to validate incoming jwt tokens
106+ string stsDiscoveryEndpoint = string . Format ( "{0}/.well-known/openid-configuration" , authority ) ;
113107 ConfigurationManager < OpenIdConnectConfiguration > configManager = new ConfigurationManager < OpenIdConnectConfiguration > ( stsDiscoveryEndpoint ) ;
114108 OpenIdConnectConfiguration config = await configManager . GetConfigurationAsync ( ) ;
115109 _issuer = config . Issuer ;
0 commit comments