I want to use the token that I get from the getAccessToken function in my Nextjs API endpoint to call my external API that I already created in the Auth0 dashboard but I’m getting this error:
# This is my NextJS API endpoint /api/books
export default withApiAuthRequired(async function getBooks(req:any, res:any) {
const { accessToken } = await getAccessToken(req, res); # <---- I see this is not a JWT token but opaque token
const response = await booksApi('/books?title=Calcu', { headers: { "Authorization": `Bearer ${accessToken}` } })
res.status(200).json({ accessToken, response })
})
I created the books-service in the API section on the Auth0 Dashboard and added ‘read:books’ to the permissions list(scopes) but I don’t know where I should specify that permission in the code.
From there it is up to you what you want to do with your API. I can point you towards an example if you tell me about your external API (what language, framework, etc).
That’d be awesome. To provide some context I’m using Serverless Framework but any NodeJS example I think is helpful. This is the code from my AWS Lambda authorizer which is an endpoint that is hit every time I send a request to other endpoints like /api/v1/products in order to get permission to work as expected.
When I verify the token I use the PEM certificate downloaded from my regular web app on the Auth0 dashboard. That’s all the code that I’m using on my backend to handle the token. Am I missing something?
And the JWT access token payload returned by Auth0 has the property aud which contains an array and that breaks something in AWS and that’s why the response is { "message": null } with status code 500.
Thanks @dan.woda for your help! Now my external API is working as expected