@@ -2,16 +2,16 @@ package main
22
33import (
44 "encoding/json"
5- "fmt"
6- "net/http"
7- "strings"
85 "errors"
6+ "fmt"
97 "log"
8+ "net/http"
109 "os"
10+ "strings"
1111
12+ jwtmiddleware "github.com/auth0/go-jwt-middleware"
1213 "github.com/codegangsta/negroni"
13- "github.com/auth0/go-jwt-middleware"
14- "github.com/dgrijalva/jwt-go"
14+ "github.com/form3tech-oss/jwt-go"
1515 "github.com/gorilla/mux"
1616 "github.com/joho/godotenv"
1717 "github.com/rs/cors"
@@ -26,11 +26,11 @@ type Jwks struct {
2626}
2727
2828type JSONWebKeys struct {
29- Kty string `json:"kty"`
30- Kid string `json:"kid"`
31- Use string `json:"use"`
32- N string `json:"n"`
33- E string `json:"e"`
29+ Kty string `json:"kty"`
30+ Kid string `json:"kid"`
31+ Use string `json:"use"`
32+ N string `json:"n"`
33+ E string `json:"e"`
3434 X5c []string `json:"x5c"`
3535}
3636
@@ -41,7 +41,7 @@ func main() {
4141 log .Print ("Error loading .env file" )
4242 }
4343
44- jwtMiddleware := jwtmiddleware .New (jwtmiddleware.Options {
44+ jwtMiddleware := jwtmiddleware .New (jwtmiddleware.Options {
4545 ValidationKeyGetter : func (token * jwt.Token ) (interface {}, error ) {
4646 // Verify 'aud' claim
4747 aud := os .Getenv ("AUTH0_AUDIENCE" )
@@ -68,9 +68,9 @@ func main() {
6868 })
6969
7070 c := cors .New (cors.Options {
71- AllowedOrigins : []string {"http://localhost:3000" },
71+ AllowedOrigins : []string {"http://localhost:3000" },
7272 AllowCredentials : true ,
73- AllowedHeaders : []string {"Authorization" },
73+ AllowedHeaders : []string {"Authorization" },
7474 })
7575
7676 r := mux .NewRouter ()
@@ -89,7 +89,7 @@ func main() {
8989 negroni .Wrap (http .HandlerFunc (func (w http.ResponseWriter , r * http.Request ) {
9090 message := "Hello from a private endpoint! You need to be authenticated to see this."
9191 responseJSON (message , w , http .StatusOK )
92- }))))
92+ }))))
9393
9494 // This route is only accessible if the user has a valid access_token with the read:messages scope
9595 // We are chaining the jwtmiddleware middleware into the negroni handler function which will check
@@ -109,22 +109,21 @@ func main() {
109109 }
110110 message := "Hello from a private endpoint! You need to be authenticated to see this."
111111 responseJSON (message , w , http .StatusOK )
112- }))))
112+ }))))
113113
114114 handler := c .Handler (r )
115115 http .Handle ("/" , r )
116116 fmt .Println ("Listening on http://localhost:3010" )
117117 http .ListenAndServe ("0.0.0.0:3010" , handler )
118118}
119119
120-
121120type CustomClaims struct {
122121 Scope string `json:"scope"`
123122 jwt.StandardClaims
124123}
125124
126125func checkScope (scope string , tokenString string ) bool {
127- token , _ := jwt .ParseWithClaims (tokenString , & CustomClaims {}, func (token * jwt.Token ) (interface {}, error ) {
126+ token , _ := jwt .ParseWithClaims (tokenString , & CustomClaims {}, func (token * jwt.Token ) (interface {}, error ) {
128127 cert , err := getPemCert (token )
129128 if err != nil {
130129 return nil , err
0 commit comments