Cod*_*000 2 javascript node.js firebase firebase-authentication firebase-realtime-database
情况:
目前,我将UID通过url传递给服务器.
然后,我使用UID检查数据库中是否存在该UID:
码:
router.get("/profile/:uid", function(req, res, next){
var uid = req.params.uid;
var userRef = admin.database().ref("users/"+uid);
userRef.once('value', function(snapshot){
if (snapshot != null) {
Run Code Online (Sandbox Code Playgroud)
问题:
这意味着任何人都可以通过构建网址并将其粘贴到搜索栏并包含该用户的UID来访问任何人的个人资料.
题:
如何在没有此类安全漏洞的情况下检查用户是否在服务器上进行了身份验证?
您需要传递身份验证令牌而不是uid.在身份验证过程之后,您将从Firebase获取uid,而不是从用户获取.
使用Firebase管理SDK验证ID令牌
卷筒纸
firebase.auth().currentUser.getToken(/* forceRefresh */ true).then(function(idToken) {
// Send token to your backend via HTTPS
// ...
}).catch(function(error) {
// Handle error
});
Run Code Online (Sandbox Code Playgroud)
服务器(NodeJs)
// idToken comes from the client app (shown above)
admin.auth().verifyIdToken(idToken)
.then(function(decodedToken) {
var uid = decodedToken.uid;
// here you can use the uid of the user without the fear of Forgery
}).catch(function(error) {
// Handle error
});
Run Code Online (Sandbox Code Playgroud)
资料来源:https: //firebase.google.com/docs/auth/admin/verify-id-tokens
| 归档时间: |
|
| 查看次数: |
872 次 |
| 最近记录: |