2015-01-15 151 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']); 
     } 
    }