Skip to content

Instantly share code, notes, and snippets.

@cleversolutions
Last active November 4, 2021 10:58
Show Gist options
  • Save cleversolutions/afcd985dbfe19b93b6436f5626c623b5 to your computer and use it in GitHub Desktop.
Save cleversolutions/afcd985dbfe19b93b6436f5626c623b5 to your computer and use it in GitHub Desktop.
Add Google Authentication to an Umbraco 9 website
using Umbraco.Cms.Core.DependencyInjection;
using Umbraco.Extensions;
using Umbraco.Cms.Web.BackOffice.Security;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Configuration;
namespace Umbraco.Cms.Web.UI.NetCore.Configuration
{
public static class GoogleAuthenticationExtensions
{
public static IUmbracoBuilder AddGoogleAuthentication(this IUmbracoBuilder builder)
{
builder.AddBackOfficeExternalLogins(loginOptions =>
loginOptions.AddBackOfficeLogin(new BackOfficeExternalLoginProviderOptions(
"btn-success",
"fa-google"
), authOptions => authOptions.AddGoogle("Umbraco.Google","Google", options =>
{
IConfigurationSection googleAuthNSection = builder.Config.GetSection("Authentication:Google");
options.ClientId = googleAuthNSection["ClientId"];
options.ClientSecret = googleAuthNSection["ClientSecret"];
})));
return builder;
}
}
}
// Add it to your startup like so
public void ConfigureServices(IServiceCollection services)
{
services.AddUmbraco(_env, _config)
.AddBackOffice()
.AddWebsite()
.AddComposers()
.AddGoogleAuthentication()
.Build();
}
@biapar
Copy link

biapar commented Nov 4, 2021

And for members? Not backoffice.

@cleversolutions
Copy link
Author

Sadly Umbraco doesn't support external login for members yet. I've raised a feature request for it, add your support if this is something you need. umbraco/Umbraco-CMS#10952

@cleversolutions
Copy link
Author

The discussion provides some hints on how to accomplish this. You will have to override MemberSignInManager and MemberManager.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment