I need a Twitter api when logging in and registering, as well as when connecting accounts, each with a different URL.
For example:
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
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.You can include the callback URL in the initial request to Twitter.
See here:
https://developer.twitter.com/en/docs/apps/callback-urls