2016-10-22 5 views
3

SPAのAPIを作成しようとしています。私は最新の.NET Core、MVC、EFを使用しています。私はJWTを使ってユーザーを認証したいので、openiddict coreを使うことにしました。私はgithub pagethis blog postの例に従って設定しようとしました。問題は、「指定された認可タイプはサポートされていません」ということです。トークンを要求するとき。ここでトークンを要求できません。空欄をリクエストしてください。

は郵便配達依頼のスクリーンショットです: Postman request

ここに私のConfigureServices方法だ:私はサンプルからAuthorizationControllerまでを使用してい

public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory) 
{ 
    loggerFactory.AddConsole(Configuration.GetSection("Logging")); 
    loggerFactory.AddDebug(); 

    if (env.IsDevelopment()) 
    { 
     app.UseDeveloperExceptionPage(); 
    } 

    app.UseApplicationInsightsRequestTelemetry(); 

    app.UseApplicationInsightsExceptionTelemetry(); 

    // don't use identity as this is a wrapper for using cookies, not needed 
    // app.UseIdentity(); 

    app.UseJwtBearerAuthentication(new JwtBearerOptions 
    { 
     AutomaticAuthenticate = true, 
     AutomaticChallenge = true, 
     RequireHttpsMetadata = false, // TODO: remove, dev only 
     Audience = "http://localhost:42443/", // TODO: ??? 
     Authority = "http://localhost:42443/" // TODO: ??? 
    }); 

    app.UseOpenIddict(); 

    app.UseMvcWithDefaultRoute(); 
} 

public void ConfigureServices(IServiceCollection services) 
{ 
    // Add framework services. 
    services.AddApplicationInsightsTelemetry(Configuration); 

    services.AddMvc(); 

    services.AddDbContext<ApplicationDbContext>(
     options => options.UseSqlServer(Configuration["Data:DefaultConnection:ConnectionString"]) 
    ); 

    services.AddIdentity<ApplicationUser, ApplicationRole>() 
     .AddEntityFrameworkStores<ApplicationDbContext>() 
     .AddDefaultTokenProviders(); 

    services.AddOpenIddict<ApplicationDbContext>() 
     .UseJsonWebTokens() 
     .EnableTokenEndpoint("/connect/token") 
     .AllowPasswordFlow() 
     .DisableHttpsRequirement() // TODO: remove in production 
     .AddEphemeralSigningKey(); // TODO: replace with a certificate, this should be used for development only 
} 

Configure方法トークン要求を処理します。 Debugger

私はなぜ見当がつかない:/connect/token要求を処理Exchange方法、のrequest引数の内容を観察することで、私はそれがヌルとしてすべてのフィールドを受け取ることを発見しました。郵便配達希望は、thisthisブログの投稿によれば正しいはずです。問題はどこだ?

答えて

4

mentioned in the samplesとして、OpenIdConnectRequestをアクションパラメータとして使用できるように、OpenIddict MVCモデルバインダを登録する必要があります。

リファレンスOpenIddict.MvcパッケージとはAddMvcBindersを呼び出し、それが動作するはずです:

services.AddOpenIddict<ApplicationDbContext>() 
    // Register the ASP.NET Core MVC binder used by OpenIddict. 
    // Note: if you don't call this method, you won't be able to 
    // bind OpenIdConnectRequest or OpenIdConnectResponse parameters. 
    .AddMvcBinders() 

... 
+1

あなたの野郎。 :)あなたは15秒で私を倒す。 –

+0

ああ、完全にその部分を逃した...私はまだ別のパッケージが必要だったことを知っていなかった:)それはそれだった!ありがとう! :) –

+1

@HonzaKalfusこのパッケージは、OpenIdConnectRequestパラメータをバインドできるようにしたい場合にのみ必要です。下位レベルのAPIを使用する場合は、 'HttpContext.GetOpenIdConnectRequest()'を使用することができます。 – Pinpoint

関連する問題