summaryrefslogtreecommitdiff
path: root/internal/api/client/auth
diff options
context:
space:
mode:
authorLibravatar R. Aidan Campbell <raidancampbell@users.noreply.github.com>2021-10-11 05:37:33 -0700
committerLibravatar GitHub <noreply@github.com>2021-10-11 14:37:33 +0200
commit083099a9575f8b2fac22c1d4a51a9dd0e2201243 (patch)
treed1787aa544679c433f797d2313ce532250fe574f /internal/api/client/auth
parentHandle forwarded messages (#273) (diff)
downloadgotosocial-083099a9575f8b2fac22c1d4a51a9dd0e2201243.tar.xz
reference global logrus (#274)
* reference logrus' global logger instead of passing and storing a logger reference everywhere * always directly use global logrus logger instead of referencing an instance * test suites should also directly use the global logrus logger * rename gin logging function to clarify that it's middleware * correct comments which erroneously referenced removed logger parameter * setting log level for tests now uses logrus' exported type instead of the string value, to guarantee error isn't possible
Diffstat (limited to 'internal/api/client/auth')
-rw-r--r--internal/api/client/auth/auth.go5
-rw-r--r--internal/api/client/auth/auth_test.go4
-rw-r--r--internal/api/client/auth/authorize.go5
-rw-r--r--internal/api/client/auth/middleware.go3
-rw-r--r--internal/api/client/auth/signin.go7
-rw-r--r--internal/api/client/auth/token.go3
6 files changed, 14 insertions, 13 deletions
diff --git a/internal/api/client/auth/auth.go b/internal/api/client/auth/auth.go
index bcc338ce0..c183576f8 100644
--- a/internal/api/client/auth/auth.go
+++ b/internal/api/client/auth/auth.go
@@ -21,7 +21,6 @@ package auth
import (
"net/http"
- "github.com/sirupsen/logrus"
"github.com/superseriousbusiness/gotosocial/internal/api"
"github.com/superseriousbusiness/gotosocial/internal/config"
"github.com/superseriousbusiness/gotosocial/internal/db"
@@ -58,17 +57,15 @@ type Module struct {
db db.DB
server oauth.Server
idp oidc.IDP
- log *logrus.Logger
}
// New returns a new auth module
-func New(config *config.Config, db db.DB, server oauth.Server, idp oidc.IDP, log *logrus.Logger) api.ClientModule {
+func New(config *config.Config, db db.DB, server oauth.Server, idp oidc.IDP) api.ClientModule {
return &Module{
config: config,
db: db,
server: server,
idp: idp,
- log: log,
}
}
diff --git a/internal/api/client/auth/auth_test.go b/internal/api/client/auth/auth_test.go
index bd4ff27fd..59a8d7b16 100644
--- a/internal/api/client/auth/auth_test.go
+++ b/internal/api/client/auth/auth_test.go
@@ -103,7 +103,7 @@ func (suite *AuthTestSuite) SetupTest() {
log := logrus.New()
log.SetLevel(logrus.TraceLevel)
- db, err := bundb.NewBunDBService(context.Background(), suite.config, log)
+ db, err := bundb.NewBunDBService(context.Background(), suite.config)
if err != nil {
logrus.Panicf("error creating database connection: %s", err)
}
@@ -124,7 +124,7 @@ func (suite *AuthTestSuite) SetupTest() {
}
}
- suite.oauthServer = oauth.New(context.Background(), suite.db, log)
+ suite.oauthServer = oauth.New(context.Background(), suite.db)
if err := suite.db.Put(context.Background(), suite.testAccount); err != nil {
logrus.Panicf("could not insert test account into db: %s", err)
diff --git a/internal/api/client/auth/authorize.go b/internal/api/client/auth/authorize.go
index 972853687..6382f473d 100644
--- a/internal/api/client/auth/authorize.go
+++ b/internal/api/client/auth/authorize.go
@@ -21,6 +21,7 @@ package auth
import (
"errors"
"fmt"
+ "github.com/sirupsen/logrus"
"net/http"
"net/url"
"strings"
@@ -37,7 +38,7 @@ import (
// The idea here is to present an oauth authorize page to the user, with a button
// that they have to click to accept.
func (m *Module) AuthorizeGETHandler(c *gin.Context) {
- l := m.log.WithField("func", "AuthorizeGETHandler")
+ l := logrus.WithField("func", "AuthorizeGETHandler")
s := sessions.Default(c)
// UserID will be set in the session by AuthorizePOSTHandler if the caller has already gone through the authentication flow
@@ -123,7 +124,7 @@ func (m *Module) AuthorizeGETHandler(c *gin.Context) {
// At this point we assume that the user has A) logged in and B) accepted that the app should act for them,
// so we should proceed with the authentication flow and generate an oauth token for them if we can.
func (m *Module) AuthorizePOSTHandler(c *gin.Context) {
- l := m.log.WithField("func", "AuthorizePOSTHandler")
+ l := logrus.WithField("func", "AuthorizePOSTHandler")
s := sessions.Default(c)
// We need to retrieve the original form submitted to the authorizeGEThandler, and
diff --git a/internal/api/client/auth/middleware.go b/internal/api/client/auth/middleware.go
index 3599c7048..1b84458b0 100644
--- a/internal/api/client/auth/middleware.go
+++ b/internal/api/client/auth/middleware.go
@@ -20,6 +20,7 @@ package auth
import (
"github.com/gin-gonic/gin"
+ "github.com/sirupsen/logrus"
"github.com/superseriousbusiness/gotosocial/internal/db"
"github.com/superseriousbusiness/gotosocial/internal/gtsmodel"
"github.com/superseriousbusiness/gotosocial/internal/oauth"
@@ -31,7 +32,7 @@ import (
// If user or account can't be found, then the handler won't *fail*, in case the server wants to allow
// public requests that don't have a Bearer token set (eg., for public instance information and so on).
func (m *Module) OauthTokenMiddleware(c *gin.Context) {
- l := m.log.WithField("func", "OauthTokenMiddleware")
+ l := logrus.WithField("func", "OauthTokenMiddleware")
l.Trace("entering OauthTokenMiddleware")
ti, err := m.server.ValidationBearerToken(c.Copy().Request)
diff --git a/internal/api/client/auth/signin.go b/internal/api/client/auth/signin.go
index 6b8bb93db..68944226f 100644
--- a/internal/api/client/auth/signin.go
+++ b/internal/api/client/auth/signin.go
@@ -21,6 +21,7 @@ package auth
import (
"context"
"errors"
+ "github.com/sirupsen/logrus"
"net/http"
"github.com/gin-contrib/sessions"
@@ -40,7 +41,7 @@ type login struct {
// The idea is to present a sign in page to the user, where they can enter their username and password.
// The form will then POST to the sign in page, which will be handled by SignInPOSTHandler
func (m *Module) SignInGETHandler(c *gin.Context) {
- l := m.log.WithField("func", "SignInGETHandler")
+ l := logrus.WithField("func", "SignInGETHandler")
l.Trace("entering sign in handler")
if m.idp != nil {
s := sessions.Default(c)
@@ -65,7 +66,7 @@ func (m *Module) SignInGETHandler(c *gin.Context) {
// The idea is to present a sign in page to the user, where they can enter their username and password.
// The handler will then redirect to the auth handler served at /auth
func (m *Module) SignInPOSTHandler(c *gin.Context) {
- l := m.log.WithField("func", "SignInPOSTHandler")
+ l := logrus.WithField("func", "SignInPOSTHandler")
s := sessions.Default(c)
form := &login{}
if err := c.ShouldBind(form); err != nil {
@@ -98,7 +99,7 @@ func (m *Module) SignInPOSTHandler(c *gin.Context) {
// address stored in the database. If OK, we return the userid (a ulid) for that user,
// so that it can be used in further Oauth flows to generate a token/retreieve an oauth client from the db.
func (m *Module) ValidatePassword(ctx context.Context, email string, password string) (userid string, err error) {
- l := m.log.WithField("func", "ValidatePassword")
+ l := logrus.WithField("func", "ValidatePassword")
// make sure an email/password was provided and bail if not
if email == "" || password == "" {
diff --git a/internal/api/client/auth/token.go b/internal/api/client/auth/token.go
index f9009767e..f24840c9f 100644
--- a/internal/api/client/auth/token.go
+++ b/internal/api/client/auth/token.go
@@ -19,6 +19,7 @@
package auth
import (
+ "github.com/sirupsen/logrus"
"net/http"
"net/url"
@@ -37,7 +38,7 @@ type tokenBody struct {
// TokenPOSTHandler should be served as a POST at https://example.org/oauth/token
// The idea here is to serve an oauth access token to a user, which can be used for authorizing against non-public APIs.
func (m *Module) TokenPOSTHandler(c *gin.Context) {
- l := m.log.WithField("func", "TokenPOSTHandler")
+ l := logrus.WithField("func", "TokenPOSTHandler")
l.Trace("entered TokenPOSTHandler")
form := &tokenBody{}