1

我有这个 Javascript 代码,它返回谷歌身份验证的令牌:

<script>
    function googleLogin(){
        var provider = new firebase.auth.GoogleAuthProvider();
        firebase.auth().useDeviceLanguage();
        firebase.auth().signInWithPopup(provider).then(function(result) {
            // This gives you a Google Access Token. You can use it to access the Google API.
            var token = result.credential.accessToken;
            // The signed-in user info.
            var user = result.user;
            // ...
    alert(token)
            var csrftoken = '{{ csrf_token }}';
            $.post("/api/login", {'csrfmiddlewaretoken': csrftoken, 'token': token});
            }).catch(function(error) {
            // Handle Errors here.
            var errorCode = error.code;
            var errorMessage = error.message;
            // The email of the user's account used.
            var email = error.email;
            // The firebase.auth.AuthCredential type that was used.
            var credential = error.credential;
            // ...
        });
    }
</script>

但是,当我尝试将此令牌发送到 pyrebase 以检索用户信息时,它会返回 INVALID_ID_TOKEN 错误

这是我将令牌发送到 pyrebase 的一段代码:

user_info = auth.get_account_info(token)

这是错误:

requests.exceptions.HTTPError: [Errno 400 Client Error: Bad Request for url: https://www.googleapis.com/identitytoolkit/v3/relyingparty/getAccountInfo?key=AIzaSyBUH-4_qFvkszGWxII8HyooOJNDqbltDKo] {
"error": {
    "code": 400,
    "message": "INVALID_ID_TOKEN",
    "errors": [
        {
        "message": "INVALID_ID_TOKEN",
        "domain": "global",
        "reason": "invalid"
        }
    ]
}
}
4

1 回答 1

1

我发送的是 Google 访问令牌,而不是 Firebase 令牌

于 2019-04-22T18:34:09.167 回答