Ok, so first of all I am not very much an expert in both java or android, in fact I am just beginner. So if anything sounds silly or irritating pardon me, I am on the verge of being blocked from asking any questions.
So, my issue is that while authenticating my server with firebase, I am facing some trouble while setting service account and creating custom token.
https://firebase.google.com/docs/admin/setup
https://firebase.google.com/docs/auth/admin/create-custom-tokens
I am taking help from here and following these steps, and this is what i have done.
FileInputStream serviceAccount = new FileInputStream("path/to/serviceAccountKey.json");
FirebaseOptions options = new FirebaseOptions.Builder()
.setCredential(FirebaseCredentials.fromCertificate(serviceAccount))
.setDatabaseUrl("https://<DATABASE_NAME>.firebaseio.com/")
.build();
FirebaseApp.initializeApp(options);
FirebaseAuth.getInstance()
.createCustomToken(uid)
.addOnSuccessListener(new OnSuccessListener<String>() {
@Override
public void onSuccess(String customToken)
{
// Send token back to client
}
});
But I am getting very unusual errors, i.e.
1) On service account - The method setCredential(FirebaseCredential)
is undefined for the type FirebaseOptions.Builder
Now I've read that setserviceaccount is deprecated, but when i am using it, its not giving me any error
2) On Creating Custom Token - The method addOnSuccessListener(new OnSuccessListener<String>(){})
is undefined for the type String
It is another method error, and also I don't know how to send the token back to client. I couldn't find any example that how should i approach it. Any help will be greatly appreciated.
Any example that how others send there token to client, would be great.