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 the code is in a callback mode, so how do I implement the 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 {
    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();
                }
            });
    return "???"; // what return here?
}

How do I return after onSuccess? 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

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How to use Firebase with Spring boot REST Application?

From Dev

How to configure spring boot application to use aspectj transactions?

From Dev

How to use WireMock on a Feign client in a Spring Boot application?

From Dev

How to use ibatis in spring boot application using annotations?

From Dev

Spring boot REST application testing approach

From Dev

Connecting MySQL to a Spring Boot REST Application

From Dev

testing spring boot rest application with restAssured

From Dev

Handling gzipped requests in a Spring Boot REST application

From Dev

Use Spring Boot Actuator without a Spring Boot Application

From Dev

How to configure oAuth2 with password flow with Swagger ui in spring boot rest application

From Dev

Is that possible to use ObjectDB in a Spring Boot application

From Dev

How to use CommonsMultipartResolver in Spring Boot

From Dev

How to use Dozer with Spring Boot?

From Dev

How to use React's BrowserRouter on client and Java REST API (Spring Boot) on the server?

From Dev

How to create a REST service with spring-boot?

From Java

How to set base url for rest in spring boot?

From Dev

How to validate Spring Boot Rest response?

From Dev

How to Authenticate each REST request with spring boot

From Dev

Error while Handling 404 error for Spring Boot REST application

From Dev

Getting "No message available" error with Spring Boot + REST application

From Dev

Using Camel with Spring-boot to build a REST Application

From Dev

Securing JSON-PATCH paths in Spring Boot Data Rest application

From Dev

Can Spring Boot application have separate security for REST APIs?

From Dev

Using Camel with Spring-boot to build a REST Application

From Dev

Accept empty String for Enum in REST calls in Spring Boot application

From Dev

How do you use both Spring Data JPA and Spring Data Elasticsearch repositories on the same domain class in a Spring Boot application?

From Dev

How can I use properties from a configuration (properties/yml) file in my Spring Boot application?

From Dev

How to use C3P0 in a spring boot hibernate multi tenant application to manage connection pool?

From Dev

How can I use properties from a configuration (properties/yml) file in my Spring Boot application?

Related Related

  1. 1

    How to use Firebase with Spring boot REST Application?

  2. 2

    How to configure spring boot application to use aspectj transactions?

  3. 3

    How to use WireMock on a Feign client in a Spring Boot application?

  4. 4

    How to use ibatis in spring boot application using annotations?

  5. 5

    Spring boot REST application testing approach

  6. 6

    Connecting MySQL to a Spring Boot REST Application

  7. 7

    testing spring boot rest application with restAssured

  8. 8

    Handling gzipped requests in a Spring Boot REST application

  9. 9

    Use Spring Boot Actuator without a Spring Boot Application

  10. 10

    How to configure oAuth2 with password flow with Swagger ui in spring boot rest application

  11. 11

    Is that possible to use ObjectDB in a Spring Boot application

  12. 12

    How to use CommonsMultipartResolver in Spring Boot

  13. 13

    How to use Dozer with Spring Boot?

  14. 14

    How to use React's BrowserRouter on client and Java REST API (Spring Boot) on the server?

  15. 15

    How to create a REST service with spring-boot?

  16. 16

    How to set base url for rest in spring boot?

  17. 17

    How to validate Spring Boot Rest response?

  18. 18

    How to Authenticate each REST request with spring boot

  19. 19

    Error while Handling 404 error for Spring Boot REST application

  20. 20

    Getting "No message available" error with Spring Boot + REST application

  21. 21

    Using Camel with Spring-boot to build a REST Application

  22. 22

    Securing JSON-PATCH paths in Spring Boot Data Rest application

  23. 23

    Can Spring Boot application have separate security for REST APIs?

  24. 24

    Using Camel with Spring-boot to build a REST Application

  25. 25

    Accept empty String for Enum in REST calls in Spring Boot application

  26. 26

    How do you use both Spring Data JPA and Spring Data Elasticsearch repositories on the same domain class in a Spring Boot application?

  27. 27

    How can I use properties from a configuration (properties/yml) file in my Spring Boot application?

  28. 28

    How to use C3P0 in a spring boot hibernate multi tenant application to manage connection pool?

  29. 29

    How can I use properties from a configuration (properties/yml) file in my Spring Boot application?

HotTag

Archive