Silverlight的Servicestack认证服务

时间:2013-10-29 13:34:21

标签: servicestack

我已完成将我的应用从WCF移植到SS,我对验证服务有疑问......我已经实现了我自己的提供商,该提供商从CredentialsAuthProvider开始并调用hxxp:// url / api / auth?username = abc& pass = 123它有效...... 我想知道(也许我错了)为什么没有AuthenticateRequest / Response DTO

我问这个问题,因为我使用了here提供的实现

对于我已创建为

的AuthenticationRequest
public class AuthRequest
{
    public string UserName { get; set; }
    public string Password { get; set; }
}

并将其传递给/ auth服务,但是当我处理响应(bool)时,我在响应回调中遇到异常

private void ResponseCallback(IAsyncResult asyncResult)
    {
        try
        {
            // Get the web response
            var webRequest = (HttpWebRequest)asyncResult.AsyncState;
            var webResponse = webRequest.EndGetResponse(asyncResult);

            // Get the web response stream
            var stream = webResponse.GetResponseStream();

            // Deserialize the json data in the response stream
            var serializer = new DataContractJsonSerializer(typeof(TResponse));


          //  bool res = (bool)serializer.ReadObject(stream); //bool cannot be converted since it's not IConvertible

             var response = (TResponse)serializer.ReadObject(stream); 
  ...}

有什么建议吗?我应该定义自己的AuthFeature吗? 感谢

1 个答案:

答案 0 :(得分:2)

您在寻找AuthResponse吗?

namespace ServiceStack.ServiceInterface.Auth
{
    [DataContract]
    public class AuthResponse
    {
        public AuthResponse();

        [DataMember(Order = 3)]
        public string ReferrerUrl { get; set; }
        [DataMember(Order = 4)]
        public ResponseStatus ResponseStatus { get; set; }
        [DataMember(Order = 1)]
        public string SessionId { get; set; }
        [DataMember(Order = 2)]
        public string UserName { get; set; }
    }
}

Auth

[DataContract]
public class Auth : IReturn<AuthResponse>
{
    [DataMember(Order = 1)]
    public string provider { get; set; }
    [DataMember(Order = 2)]
    public string State { get; set; }
    [DataMember(Order = 3)]
    public string oauth_token { get; set; }
    [DataMember(Order = 4)]
    public string oauth_verifier { get; set; }
    [DataMember(Order = 5)]
    public string UserName { get; set; }
    [DataMember(Order = 6)]
    public string Password { get; set; }
    [DataMember(Order = 7)]
    public bool? RememberMe { get; set; }
    [DataMember(Order = 8)]
    public string Continue { get; set; }
    // Thise are used for digest auth
    [DataMember(Order = 9)]
    public string nonce { get; set; }
    [DataMember(Order = 10)]
    public string uri { get; set; }
    [DataMember(Order = 11)]
    public string response { get; set; }
    [DataMember(Order = 12)]
    public string qop { get; set; }
    [DataMember(Order = 13)]
    public string nc { get; set; }
    [DataMember(Order = 14)]
    public string cnonce { get; set; }
}