Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

233
Visualizações
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
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda