GetQueryParameters() public static method

Overloaded version of GetQueryParameters to work without a IDictionary parameter
public static GetQueryParameters ( string querystring ) : string>.SortedDictionary
querystring string The query string part of the Url
return string>.SortedDictionary
Ejemplo n.º 1
0
        /// <summary>
        /// Exchanges the user-authorized request token for an access token.
        /// When successful, updates the OAuthParameter instance passed as parameter by setting
        /// Token and TokenSecret.
        /// </summary>
        /// <param name="parameters">The OAuth parameters</param>
        public static void GetAccessToken(OAuthParameters parameters)
        {
            Uri requestUri = new Uri(accessTokenUrl);

            string     headers = GenerateHeader(requestUri, "GET", parameters);
            WebRequest request = WebRequest.Create(requestUri);

            request.Headers.Add(headers);

            WebResponse response = request.GetResponse();
            string      result   = "";

            if (response != null)
            {
                Stream       responseStream = response.GetResponseStream();
                StreamReader reader         = new StreamReader(responseStream);
                result = reader.ReadToEnd();
            }

            //split results and update parameters
            SortedDictionary <string, string> responseValues = OAuthBase.GetQueryParameters(result);

            parameters.Token       = responseValues[OAuthBase.OAuthTokenKey];
            parameters.TokenSecret = responseValues[OAuthBase.OAuthTokenSecretKey];
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Exchanges the user-authorized request token for an OAuth 2.0 access token.
        /// When successful, updates the OAuthParameter instance passed as parameter by setting
        /// AccessToken, RefreshToken and TokenExpiry.
        /// </summary>
        /// <param name="queryString">The query string containing the access code</param>
        /// <param name="parameters">The OAuth 2.0 parameters</param>
        public static void GetAccessToken(String queryString, OAuth2Parameters parameters)
        {
            //split results and update parameters
            SortedDictionary <string, string> responseValues = OAuthBase.GetQueryParameters(queryString);

            parameters.AccessCode = responseValues[OAuthBase.OAuth2AccessCode];
            GetAccessToken(parameters);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Helper method which parses a querystring for the OAuth related parameters.
        /// It updates the OAuthParameter instance passed as parameter by setting
        /// Token, TokenSecret and Verifier (if present).
        /// </summary>
        /// <param name="parameters">The OAuth parameters</param>
        public static void UpdateOAuthParametersFromCallback(string queryString, OAuthParameters parameters)
        {
            //split results and update parameters
            SortedDictionary <string, string> responseValues = OAuthBase.GetQueryParameters(queryString);

            parameters.Token = responseValues[OAuthBase.OAuthTokenKey];
            if (responseValues.ContainsKey(OAuthBase.OAuthTokenSecretKey))
            {
                parameters.TokenSecret = responseValues[OAuthBase.OAuthTokenSecretKey];
            }
            if (responseValues.ContainsKey(OAuthBase.OAuthVerifierKey))
            {
                parameters.Verifier = responseValues[OAuthBase.OAuthVerifierKey];
            }
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Contacts Google for a request token, first step of the OAuth authentication process.
        /// When successful, updates the OAuthParameter instance passed as parameter by setting
        /// Token and TokenSecret.
        /// </summary>
        /// <param name="parameters">The OAuth parameters</param>
        public static void GetUnauthorizedRequestToken(OAuthParameters parameters)
        {
            Uri requestUri = new Uri(string.Format("{0}?scope={1}", requestTokenUrl, OAuthBase.EncodingPerRFC3986(parameters.Scope)));

            // callback is only needed when getting the request token
            bool callbackExists = false;

            if (!string.IsNullOrEmpty(parameters.Callback))
            {
                parameters.BaseProperties.Add(OAuthBase.OAuthCallbackKey, parameters.Callback);
                callbackExists = true;
            }

            string     headers = GenerateHeader(requestUri, "GET", parameters);
            WebRequest request = WebRequest.Create(requestUri);

            request.Headers.Add(headers);

            WebResponse response = request.GetResponse();
            string      result   = "";

            if (response != null)
            {
                Stream       responseStream = response.GetResponseStream();
                StreamReader reader         = new StreamReader(responseStream);
                result = reader.ReadToEnd();
            }

            if (callbackExists)
            {
                parameters.BaseProperties.Remove(OAuthBase.OAuthCallbackKey);
            }

            // split results and update parameters
            SortedDictionary <string, string> responseValues = OAuthBase.GetQueryParameters(result);

            parameters.Token       = responseValues[OAuthBase.OAuthTokenKey];
            parameters.TokenSecret = responseValues[OAuthBase.OAuthTokenSecretKey];
        }