feat(auth): implement OAuth 2.0 authorization code flow and dynamic client registration

- Add OAuth 2.0 support with authorization code flow and dynamic client registration.
- Introduce new handlers for OAuth metadata, client registration, authorization, and token issuance.
- Enhance authentication middleware to support OAuth client credentials.
- Create in-memory stores for authorization codes and tokens.
- Update configuration to include OAuth client details.
- Ensure validation checks for OAuth clients in the configuration.
This commit is contained in:
2026-03-26 21:17:55 +02:00
parent ed05d390b7
commit 56c84df342
19 changed files with 970 additions and 40 deletions

View File

@@ -10,10 +10,9 @@ func (c Config) Validate() error {
return fmt.Errorf("invalid config: database.url is required")
}
if len(c.Auth.Keys) == 0 {
return fmt.Errorf("invalid config: auth.keys must not be empty")
if len(c.Auth.Keys) == 0 && len(c.Auth.OAuth.Clients) == 0 {
return fmt.Errorf("invalid config: at least one of auth.keys or auth.oauth.clients must be configured")
}
for i, key := range c.Auth.Keys {
if strings.TrimSpace(key.ID) == "" {
return fmt.Errorf("invalid config: auth.keys[%d].id is required", i)
@@ -22,6 +21,14 @@ func (c Config) Validate() error {
return fmt.Errorf("invalid config: auth.keys[%d].value is required", i)
}
}
for i, client := range c.Auth.OAuth.Clients {
if strings.TrimSpace(client.ClientID) == "" {
return fmt.Errorf("invalid config: auth.oauth.clients[%d].client_id is required", i)
}
if strings.TrimSpace(client.ClientSecret) == "" {
return fmt.Errorf("invalid config: auth.oauth.clients[%d].client_secret is required", i)
}
}
if strings.TrimSpace(c.MCP.Path) == "" {
return fmt.Errorf("invalid config: mcp.path is required")