-
Notifications
You must be signed in to change notification settings - Fork 3
/
metadata.go
109 lines (103 loc) · 2.94 KB
/
metadata.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
109
// based on https://github.com/RobotsAndPencils/go-saml/metadata.go
package samlplugin
import (
"encoding/base64"
"encoding/xml"
)
func (s *SAMLPlugin) 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: "https://" + s.ServiceProvider.MetadataURL.Hostname() + s.ServiceProvider.MetadataURL.Path,
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{
WantAssertionsSigned: true,
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: base64.StdEncoding.EncodeToString(s.ServiceProvider.Certificate.Raw),
},
},
},
},
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: base64.StdEncoding.EncodeToString(s.ServiceProvider.Certificate.Raw),
},
},
},
},
// 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: "https://" + s.ServiceProvider.MetadataURL.Hostname() + s.ServiceProvider.AcsURL.Path,
Index: "0",
},
},
SingleLogoutService: SingleLogoutService{
XMLName: xml.Name{
Local: "md:SingleLogoutService",
},
Binding: "urn:oasis:names:tc:SAML:2.0:bindings:HTTP-POST",
Location: "https://" + s.ServiceProvider.MetadataURL.Hostname() + s.ServiceProvider.SloURL.Path,
},
},
}
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(b), nil
}