FIREBASE_CONFIG vs. GOOGLE_APPLICATION_CONFIG

1 week ago 13
ARTICLE AD BOX

I am working on setting up Firebase and Authentication using the Admin SDK library. Initially I set the FIREBASE_CONFIG env variable and resulted in

Error getting Auth client: google: could not find default credentials. See https://cloud.google.com/docs/authentication/external/set-up-adc for more information.

After I add GOOGLE_APPLICATION_CONFIG the authentication worked, but I can't find anything on the difference between those two environment variables. The Firebase Admin SDK NewApp method also mentions the FIREBASE_CONFIG only.

Below is code snippets of my authentication.

func NewFireBaseApp() *FireBaseApp { app, err := firebase.NewApp(context.Background(), nil) if err != nil { log.Printf("error initializing app: %v\n", err) return nil } return &FireBaseApp{app: app} } func Auth(fbApp *auth.FireBaseApp) func(http.Handler) http.Handler{ return func(next http.Handler) http.Handler { return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { log.Println("Authenticating request...") if fbApp == nil || fbApp.GetApp() == nil { log.Println("Firebase app is not initialized") http.Error(w, "Internal server error", http.StatusInternalServerError) return } authHeader := r.Header.Get("Authorization") if authHeader == "" { http.Error(w, "Authorization header missing", http.StatusUnauthorized) return } idToken := strings.TrimPrefix(authHeader, "Bearer") client, err := fbApp.GetApp().Auth(r.Context()) if err != nil { // <- error happened here http.Error(w, "Error getting Auth client: "+err.Error(), http.StatusInternalServerError) return } _, err = client.VerifyIDToken(r.Context(), strings.TrimSpace(idToken)) if err != nil { http.Error(w, "Invalid ID token: "+err.Error(), http.StatusUnauthorized) return } log.Println("Request authenticated successfully") next.ServeHTTP(w, r) }) } }
Read Entire Article