@@ -36,7 +36,7 @@ protected override async Task<AuthenticationTicket> AuthenticateCoreAsync()
3636 // indicate that authentication was rejected by application code.
3737 if ( context . Ticket == null )
3838 {
39- Options . Logger . LogInformation ( "Authentication was stopped by application code." ) ;
39+ Logger . LogInformation ( "Authentication was stopped by application code." ) ;
4040
4141 return null ;
4242 }
@@ -46,7 +46,7 @@ protected override async Task<AuthenticationTicket> AuthenticateCoreAsync()
4646
4747 else if ( context . Skipped )
4848 {
49- Options . Logger . LogInformation ( "Authentication was skipped by application code." ) ;
49+ Logger . LogInformation ( "Authentication was skipped by application code." ) ;
5050
5151 return null ;
5252 }
@@ -59,7 +59,7 @@ protected override async Task<AuthenticationTicket> AuthenticateCoreAsync()
5959 var header = Request . Headers [ OAuthIntrospectionConstants . Headers . Authorization ] ;
6060 if ( string . IsNullOrEmpty ( header ) )
6161 {
62- Options . Logger . LogDebug ( "Authentication was skipped because no bearer token was received." ) ;
62+ Logger . LogDebug ( "Authentication was skipped because no bearer token was received." ) ;
6363
6464 return null ;
6565 }
@@ -68,8 +68,8 @@ protected override async Task<AuthenticationTicket> AuthenticateCoreAsync()
6868 // See https://tools.ietf.org/html/rfc6750#section-2.1
6969 if ( ! header . StartsWith ( OAuthIntrospectionConstants . Schemes . Bearer + ' ' , StringComparison . OrdinalIgnoreCase ) )
7070 {
71- Options . Logger . LogDebug ( "Authentication was skipped because an incompatible " +
72- "scheme was used in the 'Authorization' header." ) ;
71+ Logger . LogDebug ( "Authentication was skipped because an incompatible " +
72+ "scheme was used in the 'Authorization' header." ) ;
7373
7474 return null ;
7575 }
@@ -79,8 +79,8 @@ protected override async Task<AuthenticationTicket> AuthenticateCoreAsync()
7979
8080 if ( string . IsNullOrEmpty ( token ) )
8181 {
82- Options . Logger . LogDebug ( "Authentication was skipped because the bearer token " +
83- "was missing from the 'Authorization' header." ) ;
82+ Logger . LogDebug ( "Authentication was skipped because the bearer token " +
83+ "was missing from the 'Authorization' header." ) ;
8484
8585 return null ;
8686 }
@@ -96,8 +96,8 @@ protected override async Task<AuthenticationTicket> AuthenticateCoreAsync()
9696 var payload = await GetIntrospectionPayloadAsync ( token ) ;
9797 if ( payload == null || ! payload . Value < bool > ( OAuthIntrospectionConstants . Claims . Active ) )
9898 {
99- Options . Logger . LogError ( "Authentication failed because the authorization " +
100- "server rejected the access token." ) ;
99+ Logger . LogError ( "Authentication failed because the authorization " +
100+ "server rejected the access token." ) ;
101101
102102 Context . Set ( typeof ( OAuthIntrospectionError ) . FullName , new OAuthIntrospectionError
103103 {
@@ -120,7 +120,7 @@ protected override async Task<AuthenticationTicket> AuthenticateCoreAsync()
120120 if ( ticket . Properties . ExpiresUtc . HasValue &&
121121 ticket . Properties . ExpiresUtc . Value < Options . SystemClock . UtcNow )
122122 {
123- Options . Logger . LogError ( "Authentication failed because the access token was expired." ) ;
123+ Logger . LogError ( "Authentication failed because the access token was expired." ) ;
124124
125125 Context . Set ( typeof ( OAuthIntrospectionError ) . FullName , new OAuthIntrospectionError
126126 {
@@ -135,8 +135,8 @@ protected override async Task<AuthenticationTicket> AuthenticateCoreAsync()
135135 // to be used with this resource server.
136136 if ( ! ValidateAudience ( ticket ) )
137137 {
138- Options . Logger . LogError ( "Authentication failed because the access token " +
139- "was not valid for this resource server." ) ;
138+ Logger . LogError ( "Authentication failed because the access token " +
139+ "was not valid for this resource server." ) ;
140140
141141 Context . Set ( typeof ( OAuthIntrospectionError ) . FullName , new OAuthIntrospectionError
142142 {
@@ -156,7 +156,7 @@ protected override async Task<AuthenticationTicket> AuthenticateCoreAsync()
156156 // indicate that authentication was rejected by application code.
157157 if ( notification . Ticket == null )
158158 {
159- Options . Logger . LogInformation ( "Authentication was stopped by application code." ) ;
159+ Logger . LogInformation ( "Authentication was stopped by application code." ) ;
160160
161161 return null ;
162162 }
@@ -166,7 +166,7 @@ protected override async Task<AuthenticationTicket> AuthenticateCoreAsync()
166166
167167 else if ( notification . Skipped )
168168 {
169- Options . Logger . LogInformation ( "Authentication was skipped by application code." ) ;
169+ Logger . LogInformation ( "Authentication was skipped by application code." ) ;
170170
171171 return null ;
172172 }
@@ -405,11 +405,11 @@ protected virtual async Task<JObject> GetIntrospectionPayloadAsync(string token)
405405 var response = await Options . HttpClient . SendAsync ( request , HttpCompletionOption . ResponseHeadersRead , Request . CallCancelled ) ;
406406 if ( ! response . IsSuccessStatusCode )
407407 {
408- Options . Logger . LogError ( "An error occurred while validating an access token: the remote server " +
409- "returned a {Status} response with the following payload: {Headers} {Body}." ,
410- /* Status: */ response . StatusCode ,
411- /* Headers: */ response . Headers . ToString ( ) ,
412- /* Body: */ await response . Content . ReadAsStringAsync ( ) ) ;
408+ Logger . LogError ( "An error occurred while validating an access token: the remote server " +
409+ "returned a {Status} response with the following payload: {Headers} {Body}." ,
410+ /* Status: */ response . StatusCode ,
411+ /* Headers: */ response . Headers . ToString ( ) ,
412+ /* Body: */ await response . Content . ReadAsStringAsync ( ) ) ;
413413
414414 return null ;
415415 }
@@ -425,7 +425,7 @@ protected virtual async Task<JObject> GetIntrospectionPayloadAsync(string token)
425425 {
426426 var payload = JObject . Load ( reader ) ;
427427
428- Options . Logger . LogInformation ( "The introspection response was successfully extracted: {Response}." , payload ) ;
428+ Logger . LogInformation ( "The introspection response was successfully extracted: {Response}." , payload ) ;
429429
430430 return payload ;
431431 }
@@ -437,8 +437,8 @@ exception is InvalidCastException ||
437437 exception is JsonReaderException ||
438438 exception is JsonSerializationException )
439439 {
440- Options . Logger . LogError ( "An error occurred while deserializing the " +
441- "introspection response: {Exception}." , exception ) ;
440+ Logger . LogError ( "An error occurred while deserializing the " +
441+ "introspection response: {Exception}." , exception ) ;
442442
443443 return null ;
444444 }
@@ -489,7 +489,7 @@ protected virtual async Task<AuthenticationTicket> CreateTicketAsync(string toke
489489 // Always exclude null values, as they can't be represented as valid claims.
490490 if ( property . Value . Type == JTokenType . None || property . Value . Type == JTokenType . Null )
491491 {
492- Options . Logger . LogInformation ( "The '{Claim}' claim was excluded because it was null." , property . Name ) ;
492+ Logger . LogInformation ( "The '{Claim}' claim was excluded because it was null." , property . Name ) ;
493493
494494 continue ;
495495 }
@@ -511,7 +511,7 @@ protected virtual async Task<AuthenticationTicket> CreateTicketAsync(string toke
511511 // and https://tools.ietf.org/html/rfc7519#section-4.1.6 for more information.
512512 if ( property . Value . Type != JTokenType . Float && property . Value . Type != JTokenType . Integer )
513513 {
514- Options . Logger . LogWarning ( "The 'iat' claim was ignored because it was not a decimal value." ) ;
514+ Logger . LogWarning ( "The 'iat' claim was ignored because it was not a decimal value." ) ;
515515
516516 continue ;
517517 }
@@ -529,7 +529,7 @@ protected virtual async Task<AuthenticationTicket> CreateTicketAsync(string toke
529529 // and https://tools.ietf.org/html/rfc7519#section-4.1.4 for more information.
530530 if ( property . Value . Type != JTokenType . Float && property . Value . Type != JTokenType . Integer )
531531 {
532- Options . Logger . LogWarning ( "The 'exp' claim was ignored because it was not a decimal value." ) ;
532+ Logger . LogWarning ( "The 'exp' claim was ignored because it was not a decimal value." ) ;
533533
534534 continue ;
535535 }
@@ -547,7 +547,7 @@ protected virtual async Task<AuthenticationTicket> CreateTicketAsync(string toke
547547 // and https://tools.ietf.org/html/rfc7519#section-4.1.7 for more information.
548548 if ( property . Value . Type != JTokenType . String )
549549 {
550- Options . Logger . LogWarning ( "The 'jti' claim was ignored because it was not a string value." ) ;
550+ Logger . LogWarning ( "The 'jti' claim was ignored because it was not a string value." ) ;
551551
552552 continue ;
553553 }
@@ -564,7 +564,7 @@ protected virtual async Task<AuthenticationTicket> CreateTicketAsync(string toke
564564 // and https://tools.ietf.org/html/rfc7519#section-4.1.7 for more information.
565565 if ( property . Value . Type != JTokenType . String )
566566 {
567- Options . Logger . LogWarning ( "The 'scope' claim was ignored because it was not a string value." ) ;
567+ Logger . LogWarning ( "The 'scope' claim was ignored because it was not a string value." ) ;
568568
569569 continue ;
570570 }
@@ -608,7 +608,7 @@ protected virtual async Task<AuthenticationTicket> CreateTicketAsync(string toke
608608 var audiences = ( JArray ) property . Value ;
609609 if ( audiences . Any ( audience => audience . Type != JTokenType . String ) )
610610 {
611- Options . Logger . LogWarning ( "The 'aud' claim was ignored because it was not an array of strings." ) ;
611+ Logger . LogWarning ( "The 'aud' claim was ignored because it was not an array of strings." ) ;
612612
613613 continue ;
614614 }
@@ -619,7 +619,7 @@ protected virtual async Task<AuthenticationTicket> CreateTicketAsync(string toke
619619 continue ;
620620 }
621621
622- Options . Logger . LogWarning ( "The 'aud' claim was ignored because it was not a string nor an array." ) ;
622+ Logger . LogWarning ( "The 'aud' claim was ignored because it was not a string nor an array." ) ;
623623
624624 continue ;
625625 }
@@ -751,5 +751,7 @@ protected virtual async Task<AuthenticationTicket> RetrieveTicketAsync(string to
751751
752752 return Options . AccessTokenFormat . Unprotect ( Encoding . UTF8 . GetString ( bytes ) ) ;
753753 }
754+
755+ public ILogger Logger => Options . Logger ;
754756 }
755757}
0 commit comments