forked from lyokato/goidc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
client.go
95 lines (78 loc) · 1.93 KB
/
client.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
package test_helper
import (
"github.com/lyokato/goidc/flow"
"github.com/lyokato/goidc/prompt"
)
type (
TestClient struct {
id string
ownerId int64
secret string
redirectURI string
idTokenAlg string
idTokenKeyId string
idTokenKey interface{}
grantTypes map[string]bool
Enabled bool
}
)
func NewTestClient(ownerId int64, id, secret, redirectURI, alg string, key interface{}, keyId string) *TestClient {
return &TestClient{
ownerId: ownerId,
id: id,
secret: secret,
redirectURI: redirectURI,
idTokenAlg: alg,
idTokenKey: key,
idTokenKeyId: keyId,
grantTypes: make(map[string]bool, 0),
Enabled: true,
}
}
func (c *TestClient) AllowToUseGrantType(gt string) {
c.grantTypes[gt] = true
}
func (c *TestClient) CanUseFlow(flowType flow.FlowType) bool {
return true
}
func (c *TestClient) CanUseGrantType(gt string) bool {
allowed, exists := c.grantTypes[gt]
if exists {
return allowed
} else {
return false
}
}
func (c *TestClient) CanUseRedirectURI(url string) bool {
return (c.redirectURI == url)
}
func (c *TestClient) CanUseScope(flowType flow.FlowType, scope string) bool {
return true
}
func (c *TestClient) GetOwnerUserId() int64 {
return c.ownerId
}
func (c *TestClient) GetId() string {
return c.id
}
func (c *TestClient) MatchSecret(secret string) bool {
return c.secret == secret
}
func (c *TestClient) GetIdTokenAlg() string {
return c.idTokenAlg
}
func (c *TestClient) GetIdTokenKeyId() string {
return c.idTokenKeyId
}
func (c *TestClient) GetIdTokenKey() interface{} {
return c.idTokenKey
}
func (c *TestClient) GetNoConsentPromptPolicy() prompt.NoConsentPromptPolicy {
return prompt.NoConsentPromptPolicyForceConsent
}
func (c *TestClient) GetNonePromptPolicy() prompt.NonePromptPolicy {
return prompt.NonePromptPolicyForbidden
}
func (c *TestClient) GetAssertionKey(alg, kid string) interface{} {
return []byte(c.secret)
}