KeyNotFoundException: указанный ключ 'OpenIdConnect.Code.RedirectUri' не присутствовал в словаре - PullRequest
0 голосов
/ 16 февраля 2019

Я использую промежуточное ПО vue cli с сервером идентификации с Hybrid Flow.При вызове Ajax я перенаправил вручную на identityprovider, как показано ниже.

options.Events.OnRedirectToIdentityProvider = context =>
                 {
                     if (context.Request.Path.StartsWithSegments("/api"))
                     {
                         if (context.Response.StatusCode == (int)HttpStatusCode.OK)
                         {
                             context.ProtocolMessage.State = options.StateDataFormat.Protect(context.Properties);
                             context.Response.StatusCode = (int)HttpStatusCode.Unauthorized;
                             context.Response.Headers["Location"] = context.ProtocolMessage.CreateAuthenticationRequestUrl();
                         }
                         context.HandleResponse();
                     }
                     return Task.CompletedTask;
                 };

При обратном вызове от identityserver я получаю ошибку ниже.

KeyNotFoundException: данный ключ 'OpenIdConnect.Code.RedirectUri 'отсутствует в словаре.

Ниже приведен стек вызовов.

Microsoft.AspNetCore.Authentication.RemoteAuthenticationHandler.HandleRequestAsync () Microsoft.AspNetCore.Authentication.AuthenticationMid.Invoke (контекст HttpContext). Microsoft.AspNetCore.StaticFiles.StaticFileMiddleware.Invoke (контекст HttpContext) Microsoft.AspNetCore.StaticFiles.StaticFileMiddleware.Invoke (контекст HttpContext)* Что не так?

Я использую идентификационный сервер из репо ниже.

https://github.com/IdentityServer/IdentityServer4

Мое раздвоенное репо (с кодом выше)

https://github.com/hnviradiya/asp-net-core-vue-starter

1 Ответ

0 голосов
/ 17 февраля 2019
options.Events.OnRedirectToIdentityProvider = redirectContext =>
                      {
                          if (redirectContext.Request.Path.StartsWithSegments("/api"))
                          {
                              if (redirectContext.Response.StatusCode == (int)HttpStatusCode.OK)
                              {
                                  redirectContext.Properties.RedirectUri = $"{redirectContext.Request.Scheme}://{redirectContext.Request.Host}{redirectContext.Request.PathBase}";
                                  redirectContext.Properties.Items.Add(OpenIdConnectDefaults.RedirectUriForCodePropertiesKey, redirectContext.ProtocolMessage.RedirectUri);
                                  redirectContext.ProtocolMessage.State = options.StateDataFormat.Protect(redirectContext.Properties);
                                  redirectContext.Response.StatusCode =   (int)HttpStatusCode.Unauthorized;
                                  redirectContext.Response.Headers["Location"] = redirectContext.ProtocolMessage.CreateAuthenticationRequestUrl();
                              }
                              redirectContext.HandleResponse();
                          }
                          return Task.CompletedTask;
                      };
...