skip to Main Content

I need a Twitter api when logging in and registering, as well as when connecting accounts, each with a different URL.

For example:

enter image description here

But when you set multiple redirection URLs, only the first URL works.

For example, if a user applies through test.com/profile/account,

Twitter will be redirected to test.com/signin after the operation.

If I create another multiple api with the api key and the API Key Secret for each of them, the code will be difficult and complicated.

For example, if I have two servers (development and production), I need to create six APIs

Is there a way to use an api key for all routes?

2

Answers


  1. Consider a different approach: instead of passing different callback URLs to Twitter, you can redirect the user from the callback yourself. For example, you can store the original URL into session or encode it with the state parameter (here’s how to do that with Passport.js). After you successfully authorize the user, check either the session or the state and redirect the user back.

    Login or Signup to reply.
  2. You can include the callback URL in the initial request to Twitter.

    See here:
    https://developer.twitter.com/en/docs/apps/callback-urls

    When setting up these flows for their potential users to work through, developers must pass a callback URL with their requests to the authentication endpoints that make up the flows mentioned earlier. For example, developers using OAuth 1.0a User Context must pass the callback_url parameter when making a request to the GET oauth/request_token endpoint. Similarly, developers using OAuth 2.0 Authorization Code with PKCE must pass the redirect_uri parameter with their request to the GET oauth2/authorize endpoint.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search