Использование токенов IdentityServer в службе WCF, размещенной в IIS

Я пытаюсь использовать (потреблять) токен IdentityServer в службе WCF, размещенной в IIS. Я видел образец от Доминика для самостоятельной службы WCF. Но поскольку моя служба WCF размещена в IIS, мне нужно будет настроить привязки и параметры конфигурации сервера идентификации внутри файла web.config. Может ли кто-нибудь совместно использовать файл web.config с конфигурациями IdentityServer? Пожалуйста, найдите мою текущую конфигурацию ниже:

<?xml version="1.0"?>
<configuration>
<appSettings>
<add key="aspnet:UseTaskFriendlySynchronizationContext" value="true" />
</appSettings>
<system.web>
<compilation debug="true" targetFramework="4.5.2" />
<httpRuntime targetFramework="4.5.2"/>
</system.web>
<system.serviceModel>
<bindings>
  <ws2007FederationHttpBinding>
    <binding name="WS2007FederationHttpBinding_IService1">
      <security mode="TransportWithMessageCredential">
        <message establishSecurityContext="false" issuedKeyType="BearerKey">
          <issuer address="https://localhost/dentityServer" />
        </message>
      </security>
    </binding>
  </ws2007FederationHttpBinding>
</bindings>
<client>
  <endpoint address="https://localhost/IDPWcfService1/Service1.svc" 
            binding="ws2007FederationHttpBinding" bindingConfiguration="WS2007FederationHttpBinding_IService1"
            contract="WcfService1.IService1" name="WS2007FederationHttpBinding_IService1" ></endpoint>
</client>
<behaviors>
  <serviceBehaviors>
    <behavior>
      <!-- To avoid disclosing metadata information, set the values below to false before deployment -->
      <serviceMetadata httpGetEnabled="true" httpsGetEnabled="true"/>
      <!-- To receive exception details in faults for debugging purposes, set the value below to true.  Set to false before deployment to avoid disclosing exception information -->
      <serviceDebug includeExceptionDetailInFaults="false"/>
    </behavior>
  </serviceBehaviors>
</behaviors>
<protocolMapping>
    <add binding="basicHttpsBinding" scheme="https" />
</protocolMapping>    
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />
</system.serviceModel>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true"/>
<!--
    To browse web app root directory during debugging, set the value below to true.
    Set to false before deployment to avoid disclosing web app folder information.
  -->
<directoryBrowse enabled="true"/>
</system.webServer>

</configuration>

person Venkat Naidu    schedule 12.05.2016    source источник


Ответы (1)


Я сейчас делаю то же самое, вам нужно добавить свой собственный класс-оболочку XML для инкапсуляции JWT (который является просто токеном безопасности, который будет передаваться службе при каждом вызове от клиентов, чтобы вы могли аутентифицировать клиента)

Вы можете найти более подробную информацию об этом в этой статье здесь: https://leastprivilege.com/2015/07/02/give-your-wcf-security-architecture-a-makeover-with-identityserver3/

После того, как этот шаг будет выполнен, вам нужно добавить эту настраиваемую оболочку xml в web.config следующим образом:

  <system.identityModel>
    <identityConfiguration saveBootstrapContext="true">
      <securityTokenHandlers>
        <remove type="System.IdentityModel.Tokens.Saml2SecurityTokenHandler, System.IdentityModel, Version=4.0.0.0, Culture=neutral, PublicKeyToken=abcdefg123456789"/>        
        <add type="Web.stuff.ServerSideAuthentication.IdentityServerWrappedJwtHandler, Web.stuff" />
      </securityTokenHandlers>
    </identityConfiguration>
  </system.identityModel>

Также не забудьте добавить пометку для этого нового раздела в узле configsections.

person Zeyad    schedule 19.04.2017