Exemplo n.º 1
0
        private void DoPinAuth()
        {
            pinAuth = new PinAuthorizer
            {
                Credentials = new InMemoryCredentials
                {
                    ConsumerKey    = "",
                    ConsumerSecret = ""
                },
                UseCompression           = true,
                GoToTwitterAuthorization = pageLink =>
                                           Dispatcher.BeginInvoke(() => WebBrowser.Navigate(new Uri(pageLink)))
            };

            pinAuth.BeginAuthorize(resp =>
                                   Dispatcher.BeginInvoke(() =>
            {
                switch (resp.Status)
                {
                case TwitterErrorStatus.Success:
                    break;

                case TwitterErrorStatus.TwitterApiError:
                case TwitterErrorStatus.RequestProcessingException:
                    MessageBox.Show(
                        resp.Exception.ToString(),
                        resp.Message,
                        MessageBoxButton.OK);
                    break;
                }
            }));

            twitterCtx = new TwitterContext(pinAuth);
        }
Exemplo n.º 2
0
        public void BeginAuthorize_Returns_If_Already_Authorized()
        {
            var oAuthMock = new Mock <IOAuthTwitter>();
            TwitterAsyncResponse <object> twitterResp = null;
            var pinAuth = new PinAuthorizer
            {
                Credentials = new InMemoryCredentials
                {
                    ConsumerKey    = "consumerkey",
                    ConsumerSecret = "consumersecret",
                    OAuthToken     = "oauthtoken",
                    AccessToken    = "accesstoken"
                },
                OAuthTwitter             = oAuthMock.Object,
                GetPin                   = () => "1234567",
                GoToTwitterAuthorization = link => { }
            };

            pinAuth.BeginAuthorize(resp => twitterResp = resp);

            oAuthMock.Verify(oauth =>
                             oauth.GetRequestTokenAsync(It.IsAny <Uri>(), It.IsAny <Uri>(), "oob", AuthAccessType.NoChange, false, It.IsAny <Action <string> >(), It.IsAny <Action <TwitterAsyncResponse <object> > >()),
                             Times.Never());
            Assert.Null(twitterResp);
        }
Exemplo n.º 3
0
        /**
         * In this function we firstly load the auth pin authorizer with the application credentials.
         * We also load the login twitter page in order to obtain the pin.
         */
        void OAuthPage_Loaded(object sender, RoutedEventArgs e)
        {
            //Auth definition with our application credentials
            auth = new PinAuthorizer
            {
                Credentials = new InMemoryCredentials
                {
                    ConsumerKey    = Constants.getConsumerKey(),
                    ConsumerSecret = Constants.getConsumerSecret()
                },
                UseCompression = true,
                //Browser authentication webpage
                GoToTwitterAuthorization = pageLink =>
                                           Dispatcher.RunAsync(CoreDispatcherPriority.Normal,
                                                               () => OAuthWebBrowser.Navigate(new Uri(pageLink, UriKind.Absolute)))
            };

            auth.BeginAuthorize(resp =>
                                Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
            {
                switch (resp.Status)
                {
                case TwitterErrorStatus.Success:
                    break;

                case TwitterErrorStatus.RequestProcessingException:
                case TwitterErrorStatus.TwitterApiError:
                    //new MessageDialog(resp.Error.ToString(), resp.Message).ShowAsync();
                    break;
                }
            }));
        }
Exemplo n.º 4
0
        public void BeginAuthorize_Requires_GoToTwitterAuthorization_Handler()
        {
            var pinAuth = new PinAuthorizer
            {
                Credentials  = new InMemoryCredentials(),
                OAuthTwitter = new OAuthTwitterMock(),
                GetPin       = () => "1234567",
            };

            var ex = Assert.Throws <InvalidOperationException>(() => pinAuth.BeginAuthorize(resp => { }));

            Assert.True(ex.Message.Contains("GoToTwitterAuthorization"));
        }
Exemplo n.º 5
0
        public void BeginAuthorize_Invokes_AuthorizationCompleteCallback()
        {
            var pinAuth = new PinAuthorizer
            {
                Credentials              = new InMemoryCredentials(),
                OAuthTwitter             = new OAuthTwitterMock(),
                GetPin                   = () => "1234567",
                GoToTwitterAuthorization = link => { }
            };
            TwitterAsyncResponse <object> twitterResp = null;

            pinAuth.BeginAuthorize(resp => twitterResp = resp);

            Assert.NotNull(twitterResp);
        }
Exemplo n.º 6
0
        public void BeginAuthorize_Gets_Request_Token()
        {
            var oauthRequestTokenUrl = new Uri("https://api.twitter.com/oauth/request_token");
            var oauthAuthorizeUrl    = new Uri("https://api.twitter.com/oauth/authorize");
            var oAuthMock            = new Mock <IOAuthTwitter>();
            var pinAuth = new PinAuthorizer
            {
                Credentials              = new InMemoryCredentials(),
                OAuthTwitter             = oAuthMock.Object,
                GetPin                   = () => "1234567",
                GoToTwitterAuthorization = link => { }
            };

            pinAuth.BeginAuthorize(resp => { });

            oAuthMock.Verify(oAuth =>
                             oAuth.GetRequestTokenAsync(oauthRequestTokenUrl, oauthAuthorizeUrl, "oob", AuthAccessType.NoChange, false, It.IsAny <Action <string> >(), It.IsAny <Action <TwitterAsyncResponse <object> > >()),
                             Times.Once());
        }