示例#1
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];
        }
示例#2
0
 /// <summary>
 /// Refresh the OAuth 2.0 access token.
 /// When successful, updates the OAuthParameter instance passed as parameter by setting
 /// AccessToken, RefreshToken and TokenExpiry.
 /// </summary>
 /// <param name="parameters">The OAuth 2.0 parameters</param>
 public static void RefreshAccessToken(OAuth2Parameters parameters)
 {
     OAuthBase.GetOAuth2AccessToken(parameters, OAuthBase.GetRefreshAccessTokenRequestBody(parameters));
 }
示例#3
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="parameters">The OAuth 2.0 parameters</param>
 public static void GetAccessToken(OAuth2Parameters parameters)
 {
     OAuthBase.GetOAuth2AccessToken(parameters, OAuthBase.GetExchangeAccessCodeRequestBody(parameters));
 }