Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion identity_provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,10 @@ type IdentityProvider struct {
SignatureMethod string
ValidDuration *time.Duration
ResponseFormTemplate *template.Template

// NameIDFormats are the NameID formats advertised in the IdP metadata.
// When empty it defaults to the transient format for backwards compatibility.
NameIDFormats []NameIDFormat
}

// Metadata returns the metadata structure for this identity provider.
Expand All @@ -123,6 +127,11 @@ func (idp *IdentityProvider) Metadata() *EntityDescriptor {
validDuration = DefaultValidDuration
}

nameIDFormats := idp.NameIDFormats
if len(nameIDFormats) == 0 {
nameIDFormats = []NameIDFormat{NameIDFormat("urn:oasis:names:tc:SAML:2.0:nameid-format:transient")}
}

ed := &EntityDescriptor{
EntityID: idp.MetadataURL.String(),
ValidUntil: TimeNow().Add(validDuration),
Expand Down Expand Up @@ -161,7 +170,7 @@ func (idp *IdentityProvider) Metadata() *EntityDescriptor {
},
},
},
NameIDFormats: []NameIDFormat{NameIDFormat("urn:oasis:names:tc:SAML:2.0:nameid-format:transient")},
NameIDFormats: nameIDFormats,
},
SingleSignOnServices: []Endpoint{
{
Expand Down
10 changes: 10 additions & 0 deletions identity_provider_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,16 @@
assert.Check(t, is.DeepEqual(expected, test.IDP.Metadata()))
}

func TestIDPCanAdvertiseCustomNameIDFormats(t *testing.T) {
test := NewIdentityProviderTest(t, applyKey)
test.IDP.NameIDFormats = []NameIDFormat{
NameIDFormat("urn:oasis:names:tc:SAML:1.1:nameid-format:emailAddress"),
NameIDFormat("urn:oasis:names:tc:SAML:2.0:nameid-format:persistent"),
}
got := test.IDP.Metadata().IDPSSODescriptors[0].NameIDFormats
assert.Check(t, is.DeepEqual(test.IDP.NameIDFormats, got))
}

func TestIDPHTTPCanHandleMetadataRequest(t *testing.T) {
test := NewIdentityProviderTest(t, applyKey)
w := httptest.NewRecorder()
Expand Down Expand Up @@ -1106,7 +1116,7 @@
encoded := base64.StdEncoding.EncodeToString(compressed.Bytes())

r, _ := http.NewRequest("GET", "/dontcare?"+url.Values{
"SAMLRequest": {encoded},

Check failure on line 1119 in identity_provider_test.go

View workflow job for this annotation

GitHub Actions / golangci

missing type in composite literal (typecheck)
}.Encode(), nil)
_, err = NewIdpAuthnRequest(&test.IDP, r)
assert.Error(t, err, "cannot decompress request: flate: uncompress limit exceeded (10485760 bytes)")
Expand Down
Loading