How to use Firebase with Spring boot REST Application?

dickyj :

I have a Spring Boot REST application that depends on the authentication done in Firebase. On the client side Firebase generates a token whereby in the Spring Boot, I need to verify the uid. But I noticed that the code is in a callback mode, so how do I implement the Spring Boot function so that it can finish the task?

    @RequestMapping(value = "/api/restCall", method = RequestMethod.POST, consumes = "application/json", produces = "application/json")
    public Object restCall(@RequestBody Parameters requestBody) throws Exception {

    // idToken comes from the client app (shown above)
        String idToken = requestBody.getToken();

        Task<FirebaseToken> task = FirebaseAuth.getInstance().verifyIdToken(idToken)
            .addOnSuccessListener(new OnSuccessListener<FirebaseToken>() {
                @Override
                public void onSuccess(FirebaseToken decodedToken) {
                    String uid = decodedToken.getUid();
                    // process the code here
                }
        }); 
        // how do I return here, since the code is in the onSuccess?
        // do I return as a DeferredResult? 

    }
dickyj :

Here is my own attempt to answer my own question

@RequestMapping(value = "/api/restCall", method = RequestMethod.POST, consumes = "application/json", produces = "application/json")
public Object restCall(@RequestBody Parameters requestBody,@RequestHeader(value = FIREBASETOKEN, required = true) String idToken) throws Exception {

    // idToken comes from the HTTP Header
    FirebaseToken decodedToken = FirebaseAuth.getInstance().verifyIdTokenAsync(idToken).get();
    final String uid = decodedToken.getUid();

    // process the code here
    // once it is done
    return object;

}

You can try below code as well

FirebaseAuth.getInstance().deleteUser(uid);
System.out.println("Successfully deleted user.");

for More deetails URL https://firebase.google.com/docs/auth/admin/manage-users

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=446459&siteId=1