middleware

package module
v1.0.9 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 31, 2020 License: MIT Imports: 6 Imported by: 0

README

tarent/middleware-jwt Build Status

middleware-jwt provides JWT authentication for Go. It is compatible with Go's own net/http and anything that speaks the http.Handler interface.

Examples

See the examples folder for working examples.

Installation

$ go get github.com/tarent/middleware-jwt

Usage

Since it's all http.Handler, middleware-jwt works with gorilla/mux and most other routers.

Basic usage

To run the simple example execute:

go run examples/gorilla/simple/main.go

To test it, execute the following curl in another terminal:

curl -v -H "Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiZ3JvdXBzIjpbImdyb3VwQSIsImdyb3VwQiJdLCJpYXQiOjE1MTYyMzkwMjJ9.pPJGnFh4FUJnIcnReZlrrraG0Ep_bqEadYo6iH4KdHY" localhost:8080
Advanced usage

For complex authentication scenarios, you can access the "claims" in the http context which is passed to the subsequent http handlers. This allows you to:

To run the advanced example execute:

go run examples/gorilla/advanced/main.go

To test it, execute the following curl in another terminal:

curl -v -H "Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiZ3JvdXBzIjpbImdyb3VwQSIsImdyb3VwQiJdLCJpYXQiOjE1MTYyMzkwMjJ9.pPJGnFh4FUJnIcnReZlrrraG0Ep_bqEadYo6iH4KdHY" localhost:8080

License

MIT Licensed. See the LICENSE file for details.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetGroupsFromAuthenticatedRequest

func GetGroupsFromAuthenticatedRequest(r *http.Request) []string

func JwtAuthAllowAll

func JwtAuthAllowAll(jwtSecret string) func(http.Handler) http.Handler

func JwtAuthAnyGroup

func JwtAuthAnyGroup(jwtSecret string, allowedGroups ...string) func(http.Handler) http.Handler

Types

This section is empty.

Directories

Path Synopsis
examples
Package mock_http is a generated GoMock package.
Package mock_http is a generated GoMock package.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL