Created
June 12, 2011 09:48
-
-
Save schmittjoh/1021384 to your computer and use it in GitHub Desktop.
Twitter Anywhere Authentication
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace Security\Authentication; | |
use Symfony\Component\HttpFoundation\Response; | |
use Symfony\Component\Security\Core\Exception\AuthenticationException; | |
use Symfony\Component\HttpFoundation\Request; | |
use Symfony\Component\Security\Http\Authentication\AuthenticationFailureHandlerInterface; | |
class AjaxFailureHandler implements AuthenticationFailureHandlerInterface | |
{ | |
public function onAuthenticationFailure(Request $request, AuthenticationException $exception) | |
{ | |
return new Response('', 401); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace Security\Authentication; | |
use Symfony\Component\HttpFoundation\Response; | |
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface; | |
use Symfony\Component\HttpFoundation\Request; | |
use Symfony\Component\Security\Http\Authentication\AuthenticationSuccessHandlerInterface; | |
class AjaxSuccessHandler implements AuthenticationSuccessHandlerInterface | |
{ | |
public function onAuthenticationSuccess(Request $request, TokenInterface $token) | |
{ | |
$user = $token->getUser(); | |
return new Response(json_encode(array( | |
'email' => $user->getEmail(), | |
'firstname' => $user->getFirstname(), | |
'lastname' => $user->getLastname(), | |
)), 200, array('Content-Type', 'application/json')); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
security: | |
firewalls: | |
default: | |
# ... | |
fos_twitter: | |
check_path: /twitter_login_check | |
use_twitter_anywhere: true | |
provider: twitter | |
success_handler: ajax_success_handler | |
failure_handler: ajax_failure_handler | |
logout: | |
delete_cookies: [twitter_anywhere_identity] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Yes that would be great, I have some problems too.
Thanks ! :)