auth0 / go-jwt-middleware

A Middleware for Go Programming Language to check for JWTs on HTTP requests
MIT License
1.08k stars 205 forks source link

Cannot use keyFunc as type func(context.Context) #278

Open barrychapman-scout opened 3 months ago

barrychapman-scout commented 3 months ago

Checklist

Description

I am following the example in the README, and am receiving the following error:

Cannot use 'keyFunc' (type func(ctx context.Context) (interface{}, error)) as the type func(context.Context) (interface{}, error)

The only thing I can surmise is that I am using beego, but from what I could tell - it is the same context.

    keyFunc := func(ctx context.Context) (interface{}, error) {
        // Our token must be signed using this data.
        return []byte("secret"), nil
    }

    // Set up the validator.
    jwtValidator, err := validator.New(
        keyFunc,             // error occurs here
        validator.HS256,
        "https://<issuer-url>/",
        []string{"<audience>"},
    )
    if err != nil {
        log.Fatalf("failed to set up the validator: %v", err)
    }

    middleware := jwtmiddleware.New(jwtValidator.ValidateToken)

Reproduction

Using latest SDK, used github.com/form3tech-oss/jwt-go instead of the prior.

When copying the keyFunc declaration along with the validator creator, it throws that error.

Go JWT Middleware version

2 .2.1

Go version

1.22.5 darwin/arm64

barrychapman-scout commented 2 months ago

Does anyone have any idea about this?