【问题标题】:Custom JwtSecurityTokenHandler not being invoked未调用自定义 JwtSecurityTokenHandler
【发布时间】:2013-11-05 02:40:52
【问题描述】:

我有一个使用 Azure Active Directory 进行身份验证的 .NET MVC 应用程序。

我正在尝试添加一个自定义 JWTSecurityTokenHandler 来验证一个控制台应用程序,该应用程序对该应用程序执行一些基本的 GET 请求。但是,每个请求都会被重定向到 Azure AD 登录页面,而不是传递给 JWT 处理程序(我的处理程序中的断点和日志记录语句没有被命中)。有什么想法吗?

Web.config:

  <system.identityModel>
    <identityConfiguration>
      <audienceUris>
        <add value="https://localhost:44300/" />
      </audienceUris>
      <securityTokenHandlers>
        <add type="QS.Admin.Infrastructure.MyJwtHandler, QS.Admin" />
        <securityTokenHandlerConfiguration>
          <certificateValidation certificateValidationMode="None" />
        </securityTokenHandlerConfiguration>
      </securityTokenHandlers>
      <issuerNameRegistry type="System.IdentityModel.Tokens.ValidatingIssuerNameRegistry, System.IdentityModel.Tokens.ValidatingIssuerNameRegistry">
        <authority name="https://[myaccessdomain].accesscontrol.windows.net/">
          <keys>
            <add thumbprint="[thumbprint]" />
          </keys>
          <validIssuers>
            <add name="https://[myaccessdomain].accesscontrol.windows.net/" />
          </validIssuers>
        </authority>
      </issuerNameRegistry>
      <!--certificationValidationMode set to "None" by the the Identity and Access Tool for Visual Studio. For development purposes.-->
      <certificateValidation certificateValidationMode="None" />
    </identityConfiguration>
  </system.identityModel>
  <system.identityModel.services>
    <federationConfiguration>
      <cookieHandler requireSsl="false" />
      <wsFederation passiveRedirectEnabled="true" issuer="https://[myaccessdomain].accesscontrol.windows.net/v2/wsfederation" realm="https://localhost:44300/" requireHttps="false" />
    </federationConfiguration>
  </system.identityModel.services>

【问题讨论】:

    标签: model-view-controller office365 jwt azure-active-directory


    【解决方案1】:

    除了上述建议外, jwtsecuritytokenhandler 的职责是验证 jwt 并为上游提供声明。我在您的配置中没有看到会话管理,如果缺少,每次调用主机都需要从 ACS 获取新令牌。

    【讨论】:

      【解决方案2】:

      web.config 中的设置看起来正确。

      需要检查的几件事:

      1. 确保将 ACS 配置为为您的领域颁发 JWT 令牌。

      2. 如果您从 MS 中插入 JwtSecurityTokenHandler - 它会被击中吗?这将有助于将问题与您的自定义处理程序与 ACS 或 web.config 中的设置隔离开来。

      【讨论】:

        猜你喜欢
        • 2021-11-20
        • 2021-03-10
        • 1970-01-01
        • 2015-09-13
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多