@@ -11,15 +11,19 @@ import (
11
11
"gopkg.in/oauth2.v3/models"
12
12
)
13
13
14
- // TokenConfig Token Config
14
+ // TokenConfig token configuration parameters
15
15
type TokenConfig struct {
16
- TxnCName string // Store txn collection name(The default is oauth2)
17
- BasicCName string // Store token based data collection name(The default is oauth2_basic)
18
- AccessCName string // Store access token data collection name(The default is oauth2_access)
19
- RefreshCName string // Store refresh token data collection name(The default is oauth2_refresh)
16
+ // store txn collection name(The default is oauth2)
17
+ TxnCName string
18
+ // store token based data collection name(The default is oauth2_basic)
19
+ BasicCName string
20
+ // store access token data collection name(The default is oauth2_access)
21
+ AccessCName string
22
+ // store refresh token data collection name(The default is oauth2_refresh)
23
+ RefreshCName string
20
24
}
21
25
22
- // NewDefaultTokenConfig Create default token config
26
+ // NewDefaultTokenConfig create a default token configuration
23
27
func NewDefaultTokenConfig () * TokenConfig {
24
28
return & TokenConfig {
25
29
TxnCName : "oauth2_txn" ,
@@ -29,7 +33,7 @@ func NewDefaultTokenConfig() *TokenConfig {
29
33
}
30
34
}
31
35
32
- // NewTokenStore Create a token store instance based on mongodb
36
+ // NewTokenStore create a token store instance based on mongodb
33
37
func NewTokenStore (cfg * Config , tcfgs ... * TokenConfig ) (store oauth2.TokenStore , err error ) {
34
38
ts := & TokenStore {
35
39
mcfg : cfg ,
@@ -68,7 +72,7 @@ func NewTokenStore(cfg *Config, tcfgs ...*TokenConfig) (store oauth2.TokenStore,
68
72
return
69
73
}
70
74
71
- // TokenStore MongoDB token store
75
+ // TokenStore MongoDB storage for OAuth 2.0
72
76
type TokenStore struct {
73
77
tcfg * TokenConfig
74
78
mcfg * Config
@@ -86,7 +90,7 @@ func (ts *TokenStore) cHandler(name string, handler func(c *mgo.Collection)) {
86
90
return
87
91
}
88
92
89
- // Create Create and store the new token information
93
+ // Create create and store the new token information
90
94
func (ts * TokenStore ) Create (info oauth2.TokenInfo ) (err error ) {
91
95
jv , err := json .Marshal (info )
92
96
if err != nil {
@@ -148,7 +152,7 @@ func (ts *TokenStore) Create(info oauth2.TokenInfo) (err error) {
148
152
return
149
153
}
150
154
151
- // RemoveByCode Use the authorization code to delete the token information
155
+ // RemoveByCode use the authorization code to delete the token information
152
156
func (ts * TokenStore ) RemoveByCode (code string ) (err error ) {
153
157
ts .cHandler (ts .tcfg .BasicCName , func (c * mgo.Collection ) {
154
158
verr := c .RemoveId (code )
@@ -162,7 +166,7 @@ func (ts *TokenStore) RemoveByCode(code string) (err error) {
162
166
return
163
167
}
164
168
165
- // RemoveByAccess Use the access token to delete the token information
169
+ // RemoveByAccess use the access token to delete the token information
166
170
func (ts * TokenStore ) RemoveByAccess (access string ) (err error ) {
167
171
ts .cHandler (ts .tcfg .AccessCName , func (c * mgo.Collection ) {
168
172
verr := c .RemoveId (access )
@@ -176,7 +180,7 @@ func (ts *TokenStore) RemoveByAccess(access string) (err error) {
176
180
return
177
181
}
178
182
179
- // RemoveByRefresh Use the refresh token to delete the token information
183
+ // RemoveByRefresh use the refresh token to delete the token information
180
184
func (ts * TokenStore ) RemoveByRefresh (refresh string ) (err error ) {
181
185
ts .cHandler (ts .tcfg .RefreshCName , func (c * mgo.Collection ) {
182
186
verr := c .RemoveId (refresh )
@@ -227,13 +231,13 @@ func (ts *TokenStore) getBasicID(cname, token string) (basicID string, err error
227
231
return
228
232
}
229
233
230
- // GetByCode Use the authorization code for token information data
234
+ // GetByCode use the authorization code for token information data
231
235
func (ts * TokenStore ) GetByCode (code string ) (ti oauth2.TokenInfo , err error ) {
232
236
ti , err = ts .getData (code )
233
237
return
234
238
}
235
239
236
- // GetByAccess Use the access token for token information data
240
+ // GetByAccess use the access token for token information data
237
241
func (ts * TokenStore ) GetByAccess (access string ) (ti oauth2.TokenInfo , err error ) {
238
242
basicID , err := ts .getBasicID (ts .tcfg .AccessCName , access )
239
243
if err != nil && basicID == "" {
@@ -243,7 +247,7 @@ func (ts *TokenStore) GetByAccess(access string) (ti oauth2.TokenInfo, err error
243
247
return
244
248
}
245
249
246
- // GetByRefresh Use the refresh token for token information data
250
+ // GetByRefresh use the refresh token for token information data
247
251
func (ts * TokenStore ) GetByRefresh (refresh string ) (ti oauth2.TokenInfo , err error ) {
248
252
basicID , err := ts .getBasicID (ts .tcfg .RefreshCName , refresh )
249
253
if err != nil && basicID == "" {
0 commit comments