Skip to content
Merged
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/TickerQ.Dashboard/Authentication/AuthConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,23 +15,28 @@
/// <summary>
/// Basic authentication credentials (Base64 encoded username:password)
/// </summary>
public string? BasicCredentials { get; set; }

Check warning on line 18 in src/TickerQ.Dashboard/Authentication/AuthConfig.cs

View workflow job for this annotation

GitHub Actions / PR Build and Test

The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.

/// <summary>
/// API key for authentication (sent as Bearer token)
/// </summary>
public string? ApiKey { get; set; }

Check warning on line 23 in src/TickerQ.Dashboard/Authentication/AuthConfig.cs

View workflow job for this annotation

GitHub Actions / PR Build and Test

The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.

/// <summary>
/// Custom authentication function
/// </summary>
public Func<string, bool>? CustomValidator { get; set; }

Check warning on line 28 in src/TickerQ.Dashboard/Authentication/AuthConfig.cs

View workflow job for this annotation

GitHub Actions / PR Build and Test

The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.

/// <summary>
/// Session timeout in minutes (default: 60 minutes)
/// </summary>
public int SessionTimeoutMinutes { get; set; } = 60;

/// <summary>
/// Authorization policy name for Host mode (default: null uses the default policy)
/// </summary>
public string? HostAuthorizationPolicy { get; set; }

Check warning on line 38 in src/TickerQ.Dashboard/Authentication/AuthConfig.cs

View workflow job for this annotation

GitHub Actions / PR Build and Test

The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.

/// <summary>
/// Whether authentication is enabled
/// </summary>
Expand Down
4 changes: 3 additions & 1 deletion src/TickerQ.Dashboard/DashboardOptionsBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,11 @@
}

/// <summary>Use the host application's existing authentication system</summary>
public DashboardOptionsBuilder WithHostAuthentication()
/// <param name="policy">Optional authorization policy name to require (e.g., "AdminPolicy"). If null or empty, uses the default policy.</param>
public DashboardOptionsBuilder WithHostAuthentication(string? policy = null)

Check warning on line 64 in src/TickerQ.Dashboard/DashboardOptionsBuilder.cs

View workflow job for this annotation

GitHub Actions / PR Build and Test

The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.
{
Auth.Mode = AuthMode.Host;
Auth.HostAuthorizationPolicy = policy;
return this;
}

Expand Down
11 changes: 9 additions & 2 deletions src/TickerQ.Dashboard/Endpoints/DashboardEndpoints.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,15 @@ public static void MapDashboardEndpoints<TTimeTicker, TCronTicker>(this IEndpoin
// Apply authentication if configured
if (config.Auth.Mode == AuthMode.Host)
{
// For host authentication, use default authorization
apiGroup.RequireAuthorization();
// For host authentication, use configured policy or default authorization
if (!string.IsNullOrEmpty(config.Auth.HostAuthorizationPolicy))
{
apiGroup.RequireAuthorization(config.Auth.HostAuthorizationPolicy);
}
else
{
apiGroup.RequireAuthorization();
}
}
// For other auth modes (Basic, Bearer, Custom), authentication is handled by AuthMiddleware
// API endpoints are automatically protected when auth is enabled
Expand Down
13 changes: 12 additions & 1 deletion src/TickerQ.Dashboard/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,22 @@ services.AddTickerQ<MyTimeTicker, MyCronTicker>(config =>
});
```

### Use Host Authentication with Custom Policy
```csharp
services.AddTickerQ<MyTimeTicker, MyCronTicker>(config =>
{
config.AddDashboard(dashboard =>
{
dashboard.WithHostAuthentication("AdminPolicy");
});
});
```

## πŸ”§ Fluent API Methods

- `WithBasicAuth(username, password)` - Enable username/password authentication
- `WithApiKey(apiKey)` - Enable API key authentication
- `WithHostAuthentication()` - Use your app's existing auth
- `WithHostAuthentication(policy)` - Use your app's existing auth with optional policy (e.g., "AdminPolicy")
- `SetBasePath(path)` - Set dashboard URL path
- `SetBackendDomain(domain)` - Set backend API domain
- `SetCorsPolicy(policy)` - Configure CORS
Expand Down
Loading