public void CompleteAuthorization_Gets_Access_Token() { string screenName = "JoeMayo"; string userID = "123"; const string Verifier = "1234567"; const string AuthToken = "token"; const string AuthLink = "https://authorizationlink?oauth_token=" + AuthToken + "&oauth_verifier=" + Verifier; var webAuth = new WebAuthorizer { Credentials = new InMemoryCredentials() }; var oAuthMock = new Mock <IOAuthTwitter>(); oAuthMock.Setup(oauth => oauth.GetUrlParamValue(It.IsAny <string>(), "oauth_verifier")).Returns(Verifier); oAuthMock.Setup(oauth => oauth.GetUrlParamValue(It.IsAny <string>(), "oauth_token")).Returns(AuthToken); oAuthMock.Setup(oAuth => oAuth.AuthorizationLinkGet(It.IsAny <string>(), It.IsAny <string>(), "https://authorizationlink", false, AuthAccessType.NoChange)) .Returns(AuthLink); oAuthMock.Setup(oAuth => oAuth.AccessTokenGet(AuthToken, Verifier, It.IsAny <string>(), string.Empty, out screenName, out userID)); webAuth.OAuthTwitter = oAuthMock.Object; webAuth.CompleteAuthorization(new Uri(AuthLink)); oAuthMock.Verify(oauth => oauth.AccessTokenGet(AuthToken, Verifier, It.IsAny <string>(), string.Empty, out screenName, out userID), Times.Once()); Assert.Equal(screenName, webAuth.ScreenName); Assert.Equal(userID, webAuth.UserId); }
protected void Page_Load(object sender, EventArgs e) { IOAuthCredentials creds = new SessionStateCredentials(); creds.ConsumerKey = ConfigurationManager.AppSettings["twitterConsumerKey"]; creds.ConsumerSecret = ConfigurationManager.AppSettings["twitterConsumerSecret"]; creds.AccessToken = ConfigurationManager.AppSettings["twitterAccessToken"]; creds.OAuthToken = ConfigurationManager.AppSettings["twitterOauthToken"]; //Auth Object With Credentials var auth = new WebAuthorizer { Credentials = creds }; var twitterCtx = new TwitterContext(auth); var users = (from user in twitterCtx.Status where user.Type == StatusType.User && user.ScreenName == "JoeMayo" && user.Count == 200 select user) .ToList(); UserListView.DataSource = users; UserListView.DataBind(); }
public MvcOAuthActionResult(WebAuthorizer webAuth) { _webAuth = webAuth; _services = EngineContext.Current.Resolve <ICommonServices>(); var factory = EngineContext.Current.Resolve <ILoggerFactory>(); Logger = factory.GetLogger(typeof(Log4netLogger)); }
public void BeginAuthorize_Requires_Credentials() { const string RequestUrl = "https://api.twitter.com/"; var webAuth = new WebAuthorizer(); var ex = Assert.Throws <ArgumentNullException>(() => webAuth.BeginAuthorization(new Uri(RequestUrl))); Assert.Equal("Credentials", ex.ParamName); }
public void CompleteAuthorization_Requires_Credentials() { const string AuthLink = "https://authorizationlink"; var webAuth = new WebAuthorizer(); var ex = Assert.Throws <ArgumentNullException>(() => webAuth.CompleteAuthorization(new Uri(AuthLink))); Assert.Equal("Credentials", ex.ParamName); }
protected void Page_Load(object sender, EventArgs e) { IOAuthCredentials credentials = new SessionStateCredentials(); if (credentials.ConsumerKey == null || credentials.ConsumerSecret == null) { credentials.ConsumerKey = ConfigurationManager.AppSettings["twitterConsumerKey"]; credentials.ConsumerSecret = ConfigurationManager.AppSettings["twitterConsumerSecret"]; } auth = new WebAuthorizer { Credentials = credentials, PerformRedirect = authUrl => Response.Redirect(authUrl) }; if (!Page.IsPostBack && Request.QueryString["oauth_token"] != null) { auth.CompleteAuthorization(Request.Url); } if (string.IsNullOrWhiteSpace(credentials.ConsumerKey) || string.IsNullOrWhiteSpace(credentials.ConsumerSecret)) { // The user needs to set up the web.config file to include Twitter consumer key and secret. PrivateDataMultiView.SetActiveView(SetupTwitterConsumer); } else if (auth.IsAuthorized) { screenNameLabel.Text = auth.ScreenName; PrivateDataMultiView.SetActiveView(ViewPrivateUpdates); updateBox.Focus(); } else { PrivateDataMultiView.SetActiveView(AuthorizeTwitter); } if (auth.IsAuthorized) { twitterCtx = new TwitterContext(auth); var search = (from srch in twitterCtx.Search where srch.Type == SearchType.Search && srch.Query == "LINQ to Twitter" select srch) .SingleOrDefault(); TwitterListView.DataSource = search.Statuses; TwitterListView.DataBind(); } }
public void CompleteAuthorization_Requires_A_Uri() { var webAuth = new WebAuthorizer { Credentials = new InMemoryCredentials() }; var oAuthMock = new Mock <IOAuthTwitter>(); webAuth.OAuthTwitter = oAuthMock.Object; var ex = Assert.Throws <ArgumentNullException>(() => webAuth.CompleteAuthorization(null)); Assert.Equal("callback", ex.ParamName); }
protected void Page_Load(object sender, EventArgs e) { IOAuthCredentials credentials = new SessionStateCredentials(); if (credentials.ConsumerKey == null || credentials.ConsumerSecret == null) { credentials.ConsumerKey = ConfigurationManager.AppSettings["twitterConsumerKey"]; credentials.ConsumerSecret = ConfigurationManager.AppSettings["twitterConsumerSecret"]; } auth = new WebAuthorizer { Credentials = credentials, PerformRedirect = authUrl => Response.Redirect(authUrl) };
public void BeginAuthorize_Does_Not_Require_A_Uri() { var webAuth = new WebAuthorizer { Credentials = new InMemoryCredentials() }; var oAuthMock = new Mock <IOAuthTwitter>(); webAuth.OAuthTwitter = oAuthMock.Object; string authUrl = string.Empty; webAuth.PerformRedirect = url => authUrl = url; webAuth.BeginAuthorization(null); Assert.Null(authUrl); }
public void BeginAuthorization_Calls_PerformRedirect() { const string RequestUrl = "https://api.twitter.com/"; var webAuth = new WebAuthorizer { Credentials = new InMemoryCredentials() }; var oAuthMock = new Mock <IOAuthTwitter>(); oAuthMock.Setup(oauth => oauth.FilterRequestParameters(It.IsAny <Uri>())).Returns(RequestUrl); webAuth.OAuthTwitter = oAuthMock.Object; string authUrl = string.Empty; webAuth.PerformRedirect = url => authUrl = url; webAuth.BeginAuthorization(new Uri(RequestUrl)); Assert.Null(authUrl); }
void OAuthForm_Load(object sender, EventArgs e) { auth = new WebAuthorizer { // Get the ConsumerKey and ConsumerSecret for your app and load them here. Credentials = new InMemoryCredentials { ConsumerKey = Twitter.ConsumerKey, ConsumerSecret = Twitter.ConsumerSecret }, Callback = new Uri("http://livesplit.org/twitter/"), // Note: GetPin isn't used here because we've broken the authorization // process into two parts: begin and complete PerformRedirect = pageLink => OAuthWebBrowser.Navigate(new Uri(pageLink, UriKind.Absolute)) }; auth.BeginAuthorization(new Uri("http://livesplit.org/twitter/")); }
public void BeginAuthorization_Gets_Request_Token() { const string RequestUrl = "https://api.twitter.com/"; var webAuth = new WebAuthorizer { Credentials = new InMemoryCredentials() }; var oAuthMock = new Mock <IOAuthTwitter>(); webAuth.OAuthTwitter = oAuthMock.Object; oAuthMock.Setup(oauth => oauth.FilterRequestParameters(It.IsAny <Uri>())).Returns(RequestUrl); string authUrl = string.Empty; webAuth.PerformRedirect = url => authUrl = url; webAuth.BeginAuthorization(new Uri(RequestUrl)); oAuthMock.Verify(oAuth => oAuth.AuthorizationLinkGet(It.IsAny <string>(), It.IsAny <string>(), RequestUrl, false, AuthAccessType.NoChange), Times.Once()); Assert.Null(authUrl); }
/// <summary> /// Gets a Twitter search result. /// </summary> /// <param name="query">Search query. /// API docs: https://dev.twitter.com/docs/api/1.1/get/search/tweets /// </param> /// <returns>Tweets found by search, or null if no results.</returns> public List <Status> GetTweetsBySearch(string query) { var auth = new WebAuthorizer { Credentials = new SessionStateCredentials() }; var twitterCtx = new TwitterContext(auth); var searchResults = from search in twitterCtx.Search where search.Type == SearchType.Search && search.Query == query select search; var searched = searchResults.SingleOrDefault(); if (searched != null) { return(searched.Statuses); } return(null); }
protected void Page_Load(object sender, EventArgs e) { IOAuthCredentials credentials = new InMemoryCredentials(); string authString = Session[OAuthCredentialsKey] as string; if (authString == null) { credentials.ConsumerKey = ConfigurationManager.AppSettings["twitterConsumerKey"]; credentials.ConsumerSecret = ConfigurationManager.AppSettings["twitterConsumerSecret"]; Session[OAuthCredentialsKey] = credentials.ToString(); } else { credentials.Load(authString); } auth = new WebAuthorizer { Credentials = new InMemoryCredentials { ConsumerKey = ConfigurationManager.AppSettings["twitterConsumerKey"], ConsumerSecret = ConfigurationManager.AppSettings["twitterConsumerSecret"] }, PerformRedirect = authUrl => Response.Redirect(authUrl) }; if (string.IsNullOrEmpty(credentials.ConsumerKey) || string.IsNullOrEmpty(credentials.ConsumerSecret) || !auth.IsAuthorized) { // Authorization occurs only on the home page. Response.Redirect("~/"); } updateBox.Focus(); }
public MvcOAuthActionResult(WebAuthorizer webAuth) { this.webAuth = webAuth; }