feat: add mfa session to secure otp login

This commit is contained in:
catusax
2023-07-20 15:11:39 +08:00
parent 87a962504f
commit 5018462559
9 changed files with 185 additions and 9 deletions

View File

@@ -7,18 +7,20 @@ import (
)
type provider struct {
mutex sync.Mutex
sessionStore *stores.SessionStore
stateStore *stores.StateStore
envStore *stores.EnvStore
mutex sync.Mutex
sessionStore *stores.SessionStore
mfasessionStore *stores.SessionStore
stateStore *stores.StateStore
envStore *stores.EnvStore
}
// NewInMemoryStore returns a new in-memory store.
func NewInMemoryProvider() (*provider, error) {
return &provider{
mutex: sync.Mutex{},
envStore: stores.NewEnvStore(),
sessionStore: stores.NewSessionStore(),
stateStore: stores.NewStateStore(),
mutex: sync.Mutex{},
envStore: stores.NewEnvStore(),
sessionStore: stores.NewSessionStore(),
mfasessionStore: stores.NewSessionStore(),
stateStore: stores.NewStateStore(),
}, nil
}

View File

@@ -42,6 +42,24 @@ func (c *provider) DeleteSessionForNamespace(namespace string) error {
return nil
}
func (c *provider) SetMfaSession(email, key string, expiration int64) error {
c.mfasessionStore.Set(email, key, email, expiration)
return nil
}
func (c *provider) GetMfaSession(email, key string) (string, error) {
val := c.mfasessionStore.Get(email, key)
if val == "" {
return "", fmt.Errorf("Not found")
}
return val, nil
}
func (c *provider) DeleteMfaSession(email, key string) error {
c.mfasessionStore.Remove(email, key)
return nil
}
// SetState sets the state in the in-memory store.
func (c *provider) SetState(key, state string) error {
if os.Getenv("ENV") != constants.TestEnv {