So, I have a problem with OIDC connecting with my own API in Google Cloud Run.
Did try to follow the Connect to GCP from the docs, but it doesn’t work for my case, so I changed it.
I use axios.post for my requests and just added the “Athentication” header with the getVercelOidcToken() function, but I’m always getting the error: 'Error: The ‘x-vercel-oidc-token’ header is missing from the request. Do you have the OIDC option enabled in the Vercel project settings? ’
Do have everything configured and enabled.
My code (example):
const request = await axios.post(
process.env.NEXT_PUBLIC_API +
'/api/someroute/someotherroute',
{
id: id,
},
{
headers: {
Authorization: `Bearer ${await getVercelOidcToken()}`,
},
}
)
To reproduce (locally or deployed):
Create a cloud run function in Node.js using express a middleware from the Connect to your own API with the “server.js” migrating the Typescript to Plain JS and make the function publicly accessible
Make a request using axios.post from the front end of a NextJS app to that function with the Authorization header with the getVercelOidcToken().
Did try to declare the getVercelOidcToken() as an external variable.
This is only on my preview deployment, so it’s not publicly visible. I’m 100% open to share more of the code.
NextJS
Cloud Run (node.js)