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:
@@ -67,3 +67,47 @@ func TestValidateRejectsEmptyAuthKeyValue(t *testing.T) {
|
||||
t.Fatal("Validate() error = nil, want error for empty auth key value")
|
||||
}
|
||||
}
|
||||
|
||||
func TestValidateAcceptsOAuthClients(t *testing.T) {
|
||||
cfg := validConfig()
|
||||
cfg.Auth = AuthConfig{
|
||||
OAuth: OAuthConfig{
|
||||
Clients: []OAuthClient{{
|
||||
ID: "oauth-client",
|
||||
ClientID: "client-id",
|
||||
ClientSecret: "client-secret",
|
||||
}},
|
||||
},
|
||||
}
|
||||
|
||||
if err := cfg.Validate(); err != nil {
|
||||
t.Fatalf("Validate() error = %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestValidateAcceptsBothAuthMethods(t *testing.T) {
|
||||
cfg := validConfig()
|
||||
cfg.Auth = AuthConfig{
|
||||
Keys: []APIKey{{ID: "key1", Value: "secret"}},
|
||||
OAuth: OAuthConfig{
|
||||
Clients: []OAuthClient{{
|
||||
ID: "oauth-client",
|
||||
ClientID: "client-id",
|
||||
ClientSecret: "client-secret",
|
||||
}},
|
||||
},
|
||||
}
|
||||
|
||||
if err := cfg.Validate(); err != nil {
|
||||
t.Fatalf("Validate() error = %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestValidateRejectsEmptyAuth(t *testing.T) {
|
||||
cfg := validConfig()
|
||||
cfg.Auth = AuthConfig{}
|
||||
|
||||
if err := cfg.Validate(); err == nil {
|
||||
t.Fatal("Validate() error = nil, want error when neither auth.keys nor auth.oauth.clients is configured")
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user