Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/node.js/42.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何将自定义令牌从node.js服务器发送到android客户端_Android_Node.js_Firebase_Firebase Authentication - Fatal编程技术网

如何将自定义令牌从node.js服务器发送到android客户端

如何将自定义令牌从node.js服务器发送到android客户端,android,node.js,firebase,firebase-authentication,Android,Node.js,Firebase,Firebase Authentication,我使用node.js作为android应用程序的后端服务器。 我正在从http请求接收id令牌,并从中生成自定义令牌,我正在使用此链接:但我一直在研究如何将自定义令牌发送回我的android客户端 app.get("/id-tokens/:token", function(req,res){ // Receiving id-tokens var idToken = req.params.token; admin.auth().verifyIdToken(idToken)

我使用node.js作为android应用程序的后端服务器。 我正在从http请求接收id令牌,并从中生成自定义令牌,我正在使用此链接:但我一直在研究如何将自定义令牌发送回我的android客户端

app.get("/id-tokens/:token", function(req,res){
  // Receiving id-tokens

  var idToken = req.params.token;

  admin.auth().verifyIdToken(idToken)
    .then(function(decodedToken) {
      var uid = decodedToken.uid;
    }).catch(function(error) {
      console.log("Error receiving tokens");
    });


  admin.auth().createCustomToken(uid)
    .then(function(customToken) {
      // Send token back to client?? HOW??
    })
    .catch(function(error) {
      console.log("Error creating custom token:", error);
    });

});
这里可以使用FCMFirebase云消息传递吗? 由于安全原因,我希望避免使用http方法。插座、FCM或任何更安全的方法是否可以替代?
我是安卓新手,因此任何帮助都将不胜感激…:

除了http还有别的方法吗?如果没有,那么我如何在android端接收自定义令牌?出于安全原因,我正在搜索http以外的任何其他方法…android中的一个简单http GET请求示例。如果您有安全问题,如果您想使用FCM,您应该使用https,确保它与http一样适合此用例
app.get("/id-tokens/:token", function(req,res){
  var idToken = req.params.token;

  admin.auth().verifyIdToken(idToken)
    .then(function(decodedToken) {
      var uid = decodedToken.uid;

    admin.auth().createCustomToken(uid) // you need to do this call once you have the value for uid
        .then(function(customToken) { // otherwise, uid will be undefined
            res.send(customToken) // since you are using http, just return the token like this
        })
        .catch(function(error) {
        console.log("Error creating custom token:", error);
        });
    }).catch(function(error) {
      console.log("Error receiving tokens");
    });
});