1
0
mirror of https://github.com/labstack/echo.git synced 2024-12-24 20:14:31 +02:00

Minor refactor and format

Signed-off-by: Vishal Rana <vr@labstack.com>
This commit is contained in:
Vishal Rana 2016-08-20 09:12:17 -07:00
parent 2557d33c4b
commit 87dbea59f7
2 changed files with 11 additions and 12 deletions

View File

@ -28,6 +28,10 @@ type (
// Optional. Default value "user".
ContextKey string `json:"context_key"`
// Claims are extendable claims data defining token content.
// Optional. Default value jwt.MapClaims
Claims jwt.Claims
// TokenLookup is a string in the form of "<source>:<name>" that is used
// to extract token from the request.
// Optional. Default value "header:Authorization".
@ -35,10 +39,6 @@ type (
// - "header:<name>"
// - "query:<name>"
TokenLookup string `json:"token_lookup"`
// Claims are extendable claims data defining token content.
// Optional. Default value jwt.MapClaims
Claims jwt.Claims
}
jwtExtractor func(echo.Context) (string, error)

View File

@ -10,16 +10,16 @@ import (
"github.com/stretchr/testify/assert"
)
// CustomInfo defines some custom types we're going to use within our tokens
type CustomInfo struct {
// jwtCustomInfo defines some custom types we're going to use within our tokens.
type jwtCustomInfo struct {
Name string `json:"name"`
Admin bool `json:"admin"`
}
// MyCustomClaims are custom claims expanding default ones
type MyCustomClaims struct {
// jwtCustomClaims are custom claims expanding default ones.
type jwtCustomClaims struct {
*jwt.StandardClaims
CustomInfo
jwtCustomInfo
}
func TestJWT(t *testing.T) {
@ -63,13 +63,13 @@ func TestJWT(t *testing.T) {
// Valid JWT with custom claims
config = JWTConfig{
Claims: &MyCustomClaims{},
Claims: &jwtCustomClaims{},
SigningKey: []byte("secret"),
}
h = JWTWithConfig(config)(handler)
if assert.NoError(t, h(c)) {
user := c.Get("user").(*jwt.Token)
claims := user.Claims.(*MyCustomClaims)
claims := user.Claims.(*jwtCustomClaims)
assert.Equal(t, claims.Name, "John Doe")
assert.Equal(t, claims.Admin, true)
}
@ -79,5 +79,4 @@ func TestJWT(t *testing.T) {
h = JWT([]byte("secret"))(handler)
he = h(c).(*echo.HTTPError)
assert.Equal(t, http.StatusBadRequest, he.Code)
}