User Authentication
You can make authentication calls to the Firebase Realtime Database REST API.
Retrieving an access token
To retrieve an access token you need to use a service account. Please see the guide for using Google Service Accounts. You can create a service account credential in your Firebase project from the Service Accounts section of the Firebase console.
As an example, one way to generate an appropriate oauth2 token is with the Java google-api-client.
GoogleCredential googleCred = GoogleCredential.fromStream(new FileInputStream("service_account.json"));
GoogleCredential scoped = googleCred.createScoped(
Arrays.asList(
"https://www.googleapis.com/auth/firebase.database",
"https://www.googleapis.com/auth/userinfo.email"
)
);
scoped.refreshToken();
String token = scoped.getAccessToken();
A successful request will be indicated by a 200 OK
HTTP status code. The response contains the data being retrieved:
{ "first": "Jack", "last": "Sparrow" }
Using the access token
The Database REST API accepts access_token=<TOKEN> on
the query string or header Authorization: Bearer
<TOKEN> to authenticate a request with a service account.
The following example demonstrates how you might use this with a
database containing user names. You would replace
[PROJECT_ID] with the identifier of your Firebase project.
curl 'https://[PROJECT_ID].firebaseio-demo.com/users/jack/name.json?access_token=<TOKEN>'
A successful request will be indicated by a 200 OK
HTTP status code. The response will contain the data being retrieved:
{ "first": "Jack", "last": "Sparrow" }

