diff options
| author | 2025-03-03 16:03:36 +0100 | |
|---|---|---|
| committer | 2025-03-03 15:03:36 +0000 | |
| commit | 1b37944f8b8eccc2afcfb0f603786209a3b7402d (patch) | |
| tree | 2bc0be27cf0405e16ac3e14efc3b6973eb096b8b /internal/oauth/clientstore.go | |
| parent | bumps go-ffmpreg to v0.6.6 (#3866) (diff) | |
| download | gotosocial-1b37944f8b8eccc2afcfb0f603786209a3b7402d.tar.xz | |
[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
Diffstat (limited to 'internal/oauth/clientstore.go')
| -rw-r--r-- | internal/oauth/clientstore.go | 43 |
1 files changed, 14 insertions, 29 deletions
diff --git a/internal/oauth/clientstore.go b/internal/oauth/clientstore.go index af48edac3..17de0e342 100644 --- a/internal/oauth/clientstore.go +++ b/internal/oauth/clientstore.go @@ -21,45 +21,30 @@ import ( "context" "codeberg.org/superseriousbusiness/oauth2/v4" - "codeberg.org/superseriousbusiness/oauth2/v4/models" - "github.com/superseriousbusiness/gotosocial/internal/db" - "github.com/superseriousbusiness/gotosocial/internal/gtsmodel" + "codeberg.org/superseriousbusiness/oauth2/v4/errors" + "github.com/superseriousbusiness/gotosocial/internal/state" ) type clientStore struct { - db db.DB + state *state.State } -// NewClientStore returns an implementation of the oauth2 ClientStore interface, using the given db as a storage backend. -func NewClientStore(db db.DB) oauth2.ClientStore { - pts := &clientStore{ - db: db, - } - return pts +// NewClientStore returns a minimal implementation of +// oauth2.ClientStore interface, using state as storage. +// +// Only GetByID is implemented, Set and Delete are stubs. +func NewClientStore(state *state.State) oauth2.ClientStore { + return &clientStore{state: state} } func (cs *clientStore) GetByID(ctx context.Context, clientID string) (oauth2.ClientInfo, error) { - client, err := cs.db.GetClientByID(ctx, clientID) - if err != nil { - return nil, err - } - return models.New( - client.ID, - client.Secret, - client.Domain, - client.UserID, - ), nil + return cs.state.DB.GetApplicationByClientID(ctx, clientID) } -func (cs *clientStore) Set(ctx context.Context, id string, cli oauth2.ClientInfo) error { - return cs.db.PutClient(ctx, >smodel.Client{ - ID: cli.GetID(), - Secret: cli.GetSecret(), - Domain: cli.GetDomain(), - UserID: cli.GetUserID(), - }) +func (cs *clientStore) Set(_ context.Context, _ string, _ oauth2.ClientInfo) error { + return errors.New("func oauth2.ClientStore.Set not implemented") } -func (cs *clientStore) Delete(ctx context.Context, id string) error { - return cs.db.DeleteClientByID(ctx, id) +func (cs *clientStore) Delete(_ context.Context, _ string) error { + return errors.New("func oauth2.ClientStore.Delete not implemented") } |
