Set header from server middleware
Hello! I am trying to set the "Authorization" header from server middleware, for an API.
but nothing seems to be working. I am getting 403 forbidden from my API
export default defineEventHandler(async (event) => {
const token = await $fetch('https://xxx.kinde.com/oauth2/token', {
method: 'POST',
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
},
body: new URLSearchParams({
audience: "https://xxx.kinde.com/api",
grant_type: "client_credentials",
client_id: "xxx",
client_secret: "xxx",
})
}) as { access_token: string };
// I have tried
event.headers.set('authorization', token.access_token);
// I have tried
event.node.req.headers.authorization = token.access_token;
})export default defineEventHandler(async (event) => {
const token = await $fetch('https://xxx.kinde.com/oauth2/token', {
method: 'POST',
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
},
body: new URLSearchParams({
audience: "https://xxx.kinde.com/api",
grant_type: "client_credentials",
client_id: "xxx",
client_secret: "xxx",
})
}) as { access_token: string };
// I have tried
event.headers.set('authorization', token.access_token);
// I have tried
event.node.req.headers.authorization = token.access_token;
}) const properties = await $fetch(`https://xxx.kinde.com/api/v1/users/${event.context.params?.user}/properties`, {
method: 'GET',
headers: {
'Accept': 'application/json',
}
}); const properties = await $fetch(`https://xxx.kinde.com/api/v1/users/${event.context.params?.user}/properties`, {
method: 'GET',
headers: {
'Accept': 'application/json',
}
});