@@ -18,7 +18,7 @@ namespace AspNet.Security.OAuth.<%= name %>;
18
18
/// <summary>
19
19
/// Defines a handler for authentication using <%= name %>.
20
20
/// </summary>
21
- public class < %= name % > AuthenticationHandler : OAuthHandler < < %= name % > AuthenticationOptions>
21
+ public partial class < %= name % > AuthenticationHandler : OAuthHandler < < %= name % > AuthenticationOptions>
22
22
{
23
23
/// <summary>
24
24
/// Initializes a new instance of the <see cref="<%= name %>AuthenticationHandler"/> class.
@@ -56,12 +56,7 @@ protected override async Task<AuthenticationTicket> CreateTicketAsync(
56
56
using var response = await Backchannel . SendAsync ( request , HttpCompletionOption . ResponseHeadersRead , Context . RequestAborted ) ;
57
57
if ( ! response . IsSuccessStatusCode )
58
58
{
59
- Logger . LogError ( "An error occurred while retrieving the user profile: the remote server " +
60
- "returned a {Status} response with the following payload: {Headers} {Body}." ,
61
- /* Status: */ response . StatusCode ,
62
- /* Headers: */ response . Headers . ToString ( ) ,
63
- /* Body: */ await response . Content . ReadAsStringAsync ( ) ) ;
64
-
59
+ await Log . UserProfileErrorAsync ( Logger , response , Context . RequestAborted ) ;
65
60
throw new HttpRequestException ( "An error occurred while retrieving the user profile from <%= name %>." ) ;
66
61
}
67
62
@@ -74,4 +69,23 @@ protected override async Task<AuthenticationTicket> CreateTicketAsync(
74
69
await Events . CreatingTicket ( context ) ;
75
70
return new AuthenticationTicket ( context . Principal ! , context . Properties , Scheme . Name ) ;
76
71
}
72
+
73
+ private static partial class Log
74
+ {
75
+ internal static async Task UserProfileErrorAsync ( ILogger logger , HttpResponseMessage response , CancellationToken cancellationToken )
76
+ {
77
+ UserProfileError (
78
+ logger ,
79
+ response . StatusCode ,
80
+ response . Headers . ToString ( ) ,
81
+ await response . Content . ReadAsStringAsync ( cancellationToken ) ) ;
82
+ }
83
+
84
+ [ LoggerMessage ( 1 , LogLevel . Error , "An error occurred while retrieving the user profile: the remote server returned a {Status} response with the following payload: {Headers} {Body}." ) ]
85
+ private static partial void UserProfileError (
86
+ ILogger logger ,
87
+ System . Net . HttpStatusCode status ,
88
+ string headers ,
89
+ string body ) ;
90
+ }
77
91
}
0 commit comments