Last active
November 4, 2021 10:58
-
-
Save cleversolutions/afcd985dbfe19b93b6436f5626c623b5 to your computer and use it in GitHub Desktop.
Add Google Authentication to an Umbraco 9 website
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Add it to your startup like so | |
public void ConfigureServices(IServiceCollection services) | |
{ | |
services.AddUmbraco(_env, _config) | |
.AddBackOffice() | |
.AddWebsite() | |
.AddComposers() | |
.AddGoogleAuthentication() | |
.Build(); | |
} |
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
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
And for members? Not backoffice.