I want to manage my Firebase database directly from postman or curl using Https Rest API. For example using postman and https://MY_FIREBASE_DATABSE_URL/users.json to return users json. If I set security rules for public access
{
"rules": {
".read": true,
".write": true
}
it works fine.
But if I set security rules that need authorization
{
"rules": {
".read": "auth != null",
".write": "auth != null"
}
}
I get
{"error", "permission_denied" }
As far as I understand I need to append https request with auth=SECURITY_TOKEN. Using secret key from firebase console->Service Accounts for SECURITY_TOKEN doesn't work, but anyway it says there than database secrets are deprecated.
So I download a token generator for java referenced here https://www.firebase.com/docs/rest/guide/user-auth.html#section-rest-server-authentication.
I use the following code to generate my token
public void actionPerformed(ActionEvent e) {
String uid = uidField.getText();
boolean admin = adminField.isSelected();
Map<String, Object> authPayload = new HashMap<String, Object>();
authPayload.put("uid", uid);
authPayload.put("some", "arbitrary");
authPayload.put("data", "here");
TokenOptions tokenOptions = new TokenOptions();
tokenOptions.setAdmin(admin);
TokenGenerator tokenGenerator = new TokenGenerator(<MY_DATABASE_SECRET>);
String token = tokenGenerator.createToken(authPayload, tokenOptions);
System.out.println(token);
tokenField.setText(token);
}
as mentioned here
where MY_DATABASE_SECRET is the secret key from firebase console mentioned above and uid is a user id from my Firebase users. Using this token to postman I still get permission denied.