-
-
Notifications
You must be signed in to change notification settings - Fork 795
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Login Facebookuser into Symfony per AJAX #551
Comments
Hello, I've same problem! I thinking to use iframe instead ajax call.
or something like that... |
did you fix your problem ? |
@Sshuichi Unfortunately, after a couple of days the facebook login was broken (although i did not make any changes to the related code): Suddenly, when trying to log in to the app via facebook, the login failed and the firefox console gave me an error similar to the one mentioned in this post Finally i gave up and ended up in implementing a custom solution without using the HWIOAuthBundle, which is a pity, cause this is really a great bundle (thx a lot to all the contributers for the work they put into this btw). Anyway, i am still curious if there is the possibility to do such a thing using this bundle, but unfortunately till today i don´t know if this is simply not possible or if i just missed something on how to do it : ( |
Hi ! I solved it and this is how I did it. (working example on Neargood.com)
now let's set our service in services.yml
and finally this is what you should put in your class AuthenticationHandler:
|
For the Js part, leave it as the bundle suggests. If you have any questions please let me know |
@Sshuichi
Are you refering to this description from the docs? |
Yes I meant the function fb_login body! |
@Sshuichi
This reloads the webpage, and that is exactly what must not happen in my application |
That happens only for registration , for login it will happen without reloading the page, You can check on Neargood.com how it works |
@Sshuichi
Unfortunately i cannot verify that, as trying to signup with facebook throws a
Does not work for me, as the page must not be reloaded (neither on signup nor on login) Anyway, thx for your effort.. |
I'll check that when I'm back home don't worry we'll fix that |
I have just double checked Neargood, are you using any plugin on your browser ? |
Anyways, you can make it work for the registeration as well, it's the same method but you'll need to make the redirection in your JS after receiving the answer ! I'll wait for your confirmation about Ng's fb login feature |
Sry, my bad. In fact a browser-plugin was blocking facebook on your site ; ) |
Good! now the global method (services) is in front of you, you can do whatever you want with it! |
but seems it is being redirected to an other page. on my website http://www.anagrammer.com/ I did by iframe but I do not like it. |
Hello, |
Hey, @Sshuichi. I could not understand how you did an AJAX request after receiving facebook response. The bundle suggestion in fb_init() method will always redirect the page. Can you clarify? I'm trying to achieve exaclty the same here. I was using FOSFacebookBundle, and I was able to do facebook ajax login successfully. Now, as FOSFacebookBundle is deprecated, I'm trying to achieve the same with HWIOAuthBundle. I've spent a lot of hours today, and I realize FOSFacebookBundle was able to intercept a request to if ($request->isXmlHttpRequest()) {
// return json
} I'm afraid HWIOAuthBundle developers have not thought about a route to verify authorization usign XmlHttpRequest (ajax). Today, the only way to finish authorization is doing a redirect to @stloyd I'd really appreciate if you can guide us better here. Is it possible today? How hard do you think it is to implement? I can try to help. I think this job was done in FOSFacebookBundle by this code: https://github.com/FriendsOfSymfony/FOSFacebookBundle/blob/master/Security/EntryPoint/FacebookAuthenticationEntryPoint.php. Maybe @lsmith77 or @kriswallsmith can help us clarify here. Is it an option to fork FOSFacebookBundle? |
Nobody? =/ |
I made it work on http://www.anagrammer.com/, using iframe but it is not the best solution |
Hey @vazgen, can you share your iframe solution? Thanks in advance! =) |
Hey @hugomn I can share it but I use angularjs ! would it be ok? |
No problem, @vazgen. I just want to check how you get the results from the iframe. =) |
let's say user clicks on facebook button, I create an iframe and append it to document. After that I check ones per each second (using $interval ) and if user has been authenticated I stop $interval something like
the same I use for google plus and native one. Hope this can help. |
@vazgen, thanks for your fast reply. I'm trying your solution here, but couldn't understand what your line |
@hugomn , you are right , it is being used in order to check is user logged or not
|
@vazgen, I could not make it work. When I open a frame and try to open facebook page inside it, I've got CORs errors too. Lost a lot of time with this, and could not find a way to implement ajax login with hwioauthbundle. I'll fork fosfacebookbundle as it was working fine, although hwi is an awesome bundle. Thanks for your help. |
Hello,
i am currently playing around with this bundle and was wondering if it is possible to trigger the symfony-login after a successful facebook-login (via the facebook login button) per AJAX.
If i understand this example right, in the most cases one would do the following to log the user into the symfony application:
GET
to the URL defined for thehwi_oauth_service_redirect
-routeConnectController::redirectToServiceAction()
is executed on the serverside which results in a redirect to facebooks oauth endpoint to get the oauth code (which in turn is required to log the user successfully into the symfony application).The problem i am facing now is that i am working on a single page application where the page must not be reloaded. So my first naive approach was to - in the FB.login-callback - issue the
GET
tohwi_oauth_service_redirect
(resp.login/facebook
) per AJAX like the following:When i try to do this, unfortunately i run into cross-domain-issues and Firebug shows the following message:
In contrast when i call the related URI (
MY_DOMAIN/login/facebook
) by reloading the page as shown in the docs everything works fine and the user is logged in on both sides (facebook and my symfony app).As i am not sure if am doing everything right or if i am missing something here, my question is: is it possible to trigger the symfony-login as described above (per AJAX) and am i just missing something or is it just not possible to do this?
My configuration of the bundle looks something like the following:
The text was updated successfully, but these errors were encountered: