public string GetAuthorizationURL(ITemporaryCredentials temporaryCredentials, string callbackURL) { try { var callbackParameter = _oAuthWebRequestGenerator.GenerateParameter("oauth_callback", callbackURL, true, true, false); var requestTokenResponse = _twitterRequestHandler.ExecuteQueryWithTemporaryCredentials(Resources.OAuthRequestToken, HttpMethod.POST, temporaryCredentials, new[] { callbackParameter }); if (!string.IsNullOrEmpty(requestTokenResponse) && requestTokenResponse != Resources.OAuthRequestToken) { Match tokenInformation = Regex.Match(requestTokenResponse, Resources.OAuthTokenRequestRegex); bool callbackConfirmed = Boolean.Parse(tokenInformation.Groups["oauth_callback_confirmed"].Value); if (!callbackConfirmed) { return(null); } temporaryCredentials.AuthorizationKey = tokenInformation.Groups["oauth_token"].Value; temporaryCredentials.AuthorizationSecret = tokenInformation.Groups["oauth_token_secret"].Value; return(String.Format("{0}?oauth_token={1}", Resources.OAuthRequestAuthorize, temporaryCredentials.AuthorizationKey)); } } catch (TwitterException ex) { LogExceptionOrThrow(ex); } return(null); }
// Step 2 - Generate User Credentials public IOAuthCredentials GetCredentialsFromVerifierCode(string verifierCode, ITemporaryCredentials temporaryCredentials) { try { var callbackParameter = _oAuthWebRequestGenerator.GenerateParameter("oauth_verifier", verifierCode, true, true, false); var response = _twitterRequestHandler.ExecuteQueryWithTemporaryCredentials(Resources.OAuthRequestAccessToken, HttpMethod.POST, temporaryCredentials, new[] { callbackParameter }); if (response == null) { return(null); } Match responseInformation = Regex.Match(response, Resources.OAuthTokenAccessRegex); if (responseInformation.Groups["oauth_token"] == null || responseInformation.Groups["oauth_token_secret"] == null) { return(null); } var credentials = _credentialsFactory.CreateOAuthCredentials( responseInformation.Groups["oauth_token"].Value, responseInformation.Groups["oauth_token_secret"].Value, temporaryCredentials.ConsumerKey, temporaryCredentials.ConsumerSecret); return(credentials); } catch (TwitterException ex) { if (_exceptionHandler.LogExceptions) { _exceptionHandler.AddTwitterException(ex); } if (!_exceptionHandler.SwallowWebExceptions) { throw; } } return(null); }