In my Sveltekit app I have a server.ts
file that handles the callback from Github oAuth. I use a token to then try and fetch the users information with:
const githubUserResponse = await fetch('https://api.github.com/user', {
headers: {
Accept: 'application/vnd.github.v3+json',
Authorization: `Bearer ${tokens.accessToken}`,
}
});
This request works perfectly in Postman and returns a valid response that looks like:
{
"login": "example",
"id": 000000000,
"node_id": "U_0000000000",
"avatar_url": "https://avatars.githubusercontent.com/u/000000000?v=4",
"gravatar_id": "",
...
}
But when I run this code locally in my application I get this response from the cloudflare worker that handles this request in the back end
Response {
cf: undefined,
webSocket: null,
url: 'https://api.github.com/user',
redirected: false,
ok: false,
headers: Headers(8) {
'cache-control' => 'no-cache',
'connection' => 'close',
'content-security-policy' => "default-src 'none'; style-src 'unsafe-inline'",
'content-type' => 'text/html; charset=utf-8',
'strict-transport-security' => 'max-age=31536000',
'x-content-type-options' => 'nosniff',
'x-frame-options' => 'deny',
'x-xss-protection' => '0',
[immutable]: true
},
statusText: 'Forbidden',
status: 403,
bodyUsed: false,
body: ReadableStream {
locked: false,
[state]: 'readable',
[supportsBYOB]: true,
[length]: undefined
}
}
I don’t know why the request isn’t returning any data and is “forbidden”. Is it not passing along the headers? I am new to this stack. Any help would be appreciated. Thank you!