single-page-application - 带有 SPA 和 hellojs 的 IdentityServer4
问题描述
我基于 dotnet 新模板“IdentityServer4 快速入门 UI(仅限 UI 资产)”(is4ui)创建了一个 IdentityServer。
这与服务器渲染的 MVC 应用程序一起工作得很好,但我无法让它与使用 hellojs 的 SPA 一起工作。
我正在摆弄 url 以从 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");
}
我是否必须修改身份服务器才能使它们一起工作,或者客户端部分是否缺少某些东西?
感谢您的任何建议!
解决方案
我可能会推荐使用 oidc-client-js,因为它是 OIDC 的完整实现,应该更容易开始工作。
也就是说,看起来您的第一个问题是 auth URL 应该指向授权端点而不是 UI 中的登录 - 即它应该是/connect/authorize
而不是/account/login
.
推荐阅读
- python - 重新格式化 json 文件(python)
- python - 尝试使用熊猫从网站中提取 html 表
- python - 文档中的示例在 Jupiter Notebook 中不起作用
- git - VSCode:查看整个 git commit diff
- yii2 - Windows 10 localhost 上的 yii2 框架站点 - 部署问题
- kubernetes - 如何在 Terraform 中显示 kubernetes 日志
- php - Userpermission pivot-function 只能通过 Auth 类访问
- c# - NuGet 私有服务器在推送新包时返回 502 (Bad Gateway)
- firebase - Firebase 无法识别
- python - 正则表达式提取单词并以字符串中的空格结尾