saml

package
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 7, 2026 License: Apache-2.0 Imports: 25 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// ProviderName is the auth method reported by the SAML redirect provider.
	ProviderName = "saml"

	// DefaultGroupsAttribute is the envconfig default for
	// CAESIUM_AUTH_SAML_GROUPS_ATTRIBUTE.
	DefaultGroupsAttribute = "groups"

	DefaultACSPath      = "/auth/sso/saml/acs"
	DefaultMetadataPath = "/auth/sso/saml/metadata"

	DefaultStateCookieName = "caesium_saml_state"
	DefaultStateTTL        = 10 * time.Minute

	DefaultMetadataFetchTimeout = 30 * time.Second
)

Variables

View Source
var (
	ErrMissingSAMLResponse = errors.New("saml callback missing response")
	ErrNoRedirectBinding   = errors.New("saml idp metadata does not expose HTTP-Redirect SSO")
)
View Source
var (
	ErrAssertionReplay    = errors.New("saml assertion replay detected")
	ErrMissingAssertionID = errors.New("saml assertion id is required")
)
View Source
var (
	ErrInvalidReturnTo = errors.New("invalid returnTo")
	ErrInvalidState    = errors.New("invalid saml state")
)
View Source
var ErrInvalidAssertion = errors.New("invalid saml assertion")

Functions

This section is empty.

Types

type AssertionReplayCache

type AssertionReplayCache interface {
	Record(ctx context.Context, issuer, assertionID string, expiresAt time.Time) error
}

AssertionReplayCache records assertion IDs accepted by the provider.

type Config

type Config struct {
	IDPMetadataURL  string
	IDPMetadataXML  string
	IDPMetadataFile string

	SPEntityID  string
	SPCertPath  string
	SPKeyPath   string
	ACSURL      string
	MetadataURL string

	PublicBaseURL   string
	GroupsAttribute string

	StateCookieName string
	StateTTL        time.Duration
	CookieSecure    bool
	CookieSecret    []byte

	HTTPClient  *http.Client
	ReplayCache AssertionReplayCache
}

Config configures the SAML redirect provider.

func ConfigFromEnv

func ConfigFromEnv(vars env.Environment) Config

ConfigFromEnv converts Caesium environment config into provider config. The caller must still attach a ReplayCache backed by the catalog DB before constructing the provider.

type Provider

type Provider struct {
	// contains filtered or unexported fields
}

Provider implements the Caesium browser redirect authenticator for SAML.

func New

func New(ctx context.Context, cfg Config) (*Provider, error)

New constructs a SAML SP-initiated redirect provider.

func (*Provider) Begin

func (p *Provider) Begin(w http.ResponseWriter, _ *http.Request, returnTo string) (string, error)

Begin creates a tracked AuthnRequest and returns the IdP redirect URL.

func (*Provider) ClearStateCookie

func (p *Provider) ClearStateCookie(w http.ResponseWriter, _ *http.Request)

ClearStateCookie expires the one-time pre-login state cookie.

func (*Provider) Complete

func (p *Provider) Complete(r *http.Request) (*authpkg.ExternalIdentity, error)

Complete validates the ACS callback and returns the normalized external identity.

func (*Provider) CompleteWithReturnTo

func (p *Provider) CompleteWithReturnTo(r *http.Request) (*authpkg.ExternalIdentity, string, error)

CompleteWithReturnTo validates the ACS callback and returns the RelayState return destination stored during Begin.

func (*Provider) Metadata

func (p *Provider) Metadata(w http.ResponseWriter, _ *http.Request) error

Metadata writes the SP metadata document used to register Caesium with an IdP.

func (*Provider) Name

func (p *Provider) Name() string

Name reports the provider id used by the shared SSO completion path.

type ReplayStore

type ReplayStore struct {
	// contains filtered or unexported fields
}

ReplayStore is a catalog-DB-backed replay cache for SAML assertion IDs.

func NewReplayStore

func NewReplayStore(db *gorm.DB, opts ...ReplayStoreOption) *ReplayStore

NewReplayStore creates a replay cache backed by the given database.

func (*ReplayStore) Reap

func (s *ReplayStore) Reap(ctx context.Context) (int64, error)

Reap deletes expired assertion IDs.

func (*ReplayStore) Record

func (s *ReplayStore) Record(ctx context.Context, issuer, assertionID string, expiresAt time.Time) error

Record stores a verified assertion ID. A duplicate unexpired ID is rejected.

type ReplayStoreOption

type ReplayStoreOption func(*ReplayStore)

ReplayStoreOption customizes replay-store behavior.

func WithReplayNow

func WithReplayNow(now func() time.Time) ReplayStoreOption

WithReplayNow overrides the replay-store clock. Intended for tests.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL