使用Firebase进行NodeJS身份验证 [英] NodeJS authentication with Firebase

查看:604
本文介绍了使用Firebase进行NodeJS身份验证的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想通过使用Firebase的NodeJS进行身份验证和保持会话。客户端无法直接与Firebase进行通信。简单地说:


客户端(浏览器)<----> > NodeJs(firebase-admin)< ----> Firebase


我在NodeJS中创建了Firebase客户端,然后使用登录方法:

  var firebaseClient = require('firebase'); 
firebaseClient.initializeApp(config)
firebaseClient.auth()。signInWithEmailAndPassword(req.body.email,req.body.password).catch(function(error){
console.log错误);
})

然后我创建了路由来检查已验证的用户:
$ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ var $ user $ firebaseClient.auth() .currentUser
console.log(user)
})

允许我保留1个以前登录的用户。



我想使用firebase-admin,但我不知道如何保持会话和身份验证用户

解决方案

您可以使用客户端SDK在其各自的设备/浏览器上对客户端进行身份验证,并让他们将ID令牌发送到使用书写的后端服务firebase-admin(管理员SDK)。 admin SDK提供了验证客户端发送的ID令牌的方法: https:/ /firebase.google.com/docs/auth/admin/verify-id-tokens


I would like to authenticate and keep sessions via NodeJS with Firebase. Client can't directly communicate with Firebase.

In short:

Client (browser) <----> NodeJs(firebase-admin) <----> Firebase

I created Firebase client in NodeJS, then I used login method:

var firebaseClient = require('firebase');
firebaseClient.initializeApp(config)
firebaseClient.auth().signInWithEmailAndPassword(req.body.email, req.body.password).catch(function(error){
    console.log(error);
})

and then I created route to check authenticated user:

app.get('/check',function(req,res){
    var user = firebaseClient.auth().currentUser
    console.log(user)
})

This method only allows me keep 1 previously logged user.

I would like to use firebase-admin, but I don't know how to keep session and authenticate users

解决方案

You can authenticate clients on their respective devices/browsers using the client SDK, and them get them to send an ID token to a backend service written using firebase-admin (the admin SDK). The admin SDK provides methods for validating ID tokens sent by clients: https://firebase.google.com/docs/auth/admin/verify-id-tokens

这篇关于使用Firebase进行NodeJS身份验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆