Last active
June 12, 2018 01:48
-
-
Save Sam7/de7a313a146fc843ca998fca49907feb to your computer and use it in GitHub Desktop.
UmbracoCustomOwinStartup.ConfigureBackOfficeAdfsAuthentication.cs
This file contains hidden or 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
private static void ConfigureBackOfficeAdfsAuthentication( | |
IAppBuilder app, | |
string caption = "AD FS", | |
string style = "btn-microsoft", | |
string icon = "fa-windows") | |
{ | |
// Load configuration from web.config | |
var adfsMetadataEndpoint = ConfigurationManager.AppSettings["AdfsMetadataEndpoint"]; | |
var adfsRelyingParty = ConfigurationManager.AppSettings["AdfsRelyingParty"]; | |
var adfsFederationServerIdentifier = ConfigurationManager.AppSettings["AdfsFederationServerIdentifier"]; | |
var adfsReplyUrl = ConfigurationManager.AppSettings["AdfsReplyUrl"]; | |
app.SetDefaultSignInAsAuthenticationType(Umbraco.Core.Constants.Security.BackOfficeExternalAuthenticationType); | |
var wsFedOptions = new WsFederationAuthenticationOptions | |
{ | |
Wtrealm = adfsRelyingParty, | |
MetadataAddress = adfsMetadataEndpoint, | |
SignInAsAuthenticationType = Umbraco.Core.Constants.Security.BackOfficeExternalAuthenticationType, | |
Caption = caption, | |
Wreply = adfsReplyUrl, // Redirect to the Umbraco back office after succesful authentication | |
}; | |
// The crucial bit, where we hook into the events when users login or when they are created | |
wsFedOptions.SetExternalSignInAutoLinkOptions(new ExternalSignInAutoLinkOptions(true, new string[0]) | |
{ | |
OnAutoLinking = OnAutoLinking, | |
OnExternalLogin = OnExternalLogin | |
}); | |
// Apply options | |
wsFedOptions.ForUmbracoBackOffice(style, icon); | |
wsFedOptions.AuthenticationType = adfsFederationServerIdentifier; | |
app.UseWsFederationAuthentication(wsFedOptions); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment