【问题标题】:Sending additional data along with Auth DTO in ServiceStack在 ServiceStack 中与 Auth DTO 一起发送附加数据
【发布时间】:2013-10-17 20:39:40
【问题描述】:

我有一个使用 ServiceStack 的用于 Web 服务、Android 应用程序等的 API。我目前使用在客户端看起来像这样的用户名/密码组合进行身份验证:

var authResponse = authService.Authenticate(new Auth {
provider = "credentials",
UserName = user.user_id,
Password = user.password,
RememberMe = true
});

我想做这样的事情:

var authResponse = authService.Authenticate(new Auth {
provider = "credentials",
UserName = user.user_id,
Password = user.password,
ClientCode = user.clientCode <=====
RememberMe = true
});

此时我需要发送客户端代码以及用户名/密码。另一方面,我将使用该客户端代码来确定我应该针对哪个数据库进行身份验证。

由于目前似乎无法扩展 Auth 类,我想知道是否有更简单的起点。

谢谢

【问题讨论】:

    标签: asp.net-mvc authentication mono servicestack


    【解决方案1】:

    我建议为此使用不同的身份验证提供程序实现。以下是更多详细信息:

    • 为每个客户端代码创建一个单独的类,例如:
    public class Code1AuthProvider : CredentialsAuthProvider
        {
    
            public Code1AuthProvider ()
            {
                this.Provider = "Code1";
    
            }
            public override bool TryAuthenticate(IServiceBase authService, string userName, string password)
            {
            }
            public override void OnAuthenticated(IServiceBase authService, IAuthSession session, IOAuthTokens tokens, Dictionary authInfo)
            {
            }
    }

    以同样的方式为每个代码创建单独的类。

    • 现在您需要在项目的 AppHost 文件中注册所有提供程序。

    • 现在您可以访问/Auth/Code1 作为您的身份验证。由于您使用的是单独的数据库,因此以这种方式管理代码会更容易。

    • 使用[Authenticate("Code1")] 来为特定类型的用户验证服务。

    • 在客户端,您可以使用适当的/Auth/ClientCode url 进行身份验证。

    【讨论】:

    • 这听起来不错,只要他没有太多需要管理的客户端代码。
    【解决方案2】:

    您可以尝试为客户端代码传递标头值。您可以搜索传递 API 密钥的示例。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-09-15
      • 2019-02-20
      • 2018-08-14
      • 1970-01-01
      • 2012-02-19
      • 1970-01-01
      • 1970-01-01
      • 2020-05-16
      相关资源
      最近更新 更多