/// <summary>
        /// After the user Authorizes the app, Twitter will
        /// redirect to the callback url, provided during
        /// BeginAuthorization. When redirecting, Twitter will
        /// also provide oauth_verifier and oauth_token
        /// parameters. This method uses those parameters to
        /// request an access token, which is used automatically
        /// by LINQ to Twitter when executing queries.
        /// </summary>
        /// <param name="callback">URL that Twitter redirected to after authorization</param>
        /// <returns>True if successful</returns>
        public bool CompleteAuthorization(Uri callback)
        {
            if (callback == null)
            {
                throw new ArgumentNullException("callback", "You must pass in the callback that Twitter returned after authentication.");
            }

            if (IsAuthorized)
            {
                return(true);
            }

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

            if (verifier != null)
            {
                string oAuthToken = OAuthTwitter.GetUrlParamValue(callback.Query, "oauth_token");

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

                ScreenName = screenName;
                UserId     = userID;

                Credentials.OAuthToken  = OAuthTwitter.OAuthToken;
                Credentials.AccessToken = OAuthTwitter.OAuthTokenSecret;
                Credentials.ScreenName  = screenName;
                Credentials.UserId      = userID;
            }

            return(IsAuthorized);
        }
Beispiel #2
0
        /// <summary>
        /// Asynchronously finishes the authorization process
        /// </summary>
        /// <param name="callback">Callback Url that Twitter has added parameters to</param>
        /// <param name="authorizationCompleteCallback">Action you provide for when authorization completes.</param>
        public void CompleteAuthorize(Uri callback, Action <TwitterAsyncResponse <UserIdentifier> > authorizationCompleteCallback)
        {
            if (IsAuthorized)
            {
                return;
            }

            const int QueryPart = 1;

            string[] callbackParts = callback.OriginalString.Split('?');

            if (callbackParts.Length == 2)
            {
                string oauthToken = OAuthTwitter.GetUrlParamValue(callbackParts[QueryPart], "oauth_token");
                Credentials.OAuthToken  = oauthToken;
                OAuthTwitter.OAuthToken = oauthToken;

                // we have to split on # because Twitter appends #PageName at the end of the url,
                // which identifies the Silverlight page to navigate to, but is not part of the verifier
                string verifier =
                    OAuthTwitter
                    .GetUrlParamValue(callbackParts[QueryPart], "oauth_verifier")
                    .Split('#')[0];

                if (verifier != null)
                {
                    OAuthTwitter.GetAccessTokenAsync(verifier, new Uri(OAuthAccessTokenUrl), null, authorizationCompleteCallback);
                }
            }
        }