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:
33
internal/auth/oauth_registry.go
Normal file
33
internal/auth/oauth_registry.go
Normal file
@@ -0,0 +1,33 @@
|
||||
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
|
||||
}
|
||||
Reference in New Issue
Block a user