Skip to content

manell/goswagger-jwt

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 

Repository files navigation

goswagger-jwt

JWT parsing tool for go-swagger

Installation

Install the package in your $GOPATH running:

go get github.com/manell/goswagger-jwt

Usage

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

About

JWT parsing tool for go-swagger

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages