[英]ASP.NET Core 3.1 OpenIDConnect message.state is null
因此,我目前正在尝试在我启动的 OIDC 客户端应用程序中测试response_type=token的 oidc 隐式流。
我可以通过对我的 OIDC 提供商的/authorize
请求。 但是,当响应返回到客户端中signin-oidc
redirect_uri 时,我收到以下错误:
Exception: OpenIdConnectAuthenticationHandler: message.State is null or empty.
Unknown location
Exception: An error was encountered while handling the remote login.
Microsoft.AspNetCore.Authentication.RemoteAuthenticationHandler<TOptions>.HandleRequestAsync()
这是对我的授权端点的请求的样子:
GET https://localhost:44303/oauth/oidctest/authorize?client_id=...
然后我被重定向到我的 OIDC 提供者的/authorizelogin
端点以接受应用程序。 请求如下所示:
POST https://localhost:44303/oauth/oidctest/authorizelogin HTTP/1.1
这将返回一个 302 重定向 URL,如下所示:
https://localhost:5001/signin-oidc#token_type=bearer&access_token=<access-token>&scope=openid%20profile%20address%20phone%20email&expires_in=120&state=CfDJ....JDER
如您所见,state 可满足每个请求。 所以我不确定发生了什么。
这是我的 OIDC 中间件设置在我的 ASP.NET 核心客户端应用程序的Startup.cs
中的样子:
.AddOpenIdConnect(options =>
{
options.Authority = Configuration["auth:oidc:authority"];
options.ClientId = Configuration["auth:oidc:clientid"];
options.ClientSecret = Configuration["auth:oidc:clientsecret"];
options.ResponseType = OpenIdConnectResponseType.Token;
options.GetClaimsFromUserInfoEndpoint = true;
options.SaveTokens = true;
options.UseTokenLifetime = true;
options.Scope.Add("address");
options.Scope.Add("phone");
options.Scope.Add("email");
options.TokenValidationParameters = new TokenValidationParameters
{
ValidateIssuer = true,
ValidateAudience = true,
ValidateLifetime = true,
ValidIssuer = Configuration["auth:oidc:authority"],
ValidAudience = Configuration["auth:oidc:clientid"],
ValidateIssuerSigningKey = true,
ClockSkew = TimeSpan.FromSeconds(3)
};
});
我是否需要在中间件的某处设置这个 state(尽管它看起来像是自动设置的)?
如您所见,state 可满足每个请求。 所以我不确定发生了什么。
这有点复杂:如果你仔细观察,你会看到 state(和授权响应参数的 rest)实际上是 ZE6B391A8D2C4D45902A23A8B65857 与浏览器通信的远程片段服务器的一部分. 这就是为什么您收到一条错误消息,说 state 是 null:服务器从未收到它。
在您的情况下,您所针对的授权服务器似乎不支持response_mode=form_post
并在 URL 片段中返回授权响应,这是隐式流的本机响应模式( response_type=token
)。
还值得注意的是,OIDC 客户端中间件永远不会与response_type=token
一起使用,因为此流程中没有身份令牌。
相反,请考虑使用response_type=code
(授权代码流)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.