@@ -46,14 +46,14 @@ public class OAuth2ClientBuilder
46
46
/// Discovery endpoint subpath for all OpenID Connect issuers.
47
47
/// </summary>
48
48
const string DISCOVERY_ENDPOINT = ".well-known/openid-configuration" ;
49
-
49
+
50
50
private readonly string _clientId ;
51
51
private readonly string _clientSecret ;
52
-
52
+
53
53
// At least one of the following Uris is not null
54
54
private readonly Uri ? _tokenEndpoint ;
55
55
private readonly Uri ? _issuer ;
56
-
56
+
57
57
private string ? _scope ;
58
58
private IDictionary < string , string > ? _additionalRequestParameters ;
59
59
private HttpClientHandler ? _httpClientHandler ;
@@ -72,10 +72,10 @@ public OAuth2ClientBuilder(string clientId, string clientSecret, Uri? tokenEndpo
72
72
{
73
73
_clientId = clientId ?? throw new ArgumentNullException ( nameof ( clientId ) ) ;
74
74
_clientSecret = clientSecret ?? throw new ArgumentNullException ( nameof ( clientSecret ) ) ;
75
-
75
+
76
76
if ( tokenEndpoint is null && issuer is null )
77
77
throw new ArgumentException ( "Either tokenEndpoint or issuer is required" ) ;
78
-
78
+
79
79
_tokenEndpoint = tokenEndpoint ;
80
80
_issuer = issuer ;
81
81
}
@@ -136,7 +136,7 @@ public IOAuth2Client Build()
136
136
Uri tokenEndpoint = GetTokenEndpointFromIssuerAsync ( ) . GetAwaiter ( ) . GetResult ( ) ;
137
137
return new OAuth2Client ( _clientId , _clientSecret , tokenEndpoint , _scope , _additionalRequestParameters , _httpClientHandler ) ;
138
138
}
139
-
139
+
140
140
return new OAuth2Client ( _clientId , _clientSecret , _tokenEndpoint ,
141
141
_scope , _additionalRequestParameters , _httpClientHandler ) ;
142
142
}
@@ -155,7 +155,7 @@ public async ValueTask<IOAuth2Client> BuildAsync(CancellationToken cancellationT
155
155
return new OAuth2Client ( _clientId , _clientSecret , tokenEndpoint ,
156
156
_scope , _additionalRequestParameters , _httpClientHandler ) ;
157
157
}
158
-
158
+
159
159
return new OAuth2Client ( _clientId , _clientSecret , _tokenEndpoint ,
160
160
_scope , _additionalRequestParameters , _httpClientHandler ) ;
161
161
}
@@ -171,18 +171,18 @@ private async Task<Uri> GetTokenEndpointFromIssuerAsync(CancellationToken cancel
171
171
{
172
172
throw new InvalidOperationException ( "The issuer is required" ) ;
173
173
}
174
-
174
+
175
175
using HttpClient httpClient = _httpClientHandler is null
176
- ? new HttpClient ( )
176
+ ? new HttpClient ( )
177
177
: new HttpClient ( _httpClientHandler , false ) ;
178
178
179
179
httpClient . DefaultRequestHeaders . Accept . Clear ( ) ;
180
180
httpClient . DefaultRequestHeaders . Accept . Add ( new MediaTypeWithQualityHeaderValue ( "application/json" ) ) ;
181
-
181
+
182
182
// Build endpoint from Issuer and dicovery endpoint, we can't use the Uri overload because the Issuer Uri may not have a trailing '/'
183
183
string tempIssuer = _issuer . AbsoluteUri . EndsWith ( "/" ) ? _issuer . AbsoluteUri : _issuer . AbsoluteUri + "/" ;
184
184
Uri discoveryEndpoint = new Uri ( tempIssuer + DISCOVERY_ENDPOINT ) ;
185
-
185
+
186
186
using HttpRequestMessage req = new HttpRequestMessage ( HttpMethod . Get , discoveryEndpoint ) ;
187
187
using HttpResponseMessage response = await httpClient . SendAsync ( req , cancellationToken )
188
188
. ConfigureAwait ( false ) ;
@@ -237,8 +237,8 @@ public OAuth2Client(string clientId, string clientSecret, Uri tokenEndpoint,
237
237
_additionalRequestParameters = additionalRequestParameters ?? EMPTY ;
238
238
_tokenEndpoint = tokenEndpoint ;
239
239
240
- _httpClient = httpClientHandler is null
241
- ? new HttpClient ( )
240
+ _httpClient = httpClientHandler is null
241
+ ? new HttpClient ( )
242
242
: new HttpClient ( httpClientHandler , false ) ;
243
243
244
244
_httpClient . DefaultRequestHeaders . Accept . Clear ( ) ;
0 commit comments