diff --git a/src/TwitterLogin.php b/src/TwitterLogin.php index e6ec3b9..638f9b9 100644 --- a/src/TwitterLogin.php +++ b/src/TwitterLogin.php @@ -3,6 +3,7 @@ namespace VencaX; +use Abraham; use Exception; use Nette; @@ -15,7 +16,7 @@ class TwitterLogin extends BaseLogin { public const SOCIAL_NAME = 'twitter'; - /** @var \TwitterOAuth */ + /** @var Abraham\TwitterOAuth\TwitterOAuth */ private $twitterOAuth; /** @var array Request token */ @@ -55,8 +56,13 @@ public function __construct( */ public function getLoginUrl() { - $this->twitterOAuth = new \TwitterOAuth($this->params['consumerKey'], $this->params['consumerSecret']); - $this->requestToken = $this->twitterOAuth->getRequestToken($this->params['callbackURL']); + $this->twitterOAuth = new Abraham\TwitterOAuth\TwitterOAuth($this->params['consumerKey'], $this->params['consumerSecret']); + $this->requestToken = $this->twitterOAuth->oauth( + 'oauth/request_token', + [ + 'oauth_callback' => $this->params['callbackURL'], + ] + ); $sessionSection = $this->session->getSection('twitter'); $sessionSection->oauth_token = $token = $this->requestToken['oauth_token']; @@ -84,7 +90,7 @@ public function getMe($oauthToken, $oauthVerifier) } //Create TwitteroAuth object with app key/secret and token key/secret from default phase - $this->twitterOAuth = new \TwitterOAuth($this->params['consumerKey'], $this->params['consumerSecret'], $sessionSection->oauth_token, $sessionSection->oauth_token_secret); + $this->twitterOAuth = new Abraham\TwitterOAuth\TwitterOAuth($this->params['consumerKey'], $this->params['consumerSecret'], $sessionSection->oauth_token, $sessionSection->oauth_token_secret); //Request access tokens from twitter $access_token = $this->twitterOAuth->getAccessToken($oauthVerifier); diff --git a/tests/tests/InstanceTest.phpt b/tests/tests/InstanceTest.phpt index 87b082c..1963d93 100644 --- a/tests/tests/InstanceTest.phpt +++ b/tests/tests/InstanceTest.phpt @@ -3,6 +3,7 @@ declare(strict_types=1); namespace Test; +use Abraham; use Nette; use Tester; use Tester\Assert; @@ -81,8 +82,10 @@ class InstanceTest extends Tester\TestCase public function testTwitterLoginUrl() { - //$url = $this->socialLogin->twitter->getLoginUrl(); - //Assert::same(false, $this->socialLogin->twitter->getSocialLoginCookie()); + Assert::exception(function () { + $this->socialLogin->twitter->getLoginUrl(); + }, Abraham\TwitterOAuth\TwitterOAuthException::class, '{"errors":[{"code":32,"message":"Could not authenticate you."}]}'); + Assert::same(false, $this->socialLogin->twitter->isThisServiceLastLogin()); } }