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:
@@ -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")
|
||||
|
||||
Reference in New Issue
Block a user