【发布时间】:2017-07-23 19:54:01
【问题描述】:
我在尝试使用 IdentityServer4 进行身份验证时不断收到错误消息。我已经查看了有关此问题的一些资源,但它们都与我的问题无关。
我正在向https://localhost:44377/signin-oidc 发出 json 请求,但这是从 AspCore 身份验证 DLL 记录的内容
Microsoft.AspNetCore.Authentication.OpenIdConnect.OpenIdConnectMiddleware:信息:来自 RemoteAuthentication 的错误:OpenIdConnectAuthenticationHandler:message.State 为 null 或为空..
我的 Startup.cs 配置如下所示:
services.AddIdentityServer()
.AddInMemoryIdentityResources(Config.GetIdentityResources())
.AddInMemoryApiResources(Config.GetApiResources())
.AddInMemoryClients(Config.GetClients())
.AddTestUsers(Config.GetTestUsers())
.AddTemporarySigningCredential();
app.UseIdentityServer();
app.UseCookieAuthentication(new CookieAuthenticationOptions { AuthenticationScheme = "cookie" });
app.UseOpenIdConnectAuthentication(new OpenIdConnectOptions
{
ClientId = "openIdConnectClient",
Authority = "https://localhost:44377/",
SignInScheme = "cookie",
TokenValidationParameters = new TokenValidationParameters
{
IssuerSigningKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes("clientpassword"))
},
CallbackPath = "/signin-oidc"
});
我尝试访问的客户端看起来像这样
new Client
{
ClientId = "openIdConnectClient",
ClientName = "Example Implicit Client Application",
AllowedGrantTypes = GrantTypes.Implicit,
AllowedScopes = new List<string>
{
IdentityServerConstants.StandardScopes.OpenId,
IdentityServerConstants.StandardScopes.Profile,
IdentityServerConstants.StandardScopes.Email,
"role",
"customAPI"
},
ClientSecrets = new List<Secret> {
new Secret("superSecretPassword".Sha256())},
RedirectUris = new List<string> {"https://localhost:44377/signin-oidc"},
PostLogoutRedirectUris = new List<string> {"https://localhost:44377"}
}
【问题讨论】:
-
他们在 idserver 存储库中有大量示例。你看过那里吗?
-
我看过它们,我也一直在关注教程。我只想与测试用户一起进行身份验证,我不想迁移他们的数据库。
-
您的中间件排序是否正确?这是非常具体的,必须是正确的
-
您手动向 /signin-oidc 发出 JSON 请求?此端点用于交互式浏览器流,您应该通过它自动重定向,而不是向它发出您自己的请求。初始质询将其状态存储在消息中,并需要返回以完成登录。你确定不应该改用 JwtBearer 吗?
-
@Tratcher 如何在没有客户端的情况下从 web-api 登录我只是想从邮递员那里测试
标签: c# authentication asp.net-core openid-connect identityserver4