Skip to content
This repository was archived by the owner on Nov 9, 2017. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions Security/Firewall/TwitterListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ public function setUseTwitterAnywhere($bool)

protected function attemptAuthentication(Request $request)
{
if($request->getSession()->get("oauth_token", null) && $request->get("oauth_token", null) &&
$request->getSession()->get("oauth_token", null) === $request->get("oauth_token", null))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

null is the default so you can simply omit it

{
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please use an early return instead.

if ($this->useTwitterAnywhere) {
if (null === $identity = $request->cookies->get('twitter_anywhere_identity')) {
throw new AuthenticationException(sprintf('Identity cookie "twitter_anywhere_identity" was not sent.'));
Expand All @@ -43,5 +46,6 @@ protected function attemptAuthentication(Request $request)
}

return $this->authenticationManager->authenticate(new TwitterUserToken($request->query->get('oauth_token'), $request->query->get('oauth_verifier')));
}
}
}
51 changes: 51 additions & 0 deletions Security/TwitterListener.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<?php

/*
* This file is part of the FOSTwitterBundle package.
*
* (c) FriendsOfSymfony <http://friendsofsymfony.github.com/>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace FOS\TwitterBundle\Security\Firewall;

use FOS\TwitterBundle\Security\Authentication\Token\TwitterAnywhereToken;
use Symfony\Component\Security\Core\Exception\AuthenticationException;
use FOS\TwitterBundle\Security\Authentication\Token\TwitterUserToken;
use Symfony\Component\Security\Http\Firewall\AbstractAuthenticationListener;
use Symfony\Component\HttpFoundation\Request;

/**
* Twitter authentication listener.
*/
class TwitterListener extends AbstractAuthenticationListener
{
private $useTwitterAnywhere = false;

public function setUseTwitterAnywhere($bool)
{
$this->useTwitterAnywhere = (Boolean) $bool;
}

protected function attemptAuthentication(Request $request)
{
if($request->getSession()->get("oauth_token") || $request->get("oauth_token") ||
$request->getSession()->get("oauth_token") != $request->get("oauth_token"))
return false;

if ($this->useTwitterAnywhere) {
if (null === $identity = $request->cookies->get('twitter_anywhere_identity')) {
throw new AuthenticationException(sprintf('Identity cookie "twitter_anywhere_identity" was not sent.'));
}
if (false === $pos = strpos($identity, ':')) {
throw new AuthenticationException(sprintf('The submitted identity "%s" is invalid.', $identity));
}

return $this->authenticationManager->authenticate(TwitterAnywhereToken::createUnauthenticated(substr($identity, 0, $pos), substr($identity, $pos + 1)));
}

return $this->authenticationManager->authenticate(new TwitterUserToken($request->query->get('oauth_token'), $request->query->get('oauth_verifier')));
}
}
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,4 @@
"psr-0": { "FOS\\TwitterBundle": "" }
},
"target-dir": "FOS/TwitterBundle"
}
}