This commit is contained in:
Daniel Ponte 2022-10-27 09:51:11 -04:00
parent 1c4e5f51a8
commit ed3c7abaf8
3 changed files with 14 additions and 14 deletions

View file

@ -20,9 +20,9 @@ var (
) )
type Authenticator struct { type Authenticator struct {
Flows FlowStore flows FlowStore
Sessions SessionStore sessions SessionStore
Providers map[string]AuthProvider providers map[string]AuthProvider
} }
func (a *Authenticator) InstallRoutes(e *echo.Echo) { func (a *Authenticator) InstallRoutes(e *echo.Echo) {
@ -40,7 +40,7 @@ func (a *Authenticator) InstallRoutes(e *echo.Echo) {
} }
func (a *Authenticator) Provider(name string) AuthProvider { func (a *Authenticator) Provider(name string) AuthProvider {
p, ok := a.Providers[name] p, ok := a.providers[name]
if !ok { if !ok {
return nil return nil
} }
@ -49,15 +49,15 @@ func (a *Authenticator) Provider(name string) AuthProvider {
} }
func (a *Authenticator) InitAuth(s storage.Store) error { func (a *Authenticator) InitAuth(s storage.Store) error {
a.Flows = make(FlowStore) a.flows = make(FlowStore)
a.Sessions.init() a.sessions.init()
hap, err := NewHAProvider(s) hap, err := NewHAProvider(s)
if err != nil { if err != nil {
return err return err
} }
// XXX: yuck // XXX: yuck
a.Providers = map[string]AuthProvider{ a.providers = map[string]AuthProvider{
hap.ProviderType(): hap, hap.ProviderType(): hap,
} }

View file

@ -114,7 +114,7 @@ func (a *Authenticator) NewFlow(r *FlowRequest) *Flow {
} }
flow.touch() flow.touch()
a.Flows.register(flow) a.flows.register(flow)
return flow return flow
} }
@ -159,7 +159,7 @@ func (f *Flow) progress(a *Authenticator, c echo.Context) error {
Version int `json:"version"` Version int `json:"version"`
} }
// TODO: setup the session. delete the flow. // TODO: setup the session. delete the flow.
a.Flows.Remove(f) a.flows.Remove(f)
copier.Copy(&finishedFlow, f) copier.Copy(&finishedFlow, f)
finishedFlow.Type = TypeCreateEntry finishedFlow.Type = TypeCreateEntry
finishedFlow.Title = common.AppName finishedFlow.Title = common.AppName
@ -191,7 +191,7 @@ func (a *Authenticator) LoginFlowDeleteHandler(c echo.Context) error {
return c.String(http.StatusBadRequest, "empty flow ID") return c.String(http.StatusBadRequest, "empty flow ID")
} }
delete(a.Flows, FlowID(flowID)) delete(a.flows, FlowID(flowID))
return c.String(http.StatusOK, "deleted") return c.String(http.StatusOK, "deleted")
} }
@ -226,13 +226,13 @@ func (a *Authenticator) LoginFlowHandler(c echo.Context) error {
flowID := c.Param("flow_id") flowID := c.Param("flow_id")
flow := a.Flows.Get(FlowID(flowID)) flow := a.flows.Get(FlowID(flowID))
if flow == nil { if flow == nil {
return c.String(http.StatusNotFound, "no such flow") return c.String(http.StatusNotFound, "no such flow")
} }
if time.Now().Sub(flow.ctime) > cullAge { if time.Now().Sub(flow.ctime) > cullAge {
a.Flows.Remove(flow) a.flows.Remove(flow)
return c.String(http.StatusGone, "flow timed out") return c.String(http.StatusGone, "flow timed out")
} }

View file

@ -65,7 +65,7 @@ func (a *Authenticator) NewToken(r *http.Request, f *Flow) TokenID {
Addr: r.RemoteAddr, Addr: r.RemoteAddr,
} }
a.Sessions.register(t) a.sessions.register(t)
return id return id
} }
@ -83,7 +83,7 @@ func (a *Authenticator) TokenHandler(c echo.Context) error {
return err return err
} }
if a.Sessions.verify(&rq, c.Request()) { if a.sessions.verify(&rq, c.Request()) {
// TODO: success // TODO: success
return c.String(http.StatusOK, "token good I guess") return c.String(http.StatusOK, "token good I guess")
} }