Move utils into shared folder
This commit is contained in:
parent
500bf48295
commit
c25f27e82e
22 changed files with 111 additions and 137 deletions
|
@ -4,7 +4,8 @@ import (
|
|||
"github.com/go-webauthn/webauthn/webauthn"
|
||||
"github.com/google/uuid"
|
||||
"github.com/rs/zerolog/log"
|
||||
"git.mstar.dev/mstar/linstrom/util"
|
||||
|
||||
"git.mstar.dev/mstar/linstrom/shared"
|
||||
)
|
||||
|
||||
// Session data used during login attempts with a passkey
|
||||
|
@ -19,7 +20,7 @@ type PasskeySession struct {
|
|||
|
||||
// Generate some id for a new session. Just returns a new uuid
|
||||
func (s *Storage) GenSessionID() (string, error) {
|
||||
defer util.Untrace(util.Trace(&log.Logger))
|
||||
defer shared.Untrace(shared.Trace(&log.Logger))
|
||||
x := uuid.NewString()
|
||||
log.Debug().Str("session-id", x).Msg("Generated new passkey session id")
|
||||
return x, nil
|
||||
|
@ -28,7 +29,7 @@ func (s *Storage) GenSessionID() (string, error) {
|
|||
// Look for an active session with a given id
|
||||
// Returns the session if found and a bool indicating if a session was found
|
||||
func (s *Storage) GetSession(sessionId string) (*webauthn.SessionData, bool) {
|
||||
defer util.Untrace(util.Trace(&log.Logger))
|
||||
defer shared.Untrace(shared.Trace(&log.Logger))
|
||||
log.Debug().Str("id", sessionId).Msg("Looking for passkey session")
|
||||
session := PasskeySession{}
|
||||
res := s.db.Where("id = ?", sessionId).First(&session)
|
||||
|
@ -41,7 +42,7 @@ func (s *Storage) GetSession(sessionId string) (*webauthn.SessionData, bool) {
|
|||
|
||||
// Save (or update) a session with the new data
|
||||
func (s *Storage) SaveSession(token string, data *webauthn.SessionData) {
|
||||
defer util.Untrace(util.Trace(&log.Logger))
|
||||
defer shared.Untrace(shared.Trace(&log.Logger))
|
||||
log.Debug().Str("id", token).Any("webauthn-data", data).Msg("Saving passkey session")
|
||||
session := PasskeySession{
|
||||
ID: token,
|
||||
|
@ -53,7 +54,7 @@ func (s *Storage) SaveSession(token string, data *webauthn.SessionData) {
|
|||
// Delete a session
|
||||
// NOTE: This is a hard delete since the session struct contains no DeletedAt field
|
||||
func (s *Storage) DeleteSession(token string) {
|
||||
defer util.Untrace(util.Trace(&log.Logger))
|
||||
defer shared.Untrace(shared.Trace(&log.Logger))
|
||||
log.Debug().Str("id", token).Msg("Deleting passkey session (if one exists)")
|
||||
s.db.Delete(&PasskeySession{ID: token})
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue