重定向uri不工作

时间:2015-01-15 17:49:06

标签: symfony google-oauth

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

1 个答案:

答案 0 :(得分: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']);
        }
    }