Skip to content

Commit 9207a5e

Browse files
crewjamhf
andauthored
feat: Fix wrong session attributes (crewjam#598)
* feat: Fix wrong session attributes * supply both eduPersonPrincipalName and mail attributes --------- Co-authored-by: Stojan Dimitrovski <[email protected]>
1 parent 34b084b commit 9207a5e

File tree

2 files changed

+52
-9
lines changed

2 files changed

+52
-9
lines changed

identity_provider.go

Lines changed: 30 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,14 @@ type Session struct {
3838
NameIDFormat string
3939
SubjectID string
4040

41-
Groups []string
42-
UserName string
43-
UserEmail string
44-
UserCommonName string
45-
UserSurname string
46-
UserGivenName string
47-
UserScopedAffiliation string
41+
Groups []string
42+
UserName string
43+
UserEmail string
44+
UserCommonName string
45+
UserSurname string
46+
UserGivenName string
47+
UserScopedAffiliation string
48+
EduPersonPrincipalName string `json:",omitempty"`
4849

4950
CustomAttributes []Attribute
5051
}
@@ -662,13 +663,33 @@ func (DefaultAssertionMaker) MakeAssertion(req *IdpAuthnRequest, session *Sessio
662663
}
663664

664665
if session.UserEmail != "" {
666+
attributes = append(attributes, Attribute{
667+
FriendlyName: "mail",
668+
Name: "urn:oid:0.9.2342.19200300.100.1.3",
669+
NameFormat: "urn:oasis:names:tc:SAML:2.0:attrname-format:uri",
670+
Values: []AttributeValue{{
671+
Type: "xs:string",
672+
Value: session.UserEmail,
673+
}},
674+
})
675+
}
676+
if session.EduPersonPrincipalName != "" || session.UserEmail != "" {
677+
value := session.EduPersonPrincipalName
678+
if value == "" {
679+
// We used to set eduPersonPrincipalName (urn:oid:1.3.6.1.4.1.5923.1.1.1.6)
680+
// to the value of session.UserEmail. It is more correct to set
681+
// mail (urn:oid:0.9.2342.19200300.100.1.3). To avoid breaking things,
682+
// we preserve the former behavior.
683+
value = session.UserEmail
684+
}
685+
665686
attributes = append(attributes, Attribute{
666687
FriendlyName: "eduPersonPrincipalName",
667688
Name: "urn:oid:1.3.6.1.4.1.5923.1.1.1.6",
668689
NameFormat: "urn:oasis:names:tc:SAML:2.0:attrname-format:uri",
669690
Values: []AttributeValue{{
670691
Type: "xs:string",
671-
Value: session.UserEmail,
692+
Value: value,
672693
}},
673694
})
674695
}
@@ -709,7 +730,7 @@ func (DefaultAssertionMaker) MakeAssertion(req *IdpAuthnRequest, session *Sessio
709730

710731
if session.UserScopedAffiliation != "" {
711732
attributes = append(attributes, Attribute{
712-
FriendlyName: "uid",
733+
FriendlyName: "scopedAffiliation",
713734
Name: "urn:oid:1.3.6.1.4.1.5923.1.1.1.9",
714735
NameFormat: "urn:oasis:names:tc:SAML:2.0:attrname-format:uri",
715736
Values: []AttributeValue{{

identity_provider_test.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -605,6 +605,17 @@ func TestIDPMakeAssertion(t *testing.T) {
605605
},
606606
},
607607
},
608+
{
609+
FriendlyName: "mail",
610+
Name: "urn:oid:0.9.2342.19200300.100.1.3",
611+
NameFormat: "urn:oasis:names:tc:SAML:2.0:attrname-format:uri",
612+
Values: []AttributeValue{
613+
{
614+
Type: "xs:string",
615+
616+
},
617+
},
618+
},
608619
{
609620
FriendlyName: "eduPersonPrincipalName",
610621
Name: "urn:oid:1.3.6.1.4.1.5923.1.1.1.6",
@@ -978,6 +989,17 @@ func TestIDPRequestedAttributes(t *testing.T) {
978989
},
979990
},
980991
},
992+
{
993+
FriendlyName: "mail",
994+
Name: "urn:oid:0.9.2342.19200300.100.1.3",
995+
NameFormat: "urn:oasis:names:tc:SAML:2.0:attrname-format:uri",
996+
Values: []AttributeValue{
997+
{
998+
Type: "xs:string",
999+
1000+
},
1001+
},
1002+
},
9811003
{
9821004
FriendlyName: "eduPersonPrincipalName",
9831005
Name: "urn:oid:1.3.6.1.4.1.5923.1.1.1.6",

0 commit comments

Comments
 (0)