/
authplugins.go
91 lines (77 loc) · 3.05 KB
/
authplugins.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
package kong
import (
"encoding/json"
)
const (
BasicAuthPlugin = "basic-auth"
KeyAuthPlugin = "key-auth"
OAuthPlugin = "oauth2"
)
type OAuthPluginConfig struct {
HideCredentials bool `json:"hide_credentials,omitempty"`
PersistentRefreshToken bool `json:"persistent_refresh_token,omitempty"`
ProvisionKey string `json:"provision_key,omitempty"`
RefreshTokenTTL int64 `json:"refresh_token_ttl,omitempty"`
TokenExpiration int64 `json:"token_expiration,omitempty"`
AcceptHTTPIfAlreadyTerminated bool `json:"accept_http_if_already_terminated,omitempty"`
AuthHeaderName string `json:"auth_header_name,omitempty"`
MandatoryScope bool `json:"mandatory_scope,omitempty"`
Scopes []string `json:"scopes,omitempty"`
PKCE string `json:"pkce,omitempty"`
ReuseRefreshToken bool `json:"reuse_refresh_token,omitempty"`
EnablePasswordGrant bool `json:"enable_password_grant,omitempty"`
EnableClientCredentials bool `json:"enable_client_credentials,omitempty"`
GlobalCredentials bool `json:"global_credentials,omitempty"`
Anonymous string `json:"anonymous,omitempty"`
EnableImplicitGrant bool `json:"enable_implicit_grant,omitempty"`
EnableAuthorizationCode bool `json:"enable_authorization_code,omitempty"`
}
func NewOAuthPluginConfigFromMap(mapData map[string]interface{}) (*OAuthPluginConfig, error) {
// Convert map to json string
jsonStr, err := json.Marshal(mapData)
if err != nil {
return nil, err
}
config := &OAuthPluginConfig{}
if err := json.Unmarshal(jsonStr, config); err != nil {
return nil, err
}
return config, nil
}
type KeyAuthPluginConfig struct {
KeyInQuery bool `json:"key_in_query,omitempty"`
KeyInHeader bool `json:"key_in_header,omitempty"`
KeyNames []string `json:"key_names,omitempty"`
Anonymous string `json:"anonymous,omitempty"`
RunOnPreflight bool `json:"run_on_preflight,omitempty"`
HideCredentials bool `json:"hide_credentials,omitempty"`
KeyInBody bool `json:"key_in_body,omitempty"`
}
func NewKeyAuthPluginConfigFromMap(mapData map[string]interface{}) (*KeyAuthPluginConfig, error) {
// Convert map to json string
jsonStr, err := json.Marshal(mapData)
if err != nil {
return nil, err
}
config := &KeyAuthPluginConfig{}
if err := json.Unmarshal(jsonStr, config); err != nil {
return nil, err
}
return config, nil
}
type BasicAuthPluginConfig struct {
Anonymous string `json:"anonymous,omitempty"`
HideCredentials bool `json:"hide_credentials,omitempty"`
}
func NewBasicAuthPluginConfigFromMap(mapData map[string]interface{}) (*BasicAuthPluginConfig, error) {
// Convert map to json string
jsonStr, err := json.Marshal(mapData)
if err != nil {
return nil, err
}
config := &BasicAuthPluginConfig{}
if err := json.Unmarshal(jsonStr, config); err != nil {
return nil, err
}
return config, nil
}