Authenticating an app to a Firebase Realtime database

Viewed 39

I've spent two weeks researching this to no avail. This seems to me to be a not-uncommon issue, so I'm hoping someone here can help out.

It's a basic authentication issue.

For a Java mobile app, I've created a Firebase Realtime database to hide some API keys. There won't be any writes; it's basically a one-time read situation. The database rules are set as:

{
  "rules": {
    ".read": "auth != null",
    ".write": "auth != null"
  }
}

(When the rules are set to "...: true" I have no problem reading the data from the app, since there's no authentication. But obviously, I want to lock access down a bit)

My code to get authenticated is:

    FirebaseOptions options = new FirebaseOptions.Builder()
            .setDatabaseUrl("https://xxxxx.firebaseio.com/")
            .setCredentials(GoogleCredentials.fromStream(...))
            .build();

    FirebaseApp.initializeApp (options);

The problem is, in my code I'm always getting "cannot find symbol '.setCredentials(GoogleCredentials.fromStream(...))'."

Since "Builder()" is deprecated, I've tried replacing that line with

    FirebaseOptions options = FirebaseOptions.builder()

...and when I do that, I get a "cannot find symbol builder()" (even though it's not highlighted in the code, and autocomplete has it available).

I've modified my build.gradle implementation library list with every combination I could think of, to no avail. Currently, I've got this:

implementation 'com.google.firebase:firebase-crashlytics'
implementation 'com.google.firebase:firebase-analytics'

implementation 'com.google.firebase:firebase-database'
implementation 'com.google.firebase:firebase-auth'
implementation 'com.google.firebase:firebase-admin:7.1.0'
implementation 'com.google.auth:google-auth-library-oauth2-http:1.11.0'

implementation 'io.jsonwebtoken:jjwt-impl:0.11.5'
implementation 'io.jsonwebtoken:jjwt-api:0.11.5'
implementation('io.jsonwebtoken:jjwt-orgjson:0.11.5') {
    exclude group: 'org.json', module: 'json' //provided by Android natively
}

(the jsonwebtoken libraries are used elsewhere in the project; I'm just including them here for completeness)

So, what am I doing wrong here? I'm assuming I have the wrong combination of libraries in my build.gradle. I'm also open to the possibility that I'm blind to a simple mistake.

0 Answers
Related