Split user

This commit is contained in:
Daniel 2022-11-12 13:34:39 -05:00
parent 414654585b
commit 0358eeac53
4 changed files with 43 additions and 25 deletions

2
.gitignore vendored
View file

@ -3,3 +3,5 @@ blas
!cmd/blas/ !cmd/blas/
Session.vim Session.vim
coverage.txt coverage.txt
*.dlv
*.core

View file

@ -20,6 +20,7 @@ var (
) )
type Authenticator struct { type Authenticator struct {
store AuthStore
flows FlowStore flows FlowStore
sessions SessionStore sessions SessionStore
providers map[string]AuthProvider providers map[string]AuthProvider

View file

@ -1,12 +1,10 @@
package auth package auth
import ( import (
"errors"
"net/http" "net/http"
"time" "time"
"github.com/labstack/echo/v4" "github.com/labstack/echo/v4"
"github.com/rs/zerolog/log"
) )
type SessionStore struct { type SessionStore struct {
@ -77,25 +75,6 @@ func (ss *SessionStore) verifyAndGetCredential(tr *TokenRequest, r *http.Request
return &Credential{user: user} return &Credential{user: user}
} }
type User struct {
Username string
Active bool
}
func (u *User) allowedToAuth() error {
if !u.Active {
return errors.New("user disabled")
}
return nil
}
func (a *Authenticator) getOrCreateUser(c *Credential) (*User, error) {
log.Debug().Str("user", c.user.ProviderUsername()).Msg("getOrCreateUser")
panic("not implemented")
return &User{}, nil
}
const defaultExpiration = 2 * time.Hour const defaultExpiration = 2 * time.Hour
func (a *Authenticator) NewToken(r *http.Request, user ProviderUser, f *Flow) TokenID { func (a *Authenticator) NewToken(r *http.Request, user ProviderUser, f *Flow) TokenID {

36
pkg/auth/user.go Normal file
View file

@ -0,0 +1,36 @@
package auth
import (
"errors"
"github.com/rs/zerolog/log"
)
const (
AuthKey = "auth"
)
type User struct {
Username string
UserMetadata
}
type UserMetadata struct {
Active bool
}
func (u *User) allowedToAuth() error {
if !u.Active {
return errors.New("user disabled")
}
return nil
}
func (a *Authenticator) getOrCreateUser(c *Credential) (*User, error) {
log.Debug().Str("user", c.user.ProviderUsername()).Msg("getOrCreateUser")
panic("not implemented")
return &User{}, nil
}