Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for JWT with JWKS #2589

Open
qoomon opened this issue May 2, 2024 · 2 comments
Open

Support for JWT with JWKS #2589

qoomon opened this issue May 2, 2024 · 2 comments
Labels
enhancement New feature or request.

Comments

@qoomon
Copy link

qoomon commented May 2, 2024

What is the feature you are proposing?

currently the jwt middleware requires a static secret value, however in my use case (see below) it's not a static secret instead it is retrieved from an JWKS. Therefore it would be nice if the jwt middleware also support an async function(payload: any) : string as secret parameter.

Use Case:

I'm working on a server endpoint that is called by GitHub actions to authenticate I'm using the Github Actions OIDC tokens.

Currently I'm using my own middleware by using fast-jwt with get-jwks like this

import {createVerifier, DecodedJwt, KeyFetcher} from 'fast-jwt'
import buildJwks from 'get-jwks'

const jwks = buildJwks({providerDiscovery: true})
const keyFetcher: KeyFetcher = async (jwt: DecodedJwt) => jwks.getPublicKey({
  kid: jwt.header.kid,
  alg: jwt.header.alg,
  domain: jwt.payload.iss,
})

const jwtVerifier = createVerifier({
  key: keyFetcher,
})

app.use(async (c, next) => {
  // ... get jwtTokenString value
  await jwtVerifier(jwtTokenString)
  // ... handle verification errors
  await next()
})

however it would be nice if I can switch to an official middleware.

@qoomon qoomon added the enhancement New feature or request. label May 2, 2024
@qoomon
Copy link
Author

qoomon commented May 2, 2024

probably related to #672

@sparanoid
Copy link

Apple Music API also needs kid header which is not compatible with current jwt middleware:

expected headers and payload:

{
     "alg": "ES256",
     "kid": "ABC123DEFG"
}
{
     "iss": "DEF123GHIJ",
     "iat": 1437179036,
     "exp": 1493298100
}

actual:

{
     "alg": "ES256",
     "typ": "JWT"
}
{
     "iss": "DEF123GHIJ",
     "iat": 1437179036,
     "exp": 1493298100
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request.
Projects
None yet
Development

No branches or pull requests

2 participants