Asp.net mvc 4 ID4014:未注册SecurityTokenHandler以读取安全令牌

Asp.net mvc 4 ID4014:未注册SecurityTokenHandler以读取安全令牌,asp.net-mvc-4,wif,asp.net-web-api,Asp.net Mvc 4,Wif,Asp.net Web Api,我正在拼命尝试使用ACS的JWT令牌来授权我的webapi。我到目前为止,它重定向到ACS网站,我可以登录。回拨到我的站点后,我得到: ID4014:未注册SecurityTokenHandler以读取安全性 令牌('BinarySecurityToken', '') 我读过很多关于这方面的博客,并制作了自己的CustomJwtSecurityToken。但不知怎么的,它还是不起作用。我根据这个网站做了一切: my web.config: <system.identityModel

我正在拼命尝试使用ACS的JWT令牌来授权我的webapi。我到目前为止,它重定向到ACS网站,我可以登录。回拨到我的站点后,我得到:

ID4014:未注册SecurityTokenHandler以读取安全性 令牌('BinarySecurityToken', '')

我读过很多关于这方面的博客,并制作了自己的CustomJwtSecurityToken。但不知怎么的,它还是不起作用。我根据这个网站做了一切:

my web.config:

    <system.identityModel>
    <identityConfiguration saveBootstrapContext="true" >
      <audienceUris>
        <add value="https://localhost/Connector" />
      </audienceUris>
      <securityTokenHandlers>
        <add type="Connector.Security.Azure.CustomJwtSecurityTokenHandler, Connector,   Version=1.0.0.0, Culture=neutral" />
        <securityTokenHandlerConfiguration>
          <certificateValidation certificateValidationMode="PeerTrust"/>
          <issuerTokenResolver type="Connector.Security.Azure.CustomJwtSecurityTokenHandler, Connector, Version=1.0.0.0, Culture=neutral">
            <securityKey symmetricKey="[mykey]" name="https://localhost/Connector" />
          </issuerTokenResolver>
        </securityTokenHandlerConfiguration>
      </securityTokenHandlers>

      <issuerNameRegistry type="System.IdentityModel.Tokens.ConfigurationBasedIssuerNameRegistry, System.IdentityModel, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
        <trustedIssuers>
          <add thumbprint="[mythumbprint]"
        name="https://[mycompany].accesscontrol.windows.net/" />

        </trustedIssuers>

      </issuerNameRegistry>

    </identityConfiguration>

  </system.identityModel>
  <system.identityModel.services>
    <federationConfiguration>
      <cookieHandler requireSsl="false" />
      <wsFederation passiveRedirectEnabled="true" issuer="https://[mycompany].accesscontrol.windows.net/v2/wsfederation" realm="https://localhost/Connector" requireHttps="false" />
    </federationConfiguration>
  </system.identityModel.services>

我查了一下小提琴手的反应。我收到JWT令牌。不知何故,我的站点没有将其发送给正确的处理程序。有人知道为什么或者如何调试这个吗?
令牌类型:jwt<

Microsoft为jwt令牌提供现成的处理程序。如果这符合您的需要(即,您没有编写自定义处理程序的任何特殊要求),那么我建议您使用该处理程序。我把它和ACS一起使用,效果很好。您可以将其安装为nuget(请参阅)

一个关于如何在web.config中设置它的示例,一旦安装就很好了。微软jwt安全处理程序不适用于WIF配置。如果你想让它工作,你需要继承它自己做水管。这就是为什么找不到配置文件作为示例的原因。但是,如果您愿意,我建议使用新的owin配置管道。它的数量级更简单)