-
Notifications
You must be signed in to change notification settings - Fork 9
/
app.go
183 lines (150 loc) · 8.11 KB
/
app.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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
package mem
import (
"github.com/madappgang/identifo/model"
)
// AppData is an in-memory model for model.AppData.
type AppData struct {
appData
}
type appData struct {
ID string `json:"id,omitempty"`
Secret string `json:"secret,omitempty"`
Active bool `json:"active"`
Name string `json:"name,omitempty"`
Description string `json:"description,omitempty"`
Scopes []string `json:"scopes,omitempty"`
Offline bool `json:"offline"`
Type model.AppType `json:"type,omitempty"`
RedirectURLs []string `json:"redirect_urls,omitempty"`
RefreshTokenLifespan int64 `json:"refresh_token_lifespan,omitempty"`
InviteTokenLifespan int64 `json:"invite_token_lifespan,omitempty"`
TokenLifespan int64 `json:"token_lifespan,omitempty"`
TokenPayload []string `json:"token_payload,omitempty"`
RegistrationForbidden bool `json:"registration_forbidden"`
AnonymousRegistrationAllowed bool `json:"anonymous_registration_allowed"`
TFAStatus model.TFAStatus `json:"tfa_status"`
DebugTFACode string `json:"debug_tfa_code,omitempty"`
AuthorizationWay model.AuthorizationWay `json:"authorization_way,omitempty"`
AuthorizationModel string `json:"authorization_model,omitempty"`
AuthorizationPolicy string `json:"authorization_policy,omitempty"`
RolesWhitelist []string `json:"roles_whitelist,omitempty"`
RolesBlacklist []string `json:"roles_blacklist,omitempty"`
NewUserDefaultRole string `json:"new_user_default_role,omitempty"`
AppleInfo *model.AppleInfo `json:"apple_info,omitempty"`
}
// NewAppData instantiates app data in-memory model from the general one.
func NewAppData(data model.AppData) AppData {
return AppData{appData: appData{
ID: data.ID(),
Secret: data.Secret(),
Active: data.Active(),
Name: data.Name(),
Description: data.Description(),
Scopes: data.Scopes(),
Offline: data.Offline(),
RedirectURLs: data.RedirectURLs(),
RefreshTokenLifespan: data.RefreshTokenLifespan(),
InviteTokenLifespan: data.InviteTokenLifespan(),
TokenLifespan: data.TokenLifespan(),
TokenPayload: data.TokenPayload(),
RegistrationForbidden: data.RegistrationForbidden(),
AnonymousRegistrationAllowed: data.AnonymousRegistrationAllowed(),
}}
}
// MakeAppData creates new in-memory app data instance.
func MakeAppData(id, secret string, active bool, name, description string, scopes []string, offline bool, redirectURLs []string,
refreshTokenLifespan, inviteTokenLifespan, tokenLifespan int64, tokenPayload []string, registrationForbidden bool, anonymousRegistrationAllowed bool,
tfaStatus model.TFAStatus, debugTFACode string, authzWay model.AuthorizationWay, authzModel, authzPolicy string, rolesWhitelist, rolesBlacklist []string, newUserDefaultRole string) AppData {
return AppData{appData: appData{
ID: id,
Secret: secret,
Active: active,
Name: name,
Description: description,
Scopes: scopes,
Offline: offline,
RedirectURLs: redirectURLs,
RefreshTokenLifespan: refreshTokenLifespan,
InviteTokenLifespan: inviteTokenLifespan,
TokenLifespan: tokenLifespan,
TokenPayload: tokenPayload,
RegistrationForbidden: registrationForbidden,
AnonymousRegistrationAllowed: anonymousRegistrationAllowed,
TFAStatus: tfaStatus,
DebugTFACode: debugTFACode,
AuthorizationWay: authzWay,
AuthorizationModel: authzModel,
AuthorizationPolicy: authzPolicy,
RolesWhitelist: rolesWhitelist,
RolesBlacklist: rolesBlacklist,
NewUserDefaultRole: newUserDefaultRole,
}}
}
// ID implements model.AppData interface.
func (ad *AppData) ID() string { return ad.appData.ID }
// Secret implements model.AppData interface.
func (ad *AppData) Secret() string { return ad.appData.Secret }
// Active implements model.AppData interface.
func (ad *AppData) Active() bool { return ad.appData.Active }
// Name implements model.AppData interface.
func (ad *AppData) Name() string { return ad.appData.Name }
// Description implements model.AppData interface.
func (ad *AppData) Description() string { return ad.appData.Description }
// Scopes implements model.AppData interface.
func (ad *AppData) Scopes() []string { return ad.appData.Scopes }
// Offline implements model.AppData interface.
func (ad *AppData) Offline() bool { return ad.appData.Offline }
// Type implements model.AppData interface.
func (ad *AppData) Type() model.AppType { return ad.appData.Type }
// RedirectURLs implements model.AppData interface.
func (ad *AppData) RedirectURLs() []string { return ad.appData.RedirectURLs }
// RefreshTokenLifespan implements model.AppData interface.
func (ad *AppData) RefreshTokenLifespan() int64 { return ad.appData.RefreshTokenLifespan }
// InviteTokenLifespan a inviteToken lifespan in seconds, if 0 - default one is used.
func (ad *AppData) InviteTokenLifespan() int64 { return ad.appData.InviteTokenLifespan }
// TokenLifespan implements model.AppData interface.
func (ad *AppData) TokenLifespan() int64 { return ad.appData.TokenLifespan }
// TokenPayload implements model.AppData interface.
func (ad *AppData) TokenPayload() []string { return ad.appData.TokenPayload }
// RegistrationForbidden implements model.AppData interface.
func (ad *AppData) RegistrationForbidden() bool { return ad.appData.RegistrationForbidden }
// AnonymousRegistrationAllowed implements model.AppData interface.
func (ad *AppData) AnonymousRegistrationAllowed() bool { return ad.appData.AnonymousRegistrationAllowed }
// TFAStatus implements model.AppData interface.
func (ad *AppData) TFAStatus() model.TFAStatus { return ad.appData.TFAStatus }
// DebugTFACode implements model.AppData interface.
func (ad *AppData) DebugTFACode() string { return ad.appData.DebugTFACode }
// AuthzWay implements model.AppData interface.
func (ad *AppData) AuthzWay() model.AuthorizationWay { return ad.appData.AuthorizationWay }
// AuthzModel implements model.AppData interface.
func (ad *AppData) AuthzModel() string { return ad.appData.AuthorizationModel }
// AuthzPolicy implements model.AppData interface.
func (ad *AppData) AuthzPolicy() string { return ad.appData.AuthorizationPolicy }
// RolesWhitelist implements model.AppData interface.
func (ad *AppData) RolesWhitelist() []string { return ad.appData.RolesWhitelist }
// RolesBlacklist implements model.AppData interface.
func (ad *AppData) RolesBlacklist() []string { return ad.appData.RolesBlacklist }
// NewUserDefaultRole implements model.AppData interface.
func (ad *AppData) NewUserDefaultRole() string { return ad.appData.NewUserDefaultRole }
// AppleInfo implements model.AppData interface.
func (ad *AppData) AppleInfo() *model.AppleInfo { return ad.appData.AppleInfo }
// SetSecret implements model.AppData interface.
func (ad *AppData) SetSecret(secret string) {
if ad == nil {
return
}
ad.appData.Secret = secret
}
// Sanitize removes all sensitive data.
func (ad *AppData) Sanitize() {
if ad == nil {
return
}
ad.appData.Secret = ""
if ad.appData.AppleInfo != nil {
ad.appData.AppleInfo.ClientSecret = ""
}
ad.appData.AuthorizationWay = ""
ad.appData.AuthorizationModel = ""
ad.appData.AuthorizationPolicy = ""
}