【发布时间】:2023-03-24 15:09:01
【问题描述】:
我正在查看https://identityserver.github.io/Documentation/docs/overview/mvcGettingStarted.html 的示例。这是在VS2013中。我使用谷歌浏览器作为浏览器。我已经设法进入“添加受保护的资源并显示声明”,我在 About 中添加了 AuthorizeAttribute。我运行应用程序。我点击关于。正如预期的那样,我看到了登录表单。我使用“秘密”密码以“bob”身份登录。我希望看到列有声明的“关于”表单。相反,我看到一个带有长 URI 的空白表单,然后是某种循环。
我查看了 Fiddler 以获得线索。循环是:
- GET /Home/关于 HTTP/1.1
- GET /identity/connect/authorize?...
- POST / HTTP/1.1
- POST /skypectoc/v1/pnr/parse HTTP/1.1
- 转到 1
这表明应用重定向到身份服务器,该服务器重定向回原始 URL,但应用无法识别用户已通过身份验证,因此它重定向到身份服务器。以此类推。
我的 Startup 课程是:
public class Startup
{
private static readonly OpenIdConnectAuthenticationOptions OpenIdConnectAuthenticationOptions = new OpenIdConnectAuthenticationOptions
{
Authority = "https://localhost:44300/identity/",
ClientId = "mvc",
Scope = "openid profile roles",
RedirectUri = "https://localhost:44300/",
ResponseType = "id_token",
SignInAsAuthenticationType = "Cookies"
};
private static readonly CookieAuthenticationOptions CookieAuthenticationOptions = new CookieAuthenticationOptions
{
AuthenticationType = "Cookies"
};
public void Configuration(IAppBuilder app)
{
IdentityServerServiceFactory identityServerServiceFactory = new IdentityServerServiceFactory()
.UseInMemoryUsers(Users.Get())
.UseInMemoryClients(Clients.Get())
.UseInMemoryScopes(Scopes.Get());
IdentityServerOptions identityServerOptions = new IdentityServerOptions
{
SiteName = "Embedded IdentityServer",
SigningCertificate = LoadCertificate(),
Factory = identityServerServiceFactory
};
app.Map("/identity", idsrvApp => idsrvApp.UseIdentityServer(identityServerOptions));
app.UseCookieAuthentication(CookieAuthenticationOptions);
app.UseOpenIdConnectAuthentication(OpenIdConnectAuthenticationOptions);
}
private X509Certificate2 LoadCertificate()
{
string path = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, @"bin\idsrv3test.pfx");
return new X509Certificate2(path, "idsrv3test");
}
}
我有客户
public static class Clients
{
public static IEnumerable<Client> Get()
{
return new[]
{
new Client
{
Enabled = true,
ClientName = "MVC Client",
ClientId = "mvc",
Flow = Flows.Implicit,
RedirectUris = new List<string>
{
"https://localhost:44300/"
},
AllowAccessToAllScopes = true
}
};
}
}
范围:
public static class Scopes
{
public static IEnumerable<Scope> Get()
{
List<Scope> scopes = new List<Scope>
{
new Scope
{
Enabled = true,
Name = "roles",
Type = ScopeType.Identity,
Claims = new List<ScopeClaim>
{
new ScopeClaim("roles")
}
}
};
scopes.AddRange(StandardScopes.All);
return scopes;
}
}
用户:
public static class Users
{
public static List<InMemoryUser> Get()
{
return new List<InMemoryUser>
{
new InMemoryUser
{
Username = "bob",
Password = "secret",
Subject = "1",
Claims = new[]
{
new Claim(Constants.ClaimTypes.GivenName, "Bob"),
new Claim(Constants.ClaimTypes.FamilyName, "Smith"),
new Claim(Constants.ClaimTypes.Role, "Geek"),
new Claim(Constants.ClaimTypes.Role, "Foo")
}
}
};
}
}
我认为这几乎就是从样本中转录而来的。 Startup 被重构了一点,所以我可以研究这些部分。我错过了什么?
TIA
【问题讨论】:
-
我在 Chrome 中禁用了 Skype 解析器,但问题仍然存在,只是循环的第 4 步没有发生。
标签: asp.net-mvc thinktecture-ident-server