Firebase ready starter API project written in Go
Explore the API docs »
This is a starter project for creating an App that utilises Googles Firebase Authentication system.
It allows you to get started with verifying tokens sent from your front-end interface and focus on developing your application.
Here's why:
- Extendable minimalist project
- Graceful API authentication middleware
- Covers basic app requirements in order to focus on meaningful development
- Bootstrapping, Routing & Server, DB, Caching, Auth etc..
This project utilizes the following packages. Many of these can be replaced and interchanged with other packages of your choosing.
- Router - Gin
- Database driver - PGX
- Query Builder - SQLB
- Caching - go-cache
- Commands - Cobra
- Firebase - Admin SDK
To get a local copy up and running clone the repo and follow these steps.
- In the project directory, install dependencies & packages with
go get
- Create an
.env
file - link to your DB & key file, use .env.example for reference. - Create a Postgres database for the application
- Run the table migration using
go run main.go migrate
- This will auto-generate a test user allowing you to pass the auth token "development" for testing in postman
- Serve the application using
go run main.go serve
Before getting started you should have Firebase configured and a private key file generated. For information on generating your private key file visit the firebase docs.
Ideally you should have a front-end application that at the least implements Googles Firebase UI. Alternatively, you can test all the functionality using the token "development" through postman.
When a user logs in to your front-end application using the Firebase UI, pass the users accessToken as the Authorization header on requests to this API.
All requests go through token check middleware. Once verified by the Firebase Admin SDK, the user is verified in the systems db and additional checks are performed.
The user/sync
endpoint acts to verify a user and return their application specific user information to use in your front-end.
This example Go App is written as a private application, this means users must be pre-registered in the db (invited) in order to pass authentication checks.
Admin users can create accounts for other users.
Manually create an account through the command
go run main.go user:create
When a registered user logs in for the first time, their UUID is captured and recorded.
- Create user & optional project
go run main.go user:create
- Run migrations & create test user
go run main.go migrate
- Serve application
go run main.go serve
- ReadMe
- Postman collection
- Testing
- Caching
- Improved readme & documentation
- Email notification on user registrations
Contributions are what make the open source community such an amazing place to learn, inspire, and create. Any contributions you make are greatly appreciated.
If you have a suggestion that would make this better, please fork the repo and create a pull request. You can also simply open an issue with the tag "enhancement". Don't forget to give the project a star! Thanks again!
- Fork the Project
- Create your Feature Branch (
git checkout -b feature/AmazingFeature
) - Commit your Changes (
git commit -m 'Add some AmazingFeature'
) - Push to the Branch (
git push origin feature/AmazingFeature
) - Open a Pull Request
Jack Callow - @jvckcallow - Linkedin - sjmc11@gmail.com
Project Link: https://github.com/sjmc11/firebase-auth-go-kit