api keys change encoding to base32 (#1813)
This commit is contained in:
parent
f7409ab52b
commit
75870005b2
@ -6,7 +6,7 @@ package console
|
||||
import (
|
||||
"context"
|
||||
"crypto/rand"
|
||||
"encoding/base64"
|
||||
"encoding/base32"
|
||||
"io"
|
||||
"time"
|
||||
|
||||
@ -47,7 +47,7 @@ type APIKey [24]byte
|
||||
|
||||
// String implements Stringer
|
||||
func (key APIKey) String() string {
|
||||
return base64.URLEncoding.EncodeToString(key[:])
|
||||
return base32.HexEncoding.EncodeToString(key[:])
|
||||
}
|
||||
|
||||
// APIKeyFromBytes creates new key from byte slice
|
||||
@ -57,9 +57,9 @@ func APIKeyFromBytes(b []byte) *APIKey {
|
||||
return key
|
||||
}
|
||||
|
||||
// APIKeyFromBase64 creates new key from base64 string
|
||||
func APIKeyFromBase64(s string) (*APIKey, error) {
|
||||
b, err := base64.URLEncoding.DecodeString(s)
|
||||
// APIKeyFromBase32 creates new key from base32 string
|
||||
func APIKeyFromBase32(s string) (*APIKey, error) {
|
||||
b, err := base32.HexEncoding.DecodeString(s)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
@ -77,7 +77,7 @@ func (endpoint *Endpoint) validateAuth(ctx context.Context) (*console.APIKeyInfo
|
||||
return nil, status.Errorf(codes.Unauthenticated, "Invalid API credential")
|
||||
}
|
||||
|
||||
key, err := console.APIKeyFromBase64(string(APIKey))
|
||||
key, err := console.APIKeyFromBase32(string(APIKey))
|
||||
if err != nil {
|
||||
endpoint.log.Error("unauthorized request: ", zap.Error(status.Errorf(codes.Unauthenticated, "Invalid API credential")))
|
||||
return nil, status.Errorf(codes.Unauthenticated, "Invalid API credential")
|
||||
|
Loading…
Reference in New Issue
Block a user