无法通过MVC中的Google登录通过打开Goog​​le同意屏幕(允许/拒绝)

时间:2019-10-31 05:37:38

标签: javascript google-oauth2 google-api-js-client

当我在ASP .NET MVC 5中使用通过gmail凭据登录时,无需显示允许/拒绝同意屏幕即可直接将我带入系统。

    var googleUser = {};
    var startAppA = function () {
        gapi.load('auth2', function () {
            //Retrieve the singleton for the GoogleAuth library and set up the client.
            auth2 = gapi.auth2.init({
                client_id: 'xxxxxxxxxxxxx',
                secret_key: 'xxxxxxxxxxxxxx',

                cookiepolicy: 'single_host_origin',
            });
            attachSignin(document.getElementById('googleplus'));
        });
    };

    function attachSignin(element) {
        auth2.attachClickHandler(element, {},
            function (googleUser) {
                debugger;
                $(".se-pre-con").show();
                //console.log(googleUser);
                var profiles = googleUser.getBasicProfile();

                //Crate A Bunch Of Object for Search
                var objData = {
                    Email: profiles.getEmail(),
                    LastName: profiles.getFamilyName(),
                    FirstName: profiles.getGivenName(),
                    GoogleID: profiles.getId(),
                    ProfileURL: profiles.getName(),
                };

                $.ajax({
                    type: "POST",
                    url: '@Url.Action("GoogleSignIn", "account")',
                    data: objData,
                    datatype: "json",
                    success: function (data) {
                        var return_url = '@ViewBag.ReturnUrl';
                        window.location.href = return_url;
                    }
                });
                $(".se-pre-con").hide();

            }, function (error) {
                //alert(JSON.stringify(error, undefined, 2));
            });
    }
</script>
<script>startAppA();</script>

每当有人单击“允许”按钮时,都应该弹出同意屏幕,然后用户应该使用各自的凭据进入系统。

0 个答案:

没有答案