Documentation
¶
Index ¶
- func GetAttributeValue(assertion *saml.Assertion, attributeName string) string
- func GetAttributeValues(assertion *saml.Assertion, attributeName string) []string
- type AttributeNames
- type IDTokenClaims
- type SAMLConfig
- type SAMLProvider
- func (p *SAMLProvider) CreateMiddleware(opts samlsp.Options) (*samlsp.Middleware, error)
- func (p *SAMLProvider) ExchangeCode(ctx context.Context, code string) (*TokenResponse, error)
- func (p *SAMLProvider) ExtractUserInfoFromAssertion(assertion *saml.Assertion) (*UserInfo, error)
- func (p *SAMLProvider) GenerateMetadata() (string, error)
- func (p *SAMLProvider) GetAuthorizationURL(state string) (string, error)
- func (p *SAMLProvider) GetAuthorizationURLForceAuthn(state string) (string, error)
- func (p *SAMLProvider) GetConfig() *SAMLConfig
- func (p *SAMLProvider) GetMetadata() (*saml.EntityDescriptor, error)
- func (p *SAMLProvider) GetMetadataXML() ([]byte, error)
- func (p *SAMLProvider) GetOAuth2Config() *oauth2.Config
- func (p *SAMLProvider) GetUserInfo(ctx context.Context, accessToken string) (*UserInfo, error)
- func (p *SAMLProvider) InitiateLogin(clientCallback *string) (string, string, error)
- func (p *SAMLProvider) MakeLogoutResponse(inResponseTo string, status string) (string, error)
- func (p *SAMLProvider) ParseResponse(samlResponse string) (*saml.Assertion, error)
- func (p *SAMLProvider) ProcessLogoutRequest(samlRequest string) (*saml.LogoutRequest, error)
- func (p *SAMLProvider) ValidateIDToken(ctx context.Context, idToken string) (*IDTokenClaims, error)
- type TokenResponse
- type UserInfo
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func GetAttributeValue ¶
GetAttributeValue safely retrieves an attribute value from the assertion
Types ¶
type AttributeNames ¶
type AttributeNames struct {
Email string
Name string
GivenName string
FamilyName string
Groups string
UID string
}
AttributeNames defines standard SAML attribute names
func DefaultAttributeNames ¶
func DefaultAttributeNames() AttributeNames
DefaultAttributeNames returns common SAML attribute names
func OktaAttributeNames ¶
func OktaAttributeNames() AttributeNames
OktaAttributeNames returns Okta-specific SAML attribute names
type IDTokenClaims ¶
IDTokenClaims represents claims from an ID token (stub for interface compatibility)
type SAMLConfig ¶
type SAMLConfig struct {
// Basic configuration
ID string `json:"id" yaml:"id"` // Provider ID (e.g., "saml_okta")
Name string `json:"name" yaml:"name"` // Display name
Enabled bool `json:"enabled" yaml:"enabled"` // Whether this provider is enabled
Icon string `json:"icon" yaml:"icon"` // Icon identifier
// SAML-specific configuration
EntityID string `json:"entity_id" yaml:"entity_id"` // Service Provider entity ID
ACSURL string `json:"acs_url" yaml:"acs_url"` // Assertion Consumer Service URL
SLOURL string `json:"slo_url" yaml:"slo_url"` // Single Logout URL
IDPMetadataURL string `json:"idp_metadata_url" yaml:"idp_metadata_url"` // IdP metadata URL (fetched at startup)
IDPMetadataB64XML string `json:"idp_metadata_b64xml" yaml:"idp_metadata_b64xml"` // Base64-encoded IdP metadata XML
SPPrivateKeyPath string `json:"sp_private_key_path" yaml:"sp_private_key_path"` // SP private key file path
SPCertificatePath string `json:"sp_certificate_path" yaml:"sp_certificate_path"` // SP certificate file path
SPPrivateKey string `json:"sp_private_key" yaml:"sp_private_key"` // SP private key (PEM)
SPCertificate string `json:"sp_certificate" yaml:"sp_certificate"` // SP certificate (PEM)
AllowIDPInitiated bool `json:"allow_idp_initiated" yaml:"allow_idp_initiated"` // Allow IdP-initiated SSO
ForceAuthn bool `json:"force_authn" yaml:"force_authn"` // Force reauthentication
SignRequests bool `json:"sign_requests" yaml:"sign_requests"` // Sign AuthnRequests
EncryptAssertions bool `json:"encrypt_assertions" yaml:"encrypt_assertions"` // Require encrypted assertions
// Attribute mapping
AttributeMapping map[string]string `json:"attribute_mapping" yaml:"attribute_mapping"`
// Group configuration
GroupAttributeName string `json:"group_attribute_name" yaml:"group_attribute_name"` // SAML attribute containing groups
GroupPrefix string `json:"group_prefix" yaml:"group_prefix"` // Optional prefix filter for groups
}
SAMLConfig represents the configuration for a SAML identity provider
type SAMLProvider ¶
type SAMLProvider struct {
// contains filtered or unexported fields
}
SAMLProvider implements the Provider interface for SAML authentication
func NewSAMLProvider ¶
func NewSAMLProvider(config *SAMLConfig) (*SAMLProvider, error)
NewSAMLProvider creates a new SAML provider
func (*SAMLProvider) CreateMiddleware ¶
func (p *SAMLProvider) CreateMiddleware(opts samlsp.Options) (*samlsp.Middleware, error)
CreateMiddleware creates SAML middleware for HTTP handlers
func (*SAMLProvider) ExchangeCode ¶
func (p *SAMLProvider) ExchangeCode(ctx context.Context, code string) (*TokenResponse, error)
ExchangeCode is not applicable for SAML
func (*SAMLProvider) ExtractUserInfoFromAssertion ¶
func (p *SAMLProvider) ExtractUserInfoFromAssertion(assertion *saml.Assertion) (*UserInfo, error)
ExtractUserInfoFromAssertion extracts user info from a SAML assertion
func (*SAMLProvider) GenerateMetadata ¶
func (p *SAMLProvider) GenerateMetadata() (string, error)
GenerateMetadata returns the SP metadata XML string
func (*SAMLProvider) GetAuthorizationURL ¶
func (p *SAMLProvider) GetAuthorizationURL(state string) (string, error)
GetAuthorizationURL generates a SAML authentication request URL
func (*SAMLProvider) GetAuthorizationURLForceAuthn ¶
func (p *SAMLProvider) GetAuthorizationURLForceAuthn(state string) (string, error)
GetAuthorizationURLForceAuthn generates a SAML authentication request URL with ForceAuthn=true set on the AuthnRequest, overriding the configured p.config.ForceAuthn default. Used by /oauth2/step_up (#397) to require a fresh interactive re-authentication at the IdP.
func (*SAMLProvider) GetConfig ¶
func (p *SAMLProvider) GetConfig() *SAMLConfig
GetConfig returns the SAML configuration
func (*SAMLProvider) GetMetadata ¶
func (p *SAMLProvider) GetMetadata() (*saml.EntityDescriptor, error)
GetMetadata returns the service provider metadata
func (*SAMLProvider) GetMetadataXML ¶
func (p *SAMLProvider) GetMetadataXML() ([]byte, error)
GetMetadataXML returns the service provider metadata as XML
func (*SAMLProvider) GetOAuth2Config ¶
func (p *SAMLProvider) GetOAuth2Config() *oauth2.Config
GetOAuth2Config returns nil as SAML doesn't use OAuth2
func (*SAMLProvider) GetUserInfo ¶
GetUserInfo is not applicable for SAML (user info comes from assertion)
func (*SAMLProvider) InitiateLogin ¶
func (p *SAMLProvider) InitiateLogin(clientCallback *string) (string, string, error)
InitiateLogin creates a SAML authentication request
func (*SAMLProvider) MakeLogoutResponse ¶
func (p *SAMLProvider) MakeLogoutResponse(inResponseTo string, status string) (string, error)
MakeLogoutResponse creates a SAML logout response
func (*SAMLProvider) ParseResponse ¶
func (p *SAMLProvider) ParseResponse(samlResponse string) (*saml.Assertion, error)
ParseResponse parses and validates a SAML response with full signature verification
func (*SAMLProvider) ProcessLogoutRequest ¶
func (p *SAMLProvider) ProcessLogoutRequest(samlRequest string) (*saml.LogoutRequest, error)
ProcessLogoutRequest handles a SAML logout request from the IdP.
Binding note: this accepts the HTTP-POST binding form of the request -- base64-encoded LogoutRequest XML carrying an enveloped XML signature. The HTTP-Redirect binding carries a DEFLATE-compressed payload whose signature lives in the SigAlg/Signature query parameters rather than inside the XML; that form is not supported by this method and is rejected (it fails XML parsing, or signature validation if inflated XML without an embedded signature is supplied).
SECURITY: the request is only trusted after its enveloped XML signature has been verified against the IdP signing certificate(s) from metadata. Unsigned requests are rejected outright.
func (*SAMLProvider) ValidateIDToken ¶
func (p *SAMLProvider) ValidateIDToken(ctx context.Context, idToken string) (*IDTokenClaims, error)
ValidateIDToken is not applicable for SAML
type TokenResponse ¶
TokenResponse represents the tokens returned by SAML (stub for interface compatibility)
type UserInfo ¶
type UserInfo struct {
ID string
IDType string // Type of identifier: "subject-id", "pairwise-id", "nameid"
Email string
EmailVerified bool
// EmailSynthesized is true when Email was fabricated by a fallback, not asserted by the IdP.
EmailSynthesized bool
Name string
// NameSynthesized is true when Name was fabricated by a fallback, not asserted by the IdP.
NameSynthesized bool
GivenName string
FamilyName string
Picture string
Locale string
IdP string
Groups []string
}
UserInfo represents user information extracted from SAML assertion
func ExtractUserInfo ¶
func ExtractUserInfo(assertion *saml.Assertion, config *SAMLConfig) (*UserInfo, error)
ExtractUserInfo extracts user information and groups from SAML assertion