如何使用Kentor.AuthServices在.NET中为SSO(单点登录)添加自定义属性

问题描述 投票:1回答:2

我目前正在使用名为Kentor.AuthServices的SAML2的.NET 4.5实现(请参阅github上的项目)。我想从我的网站[MySite]转到[BenefitsSiteForSingleSignon]。

我希望发送超过2个属性,1个称为语言,将是en-us,en-ca或fr-ca,1个称为employee_number,将是一个6位数字。

但是,我在这一点上陷入困​​境,我已经修改了应用程序的MVC实现中的web.config(使用来自github的SampleApplicationMVC),我可以让它向提供者发送SAML请求[BenefitsSiteForSingleSignon](对不起,如果我使用不正确的SAML术语)但我仍然坚持如何填写employee_number字段和语言字段。

我已经按照说明修改了web.config文件,如果有人有这方面的经验,将非常感谢。

总之,我需要使用Kentor.AuthServices for .NET来自我的公司网站并单点登录到另一个引入SAML2请求的外部网站。我需要提供字段语言和员工编号,发行人ID是[MySite]。谢谢!

-Web.Config开始 -

<?xml version="1.0" encoding="utf-8"?>
    <!--
      For more information on how to configure your ASP.NET application, please visit
      http://go.microsoft.com/fwlink/?LinkId=301880
      -->
    <configuration>
      <configSections>
        <section name="system.identityModel" type="System.IdentityModel.Configuration.SystemIdentityModelSection, System.IdentityModel, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089" />
        <section name="system.identityModel.services" type="System.IdentityModel.Services.Configuration.SystemIdentityModelServicesSection, System.IdentityModel.Services, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089" />
        <section name="kentor.authServices" type="Kentor.AuthServices.Configuration.KentorAuthServicesSection, Kentor.AuthServices" />
        <!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
        <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
      </configSections>
      <appSettings>
        <add key="webpages:Version" value="3.0.0.0" />
        <add key="webpages:Enabled" value="false" />
        <add key="ClientValidationEnabled" value="true" />
        <add key="UnobtrusiveJavaScriptEnabled" value="true" />
      </appSettings>
      <system.web>
        <compilation debug="true" targetFramework="4.5" />
        <httpRuntime targetFramework="4.5" />
        <authentication mode="Forms">
          <forms loginUrl="~/AuthServices/SignIn" />
        </authentication>
      </system.web>
      <system.webServer>
        <modules>
          <add name="SessionAuthenticationModule" type="System.IdentityModel.Services.SessionAuthenticationModule, System.IdentityModel.Services, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" preCondition="managedHandler" />
        </modules>
      </system.webServer>
      <kentor.authServices entityId="[MySite]" returnUrl="[MySite]">
        <metadata cacheDuration="0:15:00">
          <organization name="Kentor IT AB" displayName="Kentor" url="http://www.kentor.se" language="sv" />
          <contactPerson type="Other" email="[email protected]" />
          <requestedAttributes>
            <add friendlyName="employee_number" name="urn:employee_number" nameFormat="urn:oasis:names:tc:SAML:2.0:attrname-format:uri" isRequired="true" />
           <add friendlyName="language" name="urn:language" nameFormat="urn:oasis:names:tc:SAML:2.0:attrname-format:uri" isRequired="true" />
          </requestedAttributes>
        </metadata>
        <identityProviders>
                <add entityId="http://stubidp.kentor.se/Metadata" destinationUri="http://stubidp.kentor.se/" allowUnsolicitedAuthnResponse="true" binding="HttpRedirect">
            <signingCertificate fileName="~/App_Data/Kentor.AuthServices.StubIdp.pfx" />
          </add>
          <add entityId="[BenefitsSiteForSingleSignon]" destinationUri="[BenefitsSiteForSingleSignon]" allowUnsolicitedAuthnResponse="true" binding="HttpRedirect">
            <signingCertificate fileName="~/App_Data/BenefitsSiteSSO.cer" />
          </add>
        </identityProviders>
        <!--<federations>
          <add metadataUrl="http://localhost:52071/Federation" allowUnsolicitedAuthnResponse="true" />
        </federations>-->
      </kentor.authServices>
      <system.identityModel />
      <system.identityModel.services>
        <federationConfiguration>
          <cookieHandler requireSsl="false" />
        </federationConfiguration>
      </system.identityModel.services>
      <runtime>
        <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
          <dependentAssembly>
            <assemblyIdentity name="System.Web.Optimization" publicKeyToken="31bf3856ad364e35" />
            <bindingRedirect oldVersion="1.0.0.0-1.1.0.0" newVersion="1.1.0.0" />
          </dependentAssembly>
          <dependentAssembly>
            <assemblyIdentity name="WebGrease" publicKeyToken="31bf3856ad364e35" />
            <bindingRedirect oldVersion="0.0.0.0-1.6.5135.21930" newVersion="1.6.5135.21930" />
          </dependentAssembly>
          <dependentAssembly>
            <assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" />
            <bindingRedirect oldVersion="0.0.0.0-6.0.0.0" newVersion="6.0.0.0" />
          </dependentAssembly>
          <dependentAssembly>
            <assemblyIdentity name="System.Web.Helpers" publicKeyToken="31bf3856ad364e35" />
            <bindingRedirect oldVersion="1.0.0.0-3.0.0.0" newVersion="3.0.0.0" />
          </dependentAssembly>
          <dependentAssembly>
            <assemblyIdentity name="System.Web.WebPages" publicKeyToken="31bf3856ad364e35" />
            <bindingRedirect oldVersion="1.0.0.0-3.0.0.0" newVersion="3.0.0.0" />
          </dependentAssembly>
          <dependentAssembly>
            <assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" />
            <bindingRedirect oldVersion="1.0.0.0-5.2.2.0" newVersion="5.2.2.0" />
          </dependentAssembly>
          <dependentAssembly>
            <assemblyIdentity name="Antlr3.Runtime" publicKeyToken="eb42632606e9261f" culture="neutral" />
            <bindingRedirect oldVersion="0.0.0.0-3.5.0.2" newVersion="3.5.0.2" />
          </dependentAssembly>
        </assemblyBinding>
      </runtime>
      <entityFramework>
        <defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework">
          <parameters>
            <parameter value="v11.0" />
          </parameters>
        </defaultConnectionFactory>
        <providers>
          <provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
        </providers>
      </entityFramework>
    </configuration>
asp.net .net single-sign-on saml kentor-authservices
2个回答
4
投票

在SAML术语中,[MySite]是Idp(身份提供商),[BenefitsSiteForSingleSignOn]是SP(服务提供商)。 Kentor.AuthServices主要是SP实现;不幸的是,这不是你需要的。

但是,AuthServices中提供了创建和发送未经请求的Saml2Response所需的组件。它被称为未经请求的,因为Idp在没有SP要求的情况下向SP发送响应。要使[MySite]作为身份提供者工作并发送未经请求的响应,您应该查看Kentor.AuthServices源中的stubidp。它创建并发送Saml2Responses。

在此,您将创建一个ClaimsIdentity,其中包含用户ID和附加信息(语言,员工编号等)作为自定义声明。然后,您可以基于该标识创建Saml2Response,并在SamlRedirectBinding的帮助下将其发送到[BenefitsSiteForSingleSignOn]。


0
投票

非常有用的信息;另请注意,kentor样品的设计如下:

  1. HttpModule示例:用于模块和kentor配置理解(模块实现也被MVC中间件使用)
  2. MVC示例:用于MVC中间件和kentor配置的理解
  3. Owin示例:用于了解kentor中间件
  4. IdentityServer示例:每个人都想要这个hotcake(使用kentor中间件)
  5. 以上都是SP发起的所以KentorStub示例:用于理解idp发起(它使用MVC中间件(和MVC中间件使用httpmodule))

当你运行1,2,3,4个样本时,你会从localhost:52071/AuthServices获得SP元数据(SPSSODescriptor),但运行5会从同一个链接获得IDP元数据,即localhost:52071/AuthServices

© www.soinside.com 2019 - 2024. All rights reserved.