Vendor SharedCode locally
Docker / Docker Build & Push (push) Failing after 1m19s
Lint / Lint (push) Successful in 15s
Tests / Go backend (push) Successful in 19s
Tests / Dashboard checks (push) Successful in 18s

This commit is contained in:
Gabriel20xx committed 2026-08-06 15:52:56 +02:00
1 parent a8c51b8484
commit 6eb8f4ad60
88 files changed
+9708 -275

No files matched your search

+25
View File
@@ -0,0 +1,25 @@
package auth
import (
"crypto/rand"
"crypto/sha256"
"encoding/base64"
)
// NewSessionToken creates a random bearer token and its SHA-256 storage hash.
// Store only the hash; return the raw token to the caller that sets the cookie
// or authorization header.
func NewSessionToken() (raw string, hash string, err error) {
bytes := make([]byte, 32)
if _, err := rand.Read(bytes); err != nil {
return "", "", err
}
raw = base64.RawURLEncoding.EncodeToString(bytes)
return raw, HashToken(raw), nil
}
// HashToken creates the stable database key for a raw session/API token.
func HashToken(raw string) string {
sum := sha256.Sum256([]byte(raw))
return base64.RawURLEncoding.EncodeToString(sum[:])
}