diff options
Diffstat (limited to 'internal/oauth')
-rw-r--r-- | internal/oauth/server.go | 17 | ||||
-rw-r--r-- | internal/oauth/tokenstore.go | 16 |
2 files changed, 18 insertions, 15 deletions
diff --git a/internal/oauth/server.go b/internal/oauth/server.go index 8bac8fc2f..538288922 100644 --- a/internal/oauth/server.go +++ b/internal/oauth/server.go @@ -26,7 +26,7 @@ import ( "github.com/gin-gonic/gin" "github.com/sirupsen/logrus" "github.com/superseriousbusiness/gotosocial/internal/db" - "github.com/superseriousbusiness/gotosocial/internal/db/model" + "github.com/superseriousbusiness/gotosocial/internal/db/gtsmodel" "github.com/superseriousbusiness/oauth2/v4" "github.com/superseriousbusiness/oauth2/v4/errors" "github.com/superseriousbusiness/oauth2/v4/manage" @@ -34,6 +34,9 @@ import ( ) const ( + // SessionAuthorizedToken is the key set in the gin context for the Token + // of a User who has successfully passed Bearer token authorization. + // The interface returned from grabbing this key should be parsed as oauth2.TokenInfo SessionAuthorizedToken = "authorized_token" // SessionAuthorizedUser is the key set in the gin context for the id of // a User who has successfully passed Bearer token authorization. @@ -65,9 +68,9 @@ type s struct { type Authed struct { Token oauth2.TokenInfo - Application *model.Application - User *model.User - Account *model.Account + Application *gtsmodel.Application + User *gtsmodel.User + Account *gtsmodel.Account } // GetAuthed is a convenience function for returning an Authed struct from a gin context. @@ -96,7 +99,7 @@ func GetAuthed(c *gin.Context) (*Authed, error) { i, ok = ctx.Get(SessionAuthorizedApplication) if ok { - parsed, ok := i.(*model.Application) + parsed, ok := i.(*gtsmodel.Application) if !ok { return nil, errors.New("could not parse application from session context") } @@ -105,7 +108,7 @@ func GetAuthed(c *gin.Context) (*Authed, error) { i, ok = ctx.Get(SessionAuthorizedUser) if ok { - parsed, ok := i.(*model.User) + parsed, ok := i.(*gtsmodel.User) if !ok { return nil, errors.New("could not parse user from session context") } @@ -114,7 +117,7 @@ func GetAuthed(c *gin.Context) (*Authed, error) { i, ok = ctx.Get(SessionAuthorizedAccount) if ok { - parsed, ok := i.(*model.Account) + parsed, ok := i.(*gtsmodel.Account) if !ok { return nil, errors.New("could not parse account from session context") } diff --git a/internal/oauth/tokenstore.go b/internal/oauth/tokenstore.go index c4c9ff1d5..14caa6581 100644 --- a/internal/oauth/tokenstore.go +++ b/internal/oauth/tokenstore.go @@ -98,7 +98,7 @@ func (pts *tokenStore) Create(ctx context.Context, info oauth2.TokenInfo) error if !ok { return errors.New("info param was not a models.Token") } - if err := pts.db.Put(oauthTokenToPGToken(t)); err != nil { + if err := pts.db.Put(OAuthTokenToPGToken(t)); err != nil { return fmt.Errorf("error in tokenstore create: %s", err) } return nil @@ -130,7 +130,7 @@ func (pts *tokenStore) GetByCode(ctx context.Context, code string) (oauth2.Token if err := pts.db.GetWhere("code", code, pgt); err != nil { return nil, err } - return pgTokenToOauthToken(pgt), nil + return PGTokenToOauthToken(pgt), nil } // GetByAccess selects a token from the DB based on the Access field @@ -144,7 +144,7 @@ func (pts *tokenStore) GetByAccess(ctx context.Context, access string) (oauth2.T if err := pts.db.GetWhere("access", access, pgt); err != nil { return nil, err } - return pgTokenToOauthToken(pgt), nil + return PGTokenToOauthToken(pgt), nil } // GetByRefresh selects a token from the DB based on the Refresh field @@ -158,7 +158,7 @@ func (pts *tokenStore) GetByRefresh(ctx context.Context, refresh string) (oauth2 if err := pts.db.GetWhere("refresh", refresh, pgt); err != nil { return nil, err } - return pgTokenToOauthToken(pgt), nil + return PGTokenToOauthToken(pgt), nil } /* @@ -194,8 +194,8 @@ type Token struct { RefreshExpiresAt time.Time `pg:"type:timestamp"` } -// oauthTokenToPGToken is a lil util function that takes a gotosocial token and gives back a token for inserting into postgres -func oauthTokenToPGToken(tkn *models.Token) *Token { +// OAuthTokenToPGToken is a lil util function that takes a gotosocial token and gives back a token for inserting into postgres +func OAuthTokenToPGToken(tkn *models.Token) *Token { now := time.Now() // For the following, we want to make sure we're not adding a time.Now() to an *empty* ExpiresIn, otherwise that's @@ -236,8 +236,8 @@ func oauthTokenToPGToken(tkn *models.Token) *Token { } } -// pgTokenToOauthToken is a lil util function that takes a postgres token and gives back a gotosocial token -func pgTokenToOauthToken(pgt *Token) *models.Token { +// PGTokenToOauthToken is a lil util function that takes a postgres token and gives back a gotosocial token +func PGTokenToOauthToken(pgt *Token) *models.Token { now := time.Now() return &models.Token{ |