0
votes

[Symfony\Component\Debug\Exception\ContextErrorException]
Catchable Fatal Error: Argument 2 passed to Symfony\Component\Security\Core\Authentication\Provider\SimpleAuthenticationProvider::__construct() must implement interface Symfony\Component\Security\Core\User\UserProviderInterface, instance of Delivve\WebBundle\Service\WebKeyUsersService given, called in /home/delivve-webservice/app/cache/de_/ap_DevDebugProjectContainer.php on line 4611 and defined

What happens is that I have an api that works, but now I need to make the web service log face or google account, but this error of the above, follow this tutorial to make http://nyrodev.info/fr/posts/286/Connexions-OAuth-Multiple-avec-Symfony-2-3

And apena in OAuthMembersService.php file includes the useSymfony\Bundle\SecurityBundle\DependencyInjection\Security\UserProvider\UserProviderFactoryInterface; because symfony complained of is not having such imports.

1
What is your question?Jay Blanchard
You forgot this interface implementation: class WebKeyUsersService implements UserProviderInterfaceOIS
I UserProviderInterface this with the following name WebKeyUserProvider if you can help me I can post the codeMarcius Leandro
I repeat: You have to implement the interface in your class.OIS

1 Answers

1
votes

I'm really doubt

I implemented the following classes:

<?php

namespace Delivve\WebBundle\Security;

use HWI\Bundle\OAuthBundle\Security\Core\User\OAuthUser as BaseOAuthUser;
use HWI\Bundle\OAuthBundle\OAuth\Response\UserResponseInterface;


class WebKeyUserProvider extends BaseOAuthUser {

    protected $data;

    public function __construct(UserResponseInterface $response) {
        parent::__construct($response->getUsername());
        $this->data = array(
            'provider'=>$response->getResourceOwner()->getName(),
            'providerId'=>$response->getUsername()
        );
        $vars = array(
            'nickname',
            'realname',
            'email',
            'profilePicture',
            'accessToken',
            'refreshToken',
            'tokenSecret',
            'expiresIn',
        );
        foreach($vars as $v) {
            $fct = 'get'.ucfirst($v);
            $this->data[$v] = $response->$fct();
        }
    }

    public function getData() {
        return $this->data;
    }

    /**
     * {@inheritDoc}
     */
    public function getRoles() {
        return array('ROLE_OAUTH_USER');
    }

}


<?php

namespace Delivve\WebBundle\Service;

use Symfony\Bundle\SecurityBundle\DependencyInjection\Security\UserProvider\UserProviderFactoryInterface;
use Symfony\Component\Config\Definition\Builder\NodeDefinition;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\Security\Core\User\UserProviderInterface;
use HWI\Bundle\OAuthBundle\Security\Core\User\OAuthAwareUserProviderInterface;
use HWI\Bundle\OAuthBundle\OAuth\Response\UserResponseInterface;
use Delivve\WebBundle\Security\WebKeyUserProvider;

class WebKeyUsersService implements UserProviderFactoryInterface, OAuthAwareUserProviderInterface {

    public function loadUserByUsername($username) {
        throw new Exception('loadByUsername not implemented');
    }

    public function supportsClass($class) {
        return $class === "Delivve\\WebBundle\\Security\\WebKeyUserProvider";
    }


    public function refreshUser(\Symfony\Component\Security\Core\User\UserInterface $user) {
        if (!$this->supportsClass(get_class($user))) {
            throw new UnsupportedUserException(sprintf('Unsupported user class "%s"', get_class($user)));
        }
        return $user;
    }

    public function loadUserByOAuthUserResponse(UserResponseInterface $response) {
        return new OAuthUser($response);
    }

    public function create(ContainerBuilder $container, $id, $config)
    {
        // TODO: Implement create() method.
    }

    public function getKey()
    {
        // TODO: Implement getKey() method.
    }

    public function addConfiguration(NodeDefinition $builder)
    {
        // TODO: Implement addConfiguration() method.
    }
}

And these are my configurations:

routingSecurityOAuth.yml

hwi_oauth_login:
    resource: "@HWIOAuthBundle/Resources/config/routing/login.xml"
    prefix:   /login
hwi_oauth_redirect:
    resource: "@HWIOAuthBundle/Resources/config/routing/redirect.xml"
    prefix:   /connect
facebook_login:
    pattern: /login/check-facebook
google_login:
    pattern: /login/check-google
web_target:
    pattern: /target
    defaults: { _controller: DelivveWebBundle:Security:oauthTarget }

service

services:
    web_key_user_provider:
        class: Delivve\WebBundle\Service\WebKeyUsersService

security

security:

    providers:
        web_key_user_provider:
            id: web_key_user_provider

    firewalls:
        web_key:
            pattern:    ^/web/*
            anonymous: ~
            provider: web_key_user_provider
            oauth:
                resource_owners:
                    facebook: "/web/login/check-facebook"
                    google: "/web/login/check-google"
#                    linkedin: "/web/login/check-linkedin"
                login_path: /web/login
                failure_path: /web/login
                check_path: /web/login_check
                default_target_path: /web/target
                oauth_user_provider:
                    service: web_key_user_provider
        default:
                    anonymous: ~
    access_control:
        - { path: ˆ/web/target, roles: ROLE_OAUTH_USER }
        - { path: ˆ/web/, roles: IS_AUTHENTICATED_ANONYMOUSLY }

routing

web_key_register:
    pattern: /webRegister
    defaults: { _controller: DelivveWebBundle:Security:webRegister }

web_key:
    resource: "@DelivveWebBundle/Resources/config/routingSecurityOAuth.yml"
    prefix:   /web/

config

hwi_oauth:
    firewall_name: web_key
    resource_owners:
        facebook:
            type: facebook
            client_id:        %facebook_client_id%
            client_secret:    %facebook_client_secret%
            scope: email
            infos_url: "https://graph.facebook.com/me?fields=username,name,email,picture.type(large)"
            paths:
                email:          email
                profilepicture: picture.data.url
            options:
                display: popup
        google:
            type: google
            client_id:        %google_client_id%
            client_secret:    %google_client_secret%
            scope: "https://www.googleapis.com/auth/userinfo.email https://www.googleapis.com/auth/userinfo.profile"
            paths:
                email:           email
                profilepicture:  picture