我基于dotnet新模板"IdentityServer4快速入门UI (仅限UI资产)“(is4ui)创建了一个IdentityServer。
这与服务器呈现的MVC应用程序一起工作得很好,但是我不能让它与使用hellojs的SPA一起工作。
我在摆弄urls,以便显示来自Identity Server的登录页。登录逻辑运行得很好,但我认为缺少任何一小部分来正确地重定向到我的客户端应用程序,并使用访问令牌。
这是我用来初始化hellojs的代码:
const AuthorityUrl = 'http://localhost:5000';
hello.init({
'openidconnectdemo': {
oauth: {
version: '2',
auth: AuthorityUrl + '/Account/Login',
grant: AuthorityUrl + '/Grant'
},
scope_delim: ' '
}
});
hello.init({
openidconnectdemo: this.authConfig.clientId
});
这是登录码
hello.login('openidconnectdemo', {
redirect_uri: this.authConfig.redirectUrl,
scope: `openid profile`,
response_type: 'token',
display: 'page',
});
在AccountController的以下代码中,Identity Server尝试重定向到应用程序,但由于ReturnUrl为空而失败:
if (Url.IsLocalUrl(model.ReturnUrl))
{
return Redirect(model.ReturnUrl);
}
else if (string.IsNullOrEmpty(model.ReturnUrl))
{
return Redirect("~/");
}
else
{
// user might have clicked on a malicious link - should be logged
throw new Exception("invalid return URL");
}
我是否必须修改Identity Server才能使它们协同工作,还是客户端部分缺少某些内容?
谢谢你的建议!
发布于 2019-02-05 12:43:20
我可能会推荐使用oidc-client-js,因为它是OIDC的完整实现,应该更容易上手。
也就是说,看起来您这里的第一个问题是auth URL应该指向授权端点,而不是登录UI -也就是说,它应该是/connect/authorize
而不是/account/login
。
https://stackoverflow.com/questions/54533043
复制