forked from mikemacd/go-saml
-
Notifications
You must be signed in to change notification settings - Fork 0
/
iDPEntityDescriptor.go
108 lines (102 loc) · 2.56 KB
/
iDPEntityDescriptor.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
package saml
import (
"encoding/xml"
"fmt"
)
func (s *ServiceProviderSettings) GetEntityDescriptor() (string, error) {
d := EntityDescriptor{
XMLName: xml.Name{
Local: "md:EntityDescriptor",
},
DS: "http://www.w3.org/2000/09/xmldsig#",
XMLNS: "urn:oasis:names:tc:SAML:2.0:metadata",
MD: "urn:oasis:names:tc:SAML:2.0:metadata",
EntityId: s.AssertionConsumerServiceURL,
Extensions: Extensions{
XMLName: xml.Name{
Local: "md:Extensions",
},
Alg: "urn:oasis:names:tc:SAML:metadata:algsupport",
MDAttr: "urn:oasis:names:tc:SAML:metadata:attribute",
MDRPI: "urn:oasis:names:tc:SAML:metadata:rpi",
},
SPSSODescriptor: SPSSODescriptor{
ProtocolSupportEnumeration: "urn:oasis:names:tc:SAML:2.0:protocol",
SigningKeyDescriptor: KeyDescriptor{
XMLName: xml.Name{
Local: "md:KeyDescriptor",
},
Use: "signing",
KeyInfo: KeyInfo{
XMLName: xml.Name{
Local: "ds:KeyInfo",
},
X509Data: X509Data{
XMLName: xml.Name{
Local: "ds:X509Data",
},
X509Certificate: X509Certificate{
XMLName: xml.Name{
Local: "ds:X509Certificate",
},
Cert: s.PublicCert(),
},
},
},
},
EncryptionKeyDescriptor: KeyDescriptor{
XMLName: xml.Name{
Local: "md:KeyDescriptor",
},
Use: "encryption",
KeyInfo: KeyInfo{
XMLName: xml.Name{
Local: "ds:KeyInfo",
},
X509Data: X509Data{
XMLName: xml.Name{
Local: "ds:X509Data",
},
X509Certificate: X509Certificate{
XMLName: xml.Name{
Local: "ds:X509Certificate",
},
Cert: s.PublicCert(),
},
},
},
},
// SingleLogoutService{
// XMLName: xml.Name{
// Local: "md:SingleLogoutService",
// },
// Binding: "urn:oasis:names:tc:SAML:2.0:bindings:HTTP-Redirect",
// Location: "---TODO---",
// },
AssertionConsumerServices: []AssertionConsumerService{
{
XMLName: xml.Name{
Local: "md:AssertionConsumerService",
},
Binding: "urn:oasis:names:tc:SAML:2.0:bindings:HTTP-POST",
Location: s.AssertionConsumerServiceURL,
Index: "0",
},
{
XMLName: xml.Name{
Local: "md:AssertionConsumerService",
},
Binding: "urn:oasis:names:tc:SAML:2.0:bindings:HTTP-Artifact",
Location: s.AssertionConsumerServiceURL,
Index: "1",
},
},
},
}
b, err := xml.MarshalIndent(d, "", " ")
if err != nil {
return "", err
}
newMetadata := fmt.Sprintf("<?xml version='1.0' encoding='UTF-8'?>\n%s", b)
return string(newMetadata), nil
}