fix binding
This commit is contained in:
parent
a65c6bc394
commit
414654585b
4 changed files with 11 additions and 14 deletions
|
@ -26,7 +26,7 @@ type Authenticator struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
type AuthError struct {
|
type AuthError struct {
|
||||||
Error string `json:"error"`
|
Error string `json:"error"`
|
||||||
Description string `json:"error_description"`
|
Description string `json:"error_description"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -144,6 +144,6 @@ func genHex(l int) string {
|
||||||
if _, err := rand.Read(b); err != nil {
|
if _, err := rand.Read(b); err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
return hex.EncodeToString(b)
|
return hex.EncodeToString(b)
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,7 +14,7 @@ import (
|
||||||
type FlowStore map[FlowID]*Flow
|
type FlowStore map[FlowID]*Flow
|
||||||
|
|
||||||
type FlowRequest struct {
|
type FlowRequest struct {
|
||||||
ClientID ClientID `json:"client_id"`
|
ClientID ClientID `json:"client_id"`
|
||||||
Handler []*string `json:"handler"`
|
Handler []*string `json:"handler"`
|
||||||
RedirectURI string `json:"redirect_uri"`
|
RedirectURI string `json:"redirect_uri"`
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,6 +6,7 @@ import (
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/labstack/echo/v4"
|
"github.com/labstack/echo/v4"
|
||||||
|
"github.com/rs/zerolog/log"
|
||||||
)
|
)
|
||||||
|
|
||||||
type SessionStore struct {
|
type SessionStore struct {
|
||||||
|
@ -78,7 +79,7 @@ func (ss *SessionStore) verifyAndGetCredential(tr *TokenRequest, r *http.Request
|
||||||
|
|
||||||
type User struct {
|
type User struct {
|
||||||
Username string
|
Username string
|
||||||
Active bool
|
Active bool
|
||||||
}
|
}
|
||||||
|
|
||||||
func (u *User) allowedToAuth() error {
|
func (u *User) allowedToAuth() error {
|
||||||
|
@ -90,6 +91,7 @@ func (u *User) allowedToAuth() error {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *Authenticator) getOrCreateUser(c *Credential) (*User, error) {
|
func (a *Authenticator) getOrCreateUser(c *Credential) (*User, error) {
|
||||||
|
log.Debug().Str("user", c.user.ProviderUsername()).Msg("getOrCreateUser")
|
||||||
panic("not implemented")
|
panic("not implemented")
|
||||||
return &User{}, nil
|
return &User{}, nil
|
||||||
}
|
}
|
||||||
|
@ -117,7 +119,7 @@ type GrantType string
|
||||||
|
|
||||||
const (
|
const (
|
||||||
GTAuthorizationCode GrantType = "authorization_code"
|
GTAuthorizationCode GrantType = "authorization_code"
|
||||||
GTRefreshToken GrantType = "refresh_token"
|
GTRefreshToken GrantType = "refresh_token"
|
||||||
)
|
)
|
||||||
|
|
||||||
type ClientID string
|
type ClientID string
|
||||||
|
@ -128,9 +130,9 @@ func (c *ClientID) IsValid() bool {
|
||||||
}
|
}
|
||||||
|
|
||||||
type TokenRequest struct {
|
type TokenRequest struct {
|
||||||
ClientID ClientID `query:"client_id"`
|
ClientID ClientID `form:"client_id"`
|
||||||
Code TokenID `query:"code"`
|
Code TokenID `form:"code"`
|
||||||
GrantType GrantType `query:"grant_type"`
|
GrantType GrantType `form:"grant_type"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *Authenticator) TokenHandler(c echo.Context) error {
|
func (a *Authenticator) TokenHandler(c echo.Context) error {
|
||||||
|
@ -140,10 +142,6 @@ func (a *Authenticator) TokenHandler(c echo.Context) error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
if *rq == (TokenRequest{}) {
|
|
||||||
panic("it didn't bind")
|
|
||||||
}
|
|
||||||
|
|
||||||
switch rq.GrantType {
|
switch rq.GrantType {
|
||||||
case GTAuthorizationCode:
|
case GTAuthorizationCode:
|
||||||
if !rq.ClientID.IsValid() {
|
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"})
|
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.JSON(http.StatusUnauthorized, AuthError{Error: "access_denied", Description: err.Error()})
|
||||||
}
|
}
|
||||||
return c.String(http.StatusOK, "token good I guess")
|
return c.String(http.StatusOK, "token good I guess")
|
||||||
|
|
|
@ -33,7 +33,6 @@ func AliasHandler(toFile string) echo.HandlerFunc {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
var err error
|
var err error
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue