fix binding

This commit is contained in:
Daniel 2022-11-12 12:45:25 -05:00
parent a65c6bc394
commit 414654585b
4 changed files with 11 additions and 14 deletions

View file

@ -26,7 +26,7 @@ type Authenticator struct {
}
type AuthError struct {
Error string `json:"error"`
Error string `json:"error"`
Description string `json:"error_description"`
}

View file

@ -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"`
}

View file

@ -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")

View file

@ -33,7 +33,6 @@ func AliasHandler(toFile string) echo.HandlerFunc {
}
}
func init() {
var err error