Files
amcs/internal/auth/oauth_registry.go
Hein 56c84df342 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.
2026-03-26 21:17:55 +02:00

34 lines
829 B
Go

package auth
import (
"crypto/subtle"
"fmt"
"git.warky.dev/wdevs/amcs/internal/config"
)
type OAuthRegistry struct {
clients []config.OAuthClient
}
func NewOAuthRegistry(clients []config.OAuthClient) (*OAuthRegistry, error) {
if len(clients) == 0 {
return nil, fmt.Errorf("oauth registry requires at least one client")
}
return &OAuthRegistry{clients: append([]config.OAuthClient(nil), clients...)}, nil
}
func (o *OAuthRegistry) Lookup(clientID string, clientSecret string) (string, bool) {
for _, client := range o.clients {
if subtle.ConstantTimeCompare([]byte(client.ClientID), []byte(clientID)) == 1 &&
subtle.ConstantTimeCompare([]byte(client.ClientSecret), []byte(clientSecret)) == 1 {
if client.ID != "" {
return client.ID, true
}
return client.ClientID, true
}
}
return "", false
}