Skip to content

Commit

Permalink
Fix TwitterOAuth to Abraham\TwitterOAuth\TwitterOAuth
Browse files Browse the repository at this point in the history
  • Loading branch information
vEnCa-X committed Mar 12, 2021
1 parent cfedaa4 commit 1ebd3b4
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 6 deletions.
14 changes: 10 additions & 4 deletions src/TwitterLogin.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

namespace VencaX;

use Abraham;
use Exception;
use Nette;

Expand All @@ -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 */
Expand Down Expand Up @@ -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'];
Expand Down Expand Up @@ -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);
Expand Down
7 changes: 5 additions & 2 deletions tests/tests/InstanceTest.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ declare(strict_types=1);

namespace Test;

use Abraham;
use Nette;
use Tester;
use Tester\Assert;
Expand Down Expand Up @@ -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());
}
}
Expand Down

0 comments on commit 1ebd3b4

Please sign in to comment.