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条回答

    报告相同问题?

    悬赏问题

    • ¥30 vmware exsi重置后的密码
    • ¥15 易盾点选的cb参数怎么解啊
    • ¥15 MATLAB运行显示错误,如何解决?
    • ¥15 c++头文件不能识别CDialog
    • ¥15 Excel发现不可读取的内容
    • ¥15 UE5#if WITH_EDITOR导致打包的功能不可用
    • ¥15 关于#stm32#的问题:CANOpen的PDO同步传输问题
    • ¥20 yolov5自定义Prune报错,如何解决?
    • ¥15 电磁场的matlab仿真
    • ¥15 mars2d在vue3中的引入问题