Open anatoliy-t7 opened 3 months ago
I get the same error using the Google class. With the GitHub class, I had json parsing error since github returned 404 for the request. The .validateAuthorizationCode needs review. I suggest writing a manual fetch with your client id, secret, code according to Google's API requirements. Here is my implementation to get the token: Note that the codeVerifier might be redundant.
async function exchangeCodeForToken(code: string, codeVerifier: string) {
const response = await fetch('https://oauth2.googleapis.com/token', {
method: 'POST',
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
'Accept': 'application/json',
},
body: new URLSearchParams({
client_id: googleClientId,
client_secret: googleClientSecret,
code: code,
code_verifier: codeVerifier,
redirect_uri: googleRedirectUri,
grant_type: 'authorization_code'
}),
});
if (!response.ok) {
throw new Error(`Error: ${response.statusText}`);
}
try {
const data = await response.json();
if (data && "access_token" in data) {
const tokens = data.access_token;
return tokens;
} else if (data && "error" in data) {
console.error('Error:', data.error, data.error_description);
} else {
console.error('Unexpected result:', data);
}
} catch (error) {
console.error('Failed to parse response as JSON:', error)
}
}
Hi. I am getting an error on Google validateAuthorizationCode
What did I do wrong?
Thanks.