Verifying a token #646
Answered
by
panva
msr-kelvin-marques
asked this question in
Q&A
Verifying a token
#646
-
I'm using Next.js and I'm trying to set the middleware as an auth guard for the internal API routes. Using Auth0 for auth and via @auth0/nextjs-auth0 SDK. Trying jose for the token verification. This is how my current code is looking like: const JWKS = jose.createRemoteJWKSet(
new URL(`${process.env.AUTH0_ISSUER_BASE_URL}/.well-known/jwks.json`)
);
try {
const response = await new Promise<NextResponse>((resolve) => {
jose.jwtVerify(token, JWKS, {
issuer: `${process.env.AUTH0_ISSUER_BASE_URL}/`,
audience: process.env.AUTH0_AUDIENCE,
algorithms: ['RS256'],
})
.then(({payload, protectedHeader}) => {
resolve(NextResponse.json(payload))
})
.catch((error) => {
resolve(NextResponse.json(
{ message: "Authentication failed: Invalid token", error },
{ status: 401 }
))
})
});
return response;
} catch (error) {
return NextResponse.json({ error }, { status: 500 });
} I'm passing a valid token for an active session, but I cannot get anything but
What would I be missing? |
Beta Was this translation helpful? Give feedback.
Answered by
panva
Feb 29, 2024
Replies: 1 comment 8 replies
-
Hello
I dunno, what does the error message say? |
Beta Was this translation helpful? Give feedback.
8 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Yeah so,
Bearer <JWT>
is not the token you should be passing to verify. Just the JWT.