/// <summary> /// Following the 3-legged authorization, you can exchange a request token for an access token /// using this method. This is the third and final step of the authorization process. /// </summary> /// <param name="verifier">The verification key received after the user has accepted the app.</param> /// <returns>An instance of <see cref="OAuthAccessTokenResponse"/> representing the response.</returns> public override OAuthAccessTokenResponse GetAccessToken(string verifier) { // Flickr apparently deviates from the OAuth 1.0a specification, since they require the OAuth properties to // be specified in the query string. // Some error checking if (AccessTokenUrl == null) { throw new PropertyNotSetException("AccessTokenUrl"); } if (ConsumerKey == null) { throw new PropertyNotSetException("ConsumerKey"); } if (ConsumerSecret == null) { throw new PropertyNotSetException("ConsumerSecret"); } if (Token == null) { throw new PropertyNotSetException("Token"); } // Initialize the query string HttpQueryString queryString = new HttpQueryString { { "oauth_verifier", verifier } }; // Generate the OAuth signature string signature = GenerateSignature(HttpMethod.Get, AccessTokenUrl, queryString, null); // Append the OAuth properties to the query string queryString.Add("oauth_nonce", Nonce); queryString.Add("oauth_timestamp", Timestamp); queryString.Add("oauth_consumer_key", ConsumerKey); queryString.Add("oauth_signature_method", "HMAC-SHA1"); queryString.Add("oauth_version", "1.0"); queryString.Add("oauth_token", Token); if (!string.IsNullOrWhiteSpace(Callback)) { queryString.Add("oauth_callback", Callback); } queryString.Add("oauth_signature", signature); // Make the call to the API IHttpResponse response = HttpUtils.Requests.Get(AccessTokenUrl, queryString); // Validate the response FlickrResponse.ValidateResponse(response); // Parse the response body OAuthAccessToken body = OAuthAccessToken.Parse(this, response.Body); // Parse the response return(OAuthAccessTokenResponse.ParseResponse(response, body)); }
/// <summary> /// Following the 3-legged authorization, you can exchange a request token for an access token /// using this method. This is the third and final step of the authorization process. /// </summary> /// <param name="verifier">The verification key received after the user has accepted the app.</param> /// <returns>An instance of <see cref="OAuthAccessTokenResponse"/> representing the response.</returns> /// <see> /// <cref>https://dev.twitter.com/docs/auth/3-legged-authorization</cref> /// </see> public virtual OAuthAccessTokenResponse GetAccessToken(string verifier) { // Some error checking if (string.IsNullOrWhiteSpace(verifier)) { throw new ArgumentNullException(nameof(verifier)); } // Make the call to the API/provider IHttpResponse response = GetAccessTokenResponse(verifier); // Parse the response body OAuthAccessToken body = OAuthAccessToken.Parse(this, response.Body); // Parse the response return(OAuthAccessTokenResponse.ParseResponse(response, body)); }