@@ -170,7 +170,7 @@ const lowerBase32Chars = "abcdefghijklmnopqrstuvwxyz234567"
170170var base32Lower = base32 .NewEncoding (lowerBase32Chars ).WithPadding (base32 .NoPadding )
171171
172172// 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 ) {
174174 rBytes , err := util .CryptoRandomBytes (32 )
175175 if err != nil {
176176 return "" , err
@@ -184,7 +184,7 @@ func (app *OAuth2Application) GenerateClientSecret() (string, error) {
184184 return "" , err
185185 }
186186 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 {
188188 return "" , err
189189 }
190190 return clientSecret , nil
@@ -284,8 +284,8 @@ type UpdateOAuth2ApplicationOptions struct {
284284}
285285
286286// 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 )
289289 if err != nil {
290290 return nil , err
291291 }
@@ -352,8 +352,8 @@ func deleteOAuth2Application(ctx context.Context, id, userid int64) error {
352352}
353353
354354// 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 )
357357 if err != nil {
358358 return err
359359 }
@@ -373,8 +373,8 @@ func DeleteOAuth2Application(id, userid int64) error {
373373}
374374
375375// 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 ).
378378 Where ("uid=?" , uid ).
379379 Desc ("id" )
380380
@@ -632,18 +632,18 @@ func (err ErrOAuthApplicationNotFound) Unwrap() error {
632632}
633633
634634// GetActiveOAuth2ProviderSources returns all actived LoginOAuth2 sources
635- func GetActiveOAuth2ProviderSources () ([]* Source , error ) {
635+ func GetActiveOAuth2ProviderSources (ctx context. Context ) ([]* Source , error ) {
636636 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 {
638638 return nil , err
639639 }
640640 return sources , nil
641641}
642642
643643// 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 ) {
645645 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 )
647647 if err != nil {
648648 return nil , err
649649 }
0 commit comments