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
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ module github.com/crewjam/saml
go 1.22

require (
github.com/golang-jwt/jwt/v5 v5.2.2
github.com/beevik/etree v1.5.0
github.com/golang-jwt/jwt/v5 v5.2.2
github.com/google/go-cmp v0.7.0
github.com/mattermost/xml-roundtrip-validator v0.1.0
github.com/russellhaering/goxmldsig v1.4.0
Expand Down
11 changes: 10 additions & 1 deletion service_provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -1812,6 +1812,10 @@ func findChild(parentEl *etree.Element, childNS string, childTag string) (*etree
func elementToBytes(el *etree.Element) ([]byte, error) {
namespaces := map[string]string{}
for _, childEl := range el.FindElements("//*") {
if el.Tag != childEl.Tag {
continue
}

ns := childEl.NamespaceURI()
if ns != "" {
namespaces[childEl.Space] = ns
Expand All @@ -1821,7 +1825,11 @@ func elementToBytes(el *etree.Element) ([]byte, error) {
doc := etree.NewDocument()
doc.SetRoot(el.Copy())
for space, uri := range namespaces {
doc.Root().CreateAttr("xmlns:"+space, uri)
if space == "" {
doc.Root().CreateAttr("xmlns", uri)
} else {
doc.Root().CreateAttr("xmlns:"+space, uri)
}
}

return doc.WriteToBytes()
Expand All @@ -1833,6 +1841,7 @@ func unmarshalElement(el *etree.Element, v interface{}) error {
if err != nil {
return err
}

return xml.Unmarshal(buf, v)
}

Expand Down