Reputation: 467
in order to verify a Firebase token sent from a client app i have the following code:
Task<FirebaseToken> authTask = FirebaseAuth.getInstance().verifyIdToken("very long string token").addOnSuccessListener(new OnSuccessListener() {
@Override
public void onSuccess(Object tr) { }
}).addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(Exception excptn) { }
}).addOnCompleteListener(new OnCompleteListener() {
@Override
public void onComplete(Task task) { }
});
try {
Tasks.await(authTask);
} catch(ExecutionException | InterruptedException e ){
//handle error
}
FirebaseToken decodedToken = authTask.getResult();
String uid = decodedToken.getUid();
When deploy it through Maven/google backend api I get the following error:
java.lang.IllegalStateException: FirebaseApp with name [DEFAULT] doesn't exist
How can I resolve it?
Upvotes: 1
Views: 5494
Reputation: 2380
You have to set up a Service Account at your Google Cloud Console. Read the Docs.
Put the service account key file (.json) in your /resources/META-INF/
directory.
Make sure you have included your resource files inside the appengine-web.xml
<!-- Include resource files -->
<resource-files>
<include path="/**.json" />
<include path="/**.xml" />
<include path="/**.properties" />
</resource-files>
FirebaseOptions
with the generated service_account_key.json
file to initialize FirebaseApp
. You can do this inside a Warmup Servlet.public void init(ServletConfig config) throws ServletException {
InputStream loadedServiceAccount = config
.getServletContext()
.getResourceAsStream("/WEB-INF/service_account_key.json");
FirebaseOptions options = new FirebaseOptions.Builder()
.setServiceAccount(loadedServiceAccount)
.setDatabaseUrl("URL_FIREBASE_DATABASE").build();
FirebaseApp firebaseApp = FirebaseApp.initializeApp(options);
FirebaseAuth.getInstance(firebaseApp);
}
FirebaseAuth.getInstance()
inside your code.When your AppEngine Instance runs a beta Version (maybe 1.9.44) it will give you a noMethodFoundError. Then you can go on with this Question.
Upvotes: 2