1

I'm building a symfony REST Api in which I'm trying to get HWIOAuthBundle, FOSUserBundle and LexikJWTBundle working all together.

I followed this gist for the HWIOAuthBundle/FOSUserBundle integration.

Now I'm getting the facebook login form when hitting the /login route. But after submition I get this error :

[2/2] HttpTransportException: Error while sending HTTP request
[1/2] RequestException: Failed to connect to graph.facebook.com port 443: Bad access 


INFO - Matched route "hwi_oauth_service_redirect". 

CRITICAL - 
Uncaught PHP Exception HWI\Bundle\OAuthBundle\OAuth\Exception\HttpTransportException: 
"Error while sending HTTP request" 
at C:\myProject\vendor\hwi\oauth-bundle\OAuth\ResourceOwner\AbstractResourceOwner.php 
line 257 

DEBUG - 
Notified event "kernel.request" to listener
"Symfony\Component\EventDispatcher\Debug\WrappedListener::__invoke". 

...

I'm now looking for help about this. Or any other way to get those bundles to work together.

config.yml :

hwi_oauth:
# list of names of the firewalls in which this bundle is active, this setting MUST be set
firewall_names: [auth]

http_client:
    timeout:       10000
    verify_peer: false
    max_redirects: 1000
    ignore_errors: false

fosub:
    username_iterations: 300
    properties:
        # these properties will be used/redefined later in the custom FOSUBUserProvider service.
        facebook: facebook_id
# an optional setting to configure a query string parameter which can be used to redirect
# the user after authentication, e.g. /connect/facebook?_destination=/my/destination will
# redirect the user to /my/destination after facebook authenticates them.  If this is not
# set then the user will be redirected to the original resource that they requested, or
# the base address if no resource was requested.  This is similar to the behaviour of
# [target_path_parameter for form login](http://symfony.com/doc/2.0/cookbook/security/form_login.html).
# target_path_parameter: _destination

# an optional setting to use the HTTP REFERER header to be used in case no
# previous URL was stored in the session (i.e. no resource was requested).
# This is similar to the behaviour of
# [using the referring URL for form login](http://symfony.com/doc/2.0/cookbook/security/form_login.html#using-the-referring-url).
# use_referer: true

# here you will add one (or more) configurations for resource owners
resource_owners:
    facebook:
        type:                facebook
        client_id:           {id}
        client_secret:       {secret}
        scope:         ""
        infos_url:           "https://graph.facebook.com/me?fields=name,email,picture.type(square)"
        options:
            display: popup

security.yml :

firewalls:
     auth:
        pattern: ^/api/minisite/user/auth
        anonymous: true
        stateless: true
        form_login:
            check_path: /api/minisite/user/auth/login_check
            success_handler: lexik_jwt_authentication.handler.authentication_success
            failure_handler: lexik_jwt_authentication.handler.authentication_failure
            username_parameter: username
            password_parameter: password
            require_previous_session: false
        oauth:
            resource_owners:
                facebook:      "/api/minisite/user/auth/facebook/login/check-facebook"
            login_path:        /api/minisite/user/auth/facebook/login
            check_path: /api/minisite/user/auth/login_check
            failure_path:      /api/minisite/user/auth/facebook/login
            oauth_user_provider:
                #this is my custom user provider, created from FOSUBUserProvider - will manage the
                #automatic user registration on your site, with data from the provider (facebook. google, etc.)
                service: my_user_provider
        logout:       true
        anonymous:    true

access_control:
    - { path: ^/api/minisite/user/auth, roles: IS_AUTHENTICATED_ANONYMOUSLY }
    - { path: ^/api/minisite, roles: IS_AUTHENTICATED_FULLY }
TrtG
  • 2,778
  • 6
  • 26
  • 39
  • Looks like I only needed to clear the "ip" field in facebook developer app account. – TrtG Feb 09 '16 at 12:36

2 Answers2

1

Configure this in your config.yml file.

    hwi_oauth: 
        http_client: 
            verify_peer: false

Setting this allows you to turn off SSL verification.

Dilip Raya
  • 43
  • 1
  • 8
-1

I got the same problem using HWI on localhost. I don't know, but if it's your case, try to upload your work on a server. The reason of this issue is that your are using the port 80, but facebook need that you use the port 443 or use ipv6. Hope this help