@@ -36,6 +36,13 @@ protected override async Task<AuthenticationTicket> CreateTicketAsync([NotNull]
3636 request . Headers . Accept . Add ( new MediaTypeWithQualityHeaderValue ( "application/json" ) ) ;
3737 request . Headers . Authorization = new AuthenticationHeaderValue ( "bearer" , tokens . AccessToken ) ;
3838
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+
3946 var response = await Backchannel . SendAsync ( request , HttpCompletionOption . ResponseHeadersRead , Context . RequestAborted ) ;
4047 if ( ! response . IsSuccessStatusCode )
4148 {
@@ -68,7 +75,7 @@ protected override string BuildChallengeUrl(AuthenticationProperties properties,
6875 var address = base . BuildChallengeUrl ( properties , redirectUri ) ;
6976
7077 // 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 .
7279 return QueryHelpers . AddQueryString ( address , name : "duration" , value : "permanent" ) ;
7380 }
7481
@@ -88,6 +95,13 @@ protected override async Task<OAuthTokenResponse> ExchangeCodeAsync([NotNull] st
8895 request . Headers . Accept . Add ( new MediaTypeWithQualityHeaderValue ( "application/json" ) ) ;
8996 request . Headers . Authorization = new AuthenticationHeaderValue ( "Basic" , credentials ) ;
9097
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+
91105 request . Content = new FormUrlEncodedContent ( new Dictionary < string , string >
92106 {
93107 [ "grant_type" ] = "authorization_code" ,
0 commit comments