Documentation
¶
Index ¶
- Constants
- Variables
- func Fatal(v ...interface{})
- func Fatalf(s string, v ...interface{})
- func IsSecurityException(err error, opts *SecurityOpts) bool
- func Log(v ...interface{})
- func Logf(s string, v ...interface{})
- func SetLogger(lg Logger)
- type Assertion
- type Attribute
- type AttributeStatement
- type AttributeValue
- type AttributesMap
- type Audience
- type AudienceRestriction
- type AuthnContext
- type AuthnContextClassRef
- type AuthnRequest
- type AuthnStatement
- type Conditions
- type EncryptedAssertion
- type EncryptionMethod
- type Endpoint
- type EntitiesDescriptor
- type IDPSSODescriptor
- type IdentityProvider
- func (idp *IdentityProvider) Cert() (*pem.Block, error)
- func (idp *IdentityProvider) GetSPCertFile() (string, error)
- func (idp *IdentityProvider) GetSPMetadata() (*Metadata, error)
- func (idp *IdentityProvider) Metadata() (*Metadata, error)
- func (idp *IdentityProvider) PrivkeyFile() (string, error)
- func (idp *IdentityProvider) PubkeyFile() (string, error)
- type IdpAuthnRequest
- type IndexedEndpoint
- type Issuer
- type KeyDescriptor
- type KeyInfo
- type Logger
- type Metadata
- type NameID
- type NameIDPolicy
- type Response
- type SPSSODescriptor
- type SecurityOpts
- type ServiceProvider
- func (sp *ServiceProvider) Cert() (*pem.Block, error)
- func (sp *ServiceProvider) GetIdPAuthResource() (string, error)
- func (sp *ServiceProvider) GetIdPCertFile() (string, error)
- func (sp *ServiceProvider) GetIdPMetadata() (*Metadata, error)
- func (sp *ServiceProvider) MakeAuthenticationRequest(idpURL string) (*AuthnRequest, error)
- func (sp *ServiceProvider) Metadata() (*Metadata, error)
- func (sp *ServiceProvider) PrivkeyFile() (string, error)
- func (sp *ServiceProvider) PubkeyFile() (string, error)
- type Session
- type Status
- type StatusCode
- type Subject
- type SubjectConfirmation
- type SubjectConfirmationData
- type SubjectLocality
- type UserRequest
Constants ¶
const HTTPPostBinding = "urn:oasis:names:tc:SAML:2.0:bindings:HTTP-POST"
HTTPPostBinding is the official URN for the HTTP-POST binding (transport)
const HTTPRedirectBinding = "urn:oasis:names:tc:SAML:2.0:bindings:HTTP-Redirect"
HTTPRedirectBinding is the official URN for the HTTP-Redirect binding (transport)
const MaxIssueDelay = time.Second * 90
MaxIssueDelay is the maximum timeframe where an assertion can be considered valid.
Variables ¶
var NewID = func() string { return fmt.Sprintf("id-%x", uuid.NewV4()) }
NewID is a function that returns a unique identifier. This value can be overwritten during tests.
var Now = time.Now
Now is a function that returns the current time. This vale can be overwritten during tests.
var StatusSuccess = "urn:oasis:names:tc:SAML:2.0:status:Success"
StatusSuccess is the value of a StatusCode element when the authentication succeeds. (nominally a constant, except for testing)
var WorkDir = "/tmp"
WorkDir is a temporary directory for files. We need to write keys to disk in order for xmlsec1 to pick them and use them.
Functions ¶
func Fatal ¶ added in v0.9.1
func Fatal(v ...interface{})
Fatal prints an error. This does not end the execution of the program.
func Fatalf ¶ added in v0.9.1
func Fatalf(s string, v ...interface{})
Fatalf prints a formatted error. This does not end the execution of the program.
func IsSecurityException ¶
func IsSecurityException(err error, opts *SecurityOpts) bool
IsSecurityException returns whether the given error is a security exception not bypassed by SecurityOpts.
func Log ¶ added in v0.9.1
func Log(v ...interface{})
Log prints logging message, not necessarily an error.
Types ¶
type Assertion ¶
type Assertion struct {
XMLName xml.Name `xml:"urn:oasis:names:tc:SAML:2.0:assertion Assertion"`
ID string `xml:",attr"`
IssueInstant time.Time `xml:",attr"`
Version string `xml:",attr"`
Issuer *Issuer `xml:"urn:oasis:names:tc:SAML:2.0:assertion Issuer"`
Signature *xmlsec.Signature
Subject *Subject
Conditions *Conditions
AuthnStatement *AuthnStatement
AttributeStatement *AttributeStatement
}
Assertion represents the SAML object of the same name.
See http://docs.oasis-open.org/security/saml/v2.0/saml-core-2.0-os.pdf
type Attribute ¶
type Attribute struct {
FriendlyName string `xml:",attr"`
Name string `xml:",attr"`
NameFormat string `xml:",attr"`
Values []AttributeValue `xml:"AttributeValue"`
}
Attribute represents the SAML object of the same name.
See http://docs.oasis-open.org/security/saml/v2.0/saml-core-2.0-os.pdf
type AttributeStatement ¶
type AttributeStatement struct {
Attributes []Attribute `xml:"Attribute"`
}
AttributeStatement represents the SAML object of the same name.
See http://docs.oasis-open.org/security/saml/v2.0/saml-core-2.0-os.pdf
type AttributeValue ¶
type AttributeValue struct {
Type string `xml:"http://www.w3.org/2001/XMLSchema-instance type,attr"`
Value string `xml:",chardata"`
NameID *NameID
}
AttributeValue represents the SAML object of the same name.
See http://docs.oasis-open.org/security/saml/v2.0/saml-core-2.0-os.pdf
type AttributesMap ¶
AttributesMap is a type that provides methods for working with SAML attributes.
func NewAttributesMap ¶
func NewAttributesMap(assertion *Assertion) *AttributesMap
NewAttributesMap creates an attribute map given a third party assertion.
func (*AttributesMap) Get ¶
func (a *AttributesMap) Get(name string) string
Get returns the first value of the given attribute, if any.
type Audience ¶
type Audience struct {
Value string `xml:",chardata"`
}
Audience represents the SAML object of the same name.
See http://docs.oasis-open.org/security/saml/v2.0/saml-core-2.0-os.pdf
type AudienceRestriction ¶
type AudienceRestriction struct {
Audience *Audience
}
AudienceRestriction represents the SAML object of the same name.
See http://docs.oasis-open.org/security/saml/v2.0/saml-core-2.0-os.pdf
type AuthnContext ¶
type AuthnContext struct {
AuthnContextClassRef *AuthnContextClassRef
}
AuthnContext represents the SAML object of the same name.
See http://docs.oasis-open.org/security/saml/v2.0/saml-core-2.0-os.pdf
type AuthnContextClassRef ¶
type AuthnContextClassRef struct {
Value string `xml:",chardata"`
}
AuthnContextClassRef represents the SAML object of the same name.
See http://docs.oasis-open.org/security/saml/v2.0/saml-core-2.0-os.pdf
type AuthnRequest ¶
type AuthnRequest struct {
XMLName xml.Name `xml:"urn:oasis:names:tc:SAML:2.0:protocol AuthnRequest"`
AssertionConsumerServiceURL string `xml:",attr"`
Destination string `xml:",attr"`
ID string `xml:",attr"`
IssueInstant time.Time `xml:",attr"`
ProtocolBinding string `xml:",attr"`
Version string `xml:",attr"`
Issuer Issuer `xml:"urn:oasis:names:tc:SAML:2.0:assertion Issuer"`
Signature *xmlsec.Signature `xml:"http://www.w3.org/2000/09/xmldsig# Signature"`
NameIDPolicy NameIDPolicy `xml:"urn:oasis:names:tc:SAML:2.0:protocol NameIDPolicy"`
}
AuthnRequest represents the SAML object of the same name, a request from a service provider to authenticate a user.
See http://docs.oasis-open.org/security/saml/v2.0/saml-core-2.0-os.pdf
type AuthnStatement ¶
type AuthnStatement struct {
AuthnInstant time.Time `xml:",attr"`
SessionIndex string `xml:",attr"`
SubjectLocality SubjectLocality
AuthnContext AuthnContext
}
AuthnStatement represents the SAML object of the same name.
See http://docs.oasis-open.org/security/saml/v2.0/saml-core-2.0-os.pdf
type Conditions ¶
type Conditions struct {
NotBefore time.Time `xml:",attr"`
NotOnOrAfter time.Time `xml:",attr"`
AudienceRestriction *AudienceRestriction
}
Conditions represents the SAML object of the same name.
See http://docs.oasis-open.org/security/saml/v2.0/saml-core-2.0-os.pdf
type EncryptedAssertion ¶
EncryptedAssertion represents the SAML object of the same name.
See http://docs.oasis-open.org/security/saml/v2.0/saml-core-2.0-os.pdf
type EncryptionMethod ¶
type EncryptionMethod struct {
Algorithm string `xml:"Algorithm,attr"`
}
EncryptionMethod represents the XMLSEC object of the same name
type Endpoint ¶
type Endpoint struct {
Binding string `xml:"Binding,attr"`
Location string `xml:"Location,attr"`
ResponseLocation string `xml:"ResponseLocation,attr,omitempty"`
}
Endpoint represents the SAML EndpointType object.
See http://docs.oasis-open.org/security/saml/v2.0/saml-metadata-2.0-os.pdf section 2.2.2
type EntitiesDescriptor ¶
type EntitiesDescriptor struct {
XMLName xml.Name `xml:"urn:oasis:names:tc:SAML:2.0:metadata EntitiesDescriptor"`
EntityDescriptor []*Metadata `xml:"urn:oasis:names:tc:SAML:2.0:metadata EntityDescriptor"`
}
EntitiesDescriptor represents the SAML object of the same name.
See http://docs.oasis-open.org/security/saml/v2.0/saml-metadata-2.0-os.pdf section 2.3.1
type IDPSSODescriptor ¶
type IDPSSODescriptor struct {
XMLName xml.Name `xml:"urn:oasis:names:tc:SAML:2.0:metadata IDPSSODescriptor"`
ProtocolSupportEnumeration string `xml:"protocolSupportEnumeration,attr"`
KeyDescriptor []KeyDescriptor `xml:"KeyDescriptor"`
NameIDFormat []string `xml:"NameIDFormat"`
SingleSignOnService []Endpoint `xml:"SingleSignOnService"`
}
IDPSSODescriptor represents the SAML IDPSSODescriptorType object.
See http://docs.oasis-open.org/security/saml/v2.0/saml-metadata-2.0-os.pdf section 2.4.3
type IdentityProvider ¶
type IdentityProvider struct {
KeyFile string
CertFile string
PrivkeyPEM string
PubkeyPEM string
SSOURL string
MetadataURL string
SPMetadataURL string
SPMetadata *Metadata
SPAcsURL string
EntityID string
SecurityOpts
// contains filtered or unexported fields
}
IdentityProvider represents an identity provider.
func (*IdentityProvider) Cert ¶
func (idp *IdentityProvider) Cert() (*pem.Block, error)
Cert returns a *pem.Block value that corresponds to the IdP's certificate.
func (*IdentityProvider) GetSPCertFile ¶
func (idp *IdentityProvider) GetSPCertFile() (string, error)
GetSPCertFile returns a physical path where the SP's certificate can be accessed.
func (*IdentityProvider) GetSPMetadata ¶
func (idp *IdentityProvider) GetSPMetadata() (*Metadata, error)
GetSPMetadata returns a the SP's metadata value
func (*IdentityProvider) Metadata ¶
func (idp *IdentityProvider) Metadata() (*Metadata, error)
Metadata returns a metadata value based on the IdP's data.
func (*IdentityProvider) PrivkeyFile ¶
func (idp *IdentityProvider) PrivkeyFile() (string, error)
PrivkeyFile returns a physical path where the IdP's key can be accessed.
func (*IdentityProvider) PubkeyFile ¶
func (idp *IdentityProvider) PubkeyFile() (string, error)
PubkeyFile returns a physical path where the IdP's public key can be accessed.
type IdpAuthnRequest ¶
type IdpAuthnRequest struct {
IDP *IdentityProvider
HTTPRequest *http.Request
RelayState string
RequestBuffer []byte
Request AuthnRequest
ServiceProviderMetadata *Metadata
ACSEndpoint *IndexedEndpoint
Assertion *Assertion
AssertionBuffer []byte
Response *Response
}
IdpAuthnRequest is used by IdentityProvider to handle a single authentication request.
func (*IdpAuthnRequest) MakeAssertion ¶
func (req *IdpAuthnRequest) MakeAssertion(session *Session) error
MakeAssertion produces a SAML assertion for the given request and assigns it to req.Assertion.
func (*IdpAuthnRequest) MakeResponse ¶
func (req *IdpAuthnRequest) MakeResponse() error
MakeResponse computes the Response field of the IdpAuthnRequest
func (*IdpAuthnRequest) MarshalAssertion ¶
func (req *IdpAuthnRequest) MarshalAssertion() error
MarshalAssertion produces a valid and signed XML assertion.
type IndexedEndpoint ¶
type IndexedEndpoint struct {
Binding string `xml:"Binding,attr"`
Location string `xml:"Location,attr"`
Index int `xml:"index,attr"`
}
IndexedEndpoint represents the SAML IndexedEndpointType object.
See http://docs.oasis-open.org/security/saml/v2.0/saml-metadata-2.0-os.pdf section 2.2.3
type Issuer ¶
type Issuer struct {
XMLName xml.Name `xml:"urn:oasis:names:tc:SAML:2.0:assertion Issuer"`
Format string `xml:",attr"`
Value string `xml:",chardata"`
}
Issuer represents the SAML object of the same name.
See http://docs.oasis-open.org/security/saml/v2.0/saml-core-2.0-os.pdf
type KeyDescriptor ¶
type KeyDescriptor struct {
Use string `xml:"use,attr"`
KeyInfo KeyInfo `xml:"http://www.w3.org/2000/09/xmldsig# KeyInfo"`
EncryptionMethods []EncryptionMethod `xml:"EncryptionMethod"`
}
KeyDescriptor represents the XMLSEC object of the same name
type KeyInfo ¶
type KeyInfo struct {
XMLName xml.Name `xml:"http://www.w3.org/2000/09/xmldsig# KeyInfo"`
Certificate string `xml:"X509Data>X509Certificate"`
}
KeyInfo represents the XMLSEC object of the same name
type Logger ¶ added in v0.9.1
type Logger interface {
Printf(s string, v ...interface{})
Print(v ...interface{})
Fatalf(s string, v ...interface{})
Fatal(v ...interface{})
}
Logger provides methods for request logging and debugging.
type Metadata ¶
type Metadata struct {
XMLName xml.Name `xml:"urn:oasis:names:tc:SAML:2.0:metadata EntityDescriptor"`
ValidUntil time.Time `xml:"validUntil,attr"`
CacheDuration time.Duration `xml:"cacheDuration,attr,omitempty"`
EntityID string `xml:"entityID,attr"`
SPSSODescriptor *SPSSODescriptor `xml:"SPSSODescriptor"`
IDPSSODescriptor *IDPSSODescriptor `xml:"IDPSSODescriptor"`
}
Metadata represents the SAML EntityDescriptor object.
See http://docs.oasis-open.org/security/saml/v2.0/saml-metadata-2.0-os.pdf section 2.3.2
func GetMetadata ¶
GetMetadata takes the URL of a metadata.xml file, downloads and parses it. Returns a *Metadata value.
type NameID ¶
type NameID struct {
Format string `xml:",attr"`
NameQualifier string `xml:",attr"`
SPNameQualifier string `xml:",attr"`
Value string `xml:",chardata"`
}
NameID represents the SAML object of the same name.
See http://docs.oasis-open.org/security/saml/v2.0/saml-core-2.0-os.pdf
type NameIDPolicy ¶
type NameIDPolicy struct {
XMLName xml.Name `xml:"urn:oasis:names:tc:SAML:2.0:protocol NameIDPolicy"`
AllowCreate bool `xml:",attr"`
Format string `xml:",chardata"`
}
NameIDPolicy represents the SAML object of the same name.
See http://docs.oasis-open.org/security/saml/v2.0/saml-core-2.0-os.pdf
type Response ¶
type Response struct {
XMLName xml.Name `xml:"urn:oasis:names:tc:SAML:2.0:protocol Response"`
Destination string `xml:",attr"`
ID string `xml:",attr"`
InResponseTo string `xml:",attr"`
IssueInstant time.Time `xml:",attr"`
Version string `xml:",attr"`
Issuer *Issuer `xml:"urn:oasis:names:tc:SAML:2.0:assertion Issuer"`
Status *Status `xml:"urn:oasis:names:tc:SAML:2.0:protocol Status"`
EncryptedAssertion *EncryptedAssertion
Assertion *Assertion `xml:"urn:oasis:names:tc:SAML:2.0:assertion Assertion"`
}
Response represents the SAML object of the same name.
See http://docs.oasis-open.org/security/saml/v2.0/saml-core-2.0-os.pdf
type SPSSODescriptor ¶
type SPSSODescriptor struct {
XMLName xml.Name `xml:"urn:oasis:names:tc:SAML:2.0:metadata SPSSODescriptor"`
AuthnRequestsSigned bool `xml:",attr"`
WantAssertionsSigned bool `xml:",attr"`
ProtocolSupportEnumeration string `xml:"protocolSupportEnumeration,attr"`
KeyDescriptor []KeyDescriptor `xml:"KeyDescriptor"`
ArtifactResolutionService []IndexedEndpoint `xml:"ArtifactResolutionService"`
SingleLogoutService []Endpoint `xml:"SingleLogoutService"`
ManageNameIDService []Endpoint
NameIDFormat []string `xml:"NameIDFormat"`
AssertionConsumerService []IndexedEndpoint `xml:"AssertionConsumerService"`
AttributeConsumingService []interface{}
}
SPSSODescriptor represents the SAML SPSSODescriptorType object.
See http://docs.oasis-open.org/security/saml/v2.0/saml-metadata-2.0-os.pdf section 2.4.2
type SecurityOpts ¶
SecurityOpts allows to bypass some security checks.
type ServiceProvider ¶
type ServiceProvider struct {
IdPMetadataURL string
IdPMetadataXML []byte
IdPMetadata *Metadata
KeyFile string
CertFile string
PrivkeyPEM string
PubkeyPEM string
MetadataURL string
AcsURL string
AllowIdpInitiated bool
SecurityOpts
// contains filtered or unexported fields
}
ServiceProvider represents a service provider.
func (*ServiceProvider) Cert ¶
func (sp *ServiceProvider) Cert() (*pem.Block, error)
Cert returns a *pem.Block value that corresponds to the SP's certificate.
func (*ServiceProvider) GetIdPAuthResource ¶
func (sp *ServiceProvider) GetIdPAuthResource() (string, error)
GetIdPAuthResource returns the authentication URL for the SP.
func (*ServiceProvider) GetIdPCertFile ¶
func (sp *ServiceProvider) GetIdPCertFile() (string, error)
GetIdPCertFile returns a physical path where the IdP certificate can be accessed.
func (*ServiceProvider) GetIdPMetadata ¶
func (sp *ServiceProvider) GetIdPMetadata() (*Metadata, error)
GetIdPMetadata returns the IdP metadata value.
func (*ServiceProvider) MakeAuthenticationRequest ¶
func (sp *ServiceProvider) MakeAuthenticationRequest(idpURL string) (*AuthnRequest, error)
MakeAuthenticationRequest produces a new AuthnRequest object for the given idpURL.
func (*ServiceProvider) Metadata ¶
func (sp *ServiceProvider) Metadata() (*Metadata, error)
Metadata returns a metadata value based on the SP's data.
func (*ServiceProvider) PrivkeyFile ¶
func (sp *ServiceProvider) PrivkeyFile() (string, error)
PrivkeyFile returns a physical path where the SP's key can be accessed.
func (*ServiceProvider) PubkeyFile ¶
func (sp *ServiceProvider) PubkeyFile() (string, error)
PubkeyFile returns a physical path where the SP's public certificate can be accessed.
type Session ¶
type Session struct {
ID string
CreateTime time.Time
ExpireTime time.Time
Index string
NameID string
Groups []string
UserID string
UserFullname string
UserName string
UserEmail string
UserCommonName string
UserSurname string
UserGivenName string
}
Session represents a user session. It is returned by the SessionProvider implementation's GetSession method. Fields here are used to set fields in the SAML assertion.
type Status ¶
type Status struct {
XMLName xml.Name `xml:"urn:oasis:names:tc:SAML:2.0:protocol Status"`
StatusCode StatusCode
}
Status represents the SAML object of the same name.
See http://docs.oasis-open.org/security/saml/v2.0/saml-core-2.0-os.pdf
type StatusCode ¶
type StatusCode struct {
XMLName xml.Name `xml:"urn:oasis:names:tc:SAML:2.0:protocol StatusCode"`
Value string `xml:",attr"`
}
StatusCode represents the SAML object of the same name.
See http://docs.oasis-open.org/security/saml/v2.0/saml-core-2.0-os.pdf
type Subject ¶
type Subject struct {
XMLName xml.Name `xml:"urn:oasis:names:tc:SAML:2.0:assertion Subject"`
NameID *NameID
SubjectConfirmation *SubjectConfirmation
}
Subject represents the SAML object of the same name.
See http://docs.oasis-open.org/security/saml/v2.0/saml-core-2.0-os.pdf
type SubjectConfirmation ¶
type SubjectConfirmation struct {
Method string `xml:",attr"`
SubjectConfirmationData SubjectConfirmationData
}
SubjectConfirmation represents the SAML object of the same name.
See http://docs.oasis-open.org/security/saml/v2.0/saml-core-2.0-os.pdf
type SubjectConfirmationData ¶
type SubjectConfirmationData struct {
Address string `xml:",attr"`
InResponseTo string `xml:",attr"`
NotOnOrAfter time.Time `xml:",attr"`
Recipient string `xml:",attr"`
}
SubjectConfirmationData represents the SAML object of the same name.
See http://docs.oasis-open.org/security/saml/v2.0/saml-core-2.0-os.pdf
type SubjectLocality ¶
type SubjectLocality struct {
Address string `xml:",attr"`
}
SubjectLocality represents the SAML object of the same name.
See http://docs.oasis-open.org/security/saml/v2.0/saml-core-2.0-os.pdf
type UserRequest ¶ added in v0.9.1
type UserRequest struct {
Context context.Context
RemoteAddr string
Method string
RequestURI string
Header http.Header
Form string
Body string
}
UserRequest represents a request submitted from an user.
func InspectRequest ¶ added in v0.9.1
func InspectRequest(r *http.Request) *UserRequest
InspectRequest creates a *UserRequest from a *http.Request
func (UserRequest) String ¶ added in v0.9.1
func (ur UserRequest) String() string
String returns a formatted log with the user request, useful for debugging.
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
_example
|
|
|
servers/idp-server
command
|
|
|
servers/sp-server
command
|
|
|
middleware
|
|
|
idp
Package idp provides an IdP middleware useful for different tasks such as serving metatada, processing an assertion or initiating a login request against a SP.
|
Package idp provides an IdP middleware useful for different tasks such as serving metatada, processing an assertion or initiating a login request against a SP. |
|
sp
Package sp provides tools for buildin an SP such as serving metadata, authenticating an assertion and building assertions for IdPs.
|
Package sp provides tools for buildin an SP such as serving metadata, authenticating an assertion and building assertions for IdPs. |
|
Package xmlsec is a wrapper around the xmlsec1 command https://www.aleksey.com/xmlsec/index.html
|
Package xmlsec is a wrapper around the xmlsec1 command https://www.aleksey.com/xmlsec/index.html |
