mirror of
https://forgejo.merr.is/annika/jwtauth.git
synced 2025-12-13 05:43:16 -05:00
Include full, runnable example
This commit is contained in:
parent
04d0f4ea61
commit
d5f87ca5c3
2 changed files with 122 additions and 3 deletions
|
|
@ -38,8 +38,10 @@ all unverified tokens, see jwtauth.Authenticator.
|
|||
|
||||
# Usage
|
||||
|
||||
See the full [example](https://github.com/goware/jwtauth/blob/master/_example/main.go).
|
||||
|
||||
```go
|
||||
package myservice
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
|
@ -75,14 +77,14 @@ func router() http.Handler {
|
|||
ctx := r.Context()
|
||||
token := ctx.Value("jwt").(*jwt.Token)
|
||||
claims := token.Claims
|
||||
w.Write([]byte(fmt.Printf("protected area. hi %v", claims["user_id"])))
|
||||
w.Write([]byte(fmt.Sprintf("protected area. hi %v", claims["user_id"])))
|
||||
})
|
||||
})
|
||||
|
||||
// Public routes
|
||||
r.Group(func(r chi.Router) {
|
||||
r.Get("/", func(w http.ResponseWriter, r *http.Request) {
|
||||
w.Write([]byte("welcome"))
|
||||
w.Write([]byte("welcome anonymous"))
|
||||
})
|
||||
})
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue