Skip to content

Commit 4966437

Browse files
committed
Respect SP choice for NameID, and create test users separately
1 parent 8711f75 commit 4966437

File tree

4 files changed

+8
-33
lines changed

4 files changed

+8
-33
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ coverage.html
33
vendor/
44
**/*.cert
55
**/*.key
6+
example/*.sh
67

78
# IDE-specific settings
89
.idea

example/idp/go.mod

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,14 @@ go 1.23
44

55
toolchain go1.24.2
66

7-
require (
8-
github.com/crewjam/saml v0.5.1
9-
golang.org/x/crypto v0.33.0
10-
)
7+
require github.com/crewjam/saml v0.5.1
118

129
require (
1310
github.com/beevik/etree v1.5.0 // indirect
1411
github.com/jonboulle/clockwork v0.2.2 // indirect
1512
github.com/mattermost/xml-roundtrip-validator v0.1.0 // indirect
1613
github.com/russellhaering/goxmldsig v1.4.0 // indirect
14+
golang.org/x/crypto v0.33.0 // indirect
1715
)
1816

1917
// Replace the remote saml module with your local version

example/idp/idp.go

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@ import (
88
"net/http"
99
"net/url"
1010

11-
"golang.org/x/crypto/bcrypt"
12-
1311
"github.com/crewjam/saml/logger"
1412
"github.com/crewjam/saml/samlidp"
1513
)
@@ -47,31 +45,5 @@ func main() {
4745
logr.Fatalf("%s", err)
4846
}
4947

50-
hashedPassword, _ := bcrypt.GenerateFromPassword([]byte("hunter2"), bcrypt.DefaultCost)
51-
err = idpServer.Store.Put("/users/alice", samlidp.User{Name: "alice",
52-
HashedPassword: hashedPassword,
53-
Groups: []string{"Administrators", "Users"},
54-
55-
CommonName: "Alice Smith",
56-
Surname: "Smith",
57-
GivenName: "Alice",
58-
})
59-
if err != nil {
60-
logr.Fatalf("%s", err)
61-
}
62-
63-
err = idpServer.Store.Put("/users/bob", samlidp.User{
64-
Name: "bob",
65-
HashedPassword: hashedPassword,
66-
Groups: []string{"Users"},
67-
68-
CommonName: "Bob Smith",
69-
Surname: "Smith",
70-
GivenName: "Bob",
71-
})
72-
if err != nil {
73-
logr.Fatalf("%s", err)
74-
}
75-
7648
http.ListenAndServe(":8080", idpServer)
7749
}

identity_provider.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -802,7 +802,11 @@ func (DefaultAssertionMaker) MakeAssertion(req *IdpAuthnRequest, session *Sessio
802802

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

805-
if session.NameIDFormat != "" {
805+
// Check if the SP has requested a specific NameID format in the AuthnRequest
806+
if req.Request.NameIDPolicy != nil && req.Request.NameIDPolicy.Format != nil {
807+
nameIDFormat = *req.Request.NameIDPolicy.Format
808+
} else if session.NameIDFormat != "" {
809+
// Fall back to session's format if available
806810
nameIDFormat = session.NameIDFormat
807811
}
808812

0 commit comments

Comments
 (0)