使用邮件和密码通过 REST API 进行身份验证 [Firebase] [英] Using mail and password to authenticate via the REST API [Firebase]

查看:21
本文介绍了使用邮件和密码通过 REST API 进行身份验证 [Firebase]的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道是否可以可能使用自定义身份验证实际身份验证到 Firebase REST API 而无需>?

I was wondering whether it is possible to actually authenticate to the Firebase REST API withouth using the custom authentication?

我已经与 Firebase 合作了一段时间,目前我正在考虑将我的后端迁移到 Firebase.使用后端的应用程序当前使用 REST API,根本不需要实时数据.因此,我只想在客户端上使用 REST API 而不是完整的 Android 框架.

I've worked with Firebase now for some time and I'm currently thinking about migrating a backend of mine to Firebase. The app that uses the backend currently uses a REST API and does not need realtime data at all. Thus I'd like to use only the REST API and not the full Android framework on the clients.

是否可以使用邮件获取身份验证令牌?通过 HTTP 请求对 Firebase 进行密码身份验证?

旧文档中,我只找到了一个自定义登录的解决方案和您似乎需要的 新文档一个 Google 服务帐户.

In the old docs I've only found a solution with custom login and in the new docs you seem to need a Google Service Account.

感谢任何帮助或建议.

推荐答案

更新:Firebase REST 身份验证现已记录在案!

查看文档

通过检查 Javascript API 发送的请求,我想出了如何为 Firebase 执行电子邮件和密码身份验证.

I figured out how to perform email and password authentication for Firebase by examining the requests sent by the Javascript API.

这些 API 未记录且不受支持

Firebase 3 身份验证是 Google Identity Toolkit 的更新和重命名版本.旧文档并不完全准确,但可能有用,可以在此处找到:https://developers.google.com/identity/toolkit/web/reference/

Firebase 3 authentication is an updated and renamed version of the Google Identity Toolkit. The old documentation is not fully accurate, but may be useful and can be found here: https://developers.google.com/identity/toolkit/web/reference/

Firebase 3 要求所有请求在标头中包含 Content-Type: application/json

Firebase 3 要求将 API 密钥附加到所有身份验证请求.您可以通过访问 Firebase 项目概述并点击将 Firebase 添加到您的网络应用程序"来找到您的数据库的 API 密钥.您应该会看到一个包含如下代码的窗口:

Firebase 3 requires an API key to be attached to all authentication requests. You can find the API key for your database by visiting the Firebase project overview and clicking on "Add Firebase to your web app". You should see a window with code like the following:

<script src="https://www.gstatic.com/firebasejs/live/3.0/firebase.js">    </script>
<script>
  // Initialize Firebase
  var config = {
    apiKey: "<my-firebase-api-key>",
    authDomain: "my-firebase.firebaseapp.com",
    databaseURL: "https://my-firebase.firebaseio.com",
    storageBucket: "my-firebase.appspot.com",
  };
  firebase.initializeApp(config);
</script>

复制 apiKey 值并保存以备后用.

Copy the apiKey value and save it for later.

方法:POST

网址:https://www.googleapis.com/identitytoolkit/v3/relyingparty/signupNewUser?key=

有效载荷:

{
    email: "<email>",
    password: "<password>",
    returnSecureToken: true
}

回复:

{
    "kind": "identitytoolkit#SignupNewUserResponse",
    "localId": "<firebase-user-id>", // Use this to uniquely identify users
    "email": "<email>",
    "displayName": "",
    "idToken": "<provider-id-token>", // Use this as the auth token in database requests
    "registered": true,
    "refreshToken": "<refresh-token>",
    "expiresIn": "3600"
}

登录

方法:POST

网址:https://www.googleapis.com/identitytoolkit/v3/relyingparty/verifyPassword?key=

有效载荷:

{
    email: "<email>",
    password: "<password>",
    returnSecureToken: true
}

回复:

{
    "kind": "identitytoolkit#VerifyPasswordResponse",
    "localId": "<firebase-user-id>", // Use this to uniquely identify users
    "email": "<email>",
    "displayName": "",
    "idToken": "<provider-id-token>", // Use this as the auth token in database requests
    "registered": true,
    "refreshToken": "<refresh-token>",
    "expiresIn": "3600"
}

获取帐户信息

方法:POST

网址:https://www.googleapis.com/identitytoolkit/v3/relyingparty/getAccountInfo?key=

有效载荷:

{
    idToken: "<provider-id-token>"
}

回复:

{
    "kind": "identitytoolkit#GetAccountInfoResponse",
    "users": [
    {
        "localId": "<firebase-user-id>",
        "email": "<email>",
        "emailVerified": false,
        "providerUserInfo": [
        {
            "providerId": "<password>",
            "federatedId": "<email>",
            "email": "<email>",
            "rawId": "<email>"
        }],
        "passwordHash": "<hash>",
        "passwordUpdatedAt": 1.465327109E12,
        "validSince": "1465327108",
        "createdAt": "1465327108000"
    }]
}

<小时>

Firebase 2

这些请求返回 Firebase 文档中描述的 JSON 数据.https://www.firebase.com/docs/web/guide/login/password.html#section-logging-in

您可以通过使用以下格式发送 GET 请求来进行身份验证:

You can authenticate by sending a GET request with the following format:

https://auth.firebase.com/v2/<db_name>/auth/password?&email=<email>&password=<password>

注册

用户创建也可以通过将 _method=POST 作为查询字符串的一部分发送相同的 GET 请求来执行

Registration

User creation can also be performed by sending the same GET request with _method=POST as part of the query string

https://auth.firebase.com/v2/<db_name>/users?&email=<email>&password=<password>&_method=POST

这篇关于使用邮件和密码通过 REST API 进行身份验证 [Firebase]的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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