Example #1
0
 public SkypeClient(IHttpClient httpClient, SkypeAuthParams authParams)
 {
     this.httpClient = httpClient;
     httpClient.UpdateSharedCustomHeader("X-Skypetoken", authParams.Token);
     this.requestToken      = authParams.Token;
     this.registrationToken = authParams.RegistrationToken;
     this.messagesHost      = authParams.MessagesHost;
     this.endpointId        = authParams.EndpointId;
 }
Example #2
0
        public SkypeAuthParams Login(LoginCredentials credentials)
        {
            var response = httpClient.SendGet(SkypeApiUrls.WebLoginUrl);

            var postParameters = GetPostParameters(response.ResponseData);

            postParameters.Add("username", credentials.UserName);
            postParameters.Add("password", credentials.Password);

            var loginUrl = SkypeApiUrls.WebLoginUrlWithQuery(postParameters["client_id"]);

            response = httpClient.SendPost(loginUrl, postParameters);

            var authParams = new SkypeAuthParams {
                Token = GetToken(response.ResponseData)
            };

            var customHeaders = new Dictionary <string, string>();

            customHeaders["LockAndKey"] = GetLockAndKey();

            customHeaders["ClientInfo"] = GetClientInfo();

            customHeaders["Authentication"] = "skypetoken=" + authParams.Token;

            response =
                httpClient.SendPost(SkypeApiUrls.EndpointsUrl, new JObject(), customHeaders);

            if (response.ResponseHeaders.ContainsKey("Set-RegistrationToken"))
            {
                authParams.RegistrationToken = ParseRegistrationToken(response.ResponseHeaders["Set-RegistrationToken"]);
                authParams.EndpointId        = ParseEndpointId(response.ResponseHeaders["Set-RegistrationToken"]);
                // the endpoint post may be redirected to another server, in which case we need to use that
                // in subsequent requests
                authParams.MessagesHost = response.ResponseUrl.Host;
            }

            return(authParams);
        }