【发布时间】:2021-04-14 13:54:57
【问题描述】:
因此,我目前正在尝试在我已启动的 OIDC 客户端应用程序中测试 response_type=token 的 oidc 隐式流。
我可以通过 /authorize 向我的 OIDC 提供商提出的请求。但是,当响应返回到客户端中的 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
如您所见,每个请求都有状态。所以我不确定发生了什么。
这是我的 OIDC 中间件设置在我的 ASP.NET Core 客户端应用程序的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)
};
});
我是否需要在中间件的某处设置此状态(尽管它看起来像是自动设置的)?
【问题讨论】:
标签: c# asp.net-core oauth-2.0 openid-connect