简体   繁体   English

Android应用请求Firebase自定义身份验证

[英]Android app request Firebase custom authentication

I'm new to Firebase and Android programming, I have some questions regarding Firebase custom authentication. 我是Firebase和Android编程的新手,我对Firebase自定义身份验证有一些疑问。

I build an android application of social report (for broken public infrastructure) which needed simplest solution for automatic authentication. 我构建了一个社交报告的android应用程序(用于破坏公共基础结构),它需要最简单的自动身份验证解决方案 Since it is a social report app in which users shouldn't be bothered in registration process by inputing any kind of data. 由于它是一个社交报告应用程序,用户不应该通过输入任何类型的数据来打扰注册过程。 So I decided to use Android uuid as an identifier of user instead of email/user name/etc. 所以我决定使用Android uuid作为用户的标识符而不是电子邮件/用户名/等。 I loosely implement user authentication and registration. 我松散地实现用户身份验证和注册。 It only need Android device uuid to register/authenticate (don't even need a password). 它只需要Android设备uuid来注册/验证(甚至不需要密码)。 Although, I think I've secured user data in firebase security rules well enough. 虽然,我认为我已经很好地保护了firebase安全规则中的用户数据。

I've successfully created a custom automatic authentication/registration server with Go language which mints and store the data from the Firebase itself. 我已经成功创建了一个带有Go语言的自定义自动身份验证/注册服务器,它可以从Firebase本身创建和存储数据。 These are my current workflow: 这些是我目前的工作流程:

  1. The Android client automatically sends a request to my auth server. Android客户端自动向我的auth服务器发送请求。 The request data contains Android uuid and several other data. 请求数据包含Android uuid和其他几个数据。 I'm going to put it in onCreate activity. 我打算把它放在onCreate活动上。 So every time user opens the application up, it will request for a token. 因此,每次用户打开应用程序时,它都会请求令牌。
  2. My auth server checks whether that particular uuid is stored in my Firebase. 我的auth服务器检查特定的uuid是否存储在我的Firebase中。 If it is, then generate a JWT. 如果是,则生成JWT。 If not, my server will automatically create a new user data entry in my Firebase and send back a new JWT. 如果没有,我的服务器将自动在我的Firebase中创建一个新的用户数据条目并发回一个新的JWT。
  3. Someway save the JWT within the client app, and use that to do data transaction with firebase. 某种程度上将JWT保存在客户端应用程序中,并使用它来与firebase进行数据交易。

I managed to learn the Firebase library for Android, it is great and very simple. 我设法学习了适用于Android的Firebase库,它很棒且非常简单。 I found a lot of Android http request libraries (two of them are retrofit and volley). 我找到了很多Android http请求库(其中两个是改造和排球)。 Yet, I still uncertain of the best way to send the auth request from the Android client. 然而,我仍然不确定从Android客户端发送auth请求的最佳方式。

What is the preferred/simplest way to send custom auth request in the client app, based on the requirements and workflow I've specified above? 根据我上面指定的要求和工作流程,在客户端应用程序中发送自定义身份验证请求的首选/最简单方法是什么? Do I need to use http request library to simplify the code? 我是否需要使用http请求库来简化代码? sample/snippet of code would be very helpful. sample / snippet代码非常有用。 What is the best way to store and use the JWT in the client app? 在客户端应用程序中存储和使用JWT的最佳方法是什么? Is my current workflow good enough? 我目前的工作流程是否足够好? Evaluations are much appreciated. 评价非常感谢。


As a side note, this is my school final project, not a production application. 作为旁注,这是我的学校最终项目,而不是生产应用程序。 So I don't mind elaborate cases like whether user is having more than one phone, or buying second phone which ought to have same uuid with the previous owner, etc. Also, please spare my weird grammar/non-idiomatic language as I'm not a native english speaker. 因此,我不介意精心设计的案例,例如用户是否拥有多个电话,或购买第二部手机应该与之前的所有者具有相同的uuid等。另外,请保留我的奇怪的语法/非惯用语言,因为我我不是英语母语人士。

The easiest way with Android is to use signInWithCustomToken() on a Firebase auth object (FirebaseAuth). Android最简单的方法是在Firebase auth对象(FirebaseAuth)上使用signInWithCustomToken()。

Here is the reference in the docs, including sample implementation code: https://firebase.google.com/docs/auth/android/custom-auth 以下是文档中的参考,包括示例实现代码: https//firebase.google.com/docs/auth/android/custom-auth

Good luck with the project. 祝这个项目好运。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM