public void BeginAuthorization_Sets_ForceLogin() { const string RequestUrl = "https://api.twitter.com/"; var signInAuth = new SignInAuthorizer {Credentials = new InMemoryCredentials()}; var oAuthMock = new Mock<IOAuthTwitter>(); signInAuth.OAuthTwitter = oAuthMock.Object; oAuthMock.Setup(oauth => oauth.FilterRequestParameters(It.IsAny<Uri>())).Returns(RequestUrl); string authUrl = string.Empty; signInAuth.PerformRedirect = url => authUrl = url; signInAuth.BeginAuthorization(new Uri(RequestUrl), forceLogin: true); oAuthMock.Verify(oAuth => oAuth.AuthorizationLinkGet(It.IsAny<string>(), It.IsAny<string>(), RequestUrl, true, AuthAccessType.NoChange), Times.Once()); Assert.Null(authUrl); }
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 SignInAuthorizer { Credentials = new InMemoryCredentials { ConsumerKey = ConfigurationManager.AppSettings["twitterConsumerKey"], ConsumerSecret = ConfigurationManager.AppSettings["twitterConsumerSecret"] }, PerformRedirect = authUrl => Response.Redirect(authUrl) }; if (!Page.IsPostBack) { if (!string.IsNullOrWhiteSpace(credentials.ConsumerKey) && !string.IsNullOrWhiteSpace(credentials.ConsumerSecret)) { AuthMultiView.ActiveViewIndex = 1; if (auth.CompleteAuthorization(Request.Url)) { AuthMultiView.SetActiveView(SignedInView); screenNameLabel.Text = auth.ScreenName; } } } }