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?
}
To integrate Firebase with Spring, below is the sample code
In new Admin SDK the process is simple just use below code snippet.
For more detail visit this URL https://firebase.google.com/docs/auth/admin/manage-users
This is for a legacy code. First add Firbase dependency
Sample Code
For Complete example please gone through github below link https://github.com/savicprvoslav/Spring-Boot-starter
Here is my own attempt to answer my own question
You can try below code as well
for More deetails URL https://firebase.google.com/docs/auth/admin/manage-users