Skip to content

Instantly share code, notes, and snippets.

@dsolovay
Last active December 8, 2021 06:01

Revisions

  1. dsolovay revised this gist Sep 16, 2021. 1 changed file with 7 additions and 0 deletions.
    7 changes: 7 additions & 0 deletions Sitecore.Plugin.manifest
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,7 @@
    <?xml version="1.0" encoding="utf-8"?>
    <SitecorePlugin PluginName="SitecoreIdentitySamlDemo" AssemblyName="SitecoreIdentitySamlDemo" Version="1.0.0">
    <Dependencies>
    <Dependency name="Sitecore.Plugin.IdentityProviders">5.1.1</Dependency>
    </Dependencies>
    <Tags />
    </SitecorePlugin>
  2. dsolovay revised this gist Sep 16, 2021. 1 changed file with 3 additions and 0 deletions.
    3 changes: 3 additions & 0 deletions Package Manager Console commands
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,3 @@
    Install-Package Sitecore.Plugin.IdentityProviders -Version 5.1.1 -Source https://sitecore.myget.org/F/sc-identity/api/v3/index.json
    Install-Package IdentityServer4 -Version 2.3.2
    Install-Package Sustainsys.Saml2.AspNetCore2 -Version 2.8.0
  3. dsolovay revised this gist Sep 16, 2021. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion ConfigureSitecore.cs
    Original file line number Diff line number Diff line change
    @@ -18,7 +18,7 @@ public void ConfigureServices(IServiceCollection services)
    {
    options.SignInScheme = "idsrv.external";
    options.SignOutScheme = IdentityServerConstants.DefaultCookieAuthenticationScheme;
    options.SPOptions.EntityId = new EntityId("https://testidserver2/Saml2");
    options.SPOptions.EntityId = new EntityId("https://xp0identityserver.dev.local/Saml2");
    IdentityProvider provider = GetIdentityProvider(options.SPOptions);
    options.IdentityProviders.Add(provider);
    });
  4. dsolovay revised this gist Sep 15, 2021. 1 changed file with 22 additions and 22 deletions.
    44 changes: 22 additions & 22 deletions ConfigureSitecore.cs
    Original file line number Diff line number Diff line change
    @@ -8,28 +8,28 @@

    namespace SitecoreIdentitySamlDemo
    {
    public class ConfigureSitecore
    {
    public void ConfigureServices(IServiceCollection services)
    {
    var builder = new AuthenticationBuilder(services);
    public class ConfigureSitecore
    {
    public void ConfigureServices(IServiceCollection services)
    {
    var builder = new AuthenticationBuilder(services);

    builder.AddSaml2("Saml2", "SSO Button Text", options =>
    {
    options.SignInScheme = "idsrv.external";
    options.SignOutScheme = IdentityServerConstants.DefaultCookieAuthenticationScheme;
    options.SPOptions.EntityId = new EntityId("https://testidserver2/Saml2");
    IdentityProvider provider = GetIdentityProvider(options.SPOptions);
    options.IdentityProviders.Add(provider);
    });
    }
    builder.AddSaml2("Saml2", "SSO Button Text", options =>
    {
    options.SignInScheme = "idsrv.external";
    options.SignOutScheme = IdentityServerConstants.DefaultCookieAuthenticationScheme;
    options.SPOptions.EntityId = new EntityId("https://testidserver2/Saml2");
    IdentityProvider provider = GetIdentityProvider(options.SPOptions);
    options.IdentityProviders.Add(provider);
    });
    }

    private IdentityProvider GetIdentityProvider(SPOptions options)
    {
    var idp = new IdentityProvider(new EntityId("https://stubidp.sustainsys.com/Metadata"), options);
    idp.Binding = Saml2BindingType.HttpPost;
    idp.LoadMetadata = true;
    return idp;
    }
    }
    private IdentityProvider GetIdentityProvider(SPOptions options)
    {
    var idp = new IdentityProvider(new EntityId("https://stubidp.sustainsys.com/Metadata"), options);
    idp.Binding = Saml2BindingType.HttpPost;
    idp.LoadMetadata = true;
    return idp;
    }
    }
    }
  5. dsolovay revised this gist Sep 15, 2021. 1 changed file with 1 addition and 2 deletions.
    3 changes: 1 addition & 2 deletions Saml2Configuration.xml
    Original file line number Diff line number Diff line change
    @@ -6,8 +6,7 @@
    <Saml2Configuration type="Sitecore.Plugin.IdentityProviders.IdentityProvider, Sitecore.Plugin.IdentityProviders">
    <AuthenticationScheme>Saml2</AuthenticationScheme>
    <DisplayName>Saml2 SSO</DisplayName>
    <Enabled>true</Enabled>
    <MetadataAddress></MetadataAddress>
    <Enabled>true</Enabled>
    <ClaimsTransformations>
    <ClaimsTransformation1 type="Sitecore.Plugin.IdentityProviders.DefaultClaimsTransformation, Sitecore.Plugin.IdentityProviders">
    <SourceClaims>
  6. dsolovay revised this gist Sep 15, 2021. 1 changed file with 49 additions and 0 deletions.
    49 changes: 49 additions & 0 deletions Saml2Configuration.xml
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,49 @@
    <?xml version="1.0" encoding="utf-8"?>
    <Settings>
    <Sitecore>
    <ExternalIdentityProviders>
    <IdentityProviders>
    <Saml2Configuration type="Sitecore.Plugin.IdentityProviders.IdentityProvider, Sitecore.Plugin.IdentityProviders">
    <AuthenticationScheme>Saml2</AuthenticationScheme>
    <DisplayName>Saml2 SSO</DisplayName>
    <Enabled>true</Enabled>
    <MetadataAddress></MetadataAddress>
    <ClaimsTransformations>
    <ClaimsTransformation1 type="Sitecore.Plugin.IdentityProviders.DefaultClaimsTransformation, Sitecore.Plugin.IdentityProviders">
    <SourceClaims>
    <Claim1 type="http://schemas.xmlsoap.org/ws/2005/05/identity/claims/upn" />
    </SourceClaims>
    <NewClaims>
    <Claim1 type="email" />
    </NewClaims>
    </ClaimsTransformation1 >
    <ClaimsTransformation2 type="Sitecore.Plugin.IdentityProviders.DefaultClaimsTransformation, Sitecore.Plugin.IdentityProviders">
    <SourceClaims>
    <Claim1 type="http://schemas.xmlsoap.org/ws/2005/05/identity/claims/emailaddress" />
    </SourceClaims>
    <NewClaims>
    <Claim1 type="email" />
    </NewClaims>
    </ClaimsTransformation2>
    <AuthorRule type="Sitecore.Plugin.IdentityProviders.DefaultClaimsTransformation, Sitecore.Plugin.IdentityProviders">
    <SourceClaims>
    <Claim1 type="http://schemas.microsoft.com/ws/2008/06/identity/claims/role" value="Author" />
    </SourceClaims>
    <NewClaims>
    <Claim1 type="role" value="sitecore\Author" />
    </NewClaims>
    </AuthorRule>
    <AdminRule type="Sitecore.Plugin.IdentityProviders.DefaultClaimsTransformation, Sitecore.Plugin.IdentityProviders">
    <SourceClaims>
    <Claim1 type="http://schemas.microsoft.com/ws/2008/06/identity/claims/role" value="Administrator" />
    </SourceClaims>
    <NewClaims>
    <Claim1 type="http://www.sitecore.net/identity/claims/isAdmin" value="true"/>
    </NewClaims>
    </AdminRule>
    </ClaimsTransformations>
    </Saml2Configuration>
    </IdentityProviders>
    </ExternalIdentityProviders>
    </Sitecore>
    </Settings>
  7. dsolovay created this gist Sep 14, 2021.
    35 changes: 35 additions & 0 deletions ConfigureSitecore.cs
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,35 @@
    using IdentityServer4;
    using Microsoft.AspNetCore.Authentication;
    using Microsoft.Extensions.DependencyInjection;
    using Sustainsys.Saml2;
    using Sustainsys.Saml2.Configuration;
    using Sustainsys.Saml2.Metadata;
    using Sustainsys.Saml2.WebSso;

    namespace SitecoreIdentitySamlDemo
    {
    public class ConfigureSitecore
    {
    public void ConfigureServices(IServiceCollection services)
    {
    var builder = new AuthenticationBuilder(services);

    builder.AddSaml2("Saml2", "SSO Button Text", options =>
    {
    options.SignInScheme = "idsrv.external";
    options.SignOutScheme = IdentityServerConstants.DefaultCookieAuthenticationScheme;
    options.SPOptions.EntityId = new EntityId("https://testidserver2/Saml2");
    IdentityProvider provider = GetIdentityProvider(options.SPOptions);
    options.IdentityProviders.Add(provider);
    });
    }

    private IdentityProvider GetIdentityProvider(SPOptions options)
    {
    var idp = new IdentityProvider(new EntityId("https://stubidp.sustainsys.com/Metadata"), options);
    idp.Binding = Saml2BindingType.HttpPost;
    idp.LoadMetadata = true;
    return idp;
    }
    }
    }