@@ -36,6 +36,13 @@ protected override async Task<AuthenticationTicket> CreateTicketAsync([NotNull]
36
36
request . Headers . Accept . Add ( new MediaTypeWithQualityHeaderValue ( "application/json" ) ) ;
37
37
request . Headers . Authorization = new AuthenticationHeaderValue ( "bearer" , tokens . AccessToken ) ;
38
38
39
+ // When a custom user agent is specified in the options, add it to the request headers
40
+ // to override the default (generic) user agent used by the OAuth2 base middleware.
41
+ if ( ! string . IsNullOrEmpty ( Options . UserAgent ) )
42
+ {
43
+ request . Headers . UserAgent . ParseAdd ( Options . UserAgent ) ;
44
+ }
45
+
39
46
var response = await Backchannel . SendAsync ( request , HttpCompletionOption . ResponseHeadersRead , Context . RequestAborted ) ;
40
47
if ( ! response . IsSuccessStatusCode )
41
48
{
@@ -68,7 +75,7 @@ protected override string BuildChallengeUrl(AuthenticationProperties properties,
68
75
var address = base . BuildChallengeUrl ( properties , redirectUri ) ;
69
76
70
77
// Add duration=permanent to the authorization request to get an access token that doesn't expire after 1 hour.
71
- // See https://github.com/reddit/reddit/wiki/OAuth2#authorization.
78
+ // See https://github.com/reddit/reddit/wiki/OAuth2#authorization for more information .
72
79
return QueryHelpers . AddQueryString ( address , name : "duration" , value : "permanent" ) ;
73
80
}
74
81
@@ -88,6 +95,13 @@ protected override async Task<OAuthTokenResponse> ExchangeCodeAsync([NotNull] st
88
95
request . Headers . Accept . Add ( new MediaTypeWithQualityHeaderValue ( "application/json" ) ) ;
89
96
request . Headers . Authorization = new AuthenticationHeaderValue ( "Basic" , credentials ) ;
90
97
98
+ // When a custom user agent is specified in the options, add it to the request headers
99
+ // to override the default (generic) user agent used by the OAuth2 base middleware.
100
+ if ( ! string . IsNullOrEmpty ( Options . UserAgent ) )
101
+ {
102
+ request . Headers . UserAgent . ParseAdd ( Options . UserAgent ) ;
103
+ }
104
+
91
105
request . Content = new FormUrlEncodedContent ( new Dictionary < string , string >
92
106
{
93
107
[ "grant_type" ] = "authorization_code" ,
0 commit comments