Skip to content

Commit baed026

Browse files
jods4Copilot
andauthored
feat: add configurable policy name for Host auth (#482)
* Initial plan * Add configurable authorization policy name for Host mode Co-authored-by: jods4 <3832820+jods4@users.noreply.github.com> * Refactor: Make policy an optional parameter to WithHostAuthentication Co-authored-by: jods4 <3832820+jods4@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: jods4 <3832820+jods4@users.noreply.github.com>
1 parent 298ca68 commit baed026

File tree

4 files changed

+29
-4
lines changed

4 files changed

+29
-4
lines changed

src/TickerQ.Dashboard/Authentication/AuthConfig.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,11 @@ public class AuthConfig
3232
/// </summary>
3333
public int SessionTimeoutMinutes { get; set; } = 60;
3434

35+
/// <summary>
36+
/// Authorization policy name for Host mode (default: null uses the default policy)
37+
/// </summary>
38+
public string? HostAuthorizationPolicy { get; set; }
39+
3540
/// <summary>
3641
/// Whether authentication is enabled
3742
/// </summary>

src/TickerQ.Dashboard/DashboardOptionsBuilder.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,11 @@ public DashboardOptionsBuilder WithApiKey(string apiKey)
6060
}
6161

6262
/// <summary>Use the host application's existing authentication system</summary>
63-
public DashboardOptionsBuilder WithHostAuthentication()
63+
/// <param name="policy">Optional authorization policy name to require (e.g., "AdminPolicy"). If null or empty, uses the default policy.</param>
64+
public DashboardOptionsBuilder WithHostAuthentication(string? policy = null)
6465
{
6566
Auth.Mode = AuthMode.Host;
67+
Auth.HostAuthorizationPolicy = policy;
6668
return this;
6769
}
6870

src/TickerQ.Dashboard/Endpoints/DashboardEndpoints.cs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,15 @@ public static void MapDashboardEndpoints<TTimeTicker, TCronTicker>(this IEndpoin
4545
// Apply authentication if configured
4646
if (config.Auth.Mode == AuthMode.Host)
4747
{
48-
// For host authentication, use default authorization
49-
apiGroup.RequireAuthorization();
48+
// For host authentication, use configured policy or default authorization
49+
if (!string.IsNullOrEmpty(config.Auth.HostAuthorizationPolicy))
50+
{
51+
apiGroup.RequireAuthorization(config.Auth.HostAuthorizationPolicy);
52+
}
53+
else
54+
{
55+
apiGroup.RequireAuthorization();
56+
}
5057
}
5158
// For other auth modes (Basic, Bearer, Custom), authentication is handled by AuthMiddleware
5259
// API endpoints are automatically protected when auth is enabled

src/TickerQ.Dashboard/README.md

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,11 +48,22 @@ services.AddTickerQ<MyTimeTicker, MyCronTicker>(config =>
4848
});
4949
```
5050

51+
### Use Host Authentication with Custom Policy
52+
```csharp
53+
services.AddTickerQ<MyTimeTicker, MyCronTicker>(config =>
54+
{
55+
config.AddDashboard(dashboard =>
56+
{
57+
dashboard.WithHostAuthentication("AdminPolicy");
58+
});
59+
});
60+
```
61+
5162
## 🔧 Fluent API Methods
5263

5364
- `WithBasicAuth(username, password)` - Enable username/password authentication
5465
- `WithApiKey(apiKey)` - Enable API key authentication
55-
- `WithHostAuthentication()` - Use your app's existing auth
66+
- `WithHostAuthentication(policy)` - Use your app's existing auth with optional policy (e.g., "AdminPolicy")
5667
- `SetBasePath(path)` - Set dashboard URL path
5768
- `SetBackendDomain(domain)` - Set backend API domain
5869
- `SetCorsPolicy(policy)` - Configure CORS

0 commit comments

Comments
 (0)