How do I secure my Google Cloud Endpoints APIs with Firebase token verification?

后端 未结 1 1849
天命终不由人
天命终不由人 2020-12-11 16:27

My setup:

  • Java backend hosted on Google App Engine containing APIs that were created using Google Cloud Endpoints
  • Mobile client applications containin
相关标签:
1条回答
  • 2020-12-11 17:05

    As this authentication task is running asynchronously in task queue, you can wait until that task is ended and continue in synchronous way, optionally you can add listeners onSuccess, onFailure and onComplete.

    Task<FirebaseToken> authTask = FirebaseAuth.getInstance().verifyIdToken(idToken)
    .addOnSuccessListener(new OnSuccessListener() {
            @Override
            public void onSuccess(Object tr) {//do smtg }
        }).addOnFailureListener(new OnFailureListener() {
            @Override
            public void onFailure(Exception excptn) {//do smtg }
        }).addOnCompleteListener(new OnCompleteListener() {
            @Override
            public void onComplete(Task task) {//do smtg }
        });
        try {
            Tasks.await(authTask);
        } catch(ExecutionException | InterruptedException e ){
            //handle error
        }
        FirebaseToken decodedToken = authTask.getResult();
    
    0 讨论(0)
提交回复
热议问题