Esempio n. 1
0
 public GoPlanAppAPI(string key, string secret, string baseUrl, BaseToken accessToken)
 {
     Key         = key;
     Secret      = secret;
     BaseUrl     = baseUrl;
     AccessToken = accessToken;
 }
Esempio n. 2
0
        public BaseToken GetAccessToken(BaseToken requestToken, string verifier)
        {
            string    normalizedUrl    = "";
            string    normalizedParams = "";
            OAuthBase oauth            = new OAuthBase();
            string    timestamp        = oauth.GenerateTimeStamp();
            string    nounce           = oauth.GenerateNonce();

            //create uri
            string requestBody     = "";
            string bodyHash        = oauth.ComputeHash(HashAlgorithm.Create("SHA1"), requestBody);
            string bodyHashEscaped = Uri.EscapeDataString(bodyHash);
            //create signature
            string signature = oauth.GenerateSignature(GetAccessTokenUri(), Key, Secret, requestToken.Token, requestToken.TokenSecret, "POST", timestamp, nounce, OAuthBase.SignatureTypes.HMACSHA1, bodyHashEscaped, verifier, out normalizedUrl, out normalizedParams);

            try
            {
                //call remote server to get token
                WebClient client = new WebClient();
                string    authorizationParams =
                    string.Format(
                        "OAuth oauth_body_hash=\"{6}\", oauth_consumer_key=\"{0}\", oauth_nonce=\"{4}\", oauth_signature=\"{2}\",  oauth_signature_method=\"HMAC-SHA1\", oauth_timestamp=\"{3}\", oauth_token=\"{1}\", oauth_verifier=\"{5}\", oauth_version=\"1.0\"",
                        Uri.EscapeDataString(Key),
                        Uri.EscapeDataString(requestToken.Token),
                        Uri.EscapeDataString(signature),
                        Uri.EscapeDataString(timestamp),
                        Uri.EscapeDataString(nounce),
                        Uri.EscapeDataString(verifier),
                        Uri.EscapeDataString(bodyHash)
                        );
                client.Headers.Add("Authorization", authorizationParams);
                var result = client.UploadString(GetAccessTokenUri(), requestBody);
                AccessToken = ParseAuthTokenResponse(result);
                return(AccessToken);
            } catch (WebException ex) {
                ProcessException(ex);
                throw; //todo add exception
            }
        }