Skip to main content

Go Fiber Firebase Authentication Example

Github StackBlitz

This example demonstrates how to protect Fiber routes with Firebase Authentication by verifying Firebase ID tokens.

Requirements​

  • A Firebase project with Authentication enabled
  • A Google Service Account credential JSON file (download from Firebase Console → Project Settings → Service Accounts)

Setting Up​

Copy example.env to .env and set the path to your service account credential file:

GOOGLE_SERVICE_ACCOUNT=path/to/serviceAccountKey.json

Start​

go run main.go

Endpoints​

MethodPathAuth requiredDescription
GET/salutNoPublic greeting (French)
POST/ciaoNoPublic greeting (Italian)
GET/salantheNoPublic greeting (Sinhalese)
GET/api/helloYesProtected greeting (English)
GET/api/ayubowanYesProtected greeting with user claims

curl Examples​

Public endpoint​

curl http://localhost:3001/salut

Protected endpoint — obtain a Firebase ID token first, then:​

curl -H "Authorization: Bearer <YOUR_FIREBASE_ID_TOKEN>" \
http://localhost:3001/api/hello
curl -H "Authorization: Bearer <YOUR_FIREBASE_ID_TOKEN>" \
http://localhost:3001/api/ayubowan