{"action":"created","issue":{"url":"https://api.github.com/repos/hwi/HWIOAuthBundle/issues/551","labels_url":"https://api.github.com/repos/hwi/HWIOAuthBundle/issues/551/labels{/name}","comments_url":"https://api.github.com/repos/hwi/HWIOAuthBundle/issues/551/comments","events_url":"https://api.github.com/repos/hwi/HWIOAuthBundle/issues/551/events","html_url":"https://github.com/hwi/HWIOAuthBundle/issues/551","id":32983464,"number":551,"title":"Login Facebookuser into Symfony per AJAX","user":{"login":"fnordo","id":1086769,"avatar_url":"https://avatars.githubusercontent.com/u/1086769?v=3","gravatar_id":"","url":"https://api.github.com/users/fnordo","html_url":"https://github.com/fnordo","followers_url":"https://api.github.com/users/fnordo/followers","following_url":"https://api.github.com/users/fnordo/following{/other_user}","gists_url":"https://api.github.com/users/fnordo/gists{/gist_id}","starred_url":"https://api.github.com/users/fnordo/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/fnordo/subscriptions","organizations_url":"https://api.github.com/users/fnordo/orgs","repos_url":"https://api.github.com/users/fnordo/repos","events_url":"https://api.github.com/users/fnordo/events{/privacy}","received_events_url":"https://api.github.com/users/fnordo/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/hwi/HWIOAuthBundle/labels/Support%20request","name":"Support request","color":"0052cc"}],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":21,"created_at":"2014-05-07T13:12:01Z","updated_at":"2015-01-23T16:56:33Z","closed_at":null,"body":"Hello, \r\n\r\ni am currently playing around with this bundle and was wondering if it is possible to trigger the symfony-login after a successful facebook-login (via the facebook login button) per AJAX. \r\n\r\nIf i understand [this example](https://github.com/hwi/HWIOAuthBundle/blob/master/Resources/doc/bonus/facebook-connect.md#adding-the-facebook-login-button) right, in the most cases one would do the following to log the user into the symfony application:\r\n\r\n* Make sure that the facebook javascript SDK is loaded\r\n* When the user clicks on the facebook login button (and the user has not authorized the app) call FB.login()\r\n* After a successful login on the facebook-side,  trigger the symfony login by issuing a `GET` to the URL defined for the  `hwi_oauth_service_redirect`-route  \r\n* Then the bundles `ConnectController::redirectToServiceAction()` is executed on the serverside which results in a redirect to facebooks oauth endpoint to get the oauth code (which in turn is required   to log the user successfully into the symfony application).\r\n\r\nThe problem i am facing now is that i am working on a single page application where the page must not be reloaded. So my first naive approach was to - in the FB.login-callback - issue the `GET` to  `hwi_oauth_service_redirect` (resp. `login/facebook`) per AJAX like the following:\r\n\r\n```\r\n$.ajax({\r\n  url: 'login/facebook',\r\n  type: 'GET',\r\n  dataType: 'json',\r\n  crossDomain: true,\r\n})\r\n.done(function(data, textStatus, jqXHR){\r\n  console.info(data)\r\n})\r\n.fail(function(jqXHR, textStatus, errorThrown){\r\n  console.warn('Could not login facebook user')\r\n});\r\n\r\n```\r\nWhen i try to do this, unfortunately i run into cross-domain-issues and Firebug shows the following message: \r\n\r\n```\r\nCross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at https://www.facebook.com/dialog/oauth?response_type=code&client_id=MY_APP_CLIENT_ID&scope=emall&redirect_uri=MY_REDIRECT_UR/login/check-facebook&display=popup. This can be fixed by moving the resource to the same domain or enabling CORS.\r\n```\r\n\r\nIn contrast when i call the related URI (`MY_DOMAIN/login/facebook`) by reloading the page as shown in the [docs](https://github.com/hwi/HWIOAuthBundle/blob/master/Resources/doc/bonus/facebook-connect.md#adding-the-facebook-login-button) everything works fine and the user is logged in on both sides (facebook and my symfony app).\r\n\r\nAs i am not sure if am doing everything right or if i am missing something here, my question is: is it possible to trigger the symfony-login as described above (per AJAX) and am i just missing something or is it just not possible to do this?\r\n\r\nMy configuration of the bundle looks something like the following:\r\n\r\n```\r\n# app/config/config.yml\r\n\r\nhwi_oauth:\r\n  connect:\r\n      account_connector: my_custom_oauth_userprovider_service\r\n  firewall_name: main\r\n  fosub:\r\n      username_iterations: 5\r\n      properties:\r\n         facebook: facebookId\r\n  resource_owners:\r\n    facebook:\r\n      type:           facebook\r\n      client_id:      MY_APP_CLIENT_ID\r\n      client_secret:  MY_APP_CLIENT_SECRET\r\n      scope:          \"email\"\r\n      options:\r\n          display: popup \r\n      infos_url:     \"https://graph.facebook.com/me?fields=username,name,email,picture.type(square)\"\r\n      paths:\r\n          email:          email\r\n          profilepicture: picture.data.url\r\n\r\n```\r\n\r\n```\r\n# app/config/security.yml\r\n\r\nsecurity:\r\n    providers:\r\n        fos_userbundle:\r\n            id: fos_user.user_provider.username_email\r\n\r\n    firewalls:\r\n        main:\r\n            pattern: ^/\r\n            form_login:\r\n                success_handler: my_custom.authentication_success_handler\r\n                provider: fos_userbundle\r\n                csrf_provider: form.csrf_provider\r\n            logout:\r\n              path: /logout\r\n              success_handler: my_custom.security.handler.logout\r\n            anonymous:    true\r\n\r\n            # HWIOAuth-related configuration:\r\n            oauth:\r\n                resource_owners:\r\n                    facebook: \"/login/check-facebook\"\r\n                login_path:        /login\r\n                use_forward:       false\r\n                failure_path:      /login\r\n                success_handler: my_custom.authentication_success_handler\r\n                oauth_user_provider:\r\n                  service: my_custom.oauth_user_provider\r\n\r\n        # some configuration for other firewalls...\r\n\r\n    access_control:\r\n          - { path: ^/login$, role: IS_AUTHENTICATED_ANONYMOUSLY }\r\n          # more access_control stuff...\r\n\r\n```\r\n\r\n```\r\n# app/config/routing.yml\r\n\r\nhwi_oauth_redirect:\r\n    resource: \"@HWIOAuthBundle/Resources/config/routing/redirect.xml\"\r\n    prefix:   /login\r\n\r\nfacebook_login:\r\n    pattern: /login/facebook\r\n\r\n# imported FOS-UserBundle routes and custom routes... \r\n```\r\n"},"comment":{"url":"https://api.github.com/repos/hwi/HWIOAuthBundle/issues/comments/71224950","html_url":"https://github.com/hwi/HWIOAuthBundle/issues/551#issuecomment-71224950","issue_url":"https://api.github.com/repos/hwi/HWIOAuthBundle/issues/551","id":71224950,"user":{"login":"hugomn","id":497957,"avatar_url":"https://avatars.githubusercontent.com/u/497957?v=3","gravatar_id":"","url":"https://api.github.com/users/hugomn","html_url":"https://github.com/hugomn","followers_url":"https://api.github.com/users/hugomn/followers","following_url":"https://api.github.com/users/hugomn/following{/other_user}","gists_url":"https://api.github.com/users/hugomn/gists{/gist_id}","starred_url":"https://api.github.com/users/hugomn/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/hugomn/subscriptions","organizations_url":"https://api.github.com/users/hugomn/orgs","repos_url":"https://api.github.com/users/hugomn/repos","events_url":"https://api.github.com/users/hugomn/events{/privacy}","received_events_url":"https://api.github.com/users/hugomn/received_events","type":"User","site_admin":false},"created_at":"2015-01-23T16:56:33Z","updated_at":"2015-01-23T16:56:33Z","body":"Hey @vazgen, can you share your iframe solution? Thanks in advance! =)"}}