Google

Follow these steps to configure Google for social login:

OAuth Configuration

  1. Go to the Google Console.
  2. Create a new project.
  3. Go to Google Console → My Project → Credentials → Consent Screen and make sure to fill the Product name field.
  4. Go to Google Console → My Project → Credentials and create credentials for a new “OAuth client ID” with the following settings:
    • Application type: Web application
    • Authorized JavaScript origins: The web origin URL can be found in Craft Control Panel → Settings → Social → Login Providers → Google
    • Authorized redirect URIs: The redirect URL can be found in Craft Control Panel → Settings → Social → Login Providers → Google
  5. Google will provide you a client ID and client secret for your application, copy them to Craft Control Panel → Settings → Social → Login Providers → Google → OAuth.
  6. Go to Craft Control Panel → Settings → Social → Login Providers and enable Google.

🎉

Default User Field Mapping

The Google login provider defines the following user field mapping by default.

[
    'id' => '{{ profile.getId() }}',
    'email' => '{{ profile.getEmail() }}',
    'username' => '{{ profile.getEmail() }}',
    'photo' => '{{ profile.getAvatar() }}',
]

You can override and extend the default mapping using the loginProviders config.

Profile Object

The profile response for the Google login provider is a GoogleUser object.

Methods

  • getId()
  • getName()
  • getFirstName()
  • getLastName()
  • getEmail()
  • getAvatar()
  • toArray()