Firebase-无法通过Google登录进行身份验证

Nin*_*ina 4 google-authentication firebase

我正在玩Firebase,并试图通过Google登录进行身份验证。我创建了一个Firebase项目,并在登录方法中启用了Google提供程序。

然后在我的index.html中,这主要是由firebase init生成的。我在其中添加了按钮。

<html>
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">

    <!-- update the version number as needed -->
    <script defer src="/__/firebase/6.0.2/firebase-app.js"></script>
    <!-- include only the Firebase features as you need -->
    <script defer src="/__/firebase/6.0.2/firebase-auth.js"></script>
    <script defer src="/__/firebase/6.0.2/firebase-database.js"></script>
    <script defer src="/__/firebase/6.0.2/firebase-messaging.js"></script>
    <script defer src="/__/firebase/6.0.2/firebase-storage.js"></script>
    <!-- initialize the SDK after all desired features are loaded -->
    <script defer src="/__/firebase/init.js"></script>
    <script src="signin.js"></script>

    </style>
  </head>
  <body>
      <button id="signin">Sign in</button>
  </body>
</html>

Run Code Online (Sandbox Code Playgroud)

然后在我的signin.js中处理登录

document.addEventListener("DOMContentLoaded", function(event) { 
    var firebaseConfig = {
        apiKey: "AIzaSyC8bHVEtWDcTLJ0b8UOOZ5ClCV1tobqm5w",
        authDomain: "second-d10d4.firebaseapp.com",
        databaseURL: "https://second-d10d4.firebaseio.com",
        projectId: "second-d10d4",
        storageBucket: "second-d10d4.appspot.com",
        messagingSenderId: "912088308787",
        appId: "1:912088308787:web:24c9fa6af5dd0771"
      };
      // Initialize Firebase
      firebase.initializeApp(firebaseConfig);
    let signinbutton = document.getElementById("signin");
    signinbutton.addEventListener("click", signin);            
  });

  function signin(){
    var provider = new firebase.auth.GoogleAuthProvider()
    firebase.auth().signInWithPopup(provider)
    .then(result => {
        console.log("auth success")
        console.log(result)

        var token = result.credential.accessToken

        var user = result.user

    })
    .catch(error => {
        console.log("auth error")

        var errorCode = error.code;
        var errorMessage = error.message;

        var email = error.email;

        var credential = error.credential;

    })
}


Run Code Online (Sandbox Code Playgroud)

部署后,当我访问该站点并尝试登录时,收到此错误。

403. That’s an error.

Error: restricted_client

Application: project-912088308787

You can email the developer of this application at: unconfiguredapp@google.com

This app is not yet configured to make OAuth requests. To do that, set up the app’s OAuth consent screen in the Google Cloud Console.

Learn more

Request Details
response_type=code
client_id=912088308787-potc94v4vl23tscu3gm9pnqu282s52nl.apps.googleusercontent.com
redirect_uri=https://second-d10d4.firebaseapp.com/__/auth/handler
state=AMbdmDnNM2kSjUeMO4KsxjdWqODEehA03g2bOBE5ZMEgzwCFXx5_n81fN_IKs52mn6P9bWpzMGF0ja9gDSyA39vx5ukZo_bY6UBitPUkFTKQvK3hSYxYyrjCxW4mJ3F5076yhktxbVchOAkMtKCl7vyh2pX4SjBV2YjvP-_CL8l9y-RWaegyO7_qq7qcxXsjVe8SKziqRV_AjMt7I9GZTVfaLovBfz-KkLwG1CSGdvfXs8XZImuDz6KR9sri-QlcDFthhxih0EOi9fJt10oNYEvBNtn5Y_54sQcMVKanlnIWiltG-KJyjY_0pwy6HyhPBDdDGKUe5g
scope=openid https://www.googleapis.com/auth/userinfo.email profile https://www.googleapis.com/auth/contacts.readonly
Run Code Online (Sandbox Code Playgroud)

有人知道什么可能导致此错误吗?

编辑:问题解决了。用户提出的解决方案:Vanduc1102对其进行了修复。在Firebase项目设置中设置支持电子邮件 在此处输入图片说明 编辑31/07/2019:如果您在插入支持电子邮件后仍然遇到问题:在显示的403错误页面上,单击“了解更多”会将您带到GCP“ OAuth同意屏幕”,您将在其中看到两个字段“支持电子邮件” ”和“应用程序徽标”。对于“应用程序徽标”,可以使用任何图标/图像来标识应用程序,对于支持电子邮件,应使用Firebase控制台中使用的电子邮件。上传应用程序徽标并填写支持电子邮件字段后,请保存更改,并且Google身份验证现在应可与您的应用一起使用。

van*_*102 16

我在遵循教程时遇到了这个问题:https : //medium.com/firebase-developers/how-to-setup-firebase-authentication-with-react-in-5-minutes-maybe-10-bb8bb53e8834

我通过更正支持电子邮件字段来解决此问题,该字段为空

在此处输入图片说明

  • 哦,我的天哪,谢谢你! (3认同)

Jos*_*ven 5

您是否设置了 OAuth 同意屏幕?

如果没有,您需要在此处进行设置:https : //console.developers.google.com/apis/credentials/consent

当您尝试通过 Google 登录进行身份验证时是否收到此消息?如果是这样,请单击“了解更多”链接,它也会将您带到 OAuth 同意屏幕设置页面。

在此处输入图片说明

一定要选择一个电子邮件地址(我以前忘记了,结果导致了这个错误!)

最后,如果您已完成所有操作但仍看到错误消息,您可能需要打开隐身浏览器和/或清除缓存。