Разное происхождение JavaScript для одного и того же веб-приложения на каждом компьютере вызывает ошибку: redirect_uri_mismatch - PullRequest
1 голос
/ 03 июля 2019

Я опубликовал веб-приложение со входом в Google, используя скрипт Google Apps. Каждый раз, когда вы входите в свою учетную запись Google на другом компьютере для доступа к этому веб-приложению, появляется сообщение об ошибке: «redirect_uri_mismatch».

Я вижу, что на каждом компьютере, который входит в учетную запись Google, опубликованное веб-приложение имеет различное происхождение javaScript в ссылке на запрос, и я добавил эту ссылку в список авторизованных источников JavaScript на консоли разработчика Google для входа в систему на этом компьютере, чтобы сделать Google войдите в работу.

Я хочу, чтобы на моем console.developers.google.com был только один авторизованный источник JavaScript (скрипт приложения-ссылки). Я ожидаю, что все пользователи получат доступ и войдут без ошибки "redirect_uri_mismatch"

Неудобно, если есть тысячи пользователей, как улучшить?

код html:

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="google-signin-client_id" content="1xxxxxxxxxx-xxxxxxxxi87eht.apps.googleusercontent.com">
    <title>Oauth2 web</title>

    <!-- Google library -->
    <script src="https://apis.google.com/js/platform.js" async defer></script>

    <!-- Jquery library to print the information easier -->
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.0/jquery.min.js"></script>

    <!-- Bootstrap library for the button style-->
    <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
</head>
<body>
<div id="profileinfo">
</div>
<div class="g-signin2" data-onsuccess="onSignIn"></div>

<script>
            function onSignIn(googleUser) {
              var profile = googleUser.getBasicProfile();
              console.log('ID: ' + profile.getId()); // Do not send to your backend! Use an ID token instead.
              console.log('Name: ' + profile.getName());
              console.log('Image URL: ' + profile.getImageUrl());
              console.log('Email: ' + profile.getEmail()); // This is null if the 'email' scope is not present.

              $("#profileinfo").append("<h2>Sup " + profile.getName() + ", welcome home my friend</h2>");
              $("#profileinfo").append("<img style='width:250px;height:250px' src='" + profile.getImageUrl() + "'><br><br>");
              $("#profileinfo").append("<p>Your email is: " + profile.getEmail() + "</p>");

            }
        </script>

<button type="button" class="btn btn-danger" onclick="signOut();">Sign out</button>

<script>
            function signOut() {
               var auth2 = gapi.auth2.getAuthInstance();
               auth2.signOut().then(function () {
                 console.log('User signed out.');
               $("#profileinfo").empty();
               $("#profileinfo").append("<h2>Goodbye old friend</h2>");
               });
            }
        </script>
</body>
</html>

Ошибка при входе на другой компьютер: Error when logging in on another computer:

Изменение ссылки выделено желтым цветом: The change of the link is highlighted in yellow

1 Ответ

1 голос
/ 03 июля 2019

Это может не сработать, но вы можете по умолчанию установить значение 0 с помощью этого сценария в index.html:

<script>
  if(!/-0lu/.test(location.href)){ 
    location.href = location.href.toString().replace(/-\d+lu/,'-0lu');
  }
</script>

В вашем веб-приложении script.google.com есть встроенный фрейм в песочнице *[DIGIT]lu-script.googleusercontent.com.Мы просто пытаемся изменить местоположение этого iframe с помощью регулярных выражений.Если в качестве iframe присутствует что-то отличное от 0lu, мы заменяем его на 0lu

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...