Skip to content

Commit d8d1bff

Browse files
Merge pull request #221 from DuendeSoftware/ev/bff/allow-empty-clientsecret
allow empty clientsecret and fix clientid null in sample
2 parents 364cfed + ac24ab7 commit d8d1bff

File tree

4 files changed

+16
-15
lines changed

4 files changed

+16
-15
lines changed

access-token-management/samples/BlazorServer/Plumbing/OidcEvents.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,10 @@ public override async Task TokenValidated(TokenValidatedContext context)
2323
AccessTokenType = AccessTokenType.Parse(context.TokenEndpointResponse.TokenType),
2424
RefreshToken = RefreshToken.Parse(context.TokenEndpointResponse.RefreshToken),
2525
Scope = Scope.Parse(context.TokenEndpointResponse.Scope),
26-
ClientId = ClientId.Parse(context.ProtocolMessage.ClientId),
26+
27+
// The clientid isn't always returned from the protocol response.
28+
// Either get it from IOptions<OpenIdConnectOptions> or hard code it like below.
29+
ClientId = ClientId.Parse(context.TokenEndpointResponse.ClientId ?? "interactive.confidential.short"),
2730
IdentityToken = IdentityToken.Parse(context.TokenEndpointResponse.IdToken),
2831
Expiration = exp,
2932
});

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

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -95,11 +95,6 @@ public ValidateOptionsResult Validate(string? name, ClientCredentialsClient opti
9595
errors.Add($"{nameof(options.TokenEndpoint)} cannot be null for {subject}");
9696
}
9797

98-
if (options.ClientSecret == null)
99-
{
100-
errors.Add($"{nameof(options.ClientSecret)} cannot be null for {subject}");
101-
}
102-
10398
if (errors.Any())
10499
{
105100
return ValidateOptionsResult.Fail(errors);

access-token-management/src/AccessTokenManagement/Internal/ClientCredentialsTokenClient.cs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,6 @@ public virtual async Task<TokenResult<ClientCredentialsToken>> RequestAccessToke
4040
throw new InvalidOperationException($"No TokenEndpoint configured for client {clientName}");
4141
}
4242

43-
if (client.ClientSecret == null)
44-
{
45-
throw new InvalidOperationException($"No ClientSecret configured for client {clientName}");
46-
}
47-
4843
using var logScope = logger.BeginScope(
4944
(OTelParameters.ClientId, client.ClientId)
5045
);

access-token-management/test/AccessTokenManagement.Tests/ClientTokenManagementTests.cs

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,21 +67,29 @@ public async Task Missing_client_id_throw_exception()
6767
[Fact]
6868
public async Task Missing_client_secret_throw_exception()
6969
{
70+
71+
var mockedRequest = mockHttp.Expect("/connect/token")
72+
.Respond(_ => Some.TokenHttpResponse());
73+
74+
services.AddHttpClient(ClientCredentialsTokenManagementDefaults.BackChannelHttpClientName)
75+
.ConfigurePrimaryHttpMessageHandler(() => mockHttp);
76+
7077
services.AddClientCredentialsTokenManagement()
7178
.AddClient("test", client =>
7279
{
7380
client.TokenEndpoint = new Uri("https://as/connect/token");
74-
client.ClientId = ClientId.Parse("test");
81+
client.ClientId = The.ClientId;
7582
client.ClientSecret = null;
7683
});
7784

7885
var provider = services.BuildServiceProvider();
7986
var sut = provider.GetRequiredService<IClientCredentialsTokenManager>();
8087

81-
var action = async () => await sut.GetAccessTokenAsync(ClientCredentialsClientName.Parse("test"));
88+
var token = await sut.GetAccessTokenAsync(ClientCredentialsClientName.Parse("test")).GetToken();
89+
mockHttp.VerifyNoOutstandingExpectation();
90+
91+
token.ShouldBeEquivalentTo(Some.ClientCredentialsToken());
8292

83-
(await Should.ThrowAsync<OptionsValidationException>(action))
84-
.Message.ShouldContain("ClientId");
8593
}
8694

8795
[Fact]

0 commit comments

Comments
 (0)