BCA*_*BCA 7 architecture authentication wcf authorization desktop-application
假设我有一个.NET富客户端(WPF)应用程序,它将同时部署在3个不同的场景中:
为此应用程序实现相同的用户授权/身份验证模型的简单,经过验证的做法是什么?即,无论应用程序的部署方式如何,我都希望在表示层,应用程序层,域层等中使用相同的方法.
是否应通过我现有的Entity Framework模型在我的SQL数据库中明确维护用户/角色?应该Thread.CurrentPrincipal是需要授权某些应用程序功能的代码所使用的方法,还是应该IUserService依赖注入某些功能?
这是一个低调的应用程序,因此安全性并不重要 - 只是一些基本的东西.
谢谢
花了几个小时研究基于WIF /声明的身份验证后,我仍然没有看到有关如何创建使用此类安全性的独立.NET桌面应用程序的任何指导.所有讨论都适用于ASP.NET或WCF.我需要我的应用程序使用可以在分布式(WCF)和独立部署方案中使用的标准方法
看看这个。我想这就是您正在寻找的:
https://gist.github.com/stonetip/8745656
var tokenHandler = new JwtSecurityTokenHandler();
var convertedSecret = EncodeSigningToken(ConfigurationManager.AppSettings["ClientSecret"]);
// Set the expected properties of the JWT token in the TokenValidationParameters
var validationParameters = new TokenValidationParameters()
{
AllowedAudience = ConfigurationManager.AppSettings["AllowedAudience"],
ValidIssuer = ConfigurationManager.AppSettings["Issuer"],
SigningToken = new BinarySecretSecurityToken(convertedSecret)
};
Thread.CurrentPrincipal = tokenHandler.ValidateToken(token, validationParameters);
if (HttpContext.Current != null)
{
HttpContext.Current.User = Thread.CurrentPrincipal;
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3032 次 |
| 最近记录: |