2

我正在完成将我的应用程序从 WCF 移植到 SS,我有一个关于身份验证服务的问题......我已经实现了我自己的 Provider,它从 CredentialsAuthProvider 中屏蔽并调用 hxxp://url/api/auth?username=abc&pass =123 它有效...我想知道(也许我错了)为什么没有 AuthenticateRequest/Response DTO

我问这个是因为我使用的是这里提供的实现

对于我创建的 AuthenticationRequest

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

它被传递给 /auth 服务,但是当我必须处理响应(布尔)时,我在响应回调中遇到异常

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 吗?谢谢

4

1 回答 1

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

授权

[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; }
}
于 2013-10-30T08:39:38.550 回答