Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Failed to authorize using example #59

Open
Falci opened this issue Jan 1, 2023 · 8 comments
Open

Failed to authorize using example #59

Falci opened this issue Jan 1, 2023 · 8 comments

Comments

@Falci
Copy link

Falci commented Jan 1, 2023

Failed to authorize using example

Expected behavior

Twitter should ask to confirm if I want to give access to the app

Actual behavior

Twitter shows an error page:
image

Steps to reproduce the behavior

Access the URL from:

import "dotenv/config";
import { auth, Client } from "twitter-api-sdk";

const authClient = new auth.OAuth2User({
  client_id: process.env.CLIENT_ID,
  client_secret: process.env.CLIENT_SECRET,
  callback: process.env.CALLBACK_URL,
  scopes: ["tweet.read", "users.read", "offline.access"],
});

const client = new Client(authClient);

const authUrl = authClient.generateAuthURL({
  code_challenge_method: "s256",
});

console.log(authUrl);
// await authClient.requestAccessToken(code);

Brand new twitter account.
Fresh CLIENT_ID and CLIENT_SECRET.
Different from #38, CALLBACK_URL is added to the app's settings:
image

@risingforce9zz
Copy link

I have same issue.

node 18.12.1
typescript 4.9.4

@rojvv
Copy link
Contributor

rojvv commented Jan 10, 2023

In the meantime, you can try The oauth2-callback_pkce_plain example.

@Stefanuk12
Copy link

I fixed this issue by specifying the state

@ryanmichaelhirst
Copy link

@Stefanuk12 can you post an example of your code? I specified the state and am trying to login with window.open(resp.authUrl, '_blank') but I get the same error message as @Falci

@Stefanuk12
Copy link

@Stefanuk12 can you post an example of your code? I specified the state and am trying to login with window.open(resp.authUrl, '_blank') but I get the same error message as @Falci

const authUrl = authClient.generateAuthURL({
        code_challenge_method: "s256",
        state: STATE,
})

@ryanmichaelhirst
Copy link

Hm I get the error message when specifying s256, but the pcke plain example below does works so I went with that.

  const authUrl = authClient.generateAuthURL({
    state: STATE,
    code_challenge_method: "plain",
    code_challenge: "test",
  });

Thanks for the fast response! @Stefanuk12

@Stefanuk12
Copy link

Stefanuk12 commented Jan 15, 2023

If you're having issues, open Inspect Element > Network and filter for Fetch/XHR. Then look for the authenticate endpoint. In the response, it should tell you the issue.

@RokoTechnology
Copy link

make sure your /callback endpoint has res.send or res.redirect at the end or it will time out

app.get('/oa2-redirect', async (req, res)  => {
    const { code } = req.query
    const token = await authClient.requestAccessToken(code)
    res.send({ token })
})

works fine for me even with s256 challenge method

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants