Invalid_Grant error for OAuth 2.0

Goal for me was to initiate a redirect (in the server side) on my web app after I receive user information from discord authentication then use that information to populate the specified page that was being redirected to. Problem is I am getting an invalid_grant error with an error description of invalid "code" in my GET request. I made sure the redirect URIs were matching throughout; made sure there werent any other request calls being made at the same time; I am currently using express as my server and using express session to store my state and userinfo and axios to do my HTTP requests. I am also getting the user_info, the problem happens when it does a redirect on the server side. I am just lost in figuring out how to better diagnose this; any advice is really helpful. Does "invalid code" refer to the code used to exchange for the access token?
5 Replies
d.js toolkit
d.js toolkit4mo ago
- What's your exact discord.js npm list discord.js and node node -v version? - Not a discord.js issue? Check out #other-js-ts. - Consider reading #how-to-get-help to improve your question! - Explain what exactly your issue is. - Post the full error stack trace, not just the top part! - Show your code! - Issue solved? Press the button! - Marked as resolved by staff
kevin
kevin4mo ago
//client side request
const response = await axios.get(`https://localhost:_____/auth/callback?code=${code}&state=${state}&redirect=${encodeURIComponent(redirect)}`, {
withCredentials: true, // Ensure credentials are included
});
//client side request
const response = await axios.get(`https://localhost:_____/auth/callback?code=${code}&state=${state}&redirect=${encodeURIComponent(redirect)}`, {
withCredentials: true, // Ensure credentials are included
});
Error response data: {
error: 'invalid_grant',
error_description: 'Invalid "code" in request.'
}
Error response status: 400
Error response headers: Object [AxiosHeaders] {
date: '',
'content-type': 'application/json',
'content-length': '79',
connection: 'keep-alive',
'cache-control': 'no-store',
pragma: 'no-cache',
'set-cookie': [
'__dcfduid=59c89f9a199411efb52496b81cf4e3c6; Expires=Wed, 23-May-2029 06:10:42 GMT; Max-Age=157680000; Secure; HttpOnly; Path=/; SameSite=Lax',
'__sdcfduid=59c89f9a199411efb52496b81cf4e3c6f6a0733cf375106fe42f53996624652846ff84b51ffe23e72d97909040d0eddb; Expires=Wed, 23-May-2029 06:10:42 GMT; Max-Age=157680000; Secure; HttpOnly; Path=/; SameSite=Lax',
'__cfruid=c3dec741acb51d07e62de15bf0586d06bacc74b6-1716531042; path=/; domain=.discord.com; HttpOnly; Secure; SameSite=None',
'_cfuvid=ITAbKiFgINcOrXciQ0XU.hv0lOK6glW0LTYGgBUSNZA-1716531042409-0.0.1.1-604800000; path=/; domain=.discord.com; HttpOnly; Secure; SameSite=None'
],
'strict-transport-security': 'max-age=31536000; includeSubDomains; preload',
via: '1.1 google',
'alt-svc': 'h3=":443"; ma=86400',
'cf-cache-status': 'DYNAMIC',
'report-to': '{"endpoints":[{"url":"https:\\/\\/a.nel.cloudflare.com\\/report\\/v4?s=ccHDQwnmVDXDg4MZZxaV0w1%2B%2FEl0MK5zehhyQo9g29WU71gmlw6ZpMn%2BbuZVvZzuTXLEGydhfFTtd9RyxHUDysHv5MrQyAEmM%2FPsm3blcthkITLOy83C%2F2VjByLH"}],"group":"cf-nel","max_age":604800}',
nel: '{"success_fraction":0,"report_to":"cf-nel","max_age":604800}',
'x-content-type-options': 'nosniff',
'content-security-policy': "frame-ancestors 'none'; default-src 'none'",
server: 'cloudflare',
'cf-ray': '888b1fc5dba29023-BOS'
}
Error response data: {
error: 'invalid_grant',
error_description: 'Invalid "code" in request.'
}
Error response status: 400
Error response headers: Object [AxiosHeaders] {
date: '',
'content-type': 'application/json',
'content-length': '79',
connection: 'keep-alive',
'cache-control': 'no-store',
pragma: 'no-cache',
'set-cookie': [
'__dcfduid=59c89f9a199411efb52496b81cf4e3c6; Expires=Wed, 23-May-2029 06:10:42 GMT; Max-Age=157680000; Secure; HttpOnly; Path=/; SameSite=Lax',
'__sdcfduid=59c89f9a199411efb52496b81cf4e3c6f6a0733cf375106fe42f53996624652846ff84b51ffe23e72d97909040d0eddb; Expires=Wed, 23-May-2029 06:10:42 GMT; Max-Age=157680000; Secure; HttpOnly; Path=/; SameSite=Lax',
'__cfruid=c3dec741acb51d07e62de15bf0586d06bacc74b6-1716531042; path=/; domain=.discord.com; HttpOnly; Secure; SameSite=None',
'_cfuvid=ITAbKiFgINcOrXciQ0XU.hv0lOK6glW0LTYGgBUSNZA-1716531042409-0.0.1.1-604800000; path=/; domain=.discord.com; HttpOnly; Secure; SameSite=None'
],
'strict-transport-security': 'max-age=31536000; includeSubDomains; preload',
via: '1.1 google',
'alt-svc': 'h3=":443"; ma=86400',
'cf-cache-status': 'DYNAMIC',
'report-to': '{"endpoints":[{"url":"https:\\/\\/a.nel.cloudflare.com\\/report\\/v4?s=ccHDQwnmVDXDg4MZZxaV0w1%2B%2FEl0MK5zehhyQo9g29WU71gmlw6ZpMn%2BbuZVvZzuTXLEGydhfFTtd9RyxHUDysHv5MrQyAEmM%2FPsm3blcthkITLOy83C%2F2VjByLH"}],"group":"cf-nel","max_age":604800}',
nel: '{"success_fraction":0,"report_to":"cf-nel","max_age":604800}',
'x-content-type-options': 'nosniff',
'content-security-policy': "frame-ancestors 'none'; default-src 'none'",
server: 'cloudflare',
'cf-ray': '888b1fc5dba29023-BOS'
}
I realized I posted this in the wrong forum is there a way for me to forward this to #other-js-ts ?
Unknown User
Unknown User4mo ago
Message Not Public
Sign In & Join Server To View
kevin
kevin4mo ago
Damn
Want results from more Discord servers?
Add your server