I am a bit new with golang and trying to parse a jwt token. i am using the package github.com/dgrijalva/jwt-go for token parsing i am able to read the value of authorization header further that i am trying to pass that value to jwt for authentication as shown in below code. as soon as i reach the jwt statement getting a error message
if _, ok := token.Method.(*jwt.SigningMethodRSA); !ok {
log.Println("err in token validation!!!!")
w.WriteHeader(http.StatusForbidden)
return nil, nil //generateIAMPolicy("user", "Deny", " "), nil
}
Error Message
http: panic serving 127.0.0.1:56516: runtime error: invalid memory address or nil pointer dereference
goroutine 35 [running]:
net/http.(*conn).serve.func1()
C:/Program Files/Go/src/net/http/server.go:1850 +0xbf
panic({0xd67820, 0x12d8770})
C:/Program Files/Go/src/runtime/panic.go:890 +0x262
crypto/rsa.(*PublicKey).Size(...)
C:/Program Files/Go/src/crypto/rsa/rsa.go:54
crypto/rsa.VerifyPKCS1v15(0x0, 0x0?, {0xc0000ad740, 0x20, 0x1?}, {0xc0000c98c0?, 0x200?, 0x201?})
C:/Program Files/Go/src/crypto/rsa/pkcs1v15.go:337 +0x1e9
github.com/dgrijalva/jwt-go.(*SigningMethodRSA).Verify(0xc000008198, {0xc0000fa700, 0x324}, {0xc0000f0f2d?, 0xc0002c00f0?}, {0xd68940?, 0x0})
C:/Users/310259320/go/pkg/mod/github.com/dgrijalva/jwt-go@v3.2.0+incompatible/rsa.go:73 +0x157
github.com/dgrijalva/jwt-go.(*Parser).ParseWithClaims(0xc0000c1930, {0xc0000f0c08?, 0x8799e0?}, {0xf184c0?, 0xc0002c00f0?}, 0xc0000c1a08)
C:/Users/310259320/go/pkg/mod/github.com/dgrijalva/jwt-go@v3.2.0+incompatible/parser.go:77 +0x30d
github.com/dgrijalva/jwt-go.(*Parser).Parse(...)
C:/Users/310259320/go/pkg/mod/github.com/dgrijalva/jwt-go@v3.2.0+incompatible/parser.go:20
github.com/dgrijalva/jwt-go.Parse({0xc0000f0c08, 0x5d0}, 0x72dee7?)
C:/Users/310259320/go/pkg/mod/github.com/dgrijalva/jwt-go@v3.2.0+incompatible/token.go:89 +0x65
main.helloHandler({0xf1b6b0, 0xc0000e48c0}, 0xc0000cc100)
C:/projectcode/IndoorPositioning/OPAAuthorizer/server.go:68 +0x3d0
net/http.HandlerFunc.ServeHTTP(0xc000289af0?, {0xf1b6b0?, 0xc0000e48c0?}, 0x0?)
C:/Program Files/Go/src/net/http/server.go:2109 +0x2f
net/http.(*ServeMux).ServeHTTP(0x0?, {0xf1b6b0, 0xc0000e48c0}, 0xc0000cc100)
C:/Program Files/Go/src/net/http/server.go:2487 +0x149
net/http.serverHandler.ServeHTTP({0xc0002c0000?}, {0xf1b6b0, 0xc0000e48c0}, 0xc0000cc100)
C:/Program Files/Go/src/net/http/server.go:2947 +0x30c
net/http.(*conn).serve(0xc00027c000, {0xf1bef0, 0xc000089ef0})
C:/Program Files/Go/src/net/http/server.go:1991 +0x607
created by net/http.(*Server).Serve
I dont know how this internal server with port 127.0.0.1:56516 comes in picture.