ds2128629 2016-11-29 15:53
浏览 57

使用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?

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 Windows server update services
    • ¥15 关于#c语言#的问题:我现在在做一个墨水屏设计,2.9英寸的小屏怎么换4.2英寸大屏
    • ¥15 模糊pid与pid仿真结果几乎一样
    • ¥15 java的GUI的运用
    • ¥15 Web.config连不上数据库
    • ¥15 我想付费需要AKM公司DSP开发资料及相关开发。
    • ¥15 怎么配置广告联盟瀑布流
    • ¥15 Rstudio 保存代码闪退
    • ¥20 win系统的PYQT程序生成的数据如何放入云服务器阿里云window版?
    • ¥50 invest生境质量模块