Exemplo n.º 1
0
        private void SetupOAuth(RestRequest request, OAuth1Token requestToken, string verifier)
        {
            string nonce     = GenerateNonce();
            string timeStamp = GenerateTimeStamp();

            QueryParameterCollection parameters = new QueryParameterCollection(request.Parameters);

            OAuth1RestRequest authRestRequest = request as OAuth1RestRequest;

            if (authRestRequest != null)
            {
                parameters.AddRange(authRestRequest.OAuthValues.Select(x => new QueryParameter(x.Key, x.Value)));
                authRestRequest.OAuthValues.Clear();
            }

            if (string.IsNullOrEmpty(requestToken.Token))
            {
                throw new ArgumentException("Null Request Token");
            }

            if (string.IsNullOrEmpty(requestToken.Secret))
            {
                throw new ArgumentException("Null Request Token Secret.");
            }

            if (string.IsNullOrEmpty(verifier))
            {
                throw new ArgumentException("Null Auth Verifier.");
            }

            var signatureBase = GenerateSignatureBase(
                request.RequestUrl,
                this.AppKey,
                requestToken.Token,
                request.Method.ToString(),
                timeStamp,
                nonce,
                verifier,
                parameters);

            // obtain a signature and add it to oauth header parameters
            var signature = GenerateSignature(this.AppSecret, requestToken.Secret, signatureBase);

            parameters.Add(RestConstants.OAuthSignature, signature);

            string authHeader = GenerateAuthorizationHeader(request.RequestUrl, parameters);

            request.Headers["Authorization"] = authHeader;
        }
Exemplo n.º 2
0
        /// <summary>
        /// Gets the access token.
        /// </summary>
        /// <param name="requestToken">The request token.</param>
        /// <param name="accessTokenUrl">The access token URL.</param>
        /// <param name="verifier">The verifier.</param>
        /// <returns><see cref="OAuth1TokenCredential"/> object.</returns>
        /// <author>Anwar</author>
        /// <datetime>3/26/2011 3:31 PM</datetime>
        protected T GetAccessToken(OAuth1Token requestToken, string accessTokenUrl, string verifier)
        {
            var request = this.BuildAccessTokenRequest(requestToken, accessTokenUrl, verifier);

            request.Method = MethodType.Post;
            this.SetupOAuth(request, requestToken, verifier);

            RestResponse <T> response = this.Post <T>(request);

            if (response.Completed && response.ContentObject != null && response.ContentObject.Success)
            {
                this.Credential = response.ContentObject;
            }

            return(response.ContentObject);
        }
Exemplo n.º 3
0
        protected virtual RestRequest BuildAccessTokenRequest(OAuth1Token requestToken, string accessTokenUrl, string verifier)
        {
            RestRequest request = new RestRequest(accessTokenUrl);

            return(request);
        }