bwhttp

package
v0.0.0-...-ba4d39b Latest Latest
Warning

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

Go to latest
Published: Apr 22, 2017 License: MIT Imports: 3 Imported by: 0

README

bwhttp

-- import "github.com/ckaznocha/go-JWTBearerware/middleware/net_http"

Usage

var JWTContext bearerware.JWTContexter

JWTContext stores the request scoped tokens

func JWTHandler
func JWTHandler(
	h http.HandlerFunc,
	keyFunc jwt.Keyfunc,
	signingMethod jwt.SigningMethod,
) http.HandlerFunc

JWTHandler is JWT middleware for net/http

Documentation

Index

Examples

Constants

This section is empty.

Variables

View Source
var JWTContext bearerware.JWTContexter

JWTContext stores the request scoped tokens

Functions

func JWTHandler

func JWTHandler(
	h http.HandlerFunc,
	keyFunc jwt.Keyfunc,
	signingMethod jwt.SigningMethod,
) http.HandlerFunc

JWTHandler is JWT middleware for net/http

Example
var (
	handler = func(w http.ResponseWriter, req *http.Request) {
		token, ok := bwhttp.JWTContext.ReadJWT(req)
		if !ok {
			http.Error(
				w,
				http.StatusText(http.StatusInternalServerError),
				http.StatusInternalServerError,
			)
		}
		fmt.Fprintf(w, "Token signed using %s", token.Method)
	}
	jwtKeyFunc = func(token *jwt.Token) (interface{}, error) {
		return []byte("MySecret"), nil
	}

	mux = http.NewServeMux()
)
mux.HandleFunc(
	"/",
	bwhttp.JWTHandler(handler, jwtKeyFunc, jwt.SigningMethodHS256),
)

if err := http.ListenAndServe("localhost:8080", mux); err != nil {
	log.Print(err)
}
Output:

Types

This section is empty.

Jump to

Keyboard shortcuts

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