Skip to content

Commit b777173

Browse files
committed
Replace gorilla/mux with gin-gonic/gin
1 parent 14545af commit b777173

4 files changed

Lines changed: 158 additions & 88 deletions

File tree

01-Authorization-RS256/go.mod

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
module 01-Authorization-RS256
22

3-
go 1.17
3+
go 1.16
44

55
require (
66
github.com/auth0/go-jwt-middleware v1.0.1
7-
github.com/codegangsta/negroni v1.0.0
87
github.com/form3tech-oss/jwt-go v3.2.5+incompatible
9-
github.com/gorilla/mux v1.8.0
8+
github.com/gin-gonic/gin v1.7.4
109
github.com/joho/godotenv v1.3.0
1110
github.com/rs/cors v1.8.0
1211
)

01-Authorization-RS256/go.sum

Lines changed: 81 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,89 @@
11
github.com/auth0/go-jwt-middleware v1.0.1 h1:/fsQ4vRr4zod1wKReUH+0A3ySRjGiT9G34kypO/EKwI=
22
github.com/auth0/go-jwt-middleware v1.0.1/go.mod h1:YSeUX3z6+TF2H+7padiEqNJ73Zy9vXW72U//IgN0BIM=
3-
github.com/codegangsta/negroni v1.0.0 h1:+aYywywx4bnKXWvoWtRfJ91vC59NbEhEY03sZjQhbVY=
4-
github.com/codegangsta/negroni v1.0.0/go.mod h1:v0y3T5G7Y1UlFfyxFn/QLRU4a2EuNau2iZY63YTKWo0=
3+
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
4+
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
5+
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
6+
github.com/form3tech-oss/jwt-go v3.2.2+incompatible/go.mod h1:pbq4aXjuKjdthFRnoDwaVPLA+WlJuPGy+QneDUgJi2k=
57
github.com/form3tech-oss/jwt-go v3.2.5+incompatible h1:/l4kBbb4/vGSsdtB5nUe8L7B9mImVMaBPw9L/0TBHU8=
68
github.com/form3tech-oss/jwt-go v3.2.5+incompatible/go.mod h1:pbq4aXjuKjdthFRnoDwaVPLA+WlJuPGy+QneDUgJi2k=
7-
github.com/gorilla/mux v1.8.0 h1:i40aqfkR1h2SlN9hojwV5ZA91wcXFOvkdNIeFDP5koI=
8-
github.com/gorilla/mux v1.8.0/go.mod h1:DVbg23sWSpFRCP0SfiEN6jmj59UnW/n46BH5rLB71So=
9+
github.com/gin-contrib/sse v0.1.0 h1:Y/yl/+YNO8GZSjAhjMsSuLt29uWRFHdHYUb5lYOV9qE=
10+
github.com/gin-contrib/sse v0.1.0/go.mod h1:RHrZQHXnP2xjPF+u1gW/2HnVO7nvIa9PG3Gm+fLHvGI=
11+
github.com/gin-gonic/gin v1.5.0/go.mod h1:Nd6IXA8m5kNZdNEHMBd93KT+mdY3+bewLgRvmCsR2Do=
12+
github.com/gin-gonic/gin v1.7.4 h1:QmUZXrvJ9qZ3GfWvQ+2wnW/1ePrTEJqPKMYEU3lD/DM=
13+
github.com/gin-gonic/gin v1.7.4/go.mod h1:jD2toBW3GZUr5UMcdrwQA10I7RuaFOl/SGeDjXkfUtY=
14+
github.com/go-playground/assert/v2 v2.0.1 h1:MsBgLAaY856+nPRTKrp3/OZK38U/wa0CcBYNjji3q3A=
15+
github.com/go-playground/assert/v2 v2.0.1/go.mod h1:VDjEfimB/XKnb+ZQfWdccd7VUvScMdVu0Titje2rxJ4=
16+
github.com/go-playground/locales v0.12.1/go.mod h1:IUMDtCfWo/w/mtMfIE/IG2K+Ey3ygWanZIBtBW0W2TM=
17+
github.com/go-playground/locales v0.13.0 h1:HyWk6mgj5qFqCT5fjGBuRArbVDfE4hi8+e8ceBS/t7Q=
18+
github.com/go-playground/locales v0.13.0/go.mod h1:taPMhCMXrRLJO55olJkUXHZBHCxTMfnGwq/HNwmWNS8=
19+
github.com/go-playground/universal-translator v0.16.0/go.mod h1:1AnU7NaIRDWWzGEKwgtJRd2xk99HeFyHw3yid4rvQIY=
20+
github.com/go-playground/universal-translator v0.17.0 h1:icxd5fm+REJzpZx7ZfpaD876Lmtgy7VtROAbHHXk8no=
21+
github.com/go-playground/universal-translator v0.17.0/go.mod h1:UkSxE5sNxxRwHyU+Scu5vgOQjsIJAF8j9muTVoKLVtA=
22+
github.com/go-playground/validator/v10 v10.4.1 h1:pH2c5ADXtd66mxoE0Zm9SUhxE20r7aM3F26W0hOn+GE=
23+
github.com/go-playground/validator/v10 v10.4.1/go.mod h1:nlOn6nFhuKACm19sB/8EGNn9GlaMV7XkbRSipzJ0Ii4=
24+
github.com/golang/protobuf v1.3.2/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
25+
github.com/golang/protobuf v1.3.3 h1:gyjaxf+svBWX08ZjK86iN9geUJF0H6gp2IRKX6Nf6/I=
26+
github.com/golang/protobuf v1.3.3/go.mod h1:vzj43D7+SQXF/4pzW/hwtAqwc6iTitCiVSaWz5lYuqw=
27+
github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
28+
github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1/go.mod h1:wJfORRmW1u3UXTncJ5qlYoELFm8eSnnEO6hX4iZ3EWY=
29+
github.com/gopherjs/gopherjs v0.0.0-20200217142428-fce0ec30dd00 h1:l5lAOZEym3oK3SQ2HBHWsJUfbNBiTXJDeW2QDxw9AQ0=
30+
github.com/gopherjs/gopherjs v0.0.0-20200217142428-fce0ec30dd00/go.mod h1:wJfORRmW1u3UXTncJ5qlYoELFm8eSnnEO6hX4iZ3EWY=
31+
github.com/gorilla/mux v1.7.4 h1:VuZ8uybHlWmqV03+zRzdwKL4tUnIp1MAQtp1mIFE1bc=
32+
github.com/gorilla/mux v1.7.4/go.mod h1:DVbg23sWSpFRCP0SfiEN6jmj59UnW/n46BH5rLB71So=
933
github.com/joho/godotenv v1.3.0 h1:Zjp+RcGpHhGlrMbJzXTrZZPrWj+1vfm90La1wgB6Bhc=
1034
github.com/joho/godotenv v1.3.0/go.mod h1:7hK45KPybAkOC6peb+G5yklZfMxEjkZhHbwpqxOKXbg=
35+
github.com/json-iterator/go v1.1.7/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4=
36+
github.com/json-iterator/go v1.1.9 h1:9yzud/Ht36ygwatGx56VwCZtlI/2AD15T1X2sjSuGns=
37+
github.com/json-iterator/go v1.1.9/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4=
38+
github.com/jtolds/gls v4.20.0+incompatible h1:xdiiI2gbIgH/gLH7ADydsJ1uDOEzR8yvV7C0MuV77Wo=
39+
github.com/jtolds/gls v4.20.0+incompatible/go.mod h1:QJZ7F/aHp+rZTRtaJ1ow/lLfFfVYBRgL+9YlvaHOwJU=
40+
github.com/leodido/go-urn v1.1.0/go.mod h1:+cyI34gQWZcE1eQU7NVgKkkzdXDQHr1dBMtdAPozLkw=
41+
github.com/leodido/go-urn v1.2.0 h1:hpXL4XnriNwQ/ABnpepYM/1vCLWNDfUNts8dX3xTG6Y=
42+
github.com/leodido/go-urn v1.2.0/go.mod h1:+8+nEpDfqqsY+g338gtMEUOtuK+4dEMhiQEgxpxOKII=
43+
github.com/mattn/go-isatty v0.0.9/go.mod h1:YNRxwqDuOph6SZLI9vUUz6OYw3QyUt7WiY2yME+cCiQ=
44+
github.com/mattn/go-isatty v0.0.12 h1:wuysRhFDzyxgEmMf5xjvJ2M9dZoWAXNNr5LSBS7uHXY=
45+
github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU=
46+
github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421 h1:ZqeYNhU3OHLH3mGKHDcjJRFFRrJa6eAM5H+CtDdOsPc=
47+
github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
48+
github.com/modern-go/reflect2 v0.0.0-20180701023420-4b7aa43c6742 h1:Esafd1046DLDQ0W1YjYsBW+p8U2u7vzgW2SQVmlNazg=
49+
github.com/modern-go/reflect2 v0.0.0-20180701023420-4b7aa43c6742/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0=
50+
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
51+
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
1152
github.com/rs/cors v1.8.0 h1:P2KMzcFwrPoSjkF1WLRPsp3UMLyql8L4v9hQpVeK5so=
1253
github.com/rs/cors v1.8.0/go.mod h1:EBwu+T5AvHOcXwvZIkQFjUN6s8Czyqw12GL/Y0tUyRM=
54+
github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d/go.mod h1:OnSkiWE9lh6wB0YB77sQom3nweQdgAjqCqsofrRNTgc=
55+
github.com/smartystreets/assertions v1.1.0 h1:MkTeG1DMwsrdH7QtLXy5W+fUxWq+vmb6cLmyJ7aRtF0=
56+
github.com/smartystreets/assertions v1.1.0/go.mod h1:tcbTF8ujkAEcZ8TElKY+i30BzYlVhC/LOxJk7iOWnoo=
57+
github.com/smartystreets/goconvey v1.6.4 h1:fv0U8FUIMPNf1L9lnHLvLhgicrIVChEkdzIKYqbNC9s=
58+
github.com/smartystreets/goconvey v1.6.4/go.mod h1:syvi0/a8iFYH4r/RixwvyeAJjdLS9QV7WQ/tjFTllLA=
59+
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
60+
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
61+
github.com/stretchr/testify v1.4.0 h1:2E4SXV/wtOkTonXsotYi4li6zVWxYlZuYNCXe9XRJyk=
62+
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
63+
github.com/ugorji/go v1.1.7 h1:/68gy2h+1mWMrwZFeD1kQialdSzAb432dtpeJ42ovdo=
64+
github.com/ugorji/go v1.1.7/go.mod h1:kZn38zHttfInRq0xu/PH0az30d+z6vm202qpg1oXVMw=
65+
github.com/ugorji/go/codec v1.1.7 h1:2SvQaVZ1ouYrrKKwoSk2pzd4A9evlKJb9oTL+OaLUSs=
66+
github.com/ugorji/go/codec v1.1.7/go.mod h1:Ax+UKWsSmolVDwsd+7N3ZtXu+yMGCf907BLYF3GoBXY=
67+
github.com/urfave/negroni v1.0.0 h1:kIimOitoypq34K7TG7DUaJ9kq/N4Ofuwi1sjz0KipXc=
68+
github.com/urfave/negroni v1.0.0/go.mod h1:Meg73S6kFm/4PpbYdq35yYWoCZ9mS/YSx+lKnmiohz4=
69+
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
70+
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9 h1:psW17arqaxU48Z5kZ0CQnkZWQJsqcURM6tKiBApRjXI=
71+
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
72+
golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
73+
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
74+
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
75+
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
76+
golang.org/x/sys v0.0.0-20190813064441-fde4db37ae7a/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
77+
golang.org/x/sys v0.0.0-20200116001909-b77594299b42 h1:vEOn+mP2zCOVzKckCZy6YsCtDblrpj/w7B9nxGNELpg=
78+
golang.org/x/sys v0.0.0-20200116001909-b77594299b42/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
79+
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
80+
golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk=
81+
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
82+
golang.org/x/tools v0.0.0-20190328211700-ab21143f2384/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs=
83+
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
84+
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
85+
gopkg.in/go-playground/assert.v1 v1.2.1/go.mod h1:9RXL0bg/zibRAgZUYszZSwO/z8Y/a8bDuhia5mkpMnE=
86+
gopkg.in/go-playground/validator.v9 v9.29.1/go.mod h1:+c9/zcJMFNgbLvly1L1V+PpxWdVbfP1avr/N00E2vyQ=
87+
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
88+
gopkg.in/yaml.v2 v2.2.8 h1:obN1ZagJSUGI0Ek/LBmuj4SNLPfIny3KsKFopxRdj10=
89+
gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=

01-Authorization-RS256/middleware/jwt.go

Lines changed: 32 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -8,33 +8,43 @@ import (
88

99
"github.com/auth0/go-jwt-middleware"
1010
"github.com/form3tech-oss/jwt-go"
11+
"github.com/gin-gonic/gin"
1112
)
1213

13-
var JWT = jwtmiddleware.New(jwtmiddleware.Options{
14-
ValidationKeyGetter: func(token *jwt.Token) (interface{}, error) {
15-
// Verify 'aud' claim
16-
aud := os.Getenv("AUTH0_AUDIENCE")
17-
checkAud := token.Claims.(jwt.MapClaims).VerifyAudience(aud, false)
18-
if !checkAud {
19-
return token, errors.New("invalid audience")
20-
}
14+
// EnsureValidToken is a gin.HandlerFunc middleware that will check the validity of our JWT.
15+
func EnsureValidToken() gin.HandlerFunc {
16+
var jwtMiddleware = jwtmiddleware.New(jwtmiddleware.Options{
17+
ValidationKeyGetter: func(token *jwt.Token) (interface{}, error) {
18+
// Verify 'aud' claim
19+
aud := os.Getenv("AUTH0_AUDIENCE")
20+
checkAud := token.Claims.(jwt.MapClaims).VerifyAudience(aud, false)
21+
if !checkAud {
22+
return token, errors.New("invalid audience")
23+
}
2124

22-
// Verify 'iss' claim
23-
iss := "https://" + os.Getenv("AUTH0_DOMAIN") + "/"
24-
checkIss := token.Claims.(jwt.MapClaims).VerifyIssuer(iss, false)
25-
if !checkIss {
26-
return token, errors.New("invalid issuer")
27-
}
25+
// Verify 'iss' claim
26+
iss := "https://" + os.Getenv("AUTH0_DOMAIN") + "/"
27+
checkIss := token.Claims.(jwt.MapClaims).VerifyIssuer(iss, false)
28+
if !checkIss {
29+
return token, errors.New("invalid issuer")
30+
}
2831

29-
cert, err := getPemCert(token)
30-
if err != nil {
31-
return token, err
32-
}
32+
cert, err := getPemCert(token)
33+
if err != nil {
34+
return token, err
35+
}
36+
37+
return jwt.ParseRSAPublicKeyFromPEM([]byte(cert))
38+
},
39+
SigningMethod: jwt.SigningMethodRS256,
40+
})
3341

34-
return jwt.ParseRSAPublicKeyFromPEM([]byte(cert))
35-
},
36-
SigningMethod: jwt.SigningMethodRS256,
37-
})
42+
return func(ctx *gin.Context) {
43+
if err := jwtMiddleware.CheckJWT(ctx.Writer, ctx.Request); err != nil {
44+
ctx.AbortWithStatus(http.StatusUnauthorized)
45+
}
46+
}
47+
}
3848

3949
type Jwks struct {
4050
Keys []JSONWebKeys `json:"keys"`
Lines changed: 43 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -1,64 +1,62 @@
11
package router
22

33
import (
4-
"encoding/json"
54
"net/http"
65
"strings"
76

8-
"github.com/codegangsta/negroni"
97
"github.com/form3tech-oss/jwt-go"
10-
"github.com/gorilla/mux"
8+
"github.com/gin-gonic/gin"
119

1210
"01-Authorization-RS256/middleware"
1311
)
1412

15-
type Response struct {
16-
Message string `json:"message"`
17-
}
18-
19-
func New() *mux.Router {
20-
r := mux.NewRouter()
21-
22-
// This route is always accessible
23-
r.Handle("/api/public", http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
24-
message := "Hello from a public endpoint! You don't need to be authenticated to see this."
25-
responseJSON(message, w, http.StatusOK)
26-
}))
13+
// New sets up our routes and returns a *gin.Engine.
14+
func New() *gin.Engine {
15+
router := gin.Default()
2716

28-
// This route is only accessible if the user has a valid access_token
29-
// We are chaining the jwtmiddleware middleware into the negroni handler function which will check
30-
// for a valid token.
31-
r.Handle("/api/private", negroni.New(
32-
negroni.HandlerFunc(middleware.JWT.HandlerWithNext),
33-
negroni.Wrap(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
34-
message := "Hello from a private endpoint! You need to be authenticated to see this."
35-
responseJSON(message, w, http.StatusOK)
36-
}))))
17+
// This route is always accessible.
18+
router.Any("/api/public", func(ctx *gin.Context) {
19+
response := map[string]string{
20+
"message": "Hello from a public endpoint! You don't need to be authenticated to see this.",
21+
}
22+
ctx.JSON(http.StatusOK, response)
23+
})
24+
25+
// This route is only accessible if the user has a valid access_token.
26+
router.GET(
27+
"/api/private",
28+
middleware.EnsureValidToken(),
29+
func(ctx *gin.Context) {
30+
response := map[string]string{
31+
"message": "Hello from a private endpoint! You need to be authenticated to see this.",
32+
}
33+
ctx.JSON(http.StatusOK, response)
34+
},
35+
)
3736

38-
// This route is only accessible if the user has a valid access_token with the read:messages scope
39-
// We are chaining the jwtmiddleware middleware into the negroni handler function which will check
40-
// for a valid token and scope.
41-
r.Handle(
37+
// This route is only accessible if the user has a
38+
// valid access_token with the read:messages scope.
39+
router.GET(
4240
"/api/private-scoped",
43-
negroni.New(
44-
negroni.HandlerFunc(middleware.JWT.HandlerWithNext),
45-
negroni.Wrap(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
46-
token := r.Context().Value("user").(*jwt.Token)
47-
48-
hasScope := checkScope("read:messages", token)
49-
if !hasScope {
50-
message := "Insufficient scope."
51-
responseJSON(message, w, http.StatusForbidden)
52-
return
53-
}
54-
55-
message := "Hello from a private endpoint! You need to be authenticated to see this."
56-
responseJSON(message, w, http.StatusOK)
57-
})),
58-
),
41+
middleware.EnsureValidToken(),
42+
func(ctx *gin.Context) {
43+
token := ctx.Request.Context().Value("user").(*jwt.Token)
44+
45+
hasScope := checkScope("read:messages", token)
46+
if !hasScope {
47+
response := map[string]string{"message": "Insufficient scope."}
48+
ctx.JSON(http.StatusForbidden, response)
49+
return
50+
}
51+
52+
response := map[string]string{
53+
"message": "Hello from a private endpoint! You need to be authenticated to see this.",
54+
}
55+
ctx.JSON(http.StatusOK, response)
56+
},
5957
)
6058

61-
return r
59+
return router
6260
}
6361

6462
func checkScope(scope string, token *jwt.Token) bool {
@@ -82,17 +80,3 @@ func checkScope(scope string, token *jwt.Token) bool {
8280

8381
return false
8482
}
85-
86-
func responseJSON(message string, w http.ResponseWriter, statusCode int) {
87-
response := Response{message}
88-
89-
jsonResponse, err := json.Marshal(response)
90-
if err != nil {
91-
http.Error(w, err.Error(), http.StatusInternalServerError)
92-
return
93-
}
94-
95-
w.Header().Set("Content-Type", "application/json")
96-
w.WriteHeader(statusCode)
97-
w.Write(jsonResponse)
98-
}

0 commit comments

Comments
 (0)