对于 WPF 和 WCF 应用程序,用户 authentication/authorization 的 "best practice" 是什么?

What is considered "best practice" for user authentication/authorization for WPF and WCF applications?

假设我有一个将同时部署在 3 个不同场景中的 .NET 富客户端 (WPF) 应用程序:

  1. 客户端和服务器代码 运行s 在一个进程中
  2. 客户端代码 运行s 在 Intranet 计算机上并通过 WCF 与服务器计算机通信,其中 app/domain/infrastructure 代码 运行s
  3. 与 #2 相同,但客户端可以 运行 在防火墙外的机器上。应集中维护用户和角色的自定义列表(即,凭据不基于 windows 登录)

为此应用程序实施相同用户 authorization/authentication 模型的简单、行之有效的做法是什么?也就是说,我想在表示层、应用层、领域层等中使用相同的方法,而不管应用程序是如何部署的。

是否应该通过我现有的 Entity Framework 模型在我的 SQL 数据库中明确维护 users/roles? Thread.CurrentPrincipal 应该是需要授权某些应用程序功能的代码使用的方法,还是应该对某些 IUserService 进行依赖注入?

这是一个低调的应用程序,因此安全性不是至关重要的 -- 只是一些基本的东西。

谢谢

编辑

在花费数小时研究 WIF/基于声明的身份验证之后,我仍然没有看到任何关于如何创建采用此类安全性的独立 .NET 桌面应用程序的指南。所有讨论都针对 ASP.NET 或 WCF。我需要我的应用程序使用可用于分布式 (WCF) 和独立部署方案的标准方法

一般来说,最好使用像 JWT 这样的基于令牌的身份验证。主要原因是它在各种类型的客户端和服务器中的灵活性。例如,如果将来您需要向解决方案中添加移动应用程序(IOS、Android,随便什么),您可以在没有任何 problem.You 的情况下完成,也可以使用 [= 增强您的应用程序25=] WebApi 等服务。

因此,如果您要开始这个项目,我建议您使用基于令牌的身份验证。

查看这些网址,您可能会发现它们很有用:

https://msdn.microsoft.com/en-us/library/ms751506%28v=vs.110%29.aspx

http://www.rhyous.com/2015/02/05/basic-token-service-for-wcf-services-part-1/

看看 this.I 假设这就是您要查找的内容:

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;
        }