我正在关注IdentityServer3 jsGettingStarted示例github sample但是我正在尝试使用MVC做到这一点。(根据示例文档,IdentityServer本身位于单独的项目和解决方案中。)通过Controller-Action提供index.html页面,这很好。
登录弹出窗口“ popup.html”(实际上是“ popup.cshtml”)也是通过Controller动作显示的,它也会显示,但不会关闭并在示例页面中显示的索引页中显示用户凭据。但是,请输入一些警报,..该用户肯定已登录。
我还尝试将popup.html移到项目的根目录(以.html而不是.cshtml的形式,并更改服务器的Client.cs的RedirectUris以反映该更改),但没有成功。
是因为通过我的控制器操作提供了cshtml页面吗?文档说应该通过调用显示函数来显示,但是“ manager.events.addUserLoaded”函数没有触发,而是调用了显示函数。
我正在将VS2017 MVC5与Framework 4.8一起使用。
谢谢
<link rel="stylesheet" href="node_modules/bootstrap/dist/css/bootstrap.css" />
<script src="~/Scripts/jquery.js"></script>
<script src="~/Scripts/bootstrap.js"></script>
<script src="~/Scripts/oidc-client.js"></script>
<div>
<nav class="navbar navbar-inverse navbar-fixed-top">
<div class="container">
<div class="navbar-header">
<a class="navbar-brand" href="#">JS Application</a>
</div>
</div>
</nav>
<div class="container main-container">
<div class="row">
<div class="col-xs-12">
<ul class="list-inline list-unstyled requests">
<li><a href="index.html" class="btn btn-primary">Home</a></li>
<li><button type="button" class="btn btn-default js-login">Login</button></li>
</ul>
</div>
</div>
<div class="row">
<div class="col-xs-6">
<div class="panel panel-default">
<div class="panel-heading">User data</div>
<div class="panel-body">
<pre class="js-user"></pre>
</div>
</div>
</div>
</div>
</div>
<script language="javascript" type="text/javascript">
// helper function to show data to the user
function display(selector, data)
{
if (data && typeof data === 'string')
{
data = JSON.parse(data);
}
if (data)
{
data = JSON.stringify(data, null, 2);
}
alert("selector=" + data);
$(selector).text(data);
}
var settings = {
authority: 'https://localhost:44302', // The url of the IdentityServer
client_id: 'js',
popup_redirect_uri: 'http://localhost:44888/Account/Popup',
response_type: 'id_token token',
scope: 'openid profile email',
filterProtocolClaims: true
};
var manager = new Oidc.UserManager(settings);
var user;
manager.events.addUserLoaded(function (loadedUser)
{
alert("userManager");
user = loadedUser;
display('.js-user', user);
});
$('.js-login').on('click', function ()
{
manager
.signinPopup()
.catch(function (error)
{
console.error('error while logging in through the current window or popup', error);
});
});
</script>
通过创建一个独立的项目,而不是尝试在已经建立的项目中进行,我设法使它开始工作。我们已经在使用的脚本和CSS中存在冲突。