Пример #1
0
        /*
         * Signature base string
         * POST&https%3A%2F%2Fapi.twitter.com%2F1.1%2Fstatuses%2Fupdate.json&oauth_consumer_key%3DLK2akZl6e6BMEAPDMxGueajSp%26oauth_nonce%3D768ae59f0653f5b289fe5305c1a55033%26oauth_signature_method%3DHMAC-SHA1%26oauth_timestamp%3D1405193441%26oauth_token%3D15244042-LXQPX5ILb2TpOvXc5gBgXsIFvMQo9Zvw0DyA7i2ve%26oauth_version%3D1.0%26status%3DMaybe%2520he%2527ll%2520finally%2520find%2520his%2520keys.%2520%2523peterfalk
         *
         * Authorization header
         * Authorization: OAuth oauth_consumer_key="LK2akZl6e6BMEAPDMxGueajSp", oauth_nonce="768ae59f0653f5b289fe5305c1a55033", oauth_signature="2VcjU41Ce7LaSHTW3iWjv%2FvLKhE%3D", oauth_signature_method="HMAC-SHA1", oauth_timestamp="1405193441", oauth_token="15244042-LXQPX5ILb2TpOvXc5gBgXsIFvMQo9Zvw0DyA7i2ve", oauth_version="1.0"
         *
         *
         */

        // http://d.hatena.ne.jp/kaorun/20140518/1400392292
        // http://peterfoot.net/2014/04/14/webauthenticationbroker-wp8/
        // http://blogs.msdn.com/b/wsdevsol/archive/2014/05/08/using-the-andcontinue-methods-in-windows-phone-silverlight-8-1-apps.aspx

        // http://msdn.microsoft.com/ja-jp/library/dn631755.aspx
        // http://msdn.microsoft.com/ja-jp/library/dn596094.aspx
        public void ContinueWebAuthentication(WebAuthenticationBrokerContinuationEventArgs args)
        {
            WebAuthenticationResult result = args.WebAuthenticationResult;

            // Process the authentication result
            switch (result.ResponseStatus)
            {
            case WebAuthenticationStatus.Success:
            {
                var response = result.ResponseData.ToString();

                this.oauthVerifier = twitterOAuth.ParseRedirectToAuthResponse(response);

                this.GetAccessTokenButton.IsEnabled = true;
                this.WriteLog(String.Format("OAuthVerifier:{0}", this.oauthVerifier.OAuthVerifier));

                break;
            }

            case WebAuthenticationStatus.UserCancel:
                break;

            case WebAuthenticationStatus.ErrorHttp:
            {
                var response = result.ResponseErrorDetail.ToString();
                this.WriteLog(String.Format("Error:ContinueWebAuthentication:{0}", response));
                break;
            }

            default:
                break;
            }
        }
        //WebBrowser_Navigated:https://api.twitter.com/oauth/authorize?oauth_token=jgokD0HJa8YYL4jk0HgGIp00h5fGusXBwlwmpGJu5s
        //WebBrowser_Navigated:https://api.twitter.com/oauth/authorize
        //WebBrowser_Navigated:http://app.strawhat.net/api/KumatterSimpleClient?oauth_token=jgokD0HJa8YYL4jk0HgGIp00h5fGusXBwlwmpGJu5s&oauth_verifier=3mjYKwm0oTD42E5VcZpQ7WnSyhkMzERdWxUTK4JS0S0
        private void WebBrowser_Navigated(object sender, NavigationEventArgs e)
        {
            this.WriteLog(String.Format("WebBrowser_Navigated:{0}", e.Uri.ToString()));

            if (e.Uri.AbsoluteUri.StartsWith(OAuthCallbackUrl))
            {
                var response = this.twitterOAuth.ParseRedirectToAuthResponse(e.Uri.AbsoluteUri);
                this.WriteLog(String.Format("OAuthVerifier:{0}", response.OAuthVerifier));
                this.oauthVerifier = response;

                this.WebBrowser.Visibility = System.Windows.Visibility.Collapsed;
            }

            return;
        }
        private async void RedirectToAuthButton_Click(object sender, RoutedEventArgs e)
        {
            if (this.requestToken != null)
            {
                var redirectUrl = this.twitterOAuth.GetRedirectAuthUrl(this.requestToken);
                this.WriteLog(String.Format("Redirect URI:{0}", redirectUrl));


                Uri StartUri = new Uri(redirectUrl);
                Uri EndUri   = new Uri(TwitterOAuthConstants.OAuthCallbackUrl);
                var WebAuthenticationResult
                    = await WebAuthenticationBroker.AuthenticateAsync(WebAuthenticationOptions.None, StartUri, EndUri);

                if (WebAuthenticationResult.ResponseStatus == WebAuthenticationStatus.Success)
                {
                    var response = WebAuthenticationResult.ResponseData.ToString();

                    this.oauthVerifier = twitterOAuth.ParseRedirectToAuthResponse(response);

                    this.GetAccessTokenButton.IsEnabled = true;
                    this.WriteLog(String.Format("OAuthVerifier:{0}", this.oauthVerifier.OAuthVerifier));
                }
            }
        }