[英]Adding token generator to Rails app
I'm trying to integrate firechat into a Rails app, and am not sure where to put the snippet that generates tokens for users-- would this go in a messaging model, or similar?? 我正在尝试将firechat集成到Rails应用程序中,并且不确定在哪里将为用户生成令牌的代码片段放置在消息传递模型或类似模型中? The code is below: 代码如下:
require "firebase_token_generator"
payload = {:uid => "1", :auth_data => "foo", :other_auth_data => "bar"}
generator = Firebase::FirebaseTokenGenerator.new(" <YOUR_FIREBASE_SECRET>")
token = generator.create_token(payload)
You need to pass it to your frontend client (or views) and use it to communicate with firebase: 您需要将其传递给前端客户端(或视图),并使用它与firebase通信:
var ref = new Firebase("https://<YOUR-FIREBASE-APP>.firebaseio.com/");
ref.authWithCustomToken(AUTH_TOKEN, function(error, authData) {
if (error) {
console.log("Login Failed!", error);
} else {
console.log("Login Succeeded!", authData);
}
});
as per https://www.firebase.com/docs/web/guide/login/custom.html#section-rest-token-helper-libraries 按照https://www.firebase.com/docs/web/guide/login/custom.html#section-rest-token-helper-libraries
Therefore I'd say it needs to go into the controller in the first place. 因此,我想说它首先需要进入控制器。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.