advapi
advapi

Reputation: 3907

Servicestack Authentication Service for silverlight

I'm finishing porting my app from WCF to SS, I've got a question about the authenticationservice... I've implemented my own Provider that hinerits from CredentialsAuthProvider and calling hxxp://url/api/auth?username=abc&pass=123 it works... I was wondering (and maybe I'm wrong) why there's no AuthenticateRequest/Response DTO

I'm asking this since I'm using the implementation provided here

For the AuthenticationRequest I've created as

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

and it's passed to the /auth service, but when I've to handle the response (bool) I got an exception in the response callback

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

Any suggestion? Should I define my own AuthFeature? Thanks

Upvotes: 2

Views: 80

Answers (1)

Estyn
Estyn

Reputation: 695

Are you looking for the 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; }
    }
}

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

Upvotes: 2

Related Questions