[feature] Refactor tokens, allow multiple app redirect_uris (#3849)

* [feature] Refactor tokens, allow multiple app redirect_uris

* move + tweak handlers a bit

* return error for unset oauth2.ClientStore funcs

* wrap UpdateToken with cache

* panic handling

* cheeky little time optimization

* unlock on error
This commit is contained in:
tobi 2025-03-03 16:03:36 +01:00 committed by GitHub
commit 1b37944f8b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
77 changed files with 963 additions and 594 deletions

View file

@ -97,41 +97,6 @@ func (a *applicationDB) DeleteApplicationByClientID(ctx context.Context, clientI
return nil
}
func (a *applicationDB) GetClientByID(ctx context.Context, id string) (*gtsmodel.Client, error) {
return a.state.Caches.DB.Client.LoadOne("ID", func() (*gtsmodel.Client, error) {
var client gtsmodel.Client
if err := a.db.NewSelect().
Model(&client).
Where("? = ?", bun.Ident("id"), id).
Scan(ctx); err != nil {
return nil, err
}
return &client, nil
}, id)
}
func (a *applicationDB) PutClient(ctx context.Context, client *gtsmodel.Client) error {
return a.state.Caches.DB.Client.Store(client, func() error {
_, err := a.db.NewInsert().Model(client).Exec(ctx)
return err
})
}
func (a *applicationDB) DeleteClientByID(ctx context.Context, id string) error {
_, err := a.db.NewDelete().
Table("clients").
Where("? = ?", bun.Ident("id"), id).
Exec(ctx)
if err != nil {
return err
}
a.state.Caches.DB.Client.Invalidate("ID", id)
return nil
}
func (a *applicationDB) GetAllTokens(ctx context.Context) ([]*gtsmodel.Token, error) {
var tokenIDs []string
@ -233,6 +198,18 @@ func (a *applicationDB) PutToken(ctx context.Context, token *gtsmodel.Token) err
})
}
func (a *applicationDB) UpdateToken(ctx context.Context, token *gtsmodel.Token, columns ...string) error {
return a.state.Caches.DB.Token.Store(token, func() error {
_, err := a.db.
NewUpdate().
Model(token).
Column(columns...).
Where("? = ?", bun.Ident("id"), token.ID).
Exec(ctx)
return err
})
}
func (a *applicationDB) DeleteTokenByID(ctx context.Context, id string) error {
_, err := a.db.NewDelete().
Table("tokens").