Documentation
¶
Index ¶
- Variables
- func FetchMetadataWithRetry(ctx context.Context, client *http.Client, metadataURL url.URL, ...) (*saml.EntityDescriptor, error)
- func GenerateTestCertificate(t *testing.T) (string, string)
- func GetSPSigningCertificateFromMetadata(ctx context.Context, cfg config.Config, spEntityID string, ...) (*x509.Certificate, error)
- func LoadCertificate(certPath, keyPath string) (tls.Certificate, error)
- func ReadMetadataFromURLWithRetry(ctx context.Context, client *http.Client, metadataURL string, ...) ([]byte, error)
- type AuthRequest
- func (a *AuthRequest) Done() bool
- func (a *AuthRequest) GetAccessConsumerServiceURL() string
- func (a *AuthRequest) GetApplicationID() string
- func (a *AuthRequest) GetAuthRequestID() string
- func (a *AuthRequest) GetBindingType() string
- func (a *AuthRequest) GetDestination() string
- func (a *AuthRequest) GetID() string
- func (a *AuthRequest) GetIssuer() string
- func (a *AuthRequest) GetRelayState() string
- func (a *AuthRequest) GetUserID() string
- type IDP
- type LogoutContext
- type SPCertificateCache
- type ServiceProvider
- type ServiceProviders
- type SingleLogoutService
- type Storage
- func (s *Storage) AddAuthRequestForTesting(authRequest *AuthRequest)
- func (s *Storage) AuthRequestByID(_ context.Context, id string) (models.AuthRequestInt, error)
- func (s *Storage) CheckAndMarkLogoutRequestProcessed(contextID, requestID string) (bool, error)
- func (s *Storage) CleanupCompletedAuthRequests(maxAge time.Duration) int
- func (s *Storage) CreateAuthRequest(_ context.Context, authnRequest *samlp.AuthnRequestType, ...) (models.AuthRequestInt, error)
- func (s *Storage) CreateLogoutContext(originType, originID, targetID, relayState string) *LogoutContext
- func (s *Storage) DeleteLogoutContext(id string)
- func (s *Storage) GetAllowedSPs() []config.SPConfig
- func (s *Storage) GetCA(_ context.Context) (*key.CertificateAndKey, error)
- func (s *Storage) GetConfig() config.Config
- func (s *Storage) GetEntityByID(ctx context.Context, entityID string) (*serviceprovider.ServiceProvider, error)
- func (s *Storage) GetEntityIDByAppID(_ context.Context, appID string) (string, error)
- func (s *Storage) GetLogoutContext(id string) (*LogoutContext, error)
- func (s *Storage) GetMetadataSigningKey(_ context.Context) (*key.CertificateAndKey, error)
- func (s *Storage) GetResponseSigningKey(_ context.Context) (*key.CertificateAndKey, error)
- func (s *Storage) GetSPCertificateCache() *SPCertificateCache
- func (s *Storage) GetSingleLogoutServiceFromSP(ctx context.Context, entityID string) (*SingleLogoutService, error)
- func (s *Storage) Health(_ context.Context) error
- func (s *Storage) SetEntityIDMapping(appID, entityID string)
- func (s *Storage) SetUserinfoWithLoginName(_ context.Context, userinfo models.AttributeSetter, loginName string, _ []int) error
- func (s *Storage) SetUserinfoWithUserID(ctx context.Context, authRequestID string, userinfo models.AttributeSetter, ...) error
Constants ¶
This section is empty.
Variables ¶
var ( ErrDecodePEMBlock = errors.New("failed to decode PEM block containing certificate") ErrPrivateKeyNotRSAKey = errors.New("private key is not an RSA key") )
var ( // ErrNoSigningCertificate indicates no signing certificate was found in metadata. ErrNoSigningCertificate = errors.New("no signing certificate found in metadata") // ErrInvalidCertificate indicates the certificate data is malformed. ErrInvalidCertificate = errors.New("invalid certificate data") // ErrSPNotInAllowedList indicates the SP is not in the allowed list. ErrSPNotInAllowedList = errors.New("SP not found in allowed list") // ErrNoMetadataURL indicates no metadata URL configured for SP. ErrNoMetadataURL = errors.New("no metadata URL configured for SP") )
var ( ErrPrivateKeyIsNil = errors.New("private key is nil") ErrPrivateKeyNotRSA = errors.New("private key is not an RSA key") ErrEntityNotFound = errors.New("entity not found") ErrAuthRequestNotFound = errors.New("auth request not found") ErrInvalidAuthRequestType = errors.New("invalid auth request type") ErrLogoutContextNotFound = errors.New("logout context not found") ErrNoSPSSODescriptor = errors.New("no SPSSODescriptor found in metadata") ErrNoSingleLogoutService = errors.New("no SingleLogoutService found in metadata") )
Functions ¶
func FetchMetadataWithRetry ¶
func FetchMetadataWithRetry(ctx context.Context, client *http.Client, metadataURL url.URL, cfg config.Config) (*saml.EntityDescriptor, error)
FetchMetadataWithRetry attempts to fetch SAML metadata with exponential backoff retry logic.
func GenerateTestCertificate ¶
GenerateTestCertificate generates a self-signed certificate and private key for testing.
func GetSPSigningCertificateFromMetadata ¶
func GetSPSigningCertificateFromMetadata(ctx context.Context, cfg config.Config, spEntityID string, cache *SPCertificateCache) (*x509.Certificate, error)
GetSPSigningCertificateFromMetadata retrieves the signing certificate from SP metadata.
func LoadCertificate ¶
func LoadCertificate(certPath, keyPath string) (tls.Certificate, error)
LoadCertificate loads and parses the SP certificate and private key.
Types ¶
type AuthRequest ¶
type AuthRequest struct {
ID string
ApplicationID string
RelayState string
AccessConsumerServiceURL string
BindingType string
AuthRequestID string
Issuer string
Destination string
UserID string
IsDone bool
CompletedAt time.Time
// Assertion data from the actual IdP
Assertion *saml.Assertion
}
AuthRequest implements the models.AuthRequestInt interface.
func (*AuthRequest) Done ¶
func (a *AuthRequest) Done() bool
func (*AuthRequest) GetAccessConsumerServiceURL ¶
func (a *AuthRequest) GetAccessConsumerServiceURL() string
func (*AuthRequest) GetApplicationID ¶
func (a *AuthRequest) GetApplicationID() string
func (*AuthRequest) GetAuthRequestID ¶
func (a *AuthRequest) GetAuthRequestID() string
func (*AuthRequest) GetBindingType ¶
func (a *AuthRequest) GetBindingType() string
func (*AuthRequest) GetDestination ¶
func (a *AuthRequest) GetDestination() string
func (*AuthRequest) GetID ¶
func (a *AuthRequest) GetID() string
func (*AuthRequest) GetIssuer ¶
func (a *AuthRequest) GetIssuer() string
func (*AuthRequest) GetRelayState ¶
func (a *AuthRequest) GetRelayState() string
func (*AuthRequest) GetUserID ¶
func (a *AuthRequest) GetUserID() string
type IDP ¶
IDP represents the SAML Identity Provider configuration.
func CreateProxyIDP ¶
CreateProxyIDP creates a SAML Identity Provider middleware from the configuration.
func (*IDP) GetProvider ¶
GetProvider returns the zitadel/saml provider.
func (*IDP) GetStorage ¶
GetStorage returns the IDP's storage for testing purposes.
type LogoutContext ¶
type LogoutContext struct {
ID string // Unique logout session ID
OriginType string // "sp" or "idp" - who initiated the logout
OriginID string // Entity ID of logout initiator
TargetID string // Entity ID of logout target
RelayState string // Original relay state to be preserved
CreatedAt time.Time // For cleanup of expired contexts
LogoutRequestID string // Original logout request ID for tracking
ProcessedRequests map[string]bool // Track processed request IDs to prevent replay
}
LogoutContext stores temporary state for a logout flow. This follows the same stateless philosophy as AuthRequest, storing minimal information only during the logout process.
type SPCertificateCache ¶
type SPCertificateCache struct {
// contains filtered or unexported fields
}
SPCertificateCache caches SP signing certificates to avoid repeated metadata fetches.
func NewSPCertificateCache ¶
func NewSPCertificateCache() *SPCertificateCache
NewSPCertificateCache creates a new certificate cache.
func (*SPCertificateCache) Get ¶
func (c *SPCertificateCache) Get(entityID string) (*x509.Certificate, bool)
Get retrieves a certificate from the cache.
func (*SPCertificateCache) Set ¶
func (c *SPCertificateCache) Set(entityID string, cert *x509.Certificate)
Set stores a certificate in the cache.
type ServiceProvider ¶
type ServiceProvider struct {
ID string
Middleware *samlsp.Middleware
}
ServiceProvider represents a SAML Service Provider for a specific IDP.
type ServiceProviders ¶
type ServiceProviders struct {
Providers map[string]*ServiceProvider
Default *ServiceProvider
}
ServiceProviders manages multiple SAML Service Providers.
func CreateServiceProviders ¶
CreateServiceProviders creates Service Providers for all configured IDP.
func (*ServiceProviders) GetProvider ¶
func (s *ServiceProviders) GetProvider(id string) *ServiceProvider
GetProvider returns the IDP Service Provider for the given ID or the default if not found.
type SingleLogoutService ¶
SingleLogoutService represents a parsed SingleLogoutService endpoint from SP metadata.
type Storage ¶
type Storage struct {
// contains filtered or unexported fields
}
Storage implements the zitadel/saml Storage interfaces.
func NewStorage ¶
NewStorage creates a new Storage.
func (*Storage) AddAuthRequestForTesting ¶
func (s *Storage) AddAuthRequestForTesting(authRequest *AuthRequest)
AddAuthRequestForTesting adds an auth request to storage for testing purposes.
func (*Storage) AuthRequestByID ¶
func (*Storage) CheckAndMarkLogoutRequestProcessed ¶
CheckAndMarkLogoutRequestProcessed checks if a logout request ID has been processed and marks it as processed if not. Returns true if this is a replay.
func (*Storage) CleanupCompletedAuthRequests ¶
CleanupCompletedAuthRequests removes completed auth requests older than the specified duration.
func (*Storage) CreateAuthRequest ¶
func (s *Storage) CreateAuthRequest(_ context.Context, authnRequest *samlp.AuthnRequestType, appID, bindingType, relayState, userID string) (models.AuthRequestInt, error)
func (*Storage) CreateLogoutContext ¶
func (s *Storage) CreateLogoutContext(originType, originID, targetID, relayState string) *LogoutContext
CreateLogoutContext creates a new logout context for tracking logout flow state.
func (*Storage) DeleteLogoutContext ¶
DeleteLogoutContext removes a logout context from storage.
func (*Storage) GetAllowedSPs ¶
GetAllowedSPs returns the list of allowed service providers from configuration.
func (*Storage) GetEntityByID ¶
func (s *Storage) GetEntityByID(ctx context.Context, entityID string) (*serviceprovider.ServiceProvider, error)
func (*Storage) GetEntityIDByAppID ¶
func (*Storage) GetLogoutContext ¶
func (s *Storage) GetLogoutContext(id string) (*LogoutContext, error)
GetLogoutContext retrieves a logout context by ID.
func (*Storage) GetMetadataSigningKey ¶
func (*Storage) GetResponseSigningKey ¶
func (*Storage) GetSPCertificateCache ¶
func (s *Storage) GetSPCertificateCache() *SPCertificateCache
GetSPCertificateCache returns the SP certificate cache.
func (*Storage) GetSingleLogoutServiceFromSP ¶
func (s *Storage) GetSingleLogoutServiceFromSP(ctx context.Context, entityID string) (*SingleLogoutService, error)
GetSingleLogoutServiceFromSP extracts SingleLogoutService endpoint from SP metadata.
func (*Storage) SetEntityIDMapping ¶
SetEntityIDMapping sets the entity ID mapping for an app ID.