Skip to content

Commit

Permalink
Added Opaque Tokens
Browse files Browse the repository at this point in the history
  • Loading branch information
Ju-Wiluis William Rodriguez Hernandez committed Jul 15, 2024
1 parent 95918b3 commit 2826027
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
18 changes: 18 additions & 0 deletions auth/opaque.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package auth

import (
"crypto/rand"
"encoding/base64"
"fmt"
)

func GenerateOpaqueToken(length int) (string, error) {
// Crea un slice de bytes de longitud especificada
token := make([]byte, length)
// Llena el slice de bytes con datos aleatorios
if _, err := rand.Read(token); err != nil {
return "", fmt.Errorf("error generating token: %v", err)
}
// Codifica el slice de bytes en una cadena base64
return base64.URLEncoding.EncodeToString(token), nil
}
2 changes: 1 addition & 1 deletion redis/redis.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ func GetInstance() *redis.Client {
}

func GenerateToken(userId string) (string, error) {
token := auth.GenerateJWT(auth.User{Id: userId})
token, _ := auth.GenerateOpaqueToken(32)
err := GetInstance().Set(context.Background(), fmt.Sprintf("auth_token:%s", token), userId, 5*time.Minute).Err()
if err != nil {
return "", err
Expand Down

0 comments on commit 2826027

Please sign in to comment.