ServiceStack从我的服务调用身份验证

时间:2013-04-15 10:39:26

标签: c# servicestack

我想帮助用户从我的服务登录,所以我不是直接发布到'/ auth / basics'或'/ auth / credentials'链接,而是从我的代码中执行此操作:

public class LoginService : Service {
    public LoginResponse Post(Login req) {
        var authService = ServiceStack.WebHost.Endpoints.AppHostBase.Instance.Container.Resolve<AuthService>();
        authService.RequestContext = new HttpRequestContext(
            System.Web.HttpContext.Current.Request.ToRequest(),
            System.Web.HttpContext.Current.Response.ToResponse(), 
            null
        );
        authResponse = AuthService.Authenticate(
                           new Auth{ 
                               UserName = req.UserName, 
                               Password = req.Password,
                               RememberMe = true 
        });
        if(authResponse.UserName != null) {
            //sccessful
            //and does it automatically write session to cookies too? 
            //or do I need to write to session manually?
        }

    }
}

这是我到目前为止所想到的。这是正确的方法吗?我想和你确认一下。

0 个答案:

没有答案