How to Configure Google Login in flarum?

Using fof/oauth

To configure Google Login in Flarum using the FoF OAuth extension, follow the step-by-step instructions below. This guide assumes that you have already installed the FoF OAuth extension and have access to the Google Developer Console to create OAuth credentials.

Step 1: Install the FoF OAuth Extension

If you haven’t already installed the FoF OAuth extension, you can do so via Composer.

  1. SSH into your server where Flarum is installed and navigate to the Flarum root directory.
  2. Run the following command to install the FoF OAuth extension:

Run the following command to install the FoF OAuth extension:

composer require fof/oauth

Once the installation is complete, clear Flarum’s cache:

php flarum cache:clear
  1. Go to your Flarum Admin Panel (https://yourdomain.com/admin), navigate to the Extensions tab, and enable the FoF OAuth extension.

Step 2: Create Google OAuth Credentials

You need to create Google OAuth 2.0 credentials for your Flarum forum to enable Google login.

  1. Go to the Google API Console:
  2. Create a new project:
    • In the top-right corner, click the Project dropdown and select New Project.
    • Give your project a name (e.g., “Flarum Google Login”) and click Create.
  3. Enable the OAuth API:
    • In the API Library, search for “Google Identity Platform”.
    • Click Enable.
  4. Configure the OAuth Consent Screen:
    • Go to APIs & Services > OAuth Consent Screen on the left sidebar.
    • Choose External as the user type and click Create.
    • Fill out the required fields, such as App name, User support email, and your developer contact email.
    • Add scopes such as email and profile, which are needed to authenticate users.
    • Save the configuration.
  5. Create OAuth 2.0 Credentials:
    • Go to APIs & Services > Credentials, then click Create Credentials and choose OAuth 2.0 Client IDs.
    • Set the Application Type to Web Application.
    • In Authorized redirect URIs, add the following URL (replace yourdomain.com with your actual domain): https://yourdomain.com/auth/google/callback
    • Click Create and note down the Client ID and Client Secret that you receive, as you’ll need them for the next step.

Step 3: Configure Google Login in Flarum

Configure Google OAuth:

  • After installing the extension, go to your Flarum Admin Panel (https://yourdomain.com/admin).
  • Navigate to Extensions, find the FoF OAuth extension, and enable it.
  • Configure the OAuth credentials by going to Settings > Login Providers > Google OAuth and entering the Client ID and Client Secret you generated earlier from the Google Developer Console.

  1. Go to your Flarum Admin Panel:
    • Log in as an admin and navigate to the Settings page.
  2. Find the OAuth Providers Section:
    • Scroll down to the Login Providers section.
    • You should see the Google OAuth option provided by the FoF OAuth extension.
  3. Enter the Google OAuth Credentials:
    • Enter the Client ID and Client Secret you obtained from the Google Developer Console in the respective fields.
    • For the Redirect URL, it should be pre-configured as https://yourdomain.com/auth/google/callback.
  4. Save the Changes:
    • Click Save to apply the changes.

Step 4: Test the Google Login Integration

  1. Visit your Flarum Forum:
    • Go to your forum’s homepage (https://yourdomain.com).
  2. Click on “Login”:
    • On the login page, you should now see a Login with Google option.
  3. Test the Google Login:
    • Click Login with Google and try signing in using a Google account.
    • If everything is configured correctly, you should be able to log in using your Google credentials.