Example #1
0
        /// <summary>
        /// First part of the authorization sequence that:
        /// 1. Obtains a request token and then
        /// 2. Redirects to the Twitter authorization page
        /// </summary>
        /// <param name="forceLogin">Forces user to login for Sign-In with Twitter scenarios</param>
        /// <param name="callback">This is where you want Twitter to redirect to after authorization</param>
        public void BeginAuthorization(Uri callback, bool forceLogin)
        {
            if (IsAuthorized)
            {
                return;
            }

            string callbackStr = OAuthTwitter.FilterRequestParameters(callback);
            string link        = OAuthTwitter.AuthorizationLinkGet(OAuthRequestTokenUrl, OAuthAuthorizeUrl, callbackStr, forceLogin, AuthAccessType);

            PerformRedirect(link);
        }
Example #2
0
        /// <summary>
        /// Perform authorization
        /// </summary>
        /// <param name="forceLogin">Force the user to enter their name.</param>
        public void Authorize(bool forceLogin)
        {
            if (IsAuthorized)
            {
                return;
            }

            if (GetPin == null)
            {
                throw new InvalidOperationException("GetPin must have a handler before calling Authorize.");
            }

            if (GoToTwitterAuthorization == null)
            {
                throw new InvalidOperationException("GoToTwitterAuthorization must have a handler before calling Authorize.");
            }

            string link = OAuthTwitter.AuthorizationLinkGet(OAuthRequestTokenUrl, OAuthAuthorizeUrl, "oob", forceLogin, AuthAccessType);

            GoToTwitterAuthorization(link);

            string verifier = GetPin();

            // TODO: Refactor to share similar logic with WebAuthorizer
            string oAuthToken =
                (from nameValPair in new Uri(link).Query.TrimStart('?').Split('&')
                 let pair = nameValPair.Split('=')
                            where pair[0] == "oauth_token"
                            select pair[1])
                .SingleOrDefault();

            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;
        }
Example #3
0
 /// <summary>
 /// Get the link to Twitter's authorization page for this application.
 /// </summary>
 /// <param name="readOnly">true for read-only, otherwise read/Write</param>
 /// <returns>The url with a valid request token, or a null string.</returns>
 public string GetAuthorizationPageLink(bool readOnly, bool forceLogin)
 {
     // TODO: setting readOnly to true doesn't seem to be working; no Twitter API documentation available; check again later - Joe
     // TODO: setting forceLogin to true doesn't seem to be working; no Twitter API documentation available; fix for bug in Twitter API pending; check again later - Joe
     return(OAuthTwitter.AuthorizationLinkGet(OAuthRequestTokenUrl, OAuthAuthorizeUrl, readOnly, forceLogin));
 }