Skip to content

Commit d7fb2b0

Browse files
Merge pull request #65 from twenzel/feature/ProvideOptionForAuthorizationHeaderStyle
Provide option to set AuthorizationHeaderStyle
2 parents 1237fca + 085ca95 commit d7fb2b0

File tree

2 files changed

+25
-16
lines changed

2 files changed

+25
-16
lines changed

access-token-management/src/AccessTokenManagement/ClientCredentialsClient.cs

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,12 @@ public class ClientCredentialsClient
1414
/// The address of the token endpoint
1515
/// </summary>
1616
public string? TokenEndpoint { get; set; }
17-
17+
1818
/// <summary>
1919
/// The client ID
2020
/// </summary>
2121
public string? ClientId { get; set; }
22-
22+
2323
/// <summary>
2424
/// The static (shared) client secret
2525
/// </summary>
@@ -30,11 +30,19 @@ public class ClientCredentialsClient
3030
/// </summary>
3131
public ClientCredentialStyle ClientCredentialStyle { get; set; }
3232

33+
/// <summary>
34+
/// Gets or sets the basic authentication header style (classic HTTP vs OAuth 2).
35+
/// </summary>
36+
/// <value>
37+
/// The basic authentication header style.
38+
/// </value>
39+
public BasicAuthenticationHeaderStyle AuthorizationHeaderStyle { get; set; } = BasicAuthenticationHeaderStyle.Rfc6749;
40+
3341
/// <summary>
3442
/// The scope
3543
/// </summary>
3644
public string? Scope { get; set; }
37-
45+
3846
/// <summary>
3947
/// The resource
4048
/// </summary>
@@ -49,7 +57,7 @@ public class ClientCredentialsClient
4957
/// Additional parameters to send with token requests.
5058
/// </summary>
5159
public Parameters Parameters { get; set; } = new Parameters();
52-
60+
5361
/// <summary>
5462
/// The HTTP client instance to use for the back-channel operations, will override the HTTP client name if set
5563
/// </summary>

access-token-management/src/AccessTokenManagement/ClientCredentialsTokenEndpointService.cs

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -69,17 +69,18 @@ public virtual async Task<ClientCredentialsToken> RequestToken(
6969
ClientId = client.ClientId,
7070
ClientSecret = client.ClientSecret,
7171
ClientCredentialStyle = client.ClientCredentialStyle,
72+
AuthorizationHeaderStyle = client.AuthorizationHeaderStyle
7273
};
7374

7475
request.Parameters.AddRange(client.Parameters);
75-
76+
7677
parameters ??= new TokenRequestParameters();
77-
78+
7879
if (!string.IsNullOrWhiteSpace(parameters.Scope))
7980
{
8081
request.Scope = parameters.Scope;
8182
}
82-
83+
8384
if (!string.IsNullOrWhiteSpace(parameters.Resource))
8485
{
8586
request.Resource.Clear();
@@ -103,14 +104,14 @@ public virtual async Task<ClientCredentialsToken> RequestToken(
103104
else
104105
{
105106
var assertion = await _clientAssertionService.GetClientAssertionAsync(clientName).ConfigureAwait(false);
106-
107+
107108
if (assertion != null)
108109
{
109110
request.ClientAssertion = assertion;
110111
request.ClientCredentialStyle = ClientCredentialStyle.PostBody;
111112
}
112113
}
113-
114+
114115
request.Options.TryAdd(ClientCredentialsTokenManagementDefaults.TokenRequestParametersOptionsName, parameters);
115116

116117
var key = await _dPoPKeyMaterialService.GetKeyAsync(clientName);
@@ -134,19 +135,19 @@ public virtual async Task<ClientCredentialsToken> RequestToken(
134135
}
135136
else if (!string.IsNullOrWhiteSpace(client.HttpClientName))
136137
{
137-
httpClient = _httpClientFactory.CreateClient(client.HttpClientName);
138+
httpClient = _httpClientFactory.CreateClient(client.HttpClientName);
138139
}
139140
else
140141
{
141-
httpClient = _httpClientFactory.CreateClient(ClientCredentialsTokenManagementDefaults.BackChannelHttpClientName);
142+
httpClient = _httpClientFactory.CreateClient(ClientCredentialsTokenManagementDefaults.BackChannelHttpClientName);
142143
}
143-
144+
144145
_logger.LogDebug("Requesting client credentials access token at endpoint: {endpoint}", request.Address);
145146
var response = await httpClient.RequestClientCredentialsTokenAsync(request, cancellationToken).ConfigureAwait(false);
146147

147-
if (response.IsError &&
148-
(response.Error == OidcConstants.TokenErrors.UseDPoPNonce || response.Error == OidcConstants.TokenErrors.InvalidDPoPProof) &&
149-
key != null &&
148+
if (response.IsError &&
149+
(response.Error == OidcConstants.TokenErrors.UseDPoPNonce || response.Error == OidcConstants.TokenErrors.InvalidDPoPProof) &&
150+
key != null &&
150151
response.DPoPNonce != null)
151152
{
152153
_logger.LogDebug("Token request failed with DPoP nonce error. Retrying with new nonce.");
@@ -173,7 +174,7 @@ public virtual async Task<ClientCredentialsToken> RequestToken(
173174
Error = response.Error
174175
};
175176
}
176-
177+
177178
return new ClientCredentialsToken
178179
{
179180
AccessToken = response.AccessToken,

0 commit comments

Comments
 (0)