HWIOAuthBundle without login - symfony

I need this logic:
user login with FOS user bundle
user click on google logo (for example) and login with google+
googleId token is saved in User entity.
So there is no firewall with HWIOAuthBundle and I need to use only HWIOAuthBundle listener. Is this correct?
Thanks in advance.
v.

I think that you are looking for HWIOAuth Connect functionality so you can connect a social media account (Google) to an existing FOS user.This may help you:
https://codereviewvideos.com/blog/hwioauth-registration-form/

Related

Symfony - Ask user's password to access a route

How to implement a before filter that asks to confirm a user password to access some routes?
I'd see this when using Laravel (password.confirm middleware) but I could find similar for Symfony.
Thank you.
I can't comment so #alessandro_podo.. I'd try eventlistener but I don't know how to redirecto to login page and back to the current route. #KMAHY that's not what I need.. I don't wanna check isGranted I want to ask for user to enter username/password even if he is logged in.

Symfony with FosUserBundle - 2 different login success paths

I have 2 user roles in my application: admin and member. After a successful login, an admin user must be redirected to /admin and member must be redirected to /catalog.
Is this possible with Symfony and the FOSUserBundle?
Yes, you can modify the login behaviour. It's nothing FOSUserBundle specific, it's a Symfony feature: https://symfony.com/doc/current/security/form_login.html#always-redirect-to-the-default-page
Another solution is a custom login authentication success handler. You can find an example here: https://gist.github.com/chalasr/69ad35c11e38b8cc717f

How to add a check during the login process with Symfony FOS User

my symfony app works with dynamics subdomain, and my users can login only on their subdomain.
If user George is a user of subdomain test (he has the subdomain as a field) he can login on test.myapp.com. But during the login process I would like to check his subdomain like FOS User check the password, if the account is activated ... and stop the login process if the user is not on the right subdomain.
Thanks
If you are using FOS 2.0, events are available for you to hook into and add custom logic like this. Symfony provides the Symfony\Component\Security\Http\SecurityEvents and FOS has FOS\UserBundle\FOSUserEvents. Using the onImplicitLogin should give you access to what you need.
For a nice example of linking for a FOS event, see cheesemacfly's answer.
If you have trouble, I can write the listener and the service you need.

Auto register user with HWIOAuthBundle

I am using HWIOAuthBundle with FOSUserBundle with success.
When I go to the /login page it redirects me to the Google Accounts, authorizes and returns back to the register form with filled data (except password fields).
Is it possible to auto register user with ommiting register form ?
In this case we do not need password because of authentication with Google Account.
How should I achieve this scenario ?
A question is a bit old, but better later than never.
You just need to create a custom provider - if you want to integrate the bundle with FOSUserBundle you need to override the FOSUBUserProvider class.
In HWIOAuthBundle/Security/Core/User directory you may find all providers that are available in the OAuthBundle out of the box.
To create new user while connecting you just need to override loadUserByOAuthUserResponse() method of the FOSUBUserProvider (or EntityUserProvider, etc.) provider class. As you may see, default method throws an exception if the user is not found in database, you just need it to call userManager and create new entry.
This is exactly the same situation as with FOSFacebookBundle intergration (if you did so).
Hopes this answer helps you (especially it may sound a bit chaotic).
Edit:
I've posted a blog post explaining the integration process.
Try this gist
or this tutorial
There's a good walk-through on how to integrate HWIOAuthBundle and FOSUserBundle to achieve the automatic user registration and update here, which might be worth a read:
https://gist.github.com/danvbe/4476697
Yes of course.
You should handle a response from google and authorize user manualy something like:
// authorize
$token = new OAuthToken(null, $user->getRoles());
$token->setUser($user);
$token->setAuthenticated(true);
// update session
$session = $this->getContainer()->get('session');
$session->set('_security_secured_area', serialize($token));
$session->save();
after user was authorized redirect to the call page by user

Facebook auto-login

I have one situation. I create a website. Then I put a tab that will link to Facebook authorization login page. Can I pass login parameter(Email,Password) to the Facebook authorization login page?? So that the user can authorize the application without see the authorization login page.
Thanks.
No. You can't do that. It would require the user to give you their facebook password which obviously would be breaking all kinds of terms and conditions. This is what OAuth is for. Check out the documentation on authentication

Resources