0

I'm working on a web app and I depend on the following code for authentication (I'm using github.com/dgrijalva/jwt-go package):

func ValidateProtectedPage(protectedPage http.HandlerFunc) http.HandlerFunc {
return http.HandlerFunc(func(res http.ResponseWriter, req *http.Request) {
    // If no Auth cookie is set then return a 404 not found
    cookie, err := req.Cookie("Auth")
    if err != nil {
        Forbidden(res)
        return
    }

    // Return a Token using the cookie
    token, err := jwt.ParseWithClaims(cookie.Value, &Claims{}, func(token *jwt.Token) (interface{}, error) {
        // Make sure token's signature wasn't changed
        if _, ok := token.Method.(*jwt.SigningMethodHMAC); !ok {
            return nil, fmt.Errorf("Unexpected siging method")
        }
        return []byte(util.Secret), nil
    })

    if err != nil {
        Forbidden(res)
        return
    }

    // Grab the tokens claims and pass it into the original request
    if claims, ok := token.Claims.(*Claims); ok && token.Valid {
        ctx := context.WithValue(req.Context(), "Auth", *claims)
        protectedPage(res, req.WithContext(ctx))
    } else {
        Forbidden(res)
    }
})}

The issue is, that I'm trying to deploy my app to appengine, and I get the following errors:

planilla-go/controllers/auth.go:45: req.Context undefined (type *http.Request has no field or method Context)
planilla-go/controllers/auth.go:46: req.WithContext undefined (type *http.Request has no field or method WithContext)

From what I read this is due to incompatibilities between appengine's requests and those from go's library, but I couldn't find a workaround yet

Is there a way to wrap or convert the http.Request to use appengine's instead?

Grokify
  • 15,092
  • 6
  • 60
  • 81
Luis GG
  • 81
  • 1
  • 8
  • 1
    If you're using the standard environment, the Go version there is only 1.6. – JimB May 02 '17 at 16:36
  • 1
    Possible duplicate of [Running Go App Engine apps locally.](http://stackoverflow.com/questions/40552001/running-go-app-engine-apps-locally/40561187#40561187) – icza May 02 '17 at 16:39
  • Having similar issues go version go version go1.8.1 darwin/amd64 and deploying to App Engine too – isawk May 21 '17 at 05:37
  • @iswak, as JimB says go 1.7 and onwards are not supported by appengine, and only god knows when they are going to rollout 1.8 compatibility :/ – Luis GG May 22 '17 at 11:51

1 Answers1

0

Appengine only supports Go 1.6. A bit baffling since it renders my app useless without a major compat overhaul, but that's the current state of the platform

Luis GG
  • 81
  • 1
  • 8