2017-10-26 22 views
0

イムは、IVEは、ここで私が好きな、簡単なチュートリアルを追いましたhttp://localhost:51863/connect/token?grant_type=password&username=alice%40wonderland.com&password=P%40ssw0rd私は応答を受け取りました:invalid_request "、" error_description ":"指定されたHTTPメソッドは有効ではありません。.NETのコアOpeniddict無効な要求

私startup.cs:

services.AddDbContext<AssistDbContext>(options => 
     { 
      options.UseSqlServer(Configuration.GetConnectionString("AssistContext")); 
     }); 
     services.AddScoped<AssistDbContext, AssistDbContext>(); 

     services.AddDbContext<DbContext>(options => 
     { 
      // Configure the context to use an in-memory store. 
      options.UseInMemoryDatabase(); 
      // Register the entity sets needed by OpenIddict. 
      // Note: use the generic overload if you need 
      // to replace the default OpenIddict entities. 
      options.UseOpenIddict(); 
     }); 

     services.AddOpenIddict(options => 
     { 
      // Register the Entity Framework stores. 
      options.AddEntityFrameworkCoreStores<DbContext>(); 
      // 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. 
      options.AddMvcBinders(); 
      // Enable the token endpoint. 
      options.EnableTokenEndpoint("/api/authorization/token"); 
      // Enable the password flow. 
      options.AllowPasswordFlow(); 
      // During development, you can disable the HTTPS requirement. 
      options.DisableHttpsRequirement(); 
     }); 

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

      app.UseApplicationInsightsRequestTelemetry(); 

      app.UseApplicationInsightsExceptionTelemetry(); 

      // Register the validation middleware, that is used to decrypt 
      // the access tokens and populate the HttpContext.User property. 
      app.UseOAuthValidation(); 
      // Register the OpenIddict middleware. 
      app.UseOpenIddict(); 
      app.UseMvcWithDefaultRoute(); 

     } 

UPDATE ポストマンとのテストは404を返します:

enter image description here

ログ:

Microsoft.AspNetCore.Hosting.Internal.WebHost:情報:リクエスト開始HTTP/1.1 POST http://localhost:51863/api/Authorizationアプリケーション/ x-www-form-urlencoded 49 'dotnet.exe'(CoreCLR:clrhost): 'C:¥Users¥consultoria.nuget¥packages¥AspNet.Security.OpenIdConnect.Extensions¥1.0.2¥lib¥netstandard1.4¥AspNet.Security.OpenIdConnect.Extensions .dll '読み込みシンボルをスキップしました。モジュールが最適化され、デバッガのオプション「Just My Code」が有効になります。 'dotnet.exe'(CoreCLR:clrhost):C:¥Users¥consultoria.nuget¥packages¥Microsoft.AspNetCore.WebUtilities¥1.1.0-preview1-final¥lib¥netstandard1.3¥Microsoft.AspNetCore.WebUtilitiesにロードされました。 .dll '読み込みシンボルをスキップしました。モジュールが最適化され、デバッガのオプション「Just My Code」が有効になります。 "grant_type": "password"、 "username": "teste"、 "password": "[password_type": "[パスワード]"からのトークン要求が正常に抽出されました。セキュリティ上の理由から削除されました] " } 'dotnet.exe'(CoreCLR:clrhost):C:¥Users¥consultoria.nuget¥packages¥Microsoft.EntityFrameworkCore.InMemory¥1.0.1¥lib¥netstandard1.3¥Microsoft.EntityFrameworkCore.InMemory.dll 'がロードされました。読み込みシンボルをスキップしました。モジュールが最適化され、デバッガのオプション「Just My Code」が有効になります。 'dotnet.exe'(CoreCLR:clrhost):「C:¥Users¥consultoria.nuget¥packages¥Remotion.Linq¥2.1.1¥lib¥netstandard1.0¥Remotion.Linq.dll」をロードしました。読み込みシンボルをスキップしました。モジュールが最適化され、デバッガのオプション「Just My Code」が有効になります。 'dotnet.exe'(CoreCLR:clrhost): 'C:¥Users¥consultoria.nuget¥packages¥System.Interactive.Async¥3.0.0¥lib¥netstandard1.0¥System.Interactive.Async.dll'が読み込まれました。読み込みシンボルをスキップしました。モジュールが最適化され、デバッガのオプション「Just My Code」が有効になります。 'dotnet.exe'(CoreCLR:clrhost): 'C:¥Program Files¥dotnet¥shared¥Microsoft.NETCore.App¥1.0.1¥System.Diagnostics.StackTrace.dll'が読み込まれました。読み込みシンボルをスキップしました。モジュールが最適化され、デバッガのオプション「Just My Code」が有効になります。 'dotnet.exe'(CoreCLR:clrhost): 'C:¥Program Files¥dotnet¥shared¥Microsoft.NETCore.App¥1.0.1¥System.Reflection.Metadata.dll'が読み込まれました。読み込みシンボルをスキップしました。モジュールが最適化され、デバッガのオプション「Just My Code」が有効になります。 'dotnet.exe'(CoreCLR:clrhost): 'C:¥Program Files¥dotnet¥shared¥Microsoft.NETCore.App¥1.0.1¥System.IO.MemoryMappedFiles.dll'が読み込まれました。読み込みシンボルをスキップしました。モジュールが最適化され、デバッガのオプション「Just My Code」が有効になります。 'dotnet.exe'(CoreCLR:clrhost): 'C:¥Program Files¥dotnet¥shared¥Microsoft.NETCore.App¥1.0.1¥System.IO.UnmanagedMemoryStream.dll'が読み込まれました。読み込みシンボルをスキップしました。モジュールが最適化され、デバッガのオプション「Just My Code」が有効になります。 Microsoft.AspNetCore.Diagnostics.ExceptionHandlerMiddleware:エラー:未処理の例外が発生しました:アセンブリ 'Microsoft.EntityFrameworkCore.InMemory、Version = 1.0.1.0、Cultureから' Microsoft.EntityFrameworkCore.Storage.Internal.InMemoryTransactionManager '型のメソッド' get_CurrentTransaction ' =中立、PublicKeyToken = adb9793829ddae60 'には実装がありません。

System.TypeLoadException:メソッド 'get_CurrentTransaction' タイプの 'Microsoft.EntityFrameworkCore.Storage.Internal.InMemoryTransactionManager' アセンブリから 'Microsoft.EntityFrameworkCore.InMemory、バージョン= 1.0.1.0、文化=中立、なPublicKeyToken = adb9793829ddae60' がありません実装されています。 、Microsoft.Extensions.DependencyInjection.InMemoryServiceCollectionExtensions.AddEntityFrameworkInMemoryDatabase(IServiceCollectionサービス) 、Microsoft.EntityFrameworkCore.Internal.ServiceProviderCache <> c__DisplayClass4_1.b__2(Int64のK) System.Collections.Concurrent.ConcurrentDictionary 2.GetOrAdd(TKey key, Func 2 ValueFactoryので)Microsoft.EntityFrameworkCore.DbContext..ctor(DbContextOptionsオプションで ) ---例外はあった以前の位置からスタックトレースの終わりMicrosoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitConstructor(ConstructorCallSite constructorCallSite、のServiceProviderプロバイダ)で )(System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throwで ---スローMicrosoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitScopedで (ScopedCallSite scopedCallSite、ServiceProviderプロバイダー) 、Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolve Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitConstructor(ConstructorCallSite constructorCallSite、のServiceProviderプロバイダ)でMicrosoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitScoped(ScopedCallSite scopedCallSite、のServiceProviderプロバイダ)でr.VisitConstructor(ConstructorCallSite constructorCallSite、のServiceProviderプロバイダ) 、Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitScoped(ScopedCallSite scopedCallSite、ServiceProviderプロバイダー) 、Microsoft.Extensions.DependencyInjection.ServiceProvider < OpenIddict.OpenIddictProviderでMicrosoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetRequiredServiceでMicrosoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetRequiredService(IServiceProviderプロバイダ、タイプサービス種別)に> c__DisplayClass16_0.b__0(のServiceProviderプロバイダ) [T](IServiceProviderプロバイダ) 4.<ValidateTokenRequest>d__8.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at AspNet.Security.OpenIdConnect.Server.OpenIdConnectServerHandler.<InvokeTokenEndpointAsync>d__17.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at AspNet.Security.OpenIdConnect.Server.OpenIdConnectServerHandler.<HandleRequestAsync>d__2.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Microsoft.AspNetCore.Authentication.AuthenticationMiddleware 1.d__18.MoveNext() ---例外がスローされた前の場所からのスタックトレースの末尾--- at Microsoft.AspNetCore.Authentication.AuthenticationMiddleware 1.<Invoke>d__18.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Microsoft.AspNetCore.Authentication.AuthenticationMiddleware 1.d__18.MoveNext() ---スタックの最後例外がスローされた前の場所からトレース--- 012.例外がスローされた以前の場所からのスタックトレースの---終わり--- System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccessで (タスクタスク) System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotificationで(タスクのタスク) でMicrosoft.AspNetCore.Diagnostics.ExceptionHandlerMiddleware.d__6.MoveNext() アプリケーションの分析テレメトリ(未構成):{"name": "Microsoft.ApplicationInsights.Dev.Request"、 "time": "2017-10-27T14:41:33.6130254 Z "、" tags ":{" ai.operation.id ":" VBvjL4hwyqs = "、" ai.user.userAgent ":" Mozilla/5.0(Windows NT 10.0; Win64; x64)AppleWebKit/537.36(GeckoのようなKHTML)Chrome/61.0.3163.100 Safari/537.36 "、" ai.internal.sdkVersion ":" aspnet5c:1.0.0 "、" ai.operation.name ":" POST/api/"baseData"、 "baseData":{"ver":2、 "id": "VBvjL4hwyqs ="、 "vid"、 "名前 ":" POST /api/Authorization","startTime::"2017-10-27T14:41:33.6130254+00:00","duration":"00:00:00.4732983","success":false、 Microsoft Corporation、その関連会社及びこれらの者の供給者は、直接的、間接的、偶発的、結果的損害、逸失利益、懲罰的行為、情報:リクエストは490で終了しました。1896ms 404

答えて

1

エラーメッセージから欠落していることは非常に明確である:私は、クエリ文字列パラメータを見ることができるように、おそらくGET(間違ったHTTPメソッドを使用していますURIに添付される)。

OAuth2仕様の必要に応じてPOSTを使用してください。動作するはずです。

+0

を使用しています。現在POSTを使用していて、Postmanでテストしています。何らかの理由で404を返しています。私はAuthorizationControllerのExchange機能にアクセスできません。 –

+0

Exchangeのアクションは有効ですか? – Pinpoint

+0

私のAPI –

0

は、認証文を以下のように見えますが、コードスニペット

services.AddAuthentication(options => 
{ 
    options.DefaultScheme = OAuthValidationDefaults.AuthenticationScheme; 
}); 
+0

実際には.NETコア2.xの1.0.1 –

関連する問題