Skip to content

Commit

Permalink
feat: Add Subject ID attribute support
Browse files Browse the repository at this point in the history
  • Loading branch information
hf committed Aug 14, 2022
1 parent 5e0ffd2 commit 28f5bcf
Showing 1 changed file with 24 additions and 2 deletions.
26 changes: 24 additions & 2 deletions identity_provider.go
Expand Up @@ -36,7 +36,10 @@ type Session struct {
ExpireTime time.Time
Index string

NameID string
NameID string
NameIDFormat string
SubjectID string

Groups []string
UserName string
UserEmail string
Expand Down Expand Up @@ -734,6 +737,19 @@ func (DefaultAssertionMaker) MakeAssertion(req *IdpAuthnRequest, session *Sessio
})
}

if session.SubjectID != "" {
attributes = append(attributes, Attribute{
Name: "urn:oasis:names:tc:SAML:attribute:subject-id",
NameFormat: "urn:oasis:names:tc:SAML:2.0:attrname-format:uri",
Values: []AttributeValue{
{
Type: "xs:string",
Value: session.SubjectID,
},
},
})
}

// allow for some clock skew in the validity period using the
// issuer's apparent clock.
notBefore := req.Now.Add(-1 * MaxClockSkew)
Expand All @@ -743,6 +759,12 @@ func (DefaultAssertionMaker) MakeAssertion(req *IdpAuthnRequest, session *Sessio
notOnOrAfterAfter = notBefore.Add(MaxIssueDelay)
}

nameIDFormat := "urn:oasis:names:tc:SAML:2.0:nameid-format:transient"

if session.NameIDFormat != "" {
nameIDFormat = session.NameIDFormat
}

req.Assertion = &Assertion{
ID: fmt.Sprintf("id-%x", randomBytes(20)),
IssueInstant: TimeNow(),
Expand All @@ -753,7 +775,7 @@ func (DefaultAssertionMaker) MakeAssertion(req *IdpAuthnRequest, session *Sessio
},
Subject: &Subject{
NameID: &NameID{
Format: "urn:oasis:names:tc:SAML:2.0:nameid-format:transient",
Format: nameIDFormat,
NameQualifier: req.IDP.Metadata().EntityID,
SPNameQualifier: req.ServiceProviderMetadata.EntityID,
Value: session.NameID,
Expand Down

0 comments on commit 28f5bcf

Please sign in to comment.