Documentation
¶
Index ¶
- Constants
- Variables
- func CAEPEvents() []string
- func DefaultEndingEvents() []string
- func DefaultEventsRequested() []string
- func MetadataDocument(cfg *Config) string
- func PostFormHTML(action string, fields map[string]string, nonce, title string) string
- func RISCEvents() []string
- func SubjectOf(subID any, issuer string) map[string]string
- func VerifyCompactJWS(token string, keys []map[string]any) (map[string]any, map[string]any, error)
- type Config
- type IdpMetadata
- type KeyPair
- type Logger
- type LoginOptions
- type LoginRequest
- type MemoryReplayCache
- type MemorySessionIndex
- type ReceiverOptions
- type SamlError
- type SamlLogin
- type SamlStatus
- type ServiceProvider
- type SessionRecord
- type SignalEvent
- type SignalsReceiver
- func (r *SignalsReceiver) On(eventType string, handler func(*SignalEvent) error) *SignalsReceiver
- func (r *SignalsReceiver) PollOnce() (bool, error)
- func (r *SignalsReceiver) Start() error
- func (r *SignalsReceiver) Stop()
- func (r *SignalsReceiver) Track(localID string, login *SamlLogin, expiresAt *time.Time)
- func (r *SignalsReceiver) Untrack(localID string)
- func (r *SignalsReceiver) Verify(state string) error
- type TLSOptions
Constants ¶
const DefaultSubjectAttribute = "http://schemas.xmlsoap.org/ws/2005/05/identity/claims/nameidentifier"
Variables ¶
var Event = map[string]string{
"session_revoked": caepPrefix + "session-revoked",
"token_claims_change": caepPrefix + "token-claims-change",
"credential_change": caepPrefix + "credential-change",
"assurance_level_change": caepPrefix + "assurance-level-change",
"device_compliance_change": caepPrefix + "device-compliance-change",
"session_established": caepPrefix + "session-established",
"session_presented": caepPrefix + "session-presented",
"risk_level_change": caepPrefix + "risk-level-change",
"account_credential_change_required": riscPrefix + "account-credential-change-required",
"account_purged": riscPrefix + "account-purged",
"account_disabled": riscPrefix + "account-disabled",
"account_enabled": riscPrefix + "account-enabled",
"identifier_changed": riscPrefix + "identifier-changed",
"identifier_recycled": riscPrefix + "identifier-recycled",
"credential_compromise": riscPrefix + "credential-compromise",
"opt_in": riscPrefix + "opt-in",
"opt_out_initiated": riscPrefix + "opt-out-initiated",
"opt_out_cancelled": riscPrefix + "opt-out-cancelled",
"opt_out_effective": riscPrefix + "opt-out-effective",
"recovery_activated": riscPrefix + "recovery-activated",
"recovery_information_changed": riscPrefix + "recovery-information-changed",
"sessions_revoked": riscPrefix + "sessions-revoked",
"verification": ssfPrefix + "verification",
"stream_updated": ssfPrefix + "stream-updated",
}
Event URIs for CAEP, RISC, and SSF.
Functions ¶
func CAEPEvents ¶
func CAEPEvents() []string
CAEPEvents is every CAEP event type, in declaration order.
func DefaultEndingEvents ¶
func DefaultEndingEvents() []string
DefaultEndingEvents end the local sessions they name.
func DefaultEventsRequested ¶
func DefaultEventsRequested() []string
DefaultEventsRequested is the receiver's default subscription.
func MetadataDocument ¶
MetadataDocument is this service provider's metadata, without contacting the identity provider.
func PostFormHTML ¶
PostFormHTML is the browser form that carries an HTTP-POST SAML message.
func RISCEvents ¶
func RISCEvents() []string
RISCEvents is every RISC event type, in declaration order.
Types ¶
type Config ¶
type Config struct {
EntityID string
AcsURL string
PrivateKey *rsa.PrivateKey
PrivateKeyPEM string
Certificate *x509.Certificate
CertificatePEM string
IdpMetadata string
RequestBinding string
ResponseBinding string
ClockSkewMS int64
WantAssertionsSigned bool
WantAssertionsEncrypted bool
AllowUnsolicited bool
Signals *bool
IdpCA string
IdpEntityID string
NameIDFormat string
}
Config is the configuration with its files read and its defaults filled in. Signals is present only when CAEP and RISC are off. A nil Signals means on.
func ReadConfigFile ¶
ReadConfigFile loads a JSON configuration. Nil overrides are ignored.
func ResolveConfig ¶
ResolveConfig reads files named by the configuration and fills in defaults.
type IdpMetadata ¶
type IdpMetadata struct {
EntityID string
SSO map[string]string
ArtifactResolutionServices map[int]string
Certs []*x509.Certificate
WantAuthnRequestsSigned bool
// contains filtered or unexported fields
}
IdpMetadata is the identity provider material this service provider needs.
func ReadIDPMetadata ¶
func ReadIDPMetadata(xml string) (*IdpMetadata, error)
ReadIDPMetadata reads an identity provider's metadata document.
type KeyPair ¶
type KeyPair struct {
PrivateKeyPEM string
CertificatePEM string
Certificate *x509.Certificate
PrivateKey *rsa.PrivateKey
}
KeyPair is a self-signed certificate for a service provider's signing key.
func CreateSelfSignedKeyPair ¶
CreateSelfSignedKeyPair writes an RSA key and a self-signed certificate.
func (KeyPair) Fingerprint256 ¶
type LoginOptions ¶
type LoginOptions struct {
RelayState *string
ForceAuthn bool
IsPassive bool
SubjectHint *string
SubjectHintFormat *string
RequestBinding string
ResponseBinding string
Nonce string
}
LoginOptions selects how an AuthnRequest is built. A nil RelayState is omitted.
type LoginRequest ¶
type LoginRequest struct {
ID string
Binding string
ResponseBinding string
URL string
XML string
Fields map[string]string
HTML string
}
LoginRequest is the signed AuthnRequest, as a redirect or a POST form.
type MemoryReplayCache ¶
type MemoryReplayCache struct {
// contains filtered or unexported fields
}
MemoryReplayCache remembers which assertions have been accepted.
func NewMemoryReplayCache ¶
func NewMemoryReplayCache(maxEntries int) *MemoryReplayCache
func (*MemoryReplayCache) CheckAndRecord ¶
CheckAndRecord reports whether assertionID was already accepted.
type MemorySessionIndex ¶
type MemorySessionIndex struct {
// contains filtered or unexported fields
}
MemorySessionIndex remembers which local sessions belong to which person.
func NewMemorySessionIndex ¶
func NewMemorySessionIndex(maxEntries int) *MemorySessionIndex
func (*MemorySessionIndex) Add ¶
func (s *MemorySessionIndex) Add(session SessionRecord)
func (*MemorySessionIndex) ByEmail ¶
func (s *MemorySessionIndex) ByEmail(email string) []string
func (*MemorySessionIndex) ByIdPSession ¶
func (s *MemorySessionIndex) ByIdPSession(idpSession string) []string
func (*MemorySessionIndex) ByPerson ¶
func (s *MemorySessionIndex) ByPerson(person string) []string
func (*MemorySessionIndex) Remove ¶
func (s *MemorySessionIndex) Remove(localID string)
type ReceiverOptions ¶
type ReceiverOptions struct {
Transmitter string
OnEndSessions func(ids []string, event *SignalEvent) error
TLS *TLSOptions
Headers func() map[string]string
EventsRequested []string
EndOn []string
SessionIndex *MemorySessionIndex
SubjectAttribute string
Description string
PollIntervalMS int
MaxEvents int
Log Logger
}
ReceiverOptions configures a Shared Signals poll receiver.
type SamlError ¶
type SamlError struct {
Code string
Message string
Status *SamlStatus
Cause error
}
SamlError is every failure this package reports.
type SamlLogin ¶
type SamlLogin struct {
NameID string
NameIDFormat string
NameQualifier string
SPNameQualifier string
SessionIndex string
SessionNotOnOrAfter *time.Time
AuthnInstant time.Time
AuthnContextClassRef string
Attributes map[string][]string
AttributeFriendlyNames map[string]string
Issuer string
InResponseTo *string
RelayState *string
Binding string
Encrypted bool
ResponseID string
AssertionID string
}
SamlLogin is a person the assertion consumer accepted.
type SamlStatus ¶
SamlStatus is a non-success status an identity provider answered with.
func (SamlStatus) String ¶
func (s SamlStatus) String() string
type ServiceProvider ¶
type ServiceProvider struct {
Config *Config
Idp *IdpMetadata
// contains filtered or unexported fields
}
ServiceProvider is the SAML 2.0 service provider.
func Create ¶
func Create(config map[string]any, baseDir string, replay *MemoryReplayCache) (*ServiceProvider, error)
Create resolves config and loads the identity provider's metadata.
func FromFile ¶
func FromFile(path string, overrides map[string]any, replay *MemoryReplayCache) (*ServiceProvider, error)
FromFile loads saml.json. Nil override values are ignored.
func (*ServiceProvider) Acs ¶
func (sp *ServiceProvider) Acs(method, rawURL string, body any, requestIDs []string) (*SamlLogin, error)
Acs consumes a Response on POST, redirect, or artifact.
func (*ServiceProvider) Login ¶
func (sp *ServiceProvider) Login(opt LoginOptions) (*LoginRequest, error)
Login builds a signed AuthnRequest.
func (*ServiceProvider) Metadata ¶
func (sp *ServiceProvider) Metadata() string
Metadata is this service provider's metadata.
func (*ServiceProvider) RefreshMetadata ¶
func (sp *ServiceProvider) RefreshMetadata() (*IdpMetadata, error)
RefreshMetadata reads the identity provider metadata again.
type SessionRecord ¶
type SessionRecord struct {
LocalID string
Person string
Email string
IdPSession string
ExpiresAt *time.Time
}
SessionRecord is one local session the receiver can end.
func TrackedFrom ¶
func TrackedFrom(localID string, login *SamlLogin, subjectAttribute string, expiresAt *time.Time) SessionRecord
TrackedFrom builds the index record for a SAML login.
type SignalEvent ¶
type SignalEvent struct {
Type string
Payload map[string]any
Subject map[string]string
JTI string
Sessions []string
Ended bool
Iat any
Txn *string
}
SignalEvent is one event inside a Security Event Token.
type SignalsReceiver ¶
SignalsReceiver polls one RFC 8936 stream of CAEP and RISC events.
func NewSignalsReceiver ¶
func NewSignalsReceiver(opt ReceiverOptions) (*SignalsReceiver, error)
NewSignalsReceiver builds a receiver. It does not contact the transmitter until Start.
func (*SignalsReceiver) On ¶
func (r *SignalsReceiver) On(eventType string, handler func(*SignalEvent) error) *SignalsReceiver
On registers a handler for one event type, or "*" for every type.
func (*SignalsReceiver) PollOnce ¶
func (r *SignalsReceiver) PollOnce() (bool, error)
PollOnce fetches one batch. Concurrent callers share that single request.
func (*SignalsReceiver) Start ¶
func (r *SignalsReceiver) Start() error
Start discovers the transmitter, ensures one poll stream, and polls once before returning.
func (*SignalsReceiver) Stop ¶
func (r *SignalsReceiver) Stop()
Stop cancels the next poll and waits until a poll already running has finished.
func (*SignalsReceiver) Track ¶
func (r *SignalsReceiver) Track(localID string, login *SamlLogin, expiresAt *time.Time)
Track remembers a local session so a later event can end it.
func (*SignalsReceiver) Untrack ¶
func (r *SignalsReceiver) Untrack(localID string)
Untrack forgets a local session.
func (*SignalsReceiver) Verify ¶
func (r *SignalsReceiver) Verify(state string) error
Verify asks the transmitter to deliver a verification event.
type TLSOptions ¶
TLSOptions is the back channel's trust and client certificate.