【发布时间】:2016-06-14 20:05:02
【问题描述】:
我需要升级(或降级)我的网站以使用本地登录页面。我使用以下代码使用混合流完成了所有工作
app.UseOpenIdConnectAuthentication(new OpenIdConnectAuthenticationOptions(){});
然后当令牌返回时,它会让我访问完成 asp.net 中的身份验证逻辑——设置声明身份、主体等。
app.UseOpenIdConnectAuthentication(new OpenIdConnectAuthenticationOptions()
{
Notifications = new OpenIdConnectAuthenticationNotifications()
{
SecurityTokenValidated = async n =>
{
// perform transform, etc..
n.AuthenticationTicket = new AuthenticationTicket(
identity, n.AuthenticationTicket.Properties);
await Task.FromResult(0);
}
}
});
现在,我将从 MVC 操作方法中收集用户名和密码。我可以通过这种方式从客户端获取访问令牌。
[HttpPost]
public ActionResult Login(LoginModel model)
{
var client = new TokenClient(
StsSettings.TokenEndpoint,
ClientId,
Secret);
var x = client.RequestResourceOwnerPasswordAsync(model.UserName, model.Password, "customid openid").Result;
return View(model);
}
但我不确定告诉 ASP.NET 指向我的自定义登录页面而不是身份服务器的最简单方法。我会使用表单身份验证逻辑并创建一些 AuthenticationTicket 吗?另外,设置ClaimsIdentity 的最佳方法是什么(我知道如何收回索赔,只需要一个“钩子”)
【问题讨论】:
标签: c# asp.net oauth-2.0 identityserver3