mirror of
https://forgejo.merr.is/annika/jwtauth.git
synced 2025-12-11 12:43:14 -05:00
Update README
This commit is contained in:
parent
30d5d5b360
commit
db8fa45708
2 changed files with 9 additions and 5 deletions
2
LICENSE
2
LICENSE
|
|
@ -1,4 +1,4 @@
|
|||
Copyright (c) 2015-2016 Peter Kieltyka (https://twitter.com/peterk)
|
||||
Copyright (c) 2015-Present Peter Kieltyka (https://twitter.com/peterk)
|
||||
|
||||
MIT License
|
||||
|
||||
|
|
|
|||
12
README.md
12
README.md
|
|
@ -1,9 +1,12 @@
|
|||
jwtauth - JWT middleware for Go HTTP services
|
||||
=============================================
|
||||
jwtauth - JWT middleware for Go 1.7+ HTTP services
|
||||
==================================================
|
||||
|
||||
The `jwtauth` middleware is a simple way to verify a JWT token from a request
|
||||
and send the result down the request context (`context.Context`).
|
||||
|
||||
This package uses the new `context` package in Go 1.7 also used by `net/http`
|
||||
to manage request contexts.
|
||||
|
||||
In a complete JWT-authentication sequence, you'll first capture the token from
|
||||
a request, decode it, verify and then validate that is correctly signed and hasn't
|
||||
expired - the `jwtauth.Verifier` middleware handler takes care of all of that. Next,
|
||||
|
|
@ -63,7 +66,8 @@ func router() http.Handler {
|
|||
// and tweak it, its not scary.
|
||||
r.Use(jwtauth.Authenticator)
|
||||
|
||||
r.Get("/admin", func(ctx context.Context, w http.ResponseWriter, r *http.Request) {
|
||||
r.Get("/admin", func(w http.ResponseWriter, r *http.Request) {
|
||||
ctx := r.Context()
|
||||
token := ctx.Value("jwt").(*jwt.Token)
|
||||
claims := token.Claims
|
||||
w.Write([]byte(fmt.Printf("protected area. hi %v", claims["user_id"])))
|
||||
|
|
@ -72,7 +76,7 @@ func router() http.Handler {
|
|||
|
||||
// Public routes
|
||||
r.Group(func(r chi.Router) {
|
||||
r.Get("/", func(ctx context.Context, w http.ResponseWriter, r *http.Request) {
|
||||
r.Get("/", func(w http.ResponseWriter, r *http.Request) {
|
||||
w.Write([]byte("welcome"))
|
||||
})
|
||||
})
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue