mirror of
https://github.com/hanzo-fi/go-libs.git
synced 2026-10-30 20:53:44 +00:00
* refactor: move all packages under pkg/ for v5 Move all 13 top-level Go packages into pkg/ for a cleaner repository structure. All internal import paths updated from github.com/formancehq/go-libs/v5/<pkg> to github.com/formancehq/go-libs/v5/pkg/<pkg>. Also includes cleanup: - Fix .golangci.yml stale v4 CircuitBreaker path - Replace deprecated str.Contains with stdlib slices.Contains - Update TODO(v4) markers to TODO - Delete stale coverage.txt - Fix pgtesting timeout not being propagated to docker pool - Update docs/ARCHITECTURE.md to reflect new structure Co-Authored-By: Claude Opus 4.6 <[email protected]> * chore: remove compatibility aliases, unused params, and stub files - Remove unused type aliases (Authenticator, KeySet) from authnfx - Remove unused `debug` parameter from S3ModuleFromFlags - Delete comment-only stub files in messaging/publish/circuit/ Co-Authored-By: Claude Opus 4.6 <[email protected]> * chore: rename cli.go to flags.go for consistency Standardize naming across all packages: cli.go -> flags.go since these files all serve the same purpose (flag definitions). Co-Authored-By: Claude Opus 4.6 <[email protected]> * chore: rename * chore(deps): update all dependencies Co-Authored-By: Claude Opus 4.6 <[email protected]> * fix: resolve package name mismatches in generated mocks Generated mock files had stale package names from before the pkg/ move, causing import cycles and build failures with --build-tags it. Co-Authored-By: Claude Opus 4.6 <[email protected]> --------- Co-authored-by: Claude Opus 4.6 <[email protected]>
75 lines
2.4 KiB
Go
75 lines
2.4 KiB
Go
package oidc
|
|
|
|
import (
|
|
"slices"
|
|
)
|
|
|
|
// ValidateTokenExchangeRequest validates a TokenExchangeRequest according to RFC 8693
|
|
func ValidateTokenExchangeRequest(req *TokenExchangeRequest) error {
|
|
// Validate grant type
|
|
if req.GrantType != GrantTypeTokenExchange {
|
|
return ErrUnsupportedGrantType().WithDescription("grant_type must be %s", GrantTypeTokenExchange)
|
|
}
|
|
|
|
// Validate required parameters
|
|
if req.SubjectToken == "" {
|
|
return ErrInvalidRequest().WithDescription("subject_token is required")
|
|
}
|
|
|
|
if req.SubjectTokenType == "" {
|
|
return ErrInvalidRequest().WithDescription("subject_token_type is required")
|
|
}
|
|
|
|
// Validate subject_token_type
|
|
validSubjectTokenTypes := []TokenType{
|
|
AccessTokenType,
|
|
// RefreshTokenType, // Can be enabled if needed
|
|
// IDTokenType, // Can be enabled if needed
|
|
// JWTTokenType, // Can be enabled if needed
|
|
}
|
|
if !slices.Contains(validSubjectTokenTypes, req.SubjectTokenType) {
|
|
return ErrInvalidRequest().WithDescription("invalid subject_token_type: %s", req.SubjectTokenType)
|
|
}
|
|
|
|
// Set default requested_token_type if not provided
|
|
requestedTokenType := req.RequestedTokenType
|
|
if requestedTokenType == "" {
|
|
requestedTokenType = AccessTokenType
|
|
}
|
|
|
|
// Validate requested_token_type
|
|
validRequestedTokenTypes := []TokenType{
|
|
AccessTokenType,
|
|
// RefreshTokenType, // Can be enabled if needed
|
|
}
|
|
if !slices.Contains(validRequestedTokenTypes, requestedTokenType) {
|
|
return ErrInvalidRequest().WithDescription("invalid requested_token_type: %s", requestedTokenType)
|
|
}
|
|
|
|
// Validate actor_token and actor_token_type if provided
|
|
if req.ActorToken != "" && req.ActorTokenType == "" {
|
|
return ErrInvalidRequest().WithDescription("actor_token_type is required when actor_token is provided")
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
// ValidateTokenExchangeScopes validates that requested scopes are within the allowed scopes
|
|
func ValidateTokenExchangeScopes(requestedScopes []string, allowedScopes []string) error {
|
|
for _, requestedScope := range requestedScopes {
|
|
if !slices.Contains(allowedScopes, requestedScope) {
|
|
return ErrInvalidRequest().WithDescription("requested scope '%s' is not allowed", requestedScope)
|
|
}
|
|
}
|
|
return nil
|
|
}
|
|
|
|
// GetRequestedScopes extracts and returns the requested scopes from a TokenExchangeRequest
|
|
// If no scopes are requested, returns the default scopes provided
|
|
func GetRequestedScopes(req *TokenExchangeRequest, defaultScopes []string) []string {
|
|
if len(req.Scopes) > 0 {
|
|
return req.Scopes
|
|
}
|
|
return defaultScopes
|
|
}
|