Exemple #1
0
        public CloudPTClient(string consumerKey, string secret, string authToken, string authSecret, AccessRestrictions accessMode)
        {
            _consumerKey = consumerKey;
            _consumerSecret = secret;
            Restrictions = accessMode;

            InitializeRestClients();

            AuthenticationToken = new AuthToken(authToken, authSecret);
        }
Exemple #2
0
 public string GetOAuthAuthorizeUrl(AuthToken token)
 {
     return _reqBuilder.BuildOAuthAuthorizeUrl(token.Token);
 }
Exemple #3
0
        private AuthToken ParseToken(string p)
        {
            AuthToken token = new AuthToken();
            foreach (string s in p.Split('&'))
            {
                var urlParam = s.Split('=');

                if (urlParam[0] == "oauth_token")
                    token.Token = urlParam[1];

                if (urlParam[0] == "oauth_token_secret")
                    token.Secret = urlParam[1];
            }

            return token;
        }
Exemple #4
0
        public AuthToken GetAccessToken(AuthToken token, string pin)
        {
            _apiRestClient.Authenticator = RestSharp.Authenticators.OAuth1Authenticator.ForAccessToken(_consumerKey, _consumerSecret, token.Token, token.Secret, pin);

            RestRequest request = _reqBuilder.BuildOAuthAccessTokenRequest();

            IRestResponse response = _apiRestClient.Execute(request);

            if (response.StatusCode == System.Net.HttpStatusCode.Unauthorized)
                throw new CloudPTNetException(); //Wrong PIN

            if (response.StatusCode != System.Net.HttpStatusCode.OK)
                throw new CloudPTNetException();

            AuthenticationToken = ParseToken(response.Content);
            return _authToken;
        }