forked from Versent/saml2aws
-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathgossamer3.go
77 lines (63 loc) · 1.96 KB
/
gossamer3.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
package gossamer3
import (
"fmt"
"sort"
"github.com/GESkunkworks/gossamer3/pkg/cfg"
"github.com/GESkunkworks/gossamer3/pkg/creds"
"github.com/GESkunkworks/gossamer3/pkg/provider/pingfed"
)
// ProviderList list of providers with their MFAs
type ProviderList map[string][]string
// MFAsByProvider a list of providers with their respective supported MFAs
var MFAsByProvider = ProviderList{
"Ping": []string{"Auto", "None"}, // automatically detects PingID
//"PingOne": []string{"Auto"}, // automatically detects PingID
}
// Names get a list of provider names
func (mfbp ProviderList) Names() []string {
keys := []string{}
for k := range mfbp {
keys = append(keys, k)
}
sort.Strings(keys)
return keys
}
// Mfas retrieve a sorted list of mfas from the provider list
func (mfbp ProviderList) Mfas(provider string) []string {
mfas := mfbp[provider]
sort.Strings(mfas)
return mfas
}
func (mfbp ProviderList) stringInSlice(a string, list []string) bool {
for _, b := range list {
if b == a {
return true
}
}
return false
}
func invalidMFA(provider string, mfa string) bool {
supportedMfas := MFAsByProvider.Mfas(provider)
return !MFAsByProvider.stringInSlice(mfa, supportedMfas)
}
// SAMLClient client interface
type SAMLClient interface {
Authenticate(loginDetails *creds.LoginDetails) (string, error)
}
// NewSAMLClient create a new SAML client
func NewSAMLClient(idpAccount *cfg.IDPAccount) (SAMLClient, error) {
switch idpAccount.Provider {
case "Ping":
if invalidMFA(idpAccount.Provider, idpAccount.MFA) {
return nil, fmt.Errorf("Invalid MFA type: %v for %v provider", idpAccount.MFA, idpAccount.Provider)
}
return pingfed.New(idpAccount)
//case "PingOne":
// if invalidMFA(idpAccount.Provider, idpAccount.MFA) {
// return nil, fmt.Errorf("Invalid MFA type: %v for %v provider", idpAccount.MFA, idpAccount.Provider)
// }
// return pingone.New(idpAccount)
default:
return nil, fmt.Errorf("Invalid provider: %v", idpAccount.Provider)
}
}