firebase - Using Custom Tokens to make REST requests to FB DB as an admin -
i'm migrating new database , 3.0 client libs. i'm updating part generates custom auth token (on our server) patch
update resource in firebase db.
these patch requests used made our server firebase using admin
claims based on this: https://www.firebase.com/docs/rest/guide/user-auth.htm
for new db, i'm generating jwt token (using ruby-jwt
) this:
payload = { aud: "https://identitytoolkit.googleapis.com/google.identity.identitytoolkit.v1.identitytoolkit", claims: custom_claims.merge({ admin: true }), exp: now_seconds + (60 * 60), # maximum expiration time 1 hour iat: now_seconds, iss: service_account_email, sub: service_account_email, uid: uid } jwt.encode(payload, private_key, "rs256")
a patch
request token firebase db fails with: missing claim 'kid' in auth header
.
here equivalent of michael bleigh's answer using ruby googleauth module:
require 'googleauth' scopes = [ 'https://www.googleapis.com/auth/userinfo.email', 'https://www.googleapis.com/auth/firebase.database'] auth = ::google::auth.get_application_default(scopes) auth_client = auth.dup auth_client.sub = "service-account-email-here@yourapp.iam.gserviceaccount.com" token = auth_client.fetch_access_token!
you need set google_application_credentials
environment variable path of service account json file. value auth_client.sub
comes client_email
in json file.
of course, above, valid in server application control.
also, making request firebase rest api still exercise reader.
references
Comments
Post a Comment