![](/img/trans.png)
[英]KeyNotFoundException : The given key was not present in the dictionary
[英]KeyNotFoundException: The given key 'OpenIdConnect.Code.RedirectUri' was not present in the dictionary
我正在使用带有混合流的Identityserver和vue cli中间件。 在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.AuthenticationMiddleware.Invoke(HttpContext上下文)Microsoft.AspNetCore.StaticFiles.StaticFileMiddleware.Invoke(HttpContext上下文)Microsoft.AspNetCore.StaticFiles.StaticFileMiddleware.Invoke(HttpContext) Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware.Invoke(HttpContext上下文)
怎么了?
我正在从回购下面使用Identityserver。
https://github.com/IdentityServer/IdentityServer4
我的分叉存储库(带有上面的代码)
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;
};
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.