// NewTokenStore create a token store instance based on mongodb
NewTokenStore create a token store instance based on mongodb
// NewTokenStore create a token store instance based on mongodb
func NewTokenStore(client *mongo.Client, db string,
	collection string) (store oauth2.TokenStore) {
	ts := &MgoTokenStore{
		client:     client,
		db:         db,
		collection: collection,
	}
	option := options.Index().SetExpireAfterSeconds(1)
	_, err := ts.c(ts.collection).Indexes().CreateOne(context.TODO(), mongo.IndexModel{
		Keys:    bsonx.Doc{bsonx.Elem{Key: "ExpiredAt", Value: bsonx.Int32(1)}},
		Options: option,
	})
	if err != nil {
		panic(err)
	}
	_, err = ts.c(ts.collection).Indexes().CreateOne(context.TODO(), mongo.IndexModel{
		Keys: bsonx.Doc{bsonx.Elem{Key: "UserID", Value: bsonx.Int32(1)}},
	})
	if err != nil {
		panic(err)
	}
	_, err = ts.c(ts.collection).Indexes().CreateOne(context.TODO(), mongo.IndexModel{
		Keys: bsonx.Doc{bsonx.Elem{Key: "ClientId", Value: bsonx.Int32(1)}},
	})
	if err != nil {
		panic(err)
	}
	_, err = ts.c(ts.collection).Indexes().CreateOne(context.TODO(), mongo.IndexModel{
		Keys: bsonx.Doc{bsonx.Elem{Key: "Refresh", Value: bsonx.Int32(1)}},
	})
	if err != nil {
		panic(err)
	}
	store = ts
	return
}
func NewTokenStore ( client * mongo . Client , db string , collection string ) ( store oauth2 . TokenStore ) { ts := & MgoTokenStore { client : client , db : db , collection : collection , } option := options . Index ( ) . SetExpireAfterSeconds ( 1 ) _ , err := ts . c ( ts . collection ) . Indexes ( ) . CreateOne ( context . TODO ( ) , mongo . IndexModel { Keys : bsonx . Doc { bsonx . Elem { Key : " " , Value : bsonx . Int32 ( 1 ) } } , Options : option , } ) if err != nil { panic ( err ) } _ , err = ts . c ( ts . collection ) . Indexes ( ) . CreateOne ( context . TODO ( ) , mongo . IndexModel { Keys : bsonx . Doc { bsonx . Elem { Key : " " , Value : bsonx . Int32 ( 1 ) } } , } ) if err != nil { panic ( err ) } _ , err = ts . c ( ts . collection ) . Indexes ( ) . CreateOne ( context . TODO ( ) , mongo . IndexModel { Keys : bsonx . Doc { bsonx . Elem { Key : " " , Value : bsonx . Int32 ( 1 ) } } , } ) if err != nil { panic ( err ) } _ , err = ts . c ( ts . collection ) . Indexes ( ) . CreateOne ( context . TODO ( ) , mongo . IndexModel { Keys : bsonx . Doc { bsonx . Elem { Key : " " , Value : bsonx . Int32 ( 1 ) } } , } ) if err != nil { panic ( err ) } store = ts return }
NewTokenStore create a token store instance based on mongodb
NewTokenStore create a token store instance based on mongodb