You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Jan 20, 2025. It is now read-only.
Hi. I am getting an error on Google validateAuthorizationCode
103 | // providers are allowed to return non-400 status code for errors
104 | if (!("access_token" in result) && "error" in result) {
^
TypeError: result is not an Object. (evaluating '"access_token" in result')
at /.../node_modules/arctic/node_modules/oslo/dist/oauth2/index.js:104:33
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)
}
}
Sign up for freeto subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Hi. I am getting an error on Google validateAuthorizationCode
What did I do wrong?
Thanks.
The text was updated successfully, but these errors were encountered: