Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save Sam7/de7a313a146fc843ca998fca49907feb to your computer and use it in GitHub Desktop.
Save Sam7/de7a313a146fc843ca998fca49907feb to your computer and use it in GitHub Desktop.
UmbracoCustomOwinStartup.ConfigureBackOfficeAdfsAuthentication.cs
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