java firebase-admin无法登录用户并获得令牌没有客户端 [英] java firebase-admin cannot log user in and get token no client

查看:110
本文介绍了java firebase-admin无法登录用户并获得令牌没有客户端的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我没有前端.我希望用户将我的API(例如,邮递员)与基本的auth标头(email:password)结合使用,然后使用此标头可以从firebase获取用户数据.

I have no front end. I want users to use my API e.g (postman) with a basic auth header (email:password) and then using this header I can get the users data from firebase.

但是我找不到验证实际用户的方法吗?

however I find no method to authenticate the actual user?

 <dependency>
  <groupId>com.google.firebase</groupId>
  <artifactId>firebase-admin</artifactId>
  <version>6.11.0</version>
</dependency>

我已使用

FileInputStream serviceAccount =
  new FileInputStream("path/to/serviceAccountKey.json");

FirebaseOptions options = new FirebaseOptions.Builder()
  .setCredentials(GoogleCredentials.fromStream(serviceAccount))
  .setDatabaseUrl("https://DBNAME.firebaseio.com")
  .build();

FirebaseApp.initializeApp(options);

我试图研究这些方法:

FirebaseAuth.getInstance().
FirebaseDatabase.getInstance().

但是我看不到从服务器登录用户的选项...

but I see no options to sign in the user from my server...

似乎很容易从nodejs服务器...例如

seems very easy from nodejs server... e.g

firebase.auth().signInWithEmailAndPassword(email, password)

此方法是否存在于java/中,如何在Java中针对服务器且没有客户端?

does this method exist in java/ how can I do this in java for server and no client??

推荐答案

Firebase Auth通常的工作方式是这样的.客户端应用应登录以获取ID令牌,并将该令牌传递给每个调用的后端.后端应分别验证从客户端收到的令牌使用Firebase Admin SDK进行请求.

The way Firebase Auth generally works is like this. The client app should be signing in to get an ID token, and passing along that token to the backend for each call. The backend should verify the token received from the client with each request using the Firebase Admin SDK.

通常,客户端应用程序将使用其中一种客户端SDK用于移动和Web应用程序.它将管理每小时进行一次身份验证,获取令牌和刷新令牌的所有详细信息.

Typically, client apps will use one of the client SDKs for mobile and web apps. It will manage all the details of authenticating the user, getting a token, and refreshing the token every hour.

如果您不能使用其中一个客户端SDK,则基本上必须编写自己的SDK,或者在Internet上搜索以查看是否有人已经这样做.如果您编写自己的代码,则必须调用 Firebase Auth REST API 直接获取并刷新该令牌.使用Firebase Auth,您实际上没有其他选择,这就是它的设计方式.

If you can't use one of the client SDKs, you will essentially have to write your own, or search the internet to see if someone else has already done it. If you write your own code, you will have to invoke the Firebase Auth REST APIs directly to get and refresh that token. You don't really have any alternatives to this with Firebase Auth - that's the way it was designed.

这篇关于java firebase-admin无法登录用户并获得令牌没有客户端的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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