2015-01-15 150 views
1

我试图用hwi oauth bundle在symfony2中实现oauth google身份验证。我添加了按钮和弹出窗口打开并succesfull autenticate用户,然后在javascript中执行我的signinCallback函数。问题是我需要在登录操作之后在数据库中注册用户,所以我为此配置了redirect_uri。我使用github的成功验证测试动作,没有弹出窗口,只是创建一个<a href="https://github.com/login/oauth/authorize?scope=user:email&client_id=MY_ID">Click here</a>,并重定向到该页面,并在验证之后将我重定向到正确的重定向uri。谷歌的问题是,成功的atentication后,只调用JavaScript函数,而不是配置的uri。有没有一种方法可以用github的相同方式进行google验证?我也尝试在signinCallback函数中调用document.location = "{{ url("hwi_oauth_service_redirect", {service: "google"}) }}",但是当然得到一些与所需参数有关的错误。重定向uri不工作

回答

1

如果帮助别人这就是我如何解决:

function signinCallback(authResult) { 
     if (authResult['access_token']) { 
      // Properly authorized 
      // Hide the button 
      document.getElementById('customBtn').setAttribute('style', 'display: none'); 
      document.location = "{{ url("hwi_oauth_service_redirect", {service: "google"}) }}"; 
     } else if (authResult['error']) { 
      // If error 
      // console.log('There was an error: ' + authResult['error']); 
     } 
    }