Orchard Core Google Integration
The Google module has these feature IDs:
| Feature | ID | Current admin path |
|---|---|---|
| Google Analytics | OrchardCore.Google.Analytics | Settings → Integrations → Google Analytics |
| Google Tag Manager | OrchardCore.Google.TagManager | Settings → Integrations → Google Tag Manager |
| Google authentication | OrchardCore.Google.GoogleAuthentication | Settings → Security → Authentication → Google |
Google authentication depends on
OrchardCore.Users.ExternalAuthentication. Create an OAuth client (web
application) in the Google Cloud Console and register the callback URL; its
default path is /signin-google under the tenant. Google+ is not an Orchard
Core dependency or setup step.
The Google features use site settings, so use the generic Settings recipe
step:
{
"steps": [
{
"name": "Feature",
"enable": [
"OrchardCore.Google.Analytics",
"OrchardCore.Google.TagManager",
"OrchardCore.Google.GoogleAuthentication"
]
},
{
"name": "Settings",
"GoogleAnalyticsSettings": {
"TrackingID": "G-EXAMPLE"
},
"GoogleTagManagerSettings": {
"ContainerID": "GTM-EXAMPLE"
},
"GoogleAuthenticationSettings": {
"ClientID": "google-oauth-client-id.apps.googleusercontent.com",
"CallbackPath": "/signin-google",
"SaveTokens": false
}
}
]
}
The handler expects the stored ClientSecret to be data-protected, as it is
when saved from the admin page. A secret written by a recipe is stored as is
and fails to decrypt, so supply it through the admin page or configuration.
In 4.0, GoogleAuthenticationSettings.ClientSecretSecretName can name a
TextSecret of the Secrets module instead; it takes precedence over
ClientSecret. With the OrchardCore.Secrets feature enabled, the admin page
offers Use a secret (suggested name Google.ClientSecret), and a saved
secret can be moved without retyping it from **Tools → Security → Migrate
Secrets**. A recipe can create the secret with the Secrets step (value from
the OrchardCore__Secrets__Google.ClientSecret environment variable) and set
"ClientSecretSecretName": "Google.ClientSecret" in
GoogleAuthenticationSettings. See orchardcore-secrets.
Configuration Overrides
Call ConfigureGoogleSettings() on the OrchardCoreBuilder to override the
Google authentication settings from configuration:
builder.Services
.AddOrchardCms()
.ConfigureGoogleSettings();
{
"OrchardCore": {
"Authentication": {
"Google": {
"ClientID": "google-oauth-client-id.apps.googleusercontent.com",
"ClientSecret": "plain-client-secret",
"CallbackPath": "/signin-google",
"SaveTokens": false
}
}
}
}
ClientSecret is a plain value here, for example from the
OrchardCore__Authentication__Google__ClientSecret environment variable;
Orchard Core protects it before use. In 4.0 a configured ClientSecret logs a
LegacySecretConfiguration warning (event 8100). Because the section binds
onto GoogleAuthenticationSettings, set "ClientSecretSecretName": "Google.ClientSecret"
here instead to reference a secret, and remove ClientSecret.
Enable OrchardCore.Users.Registration only when a Google external login may
create a local Orchard user; new external users are governed by
ExternalRegistrationSettings (see orchardcore-users-roles).
Permissions
The static OrchardCore.Google.Permissions class holds
ManageGoogleAuthentication, ManageGoogleAnalytics, and
ManageGoogleTagManager; each feature registers its own provider. The removed
GoogleAnalyticsPermissionsProvider.ManageGoogleAnalytics member must be
replaced with OrchardCore.Google.Permissions.ManageGoogleAnalytics.
Upgrading from 3.x
- Rename the
OrchardCore_Googleconfiguration section toOrchardCore:Authentication:Google(the old name still works but is deprecated). - A plain
ClientSecretfrom configuration is now honored; in 3.x it had to be already protected and was otherwise ignored. It logsLegacySecretConfiguration; move it to a secret. - Saved client secrets keep working. Code reading
GoogleAuthenticationSettings.ClientSecretdirectly must also honorClientSecretSecretName. - Replace
GoogleAnalyticsPermissionsProvider.ManageGoogleAnalyticswithOrchardCore.Google.Permissions.ManageGoogleAnalytics.