2

I know this subject was already discussed but however I still cannot find a solution.

I use HWIOAuth Bundle with FOSUserBundle for my users and socials connections.

#app/config.yml

#HWIOAuthBundle
hwi_oauth:
    firewall_name: main
    resource_owners:
        facebook:
            type:          facebook
            client_id:     %oauth.facebook.id%
            client_secret: %oauth.facebook.secret%
            scope:         "email"
            options:
                display: popup
            infos_url:     "https://graph.facebook.com/me?fields=id,name,email,picture.type(square)"
            paths:
                email:          email
                profilepicture: picture.data.url
    http_client:
        verify_peer: false

How can I integrate the "profilepicture: picture.data.url" on my Twig file ?

<li class="user-header">
    <img src="{{ asset('theme/AdminLTE/dist/img/user2-160x160.jpg') }}" class="img-circle" alt="User Image" />
        <p>
           {{ app.user.username }}
        </p>
</li>

Thanks a lot, I don't understand how can I use this parameter "profilepicture: picture.data.url" to get the facebook profile picture with HWIOAuthBundle.

Michael Sivolobov
  • 12,388
  • 3
  • 43
  • 64
toniino38
  • 21
  • 2

2 Answers2

0

you can receive require details in i.e. loadUserByOAuthUserResponse(UserResponseInterface $response):

 /* @var $response \HWI\Bundle\OAuthBundle\OAuth\Response\UserResponseInterface */
    var_dump(
        $response->getEmail(),
        $response->getProfilePicture()
    );
0

I solved this issue adding a field in my Entity :

//Acme/UserBundle/Entity/User.php

/**
 * @var string
 *
 * @ORM\Column(name="profile_picture", type="string", length=250, nullable=true)
 *
 */
protected $profilePicture;

And modifying the UserProvider.php like this :

//Acme/UserBundle/OAuth/UserProvider.php

protected function updateUserByOAuthUserResponse(User $user, UserResponseInterface $response)
{

    $providerName = $response->getResourceOwner()->getName();
    $providerNameSetter = 'set'.ucfirst($providerName).'Id';
    $user->$providerNameSetter($response->getUsername());

    $user->setProfilePicture($response->getProfilePicture());

    if(!$user->getPassword()) {
        // generate unique token
        $secret = md5(uniqid(rand(), true));
        $user->setPassword($secret);


    }

    return $user;
}
toniino38
  • 21
  • 2