使用PHP和JWT验证在Javascript中生成的Firebase令牌

Working on a web app in JavaScript using Firebase authentication that needs to reach out to a remote PHP script.

The user should be able to log into the web app, then once authenticated has access to the functionality of the PHP script.

I generated a token with firebase.auth().currentUser.getToken() and successfully POSTed to the PHP server.

        firebase.auth().currentUser.getToken(true).then(function(idToken) {

        var uid = firebase.auth().currentUser.uid;


        var http = new XMLHttpRequest();
        var url = "http://localhost/json.php";
        var params = "token=" + idToken + "&uid=" + uid;
        http.open("POST", url, true);

        //Send the proper header information along with the request
        http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");

        http.onreadystatechange = function() {//Call a function when the state changes.
            if(http.readyState == 4 && http.status == 200) {
                alert(http.responseText);
            }
        }
        http.send(params);      

      //console.log("TOKEN: " + idToken);
    }).catch(function(error) {
      // Handle error
    });

However, I'm having some issue on the PHP side where all I need is to validate that the user is currently signed in. I tried the firebase/php-jwt library but I seem to be missing how to do a simple validation so the user can unlock the functionality of the PHP script.

Any ideas?

dsuoedtom207012191
dsuoedtom207012191 是的,我已经梳理了Firebase文档。如果您使用的是Node.js或Java,那就非常直接了,但是当您必须为PHP实现第三方库时,这并非如此。
接近 4 年之前 回复
duanmianzhou5353
duanmianzhou5353 还有一个类似的问题,你可能会觉得有用:stackoverflow.com/questions/37634305/...
接近 4 年之前 回复
doufen3134
doufen3134 有一个指南如何验证令牌:firebase.google.com/docs/auth/admin/verify-id-tokens
接近 4 年之前 回复
Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问
相关内容推荐