servicestack,Asp.net Mvc,Authentication,Mono,servicestack" /> servicestack,Asp.net Mvc,Authentication,Mono,servicestack" />

Asp.net mvc 在ServiceStack中与Auth DTO一起发送附加数据

Asp.net mvc 在ServiceStack中与Auth DTO一起发送附加数据,asp.net-mvc,authentication,mono,servicestack,Asp.net Mvc,Authentication,Mono,servicestack,我有一个使用ServiceStack的web服务、Android应用程序等API。我当前使用一个用户名/密码组合进行身份验证,该组合在客户端类似于: var authResponse = authService.Authenticate(new Auth { provider = "credentials", UserName = user.user_id, Password = user.password, RememberMe = true }); 我想做一些类似的事情: var auth

我有一个使用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
});
var authResponse=authService.Authenticate(新的身份验证){
provider=“凭证”,
用户名=user.user\u id,
Password=user.Password,

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

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

  • 为每个客户端代码创建一个单独的类,如:
用同样的方法为每个代码创建单独的类

  • 现在,您需要在项目的AppHost文件中注册所有提供者

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

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

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


这听起来不错,只要他没有太多的客户端代码需要管理。
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)
        {
        }
}