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