我正在尝试学习如何在我的应用程序中实现身份服务器,目前我专注于Angular 6中内置的Web应用程序。
我通过this tutorial找到了Scott Brady,这对我帮助很大。但是登录后我无法Identity Server
重定向我。
我已经完成了Identity Server
AccountController
(来自Quickstart软件包)的操作,可以看到下面的内容被调用了,但是我从未被重定向。
await HttpContext.SignInAsync(user.SubjectId, user.Username, props);
...other stuff...
return Redirect(model.ReturnUrl);
如果我删除所有断点并提交表单,就好像页面只是重新加载一样。我无法弄清我所缺少的。
我知道网址应完全匹配,否则将无法正常工作,但我已经检查过。
model.ReturnUrl
是:
/ connect / authorize / callback?client_id = angular_spa&redirect_uri = http%3A%2F%2Flocalhost%3A4200%2Fauth-callback&response_type = id_token%20token&scope = openid%20profile%20api1&state = e47c064d2d47452d9a782e5e63e7e7e76e4e24e7e76e7e7e7e7e7e0e6e0e0e0e0e7e0e0e0e0e7e7e0e0e0e0e人欧洲版
角度代码
export function getClientSettings(): UserManagerSettings {
return {
authority: 'http://localhost:5000/',
client_id: 'angular_spa',
redirect_uri: 'http://localhost:4200/auth-callback',
post_logout_redirect_uri: 'http://localhost:4200/',
response_type: "id_token token",
scope: "openid profile api1",
filterProtocolClaims: true,
loadUserInfo: true,
automaticSilentRenew: true,
silent_redirect_uri: 'http://localhost:4200/silent-refresh.html'
};
}
身份服务器
public void ConfigureServices(IServiceCollection services)
{
services.AddIdentityServer()
.AddSigningCredential(new X509Certificate2(@"myCert.pfx", "password"))
.AddInMemoryApiResources(Resources.GetApiResources())
.AddInMemoryIdentityResources(Resources.GetIdentityResources())
.AddInMemoryClients(Clients.Get())
.AddTestUsers(Users.Get())
.AddDeveloperSigningCredential();
services.AddMvc();
}
internal class Resources
{
public static IEnumerable<IdentityResource> GetIdentityResources()
{
return new List<IdentityResource> {
new IdentityResources.OpenId(),
new IdentityResources.Profile()
};
}
public static IEnumerable<ApiResource> GetApiResources()
{
return new List<ApiResource> {
new ApiResource("api1", "My API #1")
};
}
}
internal class Clients
{
public static IEnumerable<Client> Get()
{
return new List<Client> {
new Client {
ClientId = "angular_spa",
ClientName = "Angular 4 Client",
AllowedGrantTypes = GrantTypes.Implicit,
AllowedScopes = new List<string> {"openid", "profile", "api1"},
RedirectUris = new List<string> {"http://localhost:4200/auth-callback"},
PostLogoutRedirectUris = new List<string> {"http://localhost:4200/"},
AllowedCorsOrigins = new List<string> {"http://localhost:4200"},
AllowAccessTokensViaBrowser = true
}
};
}
}
internal class Users
{
public static List<TestUser> Get()
{
return new List<TestUser> {
new TestUser {
SubjectId = "5BE86359-073C-434B-AD2D-A3932222DABE",
Username = "scott",
Password = "password"
}
};
}
}
编辑:
运行身份服务器并导航到http://localhost:5000/Account/Login
,然后尝试登录会显示相同的行为
编辑2:
我克隆了the identity server samples,运行了3_ImplicitFlowAuthentication并从教程中添加了用户,但我仍然得到相同的行为