Skip to content

Commit c8a1b6a

Browse files
committed
fix(auth): require and seed client secrets for confidential OpenIddict clients
1 parent 5cc4d72 commit c8a1b6a

2 files changed

Lines changed: 19 additions & 0 deletions

File tree

src/TaskManagement.Auth/Features/Authorization/Services/OpenIddictClientSeeder.cs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,12 @@ public async Task StartAsync(CancellationToken cancellationToken)
2929
foreach (var clientSettings in _clientSettings.Clients)
3030
{
3131
var resolvedClientType = ResolveClientType(clientSettings);
32+
var resolvedClientSecret = ResolveClientSecret(clientSettings, resolvedClientType);
3233
var applicationDescriptor = new OpenIddictApplicationDescriptor
3334
{
3435
ClientId = clientSettings.ClientId,
3536
ClientType = resolvedClientType,
37+
ClientSecret = resolvedClientSecret,
3638
ConsentType = ConsentTypes.Explicit,
3739
DisplayName = clientSettings.DisplayName,
3840
Permissions =
@@ -103,5 +105,21 @@ private static string ResolveClientType(ClientSettingsOptions clientSettings)
103105
$"Unsupported OpenIddict client type '{clientSettings.ClientType}' for client '{clientSettings.ClientId}'.")
104106
};
105107
}
108+
109+
private static string? ResolveClientSecret(ClientSettingsOptions clientSettings, string resolvedClientType)
110+
{
111+
if (resolvedClientType == ClientTypes.Public)
112+
{
113+
return null;
114+
}
115+
116+
if (!string.IsNullOrWhiteSpace(clientSettings.ClientSecret))
117+
{
118+
return clientSettings.ClientSecret;
119+
}
120+
121+
throw new InvalidOperationException(
122+
$"Client '{clientSettings.ClientId}' is configured as confidential but has no client secret.");
123+
}
106124
}
107125
}

src/TaskManagement.Auth/Infrastructure/Common/Settings/ClientSettings.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ public class ClientSettingsOptions
99
{
1010
public string ClientId { get; set; } = string.Empty;
1111
public string ClientType { get; set; } = string.Empty;
12+
public string ClientSecret { get; set; } = string.Empty;
1213
public string DisplayName { get; set; } = string.Empty;
1314
public List<string> RedirectUris { get; set; } = [];
1415
public List<string> PostLogoutRedirectUris { get; set; } = [];

0 commit comments

Comments
 (0)