Firebase and Spring boot integration

Firebase can be integrated into the backend so that clients that are authenticated with firebase can call backend REST APIs.

To accomplish this few key parts must be added to the backend

  1. Maven Dependencies
  2. Filter
  3. Authentication provider
  4. Token parsing
  5. Registration

GitHub repository isĀ here.

To add firebase dependencies one library must be added

Every request to the backend must have especial header that is used by FirebaseFilter. Filter checks if header named “X-Authorization-Firebase” exists, if does not this means that request should not be processed by this filter. When token is found it is parsed using firebaseService.parseToken(xAuth) and correct Authentication is created FirebaseAuthenticationToken that is put in the securityContextHolder. Job of the filter is here done and authentication process is being taken over by authentication provider.

Authentication provider uses the FirebaseAuthenticationToken to map the token to database user and set its roles.

Firebase backend configuration is done in one Configuration class. Here I have added firebase reference bean and initialization.

Initialization of firebase depends of two properties , configuration path and database url.

This is it. Be sure to checkout the GitHub repository here.