mirror of
https://github.com/netbirdio/netbird.git
synced 2025-05-30 22:58:45 +02:00
store hashedToken as string
This commit is contained in:
parent
ed470d7dbe
commit
83e7e30218
@ -15,7 +15,7 @@ import (
|
||||
type PersonalAccessToken struct {
|
||||
ID string
|
||||
Description string
|
||||
HashedToken [32]byte
|
||||
HashedToken string
|
||||
ExpirationDate time.Time
|
||||
// scope could be added in future
|
||||
CreatedBy string
|
||||
@ -39,7 +39,7 @@ func CreateNewPAT(description string, expirationInDays int, createdBy string) (*
|
||||
}, plainToken
|
||||
}
|
||||
|
||||
func generateNewToken() ([32]byte, string) {
|
||||
func generateNewToken() (string, string) {
|
||||
secret := randStringRunes(30)
|
||||
|
||||
checksum := crc32.ChecksumIEEE([]byte(secret))
|
||||
@ -47,7 +47,7 @@ func generateNewToken() ([32]byte, string) {
|
||||
paddedChecksum := fmt.Sprintf("%06s", encodedChecksum)
|
||||
plainToken := "nbp_" + secret + paddedChecksum
|
||||
hashedToken := sha256.Sum256([]byte(plainToken))
|
||||
return hashedToken, plainToken
|
||||
return string(hashedToken[:]), plainToken
|
||||
}
|
||||
|
||||
var letterRunes = []rune("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789")
|
||||
|
@ -12,8 +12,8 @@ import (
|
||||
|
||||
func TestPAT_GenerateToken_Hashing(t *testing.T) {
|
||||
hashedToken, plainToken := generateNewToken()
|
||||
|
||||
assert.Equal(t, hashedToken, sha256.Sum256([]byte(plainToken)))
|
||||
expectedToken := sha256.Sum256([]byte(plainToken))
|
||||
assert.Equal(t, hashedToken, string(expectedToken[:]))
|
||||
}
|
||||
|
||||
func TestPAT_GenerateToken_Prefix(t *testing.T) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user