website/docs/users-sources/sources/social-logins/google/cloud/index.md
Allows users to authenticate using their Google credentials by configuring Google Cloud as a federated identity provider via OAuth2.
The following placeholders are used in this guide:
authentik.company is the FQDN of the authentik installation.To integrate Google with authentik you will need to create a new project, and OAuth credentials in the Google Developer console.
Set the following values:
Click Create.
Select your project from the drop down at the top.
Click the Credentials menu icon on the left which looks like a key.
authentikWeb Applicationhttps://authentik.company/source/oauth/callback/google/To support the integration of Google with authentik, you need to create a Google OAuth source in authentik.
Authorized redirect URI field (e.g. google), and set the following required configurations:
<client_ID><client_secret>:::info Display new source on login screen For instructions on how to display the new source on the authentik login page, refer to the Add sources to default login page documentation. :::
:::info Embed new source in flow :ak-enterprise For instructions on embedding the new source within a flow, such as an authorization flow, refer to the Source Stage documentation. :::
Google does not have the concept of a username, therefore authentik will by default prompt the user for a username when they first enroll through a google source. To change this behaviour and automatically use the email address as username, create an expression policy to set the username to the email, and bind it to the enrollment flow.
email = request.context["prompt_data"]["email"]
# Direct set username to email
request.context["prompt_data"]["username"] = email
# Set username to email without domain
# request.context["prompt_data"]["username"] = email.split("@")[0]
return False
:::note If using the default enrollment flow the policy should be bound to the default-source-enrollment-prompt stage. Ensure that the policy comes before default-source-enrollment-if-username. :::
Afterwards, any new logins will automatically have their Google email address used as their username. This can be combined with disallowing users from changing their usernames, see Configuration.