16

この回答のおかげで、HTTP REST API とメール/パスワードを介して Firebase 3 に接続できます。この API でログインすると、Firebase データベースへのアクセスに使用されるアクセス トークンが返されます。このアクセス トークンは 1 時間後に期限切れになります。ログイン後に更新トークンも返されます。これを使用して、アクセス トークンを更新できます。これが私が具体的にしていることです:

方法:

POST

URL:

https://www.googleapis.com/identitytoolkit/v3/relyingparty/verifyPassword?key=<my-firebase-api-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"
}

アクセス トークンを更新する場合:

URL:

https://securetoken.googleapis.com/v1/token?key=<my-firebase-api-key>

ペイロード:

{
    grant_type: "refresh_token",
    refresh_token: "<refresh-token>"
}

応答:

{
  "access_token": "<access-token>",
  "expires_in": "3600",
  "token_type": "Bearer",
  "refresh_token": "<refresh-token>",
  "id_token": "<id-token>",
  "user_id": "<user-id>",
  "project_id": "<project-id>"
}

アクセストークンを持っている場合、HTTP REST API 経由でデータベースにアクセスするにはどうすればよいですか?

4

1 に答える 1

16

したがって、テクニカル サポートと連絡を取った後、これが私の答えです。

データベース ルールに、実行していることと互換性のある次のようなものを含めます。

{
"rules": {
"users": {
"$user_id": {
// grants write access to the owner of this user account
// whose uid must exactly match the key ($user_id)
".write": "$user_id === auth.uid",
".read": "$user_id === auth.uid"
}
    }
  } 
}

データベースにusersテーブルを作成し、その中に、使用して<user-id>いる認証メール/パスワード アカウントの名前でテーブルを作成します。その表の中には、 経由でアクセスできる情報がありますaccess-key

次に、次のようなリクエストを送信します。

https://samplechat.firebaseio-demo.com/users/<user-id>.json?auth=<access-key>

、、またはGoogle からの JSON 応答でaccess-key認識されるキーはどこにありますか。idTokenid_Tokenaccess_key

于 2016-11-12T20:05:21.330 に答える