On the left of the dashboard, choose Projects & Apps > Default Project-xxxxxxxxx > <YOUR_APP>
Go to Keys & Tokens
Regenerate the Consumer Keys as shown, these will be OAuth1 Credentials
Store the credentials in your application .env file
TWITTER_CLIENT_ID="<YOUR_CLIENT_ID>"
TWITTER_CLIENT_SECRET="<YOUR_CLIENT_SECRET>"
TWITTER_REDIRECT_URL="https://yourapp.loophole.site/login/oauth/twitter" # I am using a SSH Tunneling service to provide a secure endpoints, there are many available like ngrok and loophole and localtunnel
Add your socialite configuration in config/services.php
use socialite as usual in your controller (issue appears here)
class SocialAuthController extends Controller
{
public function oauthRedirect(string $oauth)
{
switch ($oauth) {
case "google":
case "facebook":
case "twitter":
return Socialite::driver($oauth)->redirect();
// return Inertia::location(Socialite::driver($oauth)->redirect()); // if you use inertia
break;
default:
return redirect()->route('login');
}
}
}
Result
Fix
Go to ./vendor/league/oauth1-client/src/Server/Twitter.php
Change urlAuthorization() function from
public function urlAuthorization()
{
return 'https://api.twitter.com/oauth/authenticate';
}
to
public function urlAuthorization()
{
return 'https://api.x.com/oauth/authenticate';
}
Pull Request: Fix Twitter OAuth1a Request Token Issue
This is an explaination for the pull request used in a Laravel & Socialite Application
Motivation
Twitter OAuth2 always returns a null email, unlike OAuth1 which does not, in addition to providing the developers with much more data than OAuth2
Scenario To Reproduce
Projects & Apps > Default Project-xxxxxxxxx > <YOUR_APP>
Keys & Tokens
Consumer Keys
as shown, these will be OAuth1 Credentials.env
fileconfig/services.php
Fix
Go to
./vendor/league/oauth1-client/src/Server/Twitter.php
Change
urlAuthorization()
function fromto
and the issue will be solved