userid ass mfa session key

This commit is contained in:
catusax
2023-07-24 11:58:36 +08:00
parent 9f52c08883
commit ba0cf189de
6 changed files with 44 additions and 21 deletions

View File

@@ -42,15 +42,15 @@ func (c *provider) DeleteSessionForNamespace(namespace string) error {
return nil
}
// SetMfaSession sets the mfa session with key and value of email
func (c *provider) SetMfaSession(email, key string, expiration int64) error {
c.mfasessionStore.Set(email, key, email, expiration)
// SetMfaSession sets the mfa session with key and value of userId
func (c *provider) SetMfaSession(userId, key string, expiration int64) error {
c.mfasessionStore.Set(userId, key, userId, expiration)
return nil
}
// GetMfaSession returns value of given mfa session
func (c *provider) GetMfaSession(email, key string) (string, error) {
val := c.mfasessionStore.Get(email, key)
func (c *provider) GetMfaSession(userId, key string) (string, error) {
val := c.mfasessionStore.Get(userId, key)
if val == "" {
return "", fmt.Errorf("Not found")
}
@@ -58,8 +58,8 @@ func (c *provider) GetMfaSession(email, key string) (string, error) {
}
// DeleteMfaSession deletes given mfa session from in-memory store.
func (c *provider) DeleteMfaSession(email, key string) error {
c.mfasessionStore.Remove(email, key)
func (c *provider) DeleteMfaSession(userId, key string) error {
c.mfasessionStore.Remove(userId, key)
return nil
}

View File

@@ -12,12 +12,12 @@ type Provider interface {
DeleteAllUserSessions(userId string) error
// DeleteSessionForNamespace deletes the session for a given namespace
DeleteSessionForNamespace(namespace string) error
// SetMfaSession sets the mfa session with key and value of email
SetMfaSession(email, key string, expiration int64) error
// SetMfaSession sets the mfa session with key and value of userId
SetMfaSession(userId, key string, expiration int64) error
// GetMfaSession returns value of given mfa session
GetMfaSession(email, key string) (string, error)
GetMfaSession(userId, key string) (string, error)
// DeleteMfaSession deletes given mfa session from in-memory store.
DeleteMfaSession(email, key string) error
DeleteMfaSession(userId, key string) error
// SetState sets the login state (key, value form) in the session store
SetState(key, state string) error

View File

@@ -93,12 +93,12 @@ func (c *provider) DeleteSessionForNamespace(namespace string) error {
return nil
}
// SetMfaSession sets the mfa session with key and value of email
func (c *provider) SetMfaSession(email, key string, expiration int64) error {
// SetMfaSession sets the mfa session with key and value of userId
func (c *provider) SetMfaSession(userId, key string, expiration int64) error {
currentTime := time.Now()
expireTime := time.Unix(expiration, 0)
duration := expireTime.Sub(currentTime)
err := c.store.Set(c.ctx, fmt.Sprintf("%s%s:%s", mfaSessionPrefix, email, key), email, duration).Err()
err := c.store.Set(c.ctx, fmt.Sprintf("%s%s:%s", mfaSessionPrefix, userId, key), userId, duration).Err()
if err != nil {
log.Debug("Error saving user session to redis: ", err)
return err
@@ -106,9 +106,9 @@ func (c *provider) SetMfaSession(email, key string, expiration int64) error {
return nil
}
// GetMfaSession returns value of given mfa session
func (c *provider) GetMfaSession(email, key string) (string, error) {
data, err := c.store.Get(c.ctx, fmt.Sprintf("%s%s:%s", mfaSessionPrefix, email, key)).Result()
// GetMfaSession returns value of given mfa session
func (c *provider) GetMfaSession(userId, key string) (string, error) {
data, err := c.store.Get(c.ctx, fmt.Sprintf("%s%s:%s", mfaSessionPrefix, userId, key)).Result()
if err != nil {
return "", err
}
@@ -116,8 +116,8 @@ func (c *provider) GetMfaSession(email, key string) (string, error) {
}
// DeleteMfaSession deletes given mfa session from in-memory store.
func (c *provider) DeleteMfaSession(email, key string) error {
if err := c.store.Del(c.ctx, fmt.Sprintf("%s%s:%s", mfaSessionPrefix, email, key)).Err(); err != nil {
func (c *provider) DeleteMfaSession(userId, key string) error {
if err := c.store.Del(c.ctx, fmt.Sprintf("%s%s:%s", mfaSessionPrefix, userId, key)).Err(); err != nil {
log.Debug("Error deleting user session from redis: ", err)
// continue
}