Exemplo n.º 1
0
        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);
        }
Exemplo n.º 2
0
    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;
                }
            }
        }
    }
Exemplo n.º 3
0
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                auth = new SignInAuthorizer
                {
                    Credentials = new SessionStateCredentials
                    {
                        ConsumerKey    = ConfigurationManager.AppSettings["TwitterConsumerKey"],
                        ConsumerSecret = ConfigurationManager.AppSettings["TwitterConsumerSecret"]
                    },
                    PerformRedirect =
                        twitterUrl => Response.Redirect(twitterUrl, false)
                };

                if (!auth.IsAuthorized)
                {
                    auth.BeginAuthorization(Request.Url);
                }
                auth.CompleteAuthorization(Request.Url);

                getUserDetails();
            }
        }