Ошибка при попытке использовать Google oAuth API с hapi / bell js - PullRequest
0 голосов
/ 30 марта 2020

Я пытаюсь использовать hapi / bell и Google API oAuth, но у меня в консоли появляются следующие 2 ошибки:

Доступ к XMLHttpRequest по адресу https://accounts.google.com/o/oauth2/v2/auth?client_id=914091897182-m38hh6r2t4nhur4fgs1dn7v790l0bvrr.apps.googleusercontent.com%A&response_type=code&redirect_uri=http%3A%2F%2FLAPTOP-CEDRIC%3A3000%2Fbell%2Fdoor&state=Bj4hjqaQ0qdYuVich4ESje&scope=profile%20email '(перенаправлен с 'http://localhost: 3000 / звонок / дверь ') от источника 'http://localhost: 3000 ' заблокировано политикой CORS: Ответ на предпечатный запрос не проходит контроль доступа проверка: в запрашиваемом ресурсе отсутствует заголовок «Access-Control-Allow-Origin».

Затем:

jquery .min. js: 2 GET https://accounts.google.com/o/oauth2/v2/auth?client_id=914091897182-m38hh6r2t4nhur4fgs1dn7v790l0bvrr.apps.googleusercontent.com%A&response_type=code&redirect_uri=http%3A%2F%2FLAPTOP-CEDRIC%3A3000%2Fbell%2Fdoor&state=Bj4hjqaQ0qdYuVich4ESje&scope=profile%20email net :: ERR_FAILED

Код следует примеру из звонка: https://hapi.dev/module/bell/examples/#google

, а в переднем конце я использую в заголовке (с мопсом):

script.
    window.onLoadCallback = function start() {
        gapi.load('auth2', function() {
            auth2 = gapi.auth2.init({
                client_id: 'MYCLIENTID',
                // Scopes to request in addition to 'profile' and 'email'
                //scope: 'additional_scope'
            });
        });
    }

затем в теле:

script.
    function signInCallback(authResult) {
        if (authResult['code']) {

            // Hide the sign-in button now that the user is authorized, for example:
            $('#signinButton').attr('style', 'display: none');

            // Send the code to the server
            $.ajax({
                type: 'POST',
                url: 'http://localhost:3000/bell/door',
                // Always include an `X-Requested-With` header in every AJAX request,
                // to protect against CSRF attacks.
                headers: {
                    'X-Requested-With': 'XMLHttpRequest'
                },
                contentType: 'application/octet-stream; charset=utf-8',
                success: function (result) {
                    // Handle or verify the server response.
                },
                processData: false,
                data: authResult['code']
            });
        } else {
            // There was an error.
        }
    }
...