1

OAuth 2 リソース オーナー フローを使用して、Web API サービスに対してモバイル クライアントを承認しようとしています。Thinktecture IdentityServer を使用して、対称署名鍵で jwt トークンを発行しています。

クライアント側では、Thinktecture IdentityModel を使用してトークンの検証をセットアップしています。私の WebApiConfig は次のようになります。

        var jwtSecurityTokenHandler = new JwtSecurityTokenHandler();

        var mapping = new AuthenticationOptionMapping
        {
            // where to look for credentials
            Options = AuthenticationOptions.ForAuthorizationHeader("bearer"),

            // how to validate them
            TokenHandler = new SecurityTokenHandlerCollection { jwtSecurityTokenHandler },

            // which hint to give back if not successful
            Scheme = AuthenticationScheme.SchemeOnly("bearer")
        };
        var authConfig = new AuthenticationConfiguration(){RequireSsl = false};
        authConfig.AddMapping(mapping);
        config.MessageHandlers.Add(new AuthenticationHandler(authConfig));

私の IdentityModel.config には、次のものがあります。

<system.identityModel>
<identityConfiguration>
<claimsAuthorizationManager type="PresentationHost.Claims.MobileClaimsAuthorizationManager, PresentationHost"/>
<audienceUris>
  <add value="http://localhost:22674/" />
</audienceUris>

<securityTokenHandlers>
  <add type="System.IdentityModel.Tokens.JwtSecurityTokenHandler, System.IdentityModel.Tokens.Jwt" />
</securityTokenHandlers>

<issuerNameRegistry type="System.IdentityModel.Tokens.ValidatingIssuerNameRegistry, System.IdentityModel.Tokens.ValidatingIssuerNameRegistry">
  <authority name="http://identityserver.v2.thinktecture.com/trust/auth">
    <keys>
      <add symmetricKey="tVNRmpweBgz3xeWvSXrSwLIE3DrxJ3aawgNxZKC1Od0"/>
    </keys>
    <validIssuers>
      <add name="http://identityserver.v2.thinktecture.com/trust/auth" />
    </validIssuers>
  </authority>
</issuerNameRegistry>

<issuerTokenResolver type="System.IdentityModel.Tokens.NamedKeyIssuerTokenResolver, System.IdentityModel.Tokens.Jwt"/>
  <securityKey symmetricKey="tVNRmpweBgz3xeWvSXrSwLIE3DrxJ3aawgNxZKC1Od0" name="http://identityserver.v2.thinktecture.com/trust/auth" />


<!--certificationValidationMode set to "None" by the the Identity and Access Tool for Visual Studio. For development purposes.-->
<certificateValidation certificateValidationMode="None" />

主にhttp://leastprivilege.com/2013/07/16/identityserver-using-ws-federation-with-jwt-tokens-and-symmetric-signatures/のこのリンクから取得 しました。これは、このスタック オーバーフローの投稿で見つけました。対称キーで Microsoft JWT を構成するには?

その投稿にある派生クラスを使用しようとしましたが、この行を実行しようとしたとき:

var resolver = (NamedKeyIssuerTokenResolver)this.Configuration.IssuerTokenResolver;

IssuerTokenResolver のタイプが X509CertificateStoreResolver であり、NamedKeyIssuerTokenResolver のタイプではないため、InvalidCastException が発生します。

正しい TokenResolver を構成するために、構成またはコードにまだ何かが欠けているようです。誰か考えがありますか?

4

0 に答える 0