forked from parsable/go-saml
-
Notifications
You must be signed in to change notification settings - Fork 2
/
saml.go
79 lines (67 loc) · 1.81 KB
/
saml.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
package saml
import "github.com/dorsha/go-saml/util"
// ServiceProviderSettings provides settings to configure server acting as a SAML Service Provider.
// Expect only one IDP per SP in this configuration. If you need to configure multipe IDPs for an SP
// then configure multiple instances of this module
type ServiceProviderSettings struct {
PublicCertPath string
PrivateKeyPath string
IDPSSOURL string
IDPSSOLogoutURL string
IDPSSODescriptorURL string
IDPPublicCertPath string
AssertionConsumerServiceURL string
SPLogoutServiceUrl string
SPSignRequest bool
SPVerifyRequest bool
EnabledKeyData string
hasInit bool
publicCert string
privateKey string
iDPPublicCert string
}
type IdentityProviderSettings struct {
}
func (s *ServiceProviderSettings) Init() (err error) {
if s.hasInit {
return nil
}
s.hasInit = true
if s.SPVerifyRequest {
s.iDPPublicCert, err = util.LoadCertificate(s.IDPPublicCertPath)
if err != nil {
return err
}
}
if s.SPSignRequest {
if len(s.PublicCertPath) > 0 {
s.publicCert, err = util.LoadCertificate(s.PublicCertPath)
if err != nil {
return err
}
}
s.privateKey, err = util.LoadCertificate(s.PrivateKeyPath)
if err != nil {
return err
}
}
return nil
}
func (s *ServiceProviderSettings) PublicCert() string {
if !s.hasInit {
panic("Must call ServiceProviderSettings.Init() first")
}
return s.publicCert
}
func (s *ServiceProviderSettings) PrivateKey() string {
if !s.hasInit {
panic("Must call ServiceProviderSettings.Init() first")
}
return s.privateKey
}
func (s *ServiceProviderSettings) IDPPublicCert() string {
if !s.hasInit {
panic("Must call ServiceProviderSettings.Init() first")
}
return s.iDPPublicCert
}