-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.go
37 lines (29 loc) · 793 Bytes
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
package main
import (
"log"
"net/http"
"strings"
"github.com/gorilla/mux"
"github.com/jurabek/jwt-validation/jwt"
"github.com/jurabek/jwt-validation/middleware"
)
func main() {
httpClient := jwt.JWKHttpClient{}
verifier := jwt.JwtTokenVerifier{
JWKSUri: "https://dev-kc4te-sm.eu.auth0.com/.well-known/jwks.json",
HTTPClient: &httpClient,
}
r := mux.NewRouter()
r.HandleFunc("/info", func(w http.ResponseWriter, r *http.Request) {
t := strings.Split(r.Header.Get("Authorization"), " ")[1]
token, _ := verifier.Parse(r.Context(), t)
w.Header().Set("Content-Type", "application/json")
_, _ = w.Write([]byte(token.Raw))
})
amw := middleware.Auth{
JwtTokenVerifier: verifier,
}
r.Use(amw.Middleware)
err := http.ListenAndServe(":3000", r)
log.Fatal(err)
}