mirror of
https://forgejo.merr.is/annika/jwtauth.git
synced 2025-12-11 12:43:14 -05:00
Update formatting in README
This commit is contained in:
parent
d62dd5080d
commit
464e20f997
1 changed files with 25 additions and 23 deletions
48
README.md
48
README.md
|
|
@ -33,7 +33,8 @@ all unverified tokens, see jwtauth.Authenticator.
|
|||
package myservice
|
||||
|
||||
import (
|
||||
"github.com/dgrijalva/jwt-go"
|
||||
"net/http"
|
||||
|
||||
"github.com/goware/jwtauth"
|
||||
"github.com/pressly/chi"
|
||||
"golang.org/x/net/context"
|
||||
|
|
@ -42,37 +43,38 @@ import (
|
|||
var TokenAuth *jwtauth.JwtAuth
|
||||
|
||||
func init() {
|
||||
TokenAuth = jwtauth.New("HS256", []byte("secret"), nil)
|
||||
TokenAuth = jwtauth.New("HS256", []byte("secret"), nil)
|
||||
}
|
||||
|
||||
func router() http.Handler {
|
||||
r := chi.NewRouter()
|
||||
r := chi.NewRouter()
|
||||
|
||||
// Protected routes
|
||||
r.Group(func(r chi.Router) {
|
||||
// Seek, verify and validate JWT tokens
|
||||
r.Use(TokenAuth.Verifier)
|
||||
// Protected routes
|
||||
r.Group(func(r chi.Router) {
|
||||
// Seek, verify and validate JWT tokens
|
||||
r.Use(TokenAuth.Verifier)
|
||||
|
||||
// Handle valid / invalid tokens. In this example, we use
|
||||
// the provided authenticator middleware, but you can write your
|
||||
// own very easily, look at the Authenticator method in jwtauth.go
|
||||
// and tweak it, its not scary.
|
||||
r.Use(jwtauth.Authenticator)
|
||||
// Handle valid / invalid tokens. In this example, we use
|
||||
// the provided authenticator middleware, but you can write your
|
||||
// own very easily, look at the Authenticator method in jwtauth.go
|
||||
// and tweak it, its not scary.
|
||||
r.Use(jwtauth.Authenticator)
|
||||
|
||||
r.Get("/admin", func(ctx context.Context, w http.ResponseWriter, r *http.Request) {
|
||||
w.Write([]byte("protected"))
|
||||
})
|
||||
})
|
||||
r.Get("/admin", func(ctx context.Context, w http.ResponseWriter, r *http.Request) {
|
||||
w.Write([]byte("protected"))
|
||||
})
|
||||
})
|
||||
|
||||
// Public routes
|
||||
r.Group(func(r chi.Router) {
|
||||
r.Get("/", func(ctx context.Context, w http.ResponseWriter, r *http.Request) {
|
||||
w.Write([]byte("welcome"))
|
||||
})
|
||||
})
|
||||
// Public routes
|
||||
r.Group(func(r chi.Router) {
|
||||
r.Get("/", func(ctx context.Context, w http.ResponseWriter, r *http.Request) {
|
||||
w.Write([]byte("welcome"))
|
||||
})
|
||||
})
|
||||
|
||||
return r
|
||||
return r
|
||||
}
|
||||
|
||||
```
|
||||
|
||||
# LICENSE
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue