Created
June 12, 2011 09:48
-
-
Save schmittjoh/1021384 to your computer and use it in GitHub Desktop.
Twitter Anywhere Authentication
This file contains hidden or 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 hidden or 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 hidden or 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] |
Yes that would be great, I have some problems too.
Thanks ! :)
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thank you very much for these code samples. If possible could you please share your provider file and perhaps your user entity? I have been struggling trying to make a Twitter login for a long time and this is really the make or break where I choose Symfony or another framework for the next project.
Thanks a lot :))