JWT parsing tool for go-swagger
Install the package in your $GOPATH
running:
go get github.com/manell/goswagger-jwt
Provided a swagger definition with the following authentication:
securityDefinitions:
bearer:
type: apiKey
name: Authorization
in: header
Create a new Auth instance with a callback function that validates the field sub in a JWT:
auth := gsjwt.Auth{
Key: []byte("My secret hmac key"),
ReturnFunction: func(values map[string]interface{}) (interface{}, error) {
sub, ok := values["sub"]
if !ok {
return nil, errors.New("Sub not provided")
}
return sub, nil
}
}
Then just configure the api:
api.BearerAuth = auth.Authenticate