diff options
author | 6543 <6543@obermui.de> | 2022-05-11 13:16:35 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-05-11 13:16:35 +0200 |
commit | f41c2bec4ccadb0c147ca2588f4a00d60ae6c594 (patch) | |
tree | 4b8543a206a7fe23c518bc8f89f7f22b9f23dc4c /models/auth/oauth2.go | |
parent | cbd45471b1100bffcd2f18719b56a5da5468756b (diff) | |
download | gitea-f41c2bec4ccadb0c147ca2588f4a00d60ae6c594.tar.gz gitea-f41c2bec4ccadb0c147ca2588f4a00d60ae6c594.zip |
Delete user related oauth stuff on user deletion too (#19677)
* delete user related oauth stuff on user deletion too
* extend doctor check-db-consistency
Diffstat (limited to 'models/auth/oauth2.go')
-rw-r--r-- | models/auth/oauth2.go | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/models/auth/oauth2.go b/models/auth/oauth2.go index 4d44a8842a..ca77fcdb78 100644 --- a/models/auth/oauth2.go +++ b/models/auth/oauth2.go @@ -5,6 +5,7 @@ package auth import ( + "context" "crypto/sha256" "encoding/base32" "encoding/base64" @@ -18,6 +19,7 @@ import ( uuid "github.com/google/uuid" "golang.org/x/crypto/bcrypt" + "xorm.io/builder" "xorm.io/xorm" ) @@ -576,3 +578,21 @@ func GetActiveOAuth2SourceByName(name string) (*Source, error) { return authSource, nil } + +func DeleteOAuth2RelictsByUserID(ctx context.Context, userID int64) error { + deleteCond := builder.Select("id").From("oauth2_grant").Where(builder.Eq{"oauth2_grant.user_id": userID}) + + if _, err := db.GetEngine(ctx).In("grant_id", deleteCond). + Delete(&OAuth2AuthorizationCode{}); err != nil { + return err + } + + if err := db.DeleteBeans(ctx, + &OAuth2Application{UID: userID}, + &OAuth2Grant{UserID: userID}, + ); err != nil { + return fmt.Errorf("DeleteBeans: %v", err) + } + + return nil +} |