Bonjour,

J'intègre la solution de connexion réseaux sociaux dans FOSUSERBUNDLE avec le bundle HWIOAuthBundle

mais j'ai l'erreur suivante :

InvalidTypeException: Invalid type for path "hwi_oauth.resource_owners.facebook.client_id". Expected scalar, but got array.
Merci d'avance pour votre aide, ...

voici mon code :

SECURITY.YML

security:
    encoders:
        FOS\UserBundle\Model\UserInterface: sha512

    role_hierarchy:
        ROLE_ADMIN:       ROLE_USER
        ROLE_SUPER_ADMIN: [ROLE_ADMIN, ROLE_ALLOWED_TO_SWITCH]

    providers:
        fos_userbundle:
            id: fos_user.user_provider.username_email

    firewalls:
        main:
            pattern: ^/
            form_login:
                provider: fos_userbundle
                csrf_provider: form.csrf_provider
                login_path: /login
                check_path: /login_check
            oauth:
                resource_owners:
                    facebook:           "/connect/check-facebook"
                    google:             "/connect/check-google"
                    twitter:            "/connect/check-twitter"
                login_path:        /connect
                failure_path:      /connect

                oauth_user_provider:
                    service: hwi_oauth.user.provider.fosub_bridge
            logout:       true
            anonymous:    true

        login:
            pattern:  ^/login$
            security: false

            remember_me:
                key: "%secret%"
                lifetime: 31536000
                path: /
                domain: ~

    access_control:
        - { path: ^/login$, role: IS_AUTHENTICATED_ANONYMOUSLY }
        - { path: ^/register, role: IS_AUTHENTICATED_ANONYMOUSLY }
        - { path: ^/resetting, role: IS_AUTHENTICATED_ANONYMOUSLY }

ENTITY UTILISATEURS :


<?php
// src/UtilisateursBundle/Entity/Utilisateurs.php

namespace Utilisateurs\UtilisateursBundle\Entity;

use FOS\UserBundle\Model\User as BaseUser;
use Doctrine\ORM\Mapping as ORM;

/**
 * @ORM\Entity
 * @ORM\Table(name="utilisateurs")
 */
class Utilisateurs extends BaseUser
{
    /**
     * @ORM\Id
     * @ORM\Column(type="integer")
     * @ORM\GeneratedValue(strategy="AUTO")
     */
    protected $id;

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

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

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

    public function __construct()
    {
        parent::__construct();
        // your own logic
    }

    /**
     * @var string
     */
    public $pictureName;

    /**
     * Get id
     *
     * @return integer
     */
    public function getId()
    {
        return $this->id;
    }

    /**
     * Set pictureName
     *
     * @param string $pictureName
     * @return Utilisateurs
     */
    public function setPictureName($pictureName)
    {
        $this->pictureName = $pictureName;

        return $this;
    }

    /**
     * Get pictureName
     *
     * @return string
     */
    public function getPictureName()
    {
        return $this->pictureName;
    }

    /**
     * Set facebook_id
     *
     * @param string $facebookId
     * @return Utilisateurs
     */
    public function setFacebookId($facebookId)
    {
        $this->facebook_id = $facebookId;

        return $this;
    }

    /**
     * Get facebook_id
     *
     * @return string
     */
    public function getFacebookId()
    {
        return $this->facebook_id;
    }

    /**
     * Set google_id
     *
     * @param string $googleId
     * @return Utilisateurs
     */
    public function setGoogleId($googleId)
    {
        $this->google_id = $googleId;

        return $this;
    }

    /**
     * Get google_id
     *
     * @return string
     */
    public function getGoogleId()
    {
        return $this->google_id;
    }

    /**
     * Set twitter_id
     *
     * @param string $twitterId
     * @return Utilisateurs
     */
    public function setTwitterId($twitterId)
    {
        $this->twitter_id = $twitterId;

        return $this;
    }

    /**
     * Get twitter_id
     *
     * @return string
     */
    public function getTwitterId()
    {
        return $this->twitter_id;
    }
}

CONFIG.YML


imports:
    - { resource: parameters.yml }
    - { resource: security.yml }

framework:
    #esi:             ~
    #translator:      { fallback: %locale% }
    secret:          %secret%
    router:
        resource: "%kernel.root_dir%/config/routing.yml"
        strict_requirements: ~
    form:            ~
    csrf_protection: ~
    validation:      { enable_annotations: true }
    templating:
        engines: ['twig']
        #assets_version: SomeVersionScheme
    default_locale:  "%locale%"
    trusted_proxies: ~
    session:         ~
    fragments:       ~
    http_method_override: true

fos_user:
    db_driver: orm
    firewall_name: main
    user_class: Utilisateurs\UtilisateursBundle\Entity\Utilisateurs
    registration:
        form:
            type: utilisateurs_user_registration
        confirmation:
            enabled: false

hwi_oauth:
    connect:
        confirmation: true
        registration_form: fos_user.registration.form
    firewall_name: main
    fosub:
        username_iterations: 30
        properties:
            facebook: facebook_id
            google: google_id
            twitter: twitter_id
    resource_owners:
        # Facebook Access
        facebook:
            type:                facebook
            client_id:           [ClientID]
            client_secret:       [ClientIDSecret]
            scope:               "email"
            options:
                display: popup
        # Google Access
        google:
            type:                google
            client_id:           [ClientID]
            client_secret:       [ClientIDSecret]
            scope:               "https://www.googleapis.com/auth/userinfo.email https://www.googleapis.com/auth/userinfo.profile"
            options:
                display: popup
        # Twitter Access
        twitter:
            type:                twitter
            client_id:           [ClientID]
            client_secret:       [ClientIDSecret]
            scope:               ""

# Twig Configuration
twig:
    debug:            %kernel.debug%
    strict_variables: %kernel.debug%

# Assetic Configuration
assetic:
    debug:          %kernel.debug%
    use_controller: false
    bundles:        [ ]
    #java: /usr/bin/java
    filters:
        cssrewrite: ~
        #closure:
        #    jar: %kernel.root_dir%/Resources/java/compiler.jar
        #yui_css:
        #    jar: %kernel.root_dir%/Resources/java/yuicompressor-2.4.7.jar

# Doctrine Configuration
doctrine:
    dbal:
        driver:   %database_driver%
        host:     %database_host%
        port:     %database_port%
        dbname:   %database_name%
        user:     %database_user%
        password: %database_password%
        charset:  UTF8
        # if using pdo_sqlite as your database driver, add the path in parameters.yml
        # e.g. database_path: %kernel.root_dir%/data/data.db3
        # path:     %database_path%

    orm:
        auto_generate_proxy_classes: %kernel.debug%
        auto_mapping: true

# Swiftmailer Configuration
swiftmailer:
    transport: %mailer_transport%
    host:      %mailer_host%
    username:  %mailer_user%
    password:  %mailer_password%
    spool:     { type: memory }

knp_paginator:
    page_range: 5                      # default page range used in pagination control
    default_options:
        page_name: page                # page query parameter name
        sort_field_name: sort          # sort field query parameter name
        sort_direction_name: direction # sort direction query parameter name
        distinct: true                 # ensure distinct results, useful when ORM queries are using GROUP BY statements
    template:
        pagination: KnpPaginatorBundle:Pagination:sliding.html.twig     # sliding pagination controls template
        sortable: KnpPaginatorBundle:Pagination:sortable_link.html.twig # sort link template       

2 réponses


ok, j'ai déjà trouvé un truc : je n'avais pas renseigné les

client_id:           [ClientID]
client_secret:       [ClientIDSecret]

Maintenant : j'ai le problème suivant :
InvalidConfigurationException: Unrecognized option "firewall_name" under "hwi_oauth"

je cherche....

Le probleme est réglé :

j'ai remplacé firewall_name: main par firewall_names : [secured_area] dans le config.yml

hwi_oauth:
    connect:
        confirmation: true
        registration_form: fos_user.registration.form
    firewall_names: [secured_area]   

maintenant le message suivant apparaît :

ScopeWideningInjectionException: Scope Widening Injection detected: The definition "hwi_oauth.registration.form.handler.fosub_bridge" references the service "fos_user.registration.form.handler.default" which belongs to a narrower scope. Generally, it is safer to either move "hwi_oauth.registration.form.handler.fosub_bridge" to scope "request" or alternatively rely on the provider pattern by injecting the container itself, and requesting the service "fos_user.registration.form.handler.default" each time it is needed. In rare, special cases however that might not be necessary, then you can set the reference to strict=false to get rid of this error.

Une idée ?