@@ -170,7 +170,7 @@ const lowerBase32Chars = "abcdefghijklmnopqrstuvwxyz234567"
170
170
var base32Lower = base32 .NewEncoding (lowerBase32Chars ).WithPadding (base32 .NoPadding )
171
171
172
172
// GenerateClientSecret will generate the client secret and returns the plaintext and saves the hash at the database
173
- func (app * OAuth2Application ) GenerateClientSecret () (string , error ) {
173
+ func (app * OAuth2Application ) GenerateClientSecret (ctx context. Context ) (string , error ) {
174
174
rBytes , err := util .CryptoRandomBytes (32 )
175
175
if err != nil {
176
176
return "" , err
@@ -184,7 +184,7 @@ func (app *OAuth2Application) GenerateClientSecret() (string, error) {
184
184
return "" , err
185
185
}
186
186
app .ClientSecret = string (hashedSecret )
187
- if _ , err := db .GetEngine (db . DefaultContext ).ID (app .ID ).Cols ("client_secret" ).Update (app ); err != nil {
187
+ if _ , err := db .GetEngine (ctx ).ID (app .ID ).Cols ("client_secret" ).Update (app ); err != nil {
188
188
return "" , err
189
189
}
190
190
return clientSecret , nil
@@ -284,8 +284,8 @@ type UpdateOAuth2ApplicationOptions struct {
284
284
}
285
285
286
286
// UpdateOAuth2Application updates an oauth2 application
287
- func UpdateOAuth2Application (opts UpdateOAuth2ApplicationOptions ) (* OAuth2Application , error ) {
288
- ctx , committer , err := db .TxContext (db . DefaultContext )
287
+ func UpdateOAuth2Application (ctx context. Context , opts UpdateOAuth2ApplicationOptions ) (* OAuth2Application , error ) {
288
+ ctx , committer , err := db .TxContext (ctx )
289
289
if err != nil {
290
290
return nil , err
291
291
}
@@ -352,8 +352,8 @@ func deleteOAuth2Application(ctx context.Context, id, userid int64) error {
352
352
}
353
353
354
354
// DeleteOAuth2Application deletes the application with the given id and the grants and auth codes related to it. It checks if the userid was the creator of the app.
355
- func DeleteOAuth2Application (id , userid int64 ) error {
356
- ctx , committer , err := db .TxContext (db . DefaultContext )
355
+ func DeleteOAuth2Application (ctx context. Context , id , userid int64 ) error {
356
+ ctx , committer , err := db .TxContext (ctx )
357
357
if err != nil {
358
358
return err
359
359
}
@@ -373,8 +373,8 @@ func DeleteOAuth2Application(id, userid int64) error {
373
373
}
374
374
375
375
// ListOAuth2Applications returns a list of oauth2 applications belongs to given user.
376
- func ListOAuth2Applications (uid int64 , listOptions db.ListOptions ) ([]* OAuth2Application , int64 , error ) {
377
- sess := db .GetEngine (db . DefaultContext ).
376
+ func ListOAuth2Applications (ctx context. Context , uid int64 , listOptions db.ListOptions ) ([]* OAuth2Application , int64 , error ) {
377
+ sess := db .GetEngine (ctx ).
378
378
Where ("uid=?" , uid ).
379
379
Desc ("id" )
380
380
@@ -632,18 +632,18 @@ func (err ErrOAuthApplicationNotFound) Unwrap() error {
632
632
}
633
633
634
634
// GetActiveOAuth2ProviderSources returns all actived LoginOAuth2 sources
635
- func GetActiveOAuth2ProviderSources () ([]* Source , error ) {
635
+ func GetActiveOAuth2ProviderSources (ctx context. Context ) ([]* Source , error ) {
636
636
sources := make ([]* Source , 0 , 1 )
637
- if err := db .GetEngine (db . DefaultContext ).Where ("is_active = ? and type = ?" , true , OAuth2 ).Find (& sources ); err != nil {
637
+ if err := db .GetEngine (ctx ).Where ("is_active = ? and type = ?" , true , OAuth2 ).Find (& sources ); err != nil {
638
638
return nil , err
639
639
}
640
640
return sources , nil
641
641
}
642
642
643
643
// GetActiveOAuth2SourceByName returns a OAuth2 AuthSource based on the given name
644
- func GetActiveOAuth2SourceByName (name string ) (* Source , error ) {
644
+ func GetActiveOAuth2SourceByName (ctx context. Context , name string ) (* Source , error ) {
645
645
authSource := new (Source )
646
- has , err := db .GetEngine (db . DefaultContext ).Where ("name = ? and type = ? and is_active = ?" , name , OAuth2 , true ).Get (authSource )
646
+ has , err := db .GetEngine (ctx ).Where ("name = ? and type = ? and is_active = ?" , name , OAuth2 , true ).Get (authSource )
647
647
if err != nil {
648
648
return nil , err
649
649
}
0 commit comments