mirror of
https://github.com/minio/minio.git
synced 2025-11-21 18:26:04 -05:00
jwt: Simplify JWT parsing (#8802)
JWT parsing is simplified by using a custom claim
data structure such as MapClaims{}, also writes
a custom Unmarshaller for faster unmarshalling.
- Avoid as much reflections as possible
- Provide the right types for functions as much
as possible
- Avoid strings.Join, strings.Split to reduce
allocations, rely on indexes directly.
This commit is contained in:
@@ -36,6 +36,7 @@ import (
|
||||
jwtgo "github.com/dgrijalva/jwt-go"
|
||||
humanize "github.com/dustin/go-humanize"
|
||||
miniogopolicy "github.com/minio/minio-go/v6/pkg/policy"
|
||||
xjwt "github.com/minio/minio/cmd/jwt"
|
||||
"github.com/minio/minio/pkg/auth"
|
||||
"github.com/minio/minio/pkg/bucket/policy"
|
||||
"github.com/minio/minio/pkg/bucket/policy/condition"
|
||||
@@ -753,12 +754,10 @@ func TestWebCreateURLToken(t *testing.T) {
|
||||
}
|
||||
|
||||
func getTokenString(accessKey, secretKey string) (string, error) {
|
||||
utcNow := UTCNow()
|
||||
mapClaims := jwtgo.MapClaims{}
|
||||
mapClaims["exp"] = utcNow.Add(defaultJWTExpiry).Unix()
|
||||
mapClaims["sub"] = accessKey
|
||||
mapClaims["accessKey"] = accessKey
|
||||
token := jwtgo.NewWithClaims(jwtgo.SigningMethodHS512, mapClaims)
|
||||
claims := xjwt.NewMapClaims()
|
||||
claims.SetExpiry(UTCNow().Add(defaultJWTExpiry))
|
||||
claims.SetAccessKey(accessKey)
|
||||
token := jwtgo.NewWithClaims(jwtgo.SigningMethodHS512, claims)
|
||||
return token.SignedString([]byte(secretKey))
|
||||
}
|
||||
|
||||
@@ -1002,7 +1001,7 @@ func testDownloadWebHandler(obj ObjectLayer, instanceType string, t TestErrHandl
|
||||
}
|
||||
|
||||
if !bytes.Equal(bodyContent, bytes.NewBufferString("Authentication failed, check your access credentials").Bytes()) {
|
||||
t.Fatalf("Expected authentication error message, got %v", bodyContent)
|
||||
t.Fatalf("Expected authentication error message, got %s", string(bodyContent))
|
||||
}
|
||||
|
||||
// Unauthenticated download should fail.
|
||||
|
||||
Reference in New Issue
Block a user