diff --git a/pkg/auth/authenticator.go b/pkg/auth/authenticator.go index fe54cba..20c67ac 100644 --- a/pkg/auth/authenticator.go +++ b/pkg/auth/authenticator.go @@ -26,7 +26,7 @@ type Authenticator struct { } type AuthError struct { - Error string `json:"error"` + Error string `json:"error"` Description string `json:"error_description"` } @@ -144,6 +144,6 @@ func genHex(l int) string { if _, err := rand.Read(b); err != nil { panic(err) } - + return hex.EncodeToString(b) } diff --git a/pkg/auth/flow.go b/pkg/auth/flow.go index 84c7b7a..485d365 100644 --- a/pkg/auth/flow.go +++ b/pkg/auth/flow.go @@ -14,7 +14,7 @@ import ( type FlowStore map[FlowID]*Flow type FlowRequest struct { - ClientID ClientID `json:"client_id"` + ClientID ClientID `json:"client_id"` Handler []*string `json:"handler"` RedirectURI string `json:"redirect_uri"` } diff --git a/pkg/auth/session.go b/pkg/auth/session.go index 79106ac..5549284 100644 --- a/pkg/auth/session.go +++ b/pkg/auth/session.go @@ -6,6 +6,7 @@ import ( "time" "github.com/labstack/echo/v4" + "github.com/rs/zerolog/log" ) type SessionStore struct { @@ -78,7 +79,7 @@ func (ss *SessionStore) verifyAndGetCredential(tr *TokenRequest, r *http.Request type User struct { Username string - Active bool + Active bool } func (u *User) allowedToAuth() error { @@ -90,6 +91,7 @@ func (u *User) allowedToAuth() error { } func (a *Authenticator) getOrCreateUser(c *Credential) (*User, error) { + log.Debug().Str("user", c.user.ProviderUsername()).Msg("getOrCreateUser") panic("not implemented") return &User{}, nil } @@ -117,7 +119,7 @@ type GrantType string const ( GTAuthorizationCode GrantType = "authorization_code" - GTRefreshToken GrantType = "refresh_token" + GTRefreshToken GrantType = "refresh_token" ) type ClientID string @@ -128,9 +130,9 @@ func (c *ClientID) IsValid() bool { } type TokenRequest struct { - ClientID ClientID `query:"client_id"` - Code TokenID `query:"code"` - GrantType GrantType `query:"grant_type"` + ClientID ClientID `form:"client_id"` + Code TokenID `form:"code"` + GrantType GrantType `form:"grant_type"` } func (a *Authenticator) TokenHandler(c echo.Context) error { @@ -140,10 +142,6 @@ func (a *Authenticator) TokenHandler(c echo.Context) error { return err } - if *rq == (TokenRequest{}) { - panic("it didn't bind") - } - switch rq.GrantType { case GTAuthorizationCode: if !rq.ClientID.IsValid() { @@ -161,7 +159,7 @@ func (a *Authenticator) TokenHandler(c echo.Context) error { return c.JSON(http.StatusUnauthorized, AuthError{Error: "access_denied", Description: "bad user"}) } - if err := user.allowedToAuth(); err != nil { + if err := user.allowedToAuth(); err != nil { return c.JSON(http.StatusUnauthorized, AuthError{Error: "access_denied", Description: err.Error()}) } return c.String(http.StatusOK, "token good I guess") diff --git a/pkg/frontend/frontend.go b/pkg/frontend/frontend.go index 8961164..047e202 100644 --- a/pkg/frontend/frontend.go +++ b/pkg/frontend/frontend.go @@ -33,7 +33,6 @@ func AliasHandler(toFile string) echo.HandlerFunc { } } - func init() { var err error