Skip to content

support ClaimActions configure for dashboard #8396

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/Aspire.Dashboard/Configuration/DashboardOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,11 @@ public sealed class OpenIdConnectOptions
/// </summary>
public string RequiredClaimValue { get; set; } = "";

/// <summary>
/// Gets or sets the optional value to configure the ClaimActions of <see cref="Microsoft.AspNetCore.Authentication.OpenIdConnect.OpenIdConnectOptions"/>
/// </summary>
public string? ClaimActions { get; set; }

public string[] GetNameClaimTypes()
{
Debug.Assert(_nameClaimTypes is not null, "Should have been parsed during validation.");
Expand Down
44 changes: 44 additions & 0 deletions src/Aspire.Dashboard/DashboardWebApplication.cs
Original file line number Diff line number Diff line change
Expand Up @@ -735,6 +735,50 @@ private static void ConfigureAuthentication(WebApplicationBuilder builder, Dashb

// Avoid "message.State is null or empty" due to use of CallbackPath above.
options.SkipUnrecognizedRequests = true;

// Configure additional ClaimActions
var claimActionsMap = dashboardOptions.Frontend.OpenIdConnect.ClaimActions;
if (!string.IsNullOrEmpty(claimActionsMap))
{
var actions = claimActionsMap.Split(';', StringSplitOptions.RemoveEmptyEntries | StringSplitOptions.TrimEntries);
foreach (var action in actions)
{
var ops = action.Split(':');
switch (ops[0], ops.Length)
{
case ("Delete", _):
foreach (var item in ops.Skip(1))
{
options.ClaimActions.DeleteClaim(item);
}
break;

case ("MapUniqueJsonKey", 3):
options.ClaimActions.MapUniqueJsonKey(ops[1], ops[2]);
break;
case ("MapUniqueJsonKey", > 3):
options.ClaimActions.MapUniqueJsonKey(ops[1], ops[2], ops[3]);
break;

case ("MapJsonKey", 3):
options.ClaimActions.MapJsonKey(ops[1], ops[2]);
break;
case ("MapJsonKey", > 3):
options.ClaimActions.MapJsonKey(ops[1], ops[2], ops[3]);
break;

case ("MapJsonSubKey", 4):
options.ClaimActions.MapJsonSubKey(ops[1], ops[2], ops[3]);
break;
case ("MapJsonSubKey", > 4):
options.ClaimActions.MapJsonSubKey(ops[1], ops[2], ops[3], ops[4]);
break;

default:
throw new ArgumentException($"Invalid parameter count or not supported claim action type: {ops[0]} with {ops.Length - 1} parameters {action}");
}
}
}
});
break;
case FrontendAuthMode.BrowserToken:
Expand Down
Loading