Firebase Login - Google, Facebook and GitHub
How to let the players register and log in with their Google, Facebook or GitHub accounts through Firebase Authentication. It is the firebase feature (enabled in Features) and it is activated with the environment variables.
How it works in the game
When Firebase is enabled the login page shows the Firebase Registration box next to the regular login, the guest and the create account boxes:
- The player writes the username for the game and clicks the provider button.
- The provider popup opens and the player signs in.
- The server verifies the Firebase token and accepts the login only when the account email is verified. The first time the user is created with that username and email (with the firebase origin), the next times the same username and email log in.
The Firebase accounts do not have a usable password: the password form only works for the accounts created with the regular registration.
Setting up Firebase
- In the Firebase console create a project, add a web app and enable the Google, Facebook and GitHub sign-in providers in Authentication (the box shows the three buttons).
- Add your game domain to the authorized domains of Firebase Authentication.
- Copy the web app configuration into the project .env file (the installer has the same fields):
RELDENS_FIREBASE_ENABLE=1
RELDENS_FIREBASE_API_KEY="..."
RELDENS_FIREBASE_APP_ID="..."
RELDENS_FIREBASE_AUTH_DOMAIN="..."
RELDENS_FIREBASE_DATABASE_URL="..."
RELDENS_FIREBASE_PROJECT_ID="..."
RELDENS_FIREBASE_STORAGE_BUCKET="..."
RELDENS_FIREBASE_MESSAGING_SENDER_ID="..."
RELDENS_FIREBASE_MEASUREMENTID="..."
- Restart the server. The client reads the configuration from the server when the login page loads, so the client does not need to be rebuilt.
Code integration (advanced)
- Server: FirebasePlugin (lib/firebase/server/plugin.js) serves the client configuration on /reldens-firebase and verifies the tokens on /reldens-firebase-verify-id-token (with the home rate limiter), using FirebaseIdTokenVerifier and the Identity Toolkit accounts lookup.
- The login is completed through the reldens.processUserRequestIsValidDataBefore and reldens.loginPasswordValidationFallback events.
- Client: FirebaseConnector (lib/firebase/client/connector.js) loads the Firebase SDK, renders the provider buttons (FirebaseConst.DEFAULT_PROVIDERS_KEYS) and runs the popup sign in.
reldens