93566ce4ef
* Chore: Unify token exchange rount trippers * Remove the conditional provider for now * Remove unecessary strategy * test cleanup * Lint
44 lines
1.3 KiB
Go
44 lines
1.3 KiB
Go
package clientauth
|
|
|
|
import (
|
|
"context"
|
|
)
|
|
|
|
// NamespaceProvider is a strategy for determining the namespace to use in token exchange requests.
|
|
type NamespaceProvider interface {
|
|
GetNamespace(ctx context.Context) string
|
|
}
|
|
|
|
// AudienceProvider is a strategy for determining the audiences to use in token exchange requests.
|
|
type AudienceProvider interface {
|
|
GetAudiences(ctx context.Context) []string
|
|
}
|
|
|
|
// StaticNamespaceProvider returns a fixed namespace for all requests.
|
|
type StaticNamespaceProvider struct {
|
|
namespace string
|
|
}
|
|
|
|
// NewStaticNamespaceProvider creates a namespace provider that always returns the same namespace.
|
|
func NewStaticNamespaceProvider(namespace string) *StaticNamespaceProvider {
|
|
return &StaticNamespaceProvider{namespace: namespace}
|
|
}
|
|
|
|
func (p *StaticNamespaceProvider) GetNamespace(ctx context.Context) string {
|
|
return p.namespace
|
|
}
|
|
|
|
// StaticAudienceProvider returns a fixed set of audiences for all requests.
|
|
type StaticAudienceProvider struct {
|
|
audiences []string
|
|
}
|
|
|
|
// NewStaticAudienceProvider creates an audience provider that always returns the same audiences.
|
|
func NewStaticAudienceProvider(audiences ...string) *StaticAudienceProvider {
|
|
return &StaticAudienceProvider{audiences: audiences}
|
|
}
|
|
|
|
func (p *StaticAudienceProvider) GetAudiences(ctx context.Context) []string {
|
|
return p.audiences
|
|
}
|