-
Notifications
You must be signed in to change notification settings - Fork 2
/
util.go
94 lines (80 loc) · 1.72 KB
/
util.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
package prompt
import "strings"
const (
None = "none"
Login = "login"
Consent = "consent"
SelectAccount = "select_account"
)
type NoConsentPromptPolicy int
const (
NoConsentPromptPolicyForceConsent NoConsentPromptPolicy = iota
NoConsentPromptPolicyOmitConsentIfCan
)
type NonePromptPolicy int
const (
NonePromptPolicyForbidden NonePromptPolicy = iota
NonePromptPolicyAllowWithLoginSession
NonePromptPolicyAllowIfLoginHintMatched
NonePromptPolicyAllowIfIdTokenHintMatched
)
func Split(prompts string) []string {
return strings.Split(prompts, " ")
}
func IncludeAll(prompts string, targetPrompts []string) (bool, string) {
list := Split(prompts)
existanceMap := make(map[string]bool, 0)
for _, p := range list {
existanceMap[p] = true
}
for _, p := range targetPrompts {
if _, exists := existanceMap[p]; !exists {
return false, p
}
}
return true, ""
}
func Include(prompts string, target string) bool {
list := Split(prompts)
for _, s := range list {
if s == target {
return true
}
}
return false
}
func Validate(prompts string) bool {
list := Split(prompts)
hasNone := false
hasOther := false
for _, p := range list {
switch p {
case None:
hasNone = true
case Login:
hasOther = true
case Consent:
hasOther = true
case SelectAccount:
hasOther = true
default:
return false
}
}
if hasNone && hasOther {
return false
}
return true
}
func IncludeNone(prompts string) bool {
return Include(prompts, None)
}
func IncludeLogin(prompts string) bool {
return Include(prompts, Login)
}
func IncludeConsent(prompts string) bool {
return Include(prompts, Consent)
}
func IncludeSelectAccount(prompts string) bool {
return Include(prompts, SelectAccount)
}