Flutter + Firebase + Spring Boot + Restfull + OAuth2 : Tutorial Part 3
This probably will be the last part of the story where flutter application will access secured restful API running on top of Spring Boot
Writing Secured Spring boot
- Go to https://start.spring.io/ to create a empty spring boot project, I am doing it with gradle here but you also can use maven
- Need to add following dependencies
- spring-boot-starter-security
- spring-boot-starter-web
- firebase-admin
- lombok
Adding firebase private key
To Access firebase spring boot need to have a key for that you need to generate a private key and load it in the spring boot application.
Go to firebase project settings from Project Overview
Click on service accounts and click on generate new private key
Once this is done you will be able to download the private key
The private key needs to be added in the resource folder of the springboot application and the full name of the file needs to be added in the application.yml file
Now the spring boot application is ready to work with Firebase.
Initialisation of Firebase with Spring boot
Need to load the private key and initialise the Firebase as in below code
If you do not do the above you will get the following error
FirebaseApp with name [DEFAULT] doesn’t exist ; Firebase Token Verification
Rest of the Java code is pretty standard…
Start the Spring boot application and Press the Access REST Button
Here is the output…
TODO
This was tested with android, please have a play and test with iPhone as well. Send me your feedback … :)
All the code base is linked here
Added a new section for Springboot Reactive fans
If you like this page please Buy me a Coffee — https://www.buymeacoffee.com/shareknowlage