OAuth 2似乎拒绝了我的客户ID

时间:2018-08-11 21:33:22

标签: javascript oauth-2.0 google-oauth2

我正在跟踪使用Oauth进行身份验证/授权的教程,我已经设置了项目,获得了我的clientID和密钥,但是当我发出请求时,好像Google拒绝了我的客户ID。我有一个回调函数singInCallback,但是这里什么也没有发生,因为我没有从Google获得authResult。我做错了什么,请帮忙。下面的代码

<!DOCTYPE html>
<html>
<head>
    <meta name="google-signin-client_id" content="311627005823-d9ai9rf3sj4a1ik1738iu2647qu9458j.apps.googleusercontent.com">
    <!--LOAD PRE-REQUISITES FOR GOOGLE SIGN IN -->
    <script src="//ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js">
    </script>
    <script src="//apis.google.com/js/platform.js?onload=start"> </script>
</head>
<body>
    <div id="signinButton">
        <span class="g-signin" data-scope="openid email" data-clientid="311627005823-d9ai9rf3sj4a1ik1738iu2647qu9458j.apps.googleusercontent.com"
            data-redirecturi="postmessage" data-accesstype="offline" data-cookiepolicy="single_host_origin" data-callback="signInCallback"
            data-approvalprompt="force">
        </span>

    </div>
    <div id="result"></div>
    <script>
        function signInCallback(authResult) {
            if (authResult['code']) {
                // Hide the sign-in button now that the user is authorized
                $('#signinButton').attr('style', 'display: none');
                // Send the one-time-use code to the server, if the server responds, write a 'login successful' message to the web page and then redirect back to the main restaurants page
                $.ajax({
                    type: 'POST',
                    url: '/gconnect?state={{STATE}}',
                    processData: false,
                    data: authResult['code'],
                    contentType: 'application/octet-stream; charset=utf-8',
                    success: function (result) {
                        // Handle or verify the server response if necessary.
                        if (result) {
                            $('#result').html('Login Successful!</br>' + result + '</br>Redirecting...')
                            setTimeout(function () {
                                window.location.href = "/restaurant";
                            }, 4000);

                        } else if (authResult['error']) {
                            console.log('There was an error: ' + authResult['error']);

                        } else {

                            $('#result').html('Failed to make a server-side call. Check your configuration and console.');

                        }
                    }

                });
            }
        }

    </script> 
    </script>
</body>
</html>

0 个答案:

没有答案