diff --git a/src/Umbraco.Core/Constants-Web.cs b/src/Umbraco.Core/Constants-Web.cs index ae80c70ecd..a936b2e388 100644 --- a/src/Umbraco.Core/Constants-Web.cs +++ b/src/Umbraco.Core/Constants-Web.cs @@ -26,6 +26,15 @@ public const string BackOfficeExternalAuthenticationType = "UmbracoExternalCookie"; public const string BackOfficeExternalCookieName = "UMB_EXTLOGIN"; + /// + /// The prefix used for external identity providers for their authentication type + /// + /// + /// By default we don't want to interfere with front-end external providers and their default setup, for back office the + /// providers need to be setup differently and each auth type for the back office will be prefixed with this value + /// + public const string BackOfficeExternalAuthenticationTypePrefix = "Umbraco."; + public const string StartContentNodeIdClaimType = "http://umbraco.org/2015/02/identity/claims/backoffice/startcontentnode"; public const string StartMediaNodeIdClaimType = "http://umbraco.org/2015/02/identity/claims/backoffice/startmedianode"; public const string AllowedApplicationsClaimType = "http://umbraco.org/2015/02/identity/claims/backoffice/allowedapps"; diff --git a/src/Umbraco.Web.UI/App_Start/UmbracoBackOfficeAuthExtensions.cs b/src/Umbraco.Web.UI/App_Start/UmbracoBackOfficeAuthExtensions.cs index 180334e5a6..0090029bf4 100644 --- a/src/Umbraco.Web.UI/App_Start/UmbracoBackOfficeAuthExtensions.cs +++ b/src/Umbraco.Web.UI/App_Start/UmbracoBackOfficeAuthExtensions.cs @@ -54,51 +54,52 @@ namespace Umbraco.Web.UI ClientSecret = clientSecret, SignInAsAuthenticationType = Constants.Security.BackOfficeExternalAuthenticationType }; - msOptions.Description.ForUmbracoBackOffice(style, icon); + msOptions.ForUmbracoBackOffice(style, icon); msOptions.Caption = caption; app.UseMicrosoftAccountAuthentication(msOptions); } - */ - - ///// - ///// Configure google sign-in - ///// - ///// - ///// - ///// - ///// - ///// - ///// - ///// - ///// - ///// Nuget installation: - ///// Microsoft.Owin.Security.Google - ///// - ///// Google account documentation for ASP.Net Identity can be found: - ///// - ///// http://www.asp.net/web-api/overview/security/external-authentication-services#GOOGLE - ///// - ///// Google apps can be created here: - ///// - ///// https://developers.google.com/accounts/docs/OpenIDConnect#getcredentials - ///// - ///// - //public static void ConfigureBackOfficeGoogleAuth(this IAppBuilder app, string clientId, string clientSecret, - // string caption = "Google", string style = "btn-google-plus", string icon = "fa-google-plus") - //{ - // var googleOptions = new GoogleOAuth2AuthenticationOptions - // { - // ClientId = clientId, - // ClientSecret = clientSecret, - // SignInAsAuthenticationType = Constants.Security.BackOfficeExternalAuthenticationType - // }; - // googleOptions.Description.ForUmbracoBackOffice(style, icon); - // googleOptions.Caption = caption; - // app.UseGoogleAuthentication(googleOptions); - //} - - /* + /// + /// Configure google sign-in + /// + /// + /// + /// + /// + /// + /// + /// + /// + /// Nuget installation: + /// Microsoft.Owin.Security.Google + /// + /// Google account documentation for ASP.Net Identity can be found: + /// + /// http://www.asp.net/web-api/overview/security/external-authentication-services#GOOGLE + /// + /// Google apps can be created here: + /// + /// https://developers.google.com/accounts/docs/OpenIDConnect#getcredentials + /// + /// + public static void ConfigureBackOfficeGoogleAuth(this IAppBuilder app, string clientId, string clientSecret, + string caption = "Google", string style = "btn-google-plus", string icon = "fa-google-plus") + { + var googleOptions = new GoogleOAuth2AuthenticationOptions + { + ClientId = clientId, + ClientSecret = clientSecret, + //In order to allow using different google providers on the front-end vs the back office, + // these settings are very important to make them distinguished from one another. + SignInAsAuthenticationType = Constants.Security.BackOfficeExternalAuthenticationType, + // By default this is '/signin-google', you will need to change that default value in your + // Google developer settings for your web-app in the "REDIRECT URIS" setting + CallbackPath = new PathString("/umbraco-google-signin") + }; + googleOptions.ForUmbracoBackOffice(style, icon); + googleOptions.Caption = caption; + app.UseGoogleAuthentication(googleOptions); + } /// /// Configure facebook sign-in @@ -130,14 +131,19 @@ namespace Umbraco.Web.UI { AppId = appId, AppSecret = appSecret, - SignInAsAuthenticationType = Constants.Security.BackOfficeExternalAuthenticationType + //In order to allow using different google providers on the front-end vs the back office, + // these settings are very important to make them distinguished from one another. + SignInAsAuthenticationType = Constants.Security.BackOfficeExternalAuthenticationType, + // By default this is '/signin-facebook', you will need to change that default value in your + // Facebook developer settings for your app in the Advanced settings under "Client OAuth Login" + // in the "Valid OAuth redirect URIs", specify the full URL, for example: http://mysite.com/umbraco-facebook-signin + CallbackPath = new PathString("/umbraco-facebook-signin") }; - fbOptions.Description.ForUmbracoBackOffice(style, icon); + fbOptions.ForUmbracoBackOffice(style, icon); fbOptions.Caption = caption; app.UseFacebookAuthentication(fbOptions); } - /// /// Configure ActiveDirectory sign-in /// @@ -210,7 +216,7 @@ namespace Umbraco.Web.UI } }; - adOptions.Description.ForUmbracoBackOffice(style, icon); + adOptions.ForUmbracoBackOffice(style, icon); adOptions.Caption = caption; app.UseOpenIdConnectAuthentication(adOptions); } diff --git a/src/Umbraco.Web.UI/web.Template.Debug.config b/src/Umbraco.Web.UI/web.Template.Debug.config index caa949f801..476d664dc5 100644 --- a/src/Umbraco.Web.UI/web.Template.Debug.config +++ b/src/Umbraco.Web.UI/web.Template.Debug.config @@ -172,6 +172,34 @@ + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/Umbraco.Web/Security/Identity/AuthenticationDescriptionOptionsExtensions.cs b/src/Umbraco.Web/Security/Identity/AuthenticationDescriptionOptionsExtensions.cs index 07ed17f423..47ad1b4310 100644 --- a/src/Umbraco.Web/Security/Identity/AuthenticationDescriptionOptionsExtensions.cs +++ b/src/Umbraco.Web/Security/Identity/AuthenticationDescriptionOptionsExtensions.cs @@ -1,4 +1,5 @@ using Microsoft.Owin.Security; +using Umbraco.Core; namespace Umbraco.Web.Security.Identity { @@ -10,13 +11,21 @@ namespace Umbraco.Web.Security.Identity /// /// /// - public static void ForUmbracoBackOffice(this AuthenticationDescription options, string style, string icon) + public static void ForUmbracoBackOffice(this AuthenticationOptions options, string style, string icon) { - options.Properties["SocialStyle"] = style; - options.Properties["SocialIcon"] = icon; + Mandate.ParameterNotNullOrEmpty(options.AuthenticationType, "options.AuthenticationType"); + + //Ensure the prefix is set + if (options.AuthenticationType.StartsWith(Constants.Security.BackOfficeExternalAuthenticationTypePrefix) == false) + { + options.AuthenticationType = Constants.Security.BackOfficeExternalAuthenticationTypePrefix + options.AuthenticationType; + } + + options.Description.Properties["SocialStyle"] = style; + options.Description.Properties["SocialIcon"] = icon; //flag for use in back office - options.Properties["UmbracoBackOffice"] = true; + options.Description.Properties["UmbracoBackOffice"] = true; } } } \ No newline at end of file