forked from RobotsAndPencils/go-saml
-
Notifications
You must be signed in to change notification settings - Fork 0
/
metadata.go
36 lines (34 loc) · 849 Bytes
/
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
package saml
import (
"crypto/x509"
"encoding/base64"
"encoding/xml"
)
func ParseIDPMetadata(metadata []byte) (string, *x509.Certificate, error) {
s := EntityDescriptor{}
idPSSOURL := ""
err := xml.Unmarshal(metadata, &s)
if err != nil {
return "", nil, err
}
for _, entry := range s.IDPSSODescriptor.SSOService {
if entry.Binding == "urn:oasis:names:tc:SAML:2.0:bindings:HTTP-POST" {
idPSSOURL = entry.Location
break
}
}
for _, entry := range s.IDPSSODescriptor.KeyDescriptor {
if entry.Use == "signing" {
certstr, err := base64.StdEncoding.DecodeString(entry.KeyInfo.X509Data.X509Certificate.Cert)
if err != nil {
return "", nil, err
}
cert, err := x509.ParseCertificate([]byte(certstr))
if err != nil {
return "", nil, err
}
return idPSSOURL, cert, nil
}
}
return idPSSOURL, nil, nil
}