@@ -11,15 +11,19 @@ import (
1111"gopkg.in/oauth2.v3/models"
1212)
1313
14- // TokenConfig Token Config
14+ // TokenConfig token configuration parameters
1515type 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
2024}
2125
22- // NewDefaultTokenConfig Create default token config
26+ // NewDefaultTokenConfig create a default token configuration
2327func NewDefaultTokenConfig () * TokenConfig {
2428return & TokenConfig {
2529TxnCName : "oauth2_txn" ,
@@ -29,7 +33,7 @@ func NewDefaultTokenConfig() *TokenConfig {
2933}
3034}
3135
32- // NewTokenStore Create a token store instance based on mongodb
36+ // NewTokenStore create a token store instance based on mongodb
3337func NewTokenStore (cfg * Config , tcfgs ... * TokenConfig ) (store oauth2.TokenStore , err error ) {
3438ts := & TokenStore {
3539mcfg : cfg ,
@@ -68,7 +72,7 @@ func NewTokenStore(cfg *Config, tcfgs ...*TokenConfig) (store oauth2.TokenStore,
6872return
6973}
7074
71- // TokenStore MongoDB token store
75+ // TokenStore MongoDB storage for OAuth 2.0
7276type TokenStore struct {
7377tcfg * TokenConfig
7478mcfg * Config
@@ -86,7 +90,7 @@ func (ts *TokenStore) cHandler(name string, handler func(c *mgo.Collection)) {
8690return
8791}
8892
89- // Create Create and store the new token information
93+ // Create create and store the new token information
9094func (ts * TokenStore ) Create (info oauth2.TokenInfo ) (err error ) {
9195jv , err := json .Marshal (info )
9296if err != nil {
@@ -148,7 +152,7 @@ func (ts *TokenStore) Create(info oauth2.TokenInfo) (err error) {
148152return
149153}
150154
151- // RemoveByCode Use the authorization code to delete the token information
155+ // RemoveByCode use the authorization code to delete the token information
152156func (ts * TokenStore ) RemoveByCode (code string ) (err error ) {
153157ts .cHandler (ts .tcfg .BasicCName , func (c * mgo.Collection ) {
154158verr := c .RemoveId (code )
@@ -162,7 +166,7 @@ func (ts *TokenStore) RemoveByCode(code string) (err error) {
162166return
163167}
164168
165- // RemoveByAccess Use the access token to delete the token information
169+ // RemoveByAccess use the access token to delete the token information
166170func (ts * TokenStore ) RemoveByAccess (access string ) (err error ) {
167171ts .cHandler (ts .tcfg .AccessCName , func (c * mgo.Collection ) {
168172verr := c .RemoveId (access )
@@ -176,7 +180,7 @@ func (ts *TokenStore) RemoveByAccess(access string) (err error) {
176180return
177181}
178182
179- // RemoveByRefresh Use the refresh token to delete the token information
183+ // RemoveByRefresh use the refresh token to delete the token information
180184func (ts * TokenStore ) RemoveByRefresh (refresh string ) (err error ) {
181185ts .cHandler (ts .tcfg .RefreshCName , func (c * mgo.Collection ) {
182186verr := c .RemoveId (refresh )
@@ -227,13 +231,13 @@ func (ts *TokenStore) getBasicID(cname, token string) (basicID string, err error
227231return
228232}
229233
230- // GetByCode Use the authorization code for token information data
234+ // GetByCode use the authorization code for token information data
231235func (ts * TokenStore ) GetByCode (code string ) (ti oauth2.TokenInfo , err error ) {
232236ti , err = ts .getData (code )
233237return
234238}
235239
236- // GetByAccess Use the access token for token information data
240+ // GetByAccess use the access token for token information data
237241func (ts * TokenStore ) GetByAccess (access string ) (ti oauth2.TokenInfo , err error ) {
238242basicID , err := ts .getBasicID (ts .tcfg .AccessCName , access )
239243if err != nil && basicID == "" {
@@ -243,7 +247,7 @@ func (ts *TokenStore) GetByAccess(access string) (ti oauth2.TokenInfo, err error
243247return
244248}
245249
246- // GetByRefresh Use the refresh token for token information data
250+ // GetByRefresh use the refresh token for token information data
247251func (ts * TokenStore ) GetByRefresh (refresh string ) (ti oauth2.TokenInfo , err error ) {
248252basicID , err := ts .getBasicID (ts .tcfg .RefreshCName , refresh )
249253if err != nil && basicID == "" {
0 commit comments