Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

229
Views
Resolving invalid_grant in Reddit

I am trying to authenticate my third party app against a Reddit account using oauth.

I first hit this endpoint

let authorizationUrl = https://www.reddit.com/api/v1/authorize?client_id=${redditClientId}&response_type=code&state=${state}&redirect_uri=${oAuthCallbackURL}&duration=permanent&scope=${scopes};

and then I was sent a code to my callback url

then I hit the next endpoint like this:

    let accessTokenUrl = `https://www.reddit.com/api/v1/access_token`;
    let accessTokenRequest = new URLSearchParams();
    accessTokenRequest.append("grant_type", "authorization_code");
    accessTokenRequest.append("code", code);
    accessTokenRequest.append("redirect_uri", oAuthCallbackURL);

    let redditClientId = process.env.REDDIT_CLIENT_ID;
    let redditSecret = process.env.REDDIT_SECRET;
    const clientIdAndSecretBase64 = 
    Buffer.from(`${redditClientId}:${redditSecret}`).toString('base64');
    try {
        let authorizationCodeResponse = await axios.post(accessTokenUrl, accessTokenRequest, {
            headers: {
                'Content-Type': 'application/x-www-form-urlencoded',
                'Authorization': `Basic ${clientIdAndSecretBase64}`
            }
        });
        let { data } = authorizationCodeResponse;
        console.log(authorizationCodeResponse);
        console.log(`Reddit OAUTH Response=${JSON.stringify(data, null, 2)}`);
    } catch (e) {
        console.log(e);
}

But all I keep getting back is this error:

Reddit OAUTH Response={ "error": "invalid_grant" }

On careful observation of Reddit docs I saw a line that says invalid_grant is only thrown when

The code has expired or already been used

This makes no sense because during the testing phase I forgot to save the access token. I should be able to reinitiate this request anytime. Why this limitation? I wanted to really see what the response is like before saving the access token. Now, clearly it seems there is no way to resolve this issue.

But any insight will be really appreciated.

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!