Beispiel #1
0
        public void FilterRequestParameters_Splits_Url_Properly()
        {
            var oaTwit  = new OAuthTwitter();
            var fullUrl = new Uri("http://www.mySite.com?oauth_token=123&p1=v1");

            string filteredUrl = oaTwit.FilterRequestParameters(fullUrl);

            Assert.Equal("http://www.mysite.com/?p1=v1", filteredUrl);
        }
        /// <summary>
        /// Performs authentication asynchronously, managing entire OAuth workflow
        /// </summary>
        /// <returns>TwitterAuthProviderUser with ScreenName and ID</returns>
        internal async Task <TwitterAuthProviderUser> AuthenticateAsync()
        {
            string callbackStr = OAuthTwitter.FilterRequestParameters(callback);
            string link        = OAuthTwitter.AuthorizationLinkGet(OAuthRequestTokenUrl, OAuthAuthorizeUrl, callbackStr, false, AuthAccessType);

            WebAuthenticationResult webAuthenticationResult =
                await WebAuthenticationBroker.AuthenticateAsync(
                    WebAuthenticationOptions.None,
                    new Uri(link),
                    callback);

            if (webAuthenticationResult.ResponseStatus == WebAuthenticationStatus.Success)
            {
                var authCallbackUri = new Uri(webAuthenticationResult.ResponseData);

                string verifier = OAuthTwitter.GetUrlParamValue(authCallbackUri.Query, "oauth_verifier");

                string oAuthToken = OAuthTwitter.GetUrlParamValue(authCallbackUri.Query, "oauth_token");

                string screenName;
                string userID;
                OAuthTwitter.AccessTokenGet(oAuthToken, verifier, OAuthAccessTokenUrl, string.Empty, out screenName, out userID);

                ScreenName = screenName;
                UserId     = userID;

                OAuthToken       = OAuthTwitter.OAuthToken;
                OAuthTokenSecret = OAuthTwitter.OAuthTokenSecret;

                return(new TwitterAuthProviderUser
                {
                    UserName = screenName,
                    Id = userID
                });
            }

            return(new TwitterAuthProviderUser
            {
                UserName = "",
                Id = ""
            });
        }