fix: auth flow
This commit is contained in:
@@ -20,7 +20,7 @@ func StringSliceContains(s []string, e string) bool {
|
||||
|
||||
// SaveSessionInDB saves sessions generated for a given user with meta information
|
||||
// Do not store token here as that could be security breach
|
||||
func SaveSessionInDB(userId string, c *gin.Context) {
|
||||
func SaveSessionInDB(c *gin.Context, userId string) {
|
||||
sessionData := models.Session{
|
||||
UserID: userId,
|
||||
UserAgent: GetUserAgent(c.Request),
|
||||
|
36
server/utils/nonce.go
Normal file
36
server/utils/nonce.go
Normal file
@@ -0,0 +1,36 @@
|
||||
package utils
|
||||
|
||||
import (
|
||||
"github.com/google/uuid"
|
||||
|
||||
"github.com/authorizerdev/authorizer/server/crypto"
|
||||
)
|
||||
|
||||
// GenerateNonce generats random nonce string and returns
|
||||
// the nonce string, nonce hash, error
|
||||
func GenerateNonce() (string, string, error) {
|
||||
nonce := uuid.New().String()
|
||||
nonceHash, err := crypto.EncryptAES(nonce)
|
||||
if err != nil {
|
||||
return "", "", err
|
||||
}
|
||||
return nonce, nonceHash, err
|
||||
}
|
||||
|
||||
// EncryptNonce nonce string
|
||||
func EncryptNonce(nonce string) (string, error) {
|
||||
nonceHash, err := crypto.EncryptAES(nonce)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
return nonceHash, err
|
||||
}
|
||||
|
||||
// DecryptNonce nonce string
|
||||
func DecryptNonce(nonceHash string) (string, error) {
|
||||
nonce, err := crypto.DecryptAES(nonceHash)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
return nonce, err
|
||||
}
|
Reference in New Issue
Block a user