Documentation
¶
Overview ¶
Package saml is a pure-Go (CGO=0), MRI-faithful port of Ruby's ruby-saml gem (OneLogin::RubySaml), the SAML 2.0 Service Provider toolkit.
It mirrors the surface of ruby-saml while building on the pure-Go SAML ecosystem — github.com/crewjam/saml for the SAML schema types and github.com/russellhaering/goxmldsig for XML digital-signature validation — rather than reimplementing XML signing or the SAML schema from scratch.
Surface ¶
- Settings mirrors OneLogin::RubySaml::Settings: IdP and SP configuration (idp_sso_target_url, idp_cert / idp_cert_fingerprint, sp_entity_id, assertion_consumer_service_url, name_identifier_format, private_key / certificate) plus security options (want_assertions_signed, signature_method, digest_method).
- Authrequest mirrors OneLogin::RubySaml::Authrequest: Create builds the SP-initiated SSO redirect URL and the deflate+base64 SAMLRequest.
- Response mirrors OneLogin::RubySaml::Response: IsValid validates the XML signature (via the IdP certificate or its fingerprint), the Conditions window (NotBefore / NotOnOrAfter with clock drift), the audience, the destination, the InResponseTo correlation and the issuer; NameID, Attributes (multi-valued), SessionIndex, StatusCode and Issuers extract the assertion contents.
- Metadata mirrors OneLogin::RubySaml::Metadata (SP metadata generation) and IdpMetadataParser ingests IdP metadata into a Settings.
- Logoutrequest and SloLogoutresponse implement SP-initiated Single Logout.
- ValidationError mirrors OneLogin::RubySaml::ValidationError.
All time-dependent validation reads the clock through an injectable seam so the Conditions checks are deterministic and timezone-independent.
Index ¶
- Constants
- func DecodeSAMLRequest(encoded string) ([]byte, error)
- type Authrequest
- type IdpMetadataParser
- type Logoutrequest
- type Metadata
- type Response
- func (r *Response) Attributes() map[string][]string
- func (r *Response) Destination() string
- func (r *Response) InResponseTo() string
- func (r *Response) IsValid() bool
- func (r *Response) Issuers() []string
- func (r *Response) NameID() string
- func (r *Response) SessionIndex() string
- func (r *Response) StatusCode() string
- func (r *Response) Validate() error
- type Settings
- type SloLogoutresponse
- type ValidationError
Constants ¶
const ( HTTPRedirectBinding = "urn:oasis:names:tc:SAML:2.0:bindings:HTTP-Redirect" HTTPPostBinding = "urn:oasis:names:tc:SAML:2.0:bindings:HTTP-POST" NameIDFormatEmail = "urn:oasis:names:tc:SAML:1.1:nameid-format:emailAddress" NameIDFormatTransient = "urn:oasis:names:tc:SAML:2.0:nameid-format:transient" NameIDFormatPersistent = "urn:oasis:names:tc:SAML:2.0:nameid-format:persistent" NameIDFormatUnspecified = "urn:oasis:names:tc:SAML:1.1:nameid-format:unspecified" SignatureMethodRSASHA1 = "http://www.w3.org/2000/09/xmldsig#rsa-sha1" SignatureMethodRSASHA256 = "http://www.w3.org/2001/04/xmldsig-more#rsa-sha256" DigestMethodSHA1 = "http://www.w3.org/2000/09/xmldsig#sha1" DigestMethodSHA256 = "http://www.w3.org/2001/04/xmlenc#sha256" )
Common SAML binding, format and algorithm identifiers, mirroring the constants ruby-saml exposes.
Variables ¶
This section is empty.
Functions ¶
func DecodeSAMLRequest ¶
DecodeSAMLRequest reverses SAMLRequest (base64 + inflate), returning the AuthnRequest XML. It is exposed so callers (and tests) can verify the encoded payload round-trips to well-formed XML.
Types ¶
type Authrequest ¶
type Authrequest struct {
// UUID holds the ID of the most recently created request, matching the
// ruby-saml attribute of the same name (used to correlate InResponseTo).
UUID string
}
Authrequest mirrors OneLogin::RubySaml::Authrequest, the builder for an SP-initiated SSO AuthnRequest.
func (*Authrequest) Create ¶
func (a *Authrequest) Create(s *Settings, relayState string) (string, error)
Create mirrors OneLogin::RubySaml::Authrequest#create: it returns the full IdP redirect URL carrying the SAMLRequest (and RelayState, when non-empty).
func (*Authrequest) SAMLRequest ¶
func (a *Authrequest) SAMLRequest(s *Settings) (string, error)
SAMLRequest returns the deflate+base64 encoded AuthnRequest, the value placed in the SAMLRequest query parameter of the HTTP-Redirect binding.
type IdpMetadataParser ¶
type IdpMetadataParser struct{}
IdpMetadataParser mirrors OneLogin::RubySaml::IdpMetadataParser: it ingests an IdP EntityDescriptor and populates the IdP-facing fields of a Settings.
type Logoutrequest ¶
type Logoutrequest struct {
// UUID holds the ID of the most recently created request.
UUID string
}
Logoutrequest mirrors OneLogin::RubySaml::Logoutrequest, the builder for an SP-initiated Single Logout request.
type Metadata ¶
type Metadata struct{}
Metadata mirrors OneLogin::RubySaml::Metadata, the generator for SP metadata.
type Response ¶
type Response struct {
// ExpectedInResponseTo, when set, is compared against the response's
// InResponseTo attribute during validation (mirrors ruby-saml's
// matches_request_id option).
ExpectedInResponseTo string
// Errors accumulates the validation failures found by IsValid, mirroring
// ruby-saml's @errors array.
Errors []string
// contains filtered or unexported fields
}
Response mirrors OneLogin::RubySaml::Response, the parsed and validatable SAML 2.0 authentication response received at the SP Assertion Consumer Service.
func NewResponse ¶
NewResponse parses a SAML Response. The input is either the base64-encoded response as delivered on the HTTP-POST binding, or the raw XML document.
func (*Response) Attributes ¶
Attributes returns the assertion's attributes as a multi-valued map, mirroring ruby-saml's OneLogin::RubySaml::Attributes (each key maps to all its values).
func (*Response) Destination ¶
Destination returns the Response Destination attribute.
func (*Response) InResponseTo ¶
InResponseTo returns the Response InResponseTo attribute.
func (*Response) IsValid ¶
IsValid mirrors OneLogin::RubySaml::Response#is_valid?. It runs every validation, appends each failure to Errors, and reports whether the response is valid. It never depends on the local timezone: all comparisons use UTC instants read through the injectable clock.
func (*Response) Issuers ¶
Issuers returns the unique issuer values from the Response and its Assertion.
func (*Response) SessionIndex ¶
SessionIndex returns the AuthnStatement SessionIndex, if present.
func (*Response) StatusCode ¶
StatusCode returns the top-level samlp:Status/StatusCode Value.
type Settings ¶
type Settings struct {
// IdP configuration.
IdPEntityID string // idp_entity_id (expected issuer)
IdPSSOTargetURL string // idp_sso_target_url
IdPSLOTargetURL string // idp_slo_target_url
IdPCert string // idp_cert (PEM)
IdPCertFingerprint string // idp_cert_fingerprint (hex, ':'-separated allowed)
IdPCertFingerprintAlgorithm string // sha1 (default) or sha256
// SP configuration.
SPEntityID string // sp_entity_id / issuer
AssertionConsumerServiceURL string // assertion_consumer_service_url
NameIdentifierFormat string // name_identifier_format
Certificate string // certificate (PEM)
PrivateKey string // private_key (PEM)
// Security options (subset of ruby-saml's security hash).
WantAssertionsSigned bool
SignatureMethod string
DigestMethod string
// AllowedClockDrift is the tolerance applied to condition timestamps,
// mirroring ruby-saml's allowed_clock_drift.
AllowedClockDrift time.Duration
// Audience is the expected audience URI; defaults to SPEntityID when blank.
Audience string
}
Settings mirrors OneLogin::RubySaml::Settings: the SP and IdP configuration that drives request generation and response validation.
type SloLogoutresponse ¶
type SloLogoutresponse struct {
// UUID holds the ID of the most recently created response.
UUID string
}
SloLogoutresponse mirrors OneLogin::RubySaml::SloLogoutresponse, the builder for the SP's response to an IdP-initiated logout request.
type ValidationError ¶
type ValidationError struct {
Message string
}
ValidationError mirrors OneLogin::RubySaml::ValidationError, the exception ruby-saml raises when a SAML document fails a validation check. In this pure-Go port it is a plain error value; callers inspect Message (or use it via the standard error interface). It corresponds to the single message that aborts a fail-fast validation in the Ruby gem.
func (*ValidationError) Error ¶
func (e *ValidationError) Error() string
Error implements the error interface.
