0

私はasp.netコア2.0でIdentity Server 4を開発しています。 ConfigurationServicesでIdentityServer4 with asp.net core2.0 erron on AuthenticationOptionsクラス

()Iを添加する方法:

app.UseIdentityServerAuthentication(new IdentityServerAuthenticationOptions 
     { 
      Authority = "http://localhost:59391", 
      RequireHttpsMetadata = false, 

      ApiName = "api1" 
     }); 

しかし、というエラーをコンパイル与える:それは 'Microsoft.AspNetCore.Authentication' で定義される

'AuthenticationOptions' クレームを入力するための基準しかしそれは見つからなかった。

私はアセンブリコードに見て:私はこのGithub linkで多くのことを議論した。このsample project(.NETのコア1.1)とAuthenticationOptionsビルドエラーに基づいていますが、アイデンティティ・サーバー4ではないように思える働い

namespace Microsoft.AspNetCore.Builder 
    { 
    public class IdentityServerAuthenticationOptions : Builder.AuthenticationOptions 
    { 
     // properties goes here 
    } 
    } 

asp .net core2.0で完全にサポートされています。それは本当ですか?

このエラーを解決する方法や、この問題を回避する方法についてご意見をお寄せください。

答えて

1

これは正しい - 認証ミドルウェアがasp.netコア2.0で変更されました。私はrelease candidate of IndentityServer4.AccessTokenValidation for 2.0があると信じています。しかし、現時点では、Identity Serverのドキュメントとサンプルは2.0用に更新されていません。

1つの方法は、Microsoft JwtBearerハンドラを使用してAPIを保護することです。 IdentityServer4.AccessTokenValidationライブラリは、これをフードの下で使用します。これは、(ConfigureServices()内)のようになります。

services.AddAuthentication(o => 
{ 
    o.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme; 
    o.DefaultChallengeScheme = JwtBearerDefaults.AuthenticationScheme; 
}) 
.AddJwtBearer(o => 
{ 
    o.Audience = "api1"; 
    o.Authority = "http://localhost:59391"; 
    o.RequireHttpsMetadata = false; 
}); 

別のオプションはIdentityServer4.AccessTokenValidation 2.0 rcを使用するようにコードを更新することです。私はまだこれを試していないが、これは次のようになります:

services.AddAuthentication(IdentityServerAuthenticationDefaults.AuthenticationScheme) 
.AddIdentityServerAuthentication(o => 
{ 
    o.ApiName = "api1"; 
    o.Authority = "http://localhost:59391"; 
    o.RequireHttpsMetadata = false; 
});