示例#1
0
        public HttpWebRequest GetHttpGetRequest(Uri oauthUrl, string callbackUrl, AuthAccessType authAccessType)
        {
            string signedUrl   = null;
            string queryString = null;
            string callback    = callbackUrl ?? string.Empty;
            var    request     = new Request(oauthUrl.ToString());

            GetOAuthQueryString(HttpMethod.GET, request, callback, out signedUrl, out queryString);

            var finalUrl = ProxyUrl + request.FullUrl;

            var req = System.Net.WebRequest.Create(finalUrl) as HttpWebRequest;

            req.Headers[HttpRequestHeader.Authorization] = PrepareAuthHeader(queryString);
            req.Method = HttpMethod.GET.ToString();

#if !SILVERLIGHT || WINDOWS_PHONE
            req.Headers[HttpRequestHeader.AcceptEncoding] = "deflate,gzip";
#endif

#if !SILVERLIGHT && !NETFX_CORE
            req.ServicePoint.Expect100Continue = false;
            req.UserAgent = OAuthUserAgent;
            if (Proxy != null)
            {
                req.Proxy = Proxy;
            }
#endif
            return(req);
        }
示例#2
0
        /// <summary>
        /// Asynchronous request for OAuth access token
        /// </summary>
        /// <param name="verifier">Verification token provided by Twitter after user authorizes (7-digit number for Pin authorization too)</param>
        /// <param name="oauthAccessTokenUrl">Access token URL</param>
        /// <param name="twitterCallbackUrl">URL for your app that Twitter redirects to after authorization (null for Pin authorization)</param>
        /// <param name="authenticationCompleteCallback">Callback to application after response completes (contains UserID and ScreenName)</param>
        public void GetAccessTokenAsync(
            string verifier,
            Uri oauthAccessTokenUrl,
            string twitterCallbackUrl,
            AuthAccessType authAccessType,
            Action <TwitterAsyncResponse <UserIdentifier> > authenticationCompleteCallback)
        {
            OAuthVerifier = verifier;

            var req = GetHttpGetRequest(oauthAccessTokenUrl, twitterCallbackUrl, authAccessType);

            req.BeginGetResponse(
                new AsyncCallback(
                    ar =>
            {
                string screenName = string.Empty;
                string userID     = string.Empty;

                var twitterResponse = new TwitterAsyncResponse <UserIdentifier>();

                try
                {
                    var res = req.EndGetResponse(ar) as HttpWebResponse;

                    string accessTokenResponse = GetHttpResponse(res);

                    ProcessAccessTokenResponse(ref screenName, ref userID, accessTokenResponse);
                }
                catch (TwitterQueryException tqe)
                {
                    twitterResponse.Status    = TwitterErrorStatus.TwitterApiError;
                    twitterResponse.Message   = "Error while communicating with Twitter. Please see Error property for details.";
                    twitterResponse.Exception = tqe;
                }
                catch (Exception ex)
                {
                    twitterResponse.Status    = TwitterErrorStatus.TwitterApiError;
                    twitterResponse.Message   = "Error during LINQ to Twitter processing. Please see Error property for details.";
                    twitterResponse.Exception = ex;
                }
                finally
                {
                    if (authenticationCompleteCallback != null)
                    {
                        twitterResponse.State =
                            new UserIdentifier
                        {
                            ID         = userID,
                            UserID     = userID,
                            ScreenName = screenName
                        };
                        authenticationCompleteCallback(twitterResponse);
                    }
                }
            }), null);
        }
示例#3
0
        /// <summary>
        /// Asynchronous request for OAuth request token
        /// </summary>
        /// <param name="oauthRequestTokenUrl">Url to make initial request on</param>
        /// <param name="oauthAuthorizeUrl">Url to send user to for authorization</param>
        /// <param name="twitterCallbackUrl">Url for Twitter to redirect to after authorization (null for Pin authorization)</param>
        /// <param name="forceLogin">Should user be forced to log in to authorize this app</param>
        /// <param name="authorizationCallback">Lambda to let program perform redirect to authorization page</param>
        /// <param name="authenticationCompleteCallback">Lambda to invoke to let user know when authorization completes</param>
        public void GetRequestTokenAsync(
            Uri oauthRequestTokenUrl,
            Uri oauthAuthorizeUrl,
            string twitterCallbackUrl,
            AuthAccessType authAccessType,
            bool forceLogin,
            Action <string> authorizationCallback,
            Action <TwitterAsyncResponse <object> > authenticationCompleteCallback)
        {
            var req = GetHttpGetRequest(oauthRequestTokenUrl, twitterCallbackUrl, authAccessType);

            req.BeginGetResponse(
                new AsyncCallback(
                    ar =>
            {
                var twitterResponse = new TwitterAsyncResponse <object>();

                try
                {
                    var res = req.EndGetResponse(ar) as HttpWebResponse;

                    string requestTokenResponse = GetHttpResponse(res);

                    string authorizationUrl = PrepareAuthorizeUrl(oauthAuthorizeUrl.ToString(), forceLogin, requestTokenResponse);

                    authorizationCallback(authorizationUrl);
                }
                catch (TwitterQueryException tqe)
                {
                    twitterResponse.Status    = TwitterErrorStatus.TwitterApiError;
                    twitterResponse.Message   = "Error while communicating with Twitter. Please see Error property for details.";
                    twitterResponse.Exception = tqe;
                }
                catch (Exception ex)
                {
                    twitterResponse.Status    = TwitterErrorStatus.TwitterApiError;
                    twitterResponse.Message   = "Error during LINQ to Twitter processing. Please see Error property for details.";
                    twitterResponse.Exception = ex;
                }
                finally
                {
                    if (authenticationCompleteCallback != null)
                    {
                        authenticationCompleteCallback(twitterResponse);
                    }
                }
            }), null);
        }
        public AuthorizerBase(bool forceLogin, AuthAccessType accessType, string prefillScreenName)
        {
            ForceLogin          = forceLogin;
            AccessType          = accessType;
            PreFillScreenName   = prefillScreenName;
            SupportsCompression = true;

            if (string.IsNullOrWhiteSpace(UserAgent))
            {
                UserAgent = L2TKeys.DefaultUserAgent;
            }

            OAuthRequestTokenUrl = "https://api.twitter.com/oauth/request_token";
            OAuthAuthorizeUrl    = "https://api.twitter.com/oauth/authorize";
            OAuthAccessTokenUrl  = "https://api.twitter.com/oauth/access_token";
        }
        public AuthorizerBase(bool forceLogin, AuthAccessType accessType, string prefillScreenName)
        {
            ForceLogin = forceLogin;
            AccessType = accessType;
            PreFillScreenName = prefillScreenName;
            SupportsCompression = true;

            if (string.IsNullOrWhiteSpace(UserAgent))
                UserAgent = L2TKeys.DefaultUserAgent;

            OAuthRequestTokenUrl = "https://api.twitter.com/oauth/request_token";
            OAuthAuthorizeUrl = "https://api.twitter.com/oauth/authorize";
            OAuthAccessTokenUrl = "https://api.twitter.com/oauth/access_token";
        }
 public string oAuthWebRequest(HttpMethod method, string url, string postData, string callback, AuthAccessType authAccessType)
 {
     throw new NotImplementedException();
 }
示例#7
0
 public void GetRequestTokenAsync(Uri oauthRequestTokenUrl, Uri oauthAuthorizeUrl, string twitterCallbackUrl, AuthAccessType authAccessType, bool forceLogin, Action<string> authorizationCallback, Action<TwitterAsyncResponse<object>> authenticationCompleteCallback)
 {
     authenticationCompleteCallback(new TwitterAsyncResponse<object>());
 }
示例#8
0
 public string oAuthWebRequest(HttpMethod method, string url, string postData, string callback, AuthAccessType authAccessType)
 {
     throw new NotImplementedException();
 }
示例#9
0
 public string AuthorizationLinkGet(string requestToken, string authorizeUrl, string callback, bool forceLogin, AuthAccessType authAccessType)
 {
     throw new NotImplementedException();
 }
示例#10
0
 public void GetAccessTokenAsync(string verifier, Uri oauthAccessTokenUrl, string twitterCallbackUrl, AuthAccessType authAccessType, Action<TwitterAsyncResponse<UserIdentifier>> authenticationCompleteCallback)
 {
     authenticationCompleteCallback(new TwitterAsyncResponse<UserIdentifier>());
 }
示例#11
0
 public string AuthorizationLinkGet(string requestToken, string authorizeUrl, string callback, bool forceLogin, AuthAccessType authAccessType)
 {
     throw new NotImplementedException();
 }
示例#12
0
 public AspNetAuthorizer(bool forceLogin, AuthAccessType accessType, string preFillScreenName)
     : base(forceLogin, accessType, preFillScreenName)
 {
 }
示例#13
0
        /// <summary>
        /// Asynchronous request for OAuth access token
        /// </summary>
        /// <param name="verifier">Verification token provided by Twitter after user authorizes (7-digit number for Pin authorization too)</param>
        /// <param name="oauthAccessTokenUrl">Access token URL</param>
        /// <param name="twitterCallbackUrl">URL for your app that Twitter redirects to after authorization (null for Pin authorization)</param>
        /// <param name="authenticationCompleteCallback">Callback to application after response completes (contains UserID and ScreenName)</param>
        public void GetAccessTokenAsync(
            string verifier,
            Uri oauthAccessTokenUrl,
            string twitterCallbackUrl,
            AuthAccessType authAccessType,
            Action<TwitterAsyncResponse<UserIdentifier>> authenticationCompleteCallback)
        {
            OAuthVerifier = verifier;

            var req = GetHttpGetRequest(oauthAccessTokenUrl, twitterCallbackUrl, authAccessType);

            req.BeginGetResponse(
                new AsyncCallback(
                    ar =>
                    {
                        string screenName = string.Empty;
                        string userID = string.Empty;

                        var twitterResponse = new TwitterAsyncResponse<UserIdentifier>();

                        try
                        {

                            var res = req.EndGetResponse(ar) as HttpWebResponse;

                            string accessTokenResponse = GetHttpResponse(res);

                            ProcessAccessTokenResponse(ref screenName, ref userID, accessTokenResponse);
                        }
                        catch (TwitterQueryException tqe)
                        {
                            twitterResponse.Status = TwitterErrorStatus.TwitterApiError;
                            twitterResponse.Message = "Error while communicating with Twitter. Please see Error property for details.";
                            twitterResponse.Exception = tqe;
                        }
                        catch (Exception ex)
                        {
                            twitterResponse.Status = TwitterErrorStatus.TwitterApiError;
                            twitterResponse.Message = "Error during LINQ to Twitter processing. Please see Error property for details.";
                            twitterResponse.Exception = ex;
                        }
                        finally
                        {
                            if (authenticationCompleteCallback != null)
                            {
                                twitterResponse.State =
                                    new UserIdentifier
                                    {
                                        ID = userID,
                                        UserID = userID,
                                        ScreenName = screenName
                                    };
                                authenticationCompleteCallback(twitterResponse); 
                            }
                        }
                    }), null);

        }
示例#14
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 AuthorizationLinkGet(string requestToken, string authorizeUrl, string callback, bool forceLogin, AuthAccessType authAccessToken)
        {
            var request = new Request(requestToken);

            if (authAccessToken != AuthAccessType.NoChange)
            {
                request.RequestParameters.Add(
                    new QueryParameter(OAuthXAccessTypeKey, authAccessToken.ToString().ToLower()));
            }

            var response = OAuthWebRequest(HttpMethod.GET, request, null, EncodeToProtectMultiByteCharUrl(callback));

            return(PrepareAuthorizeUrl(authorizeUrl, forceLogin, response));
        }
示例#15
0
        /// <summary>
        /// Asynchronous request for OAuth request token
        /// </summary>
        /// <param name="oauthRequestTokenUrl">Url to make initial request on</param>
        /// <param name="oauthAuthorizeUrl">Url to send user to for authorization</param>
        /// <param name="twitterCallbackUrl">Url for Twitter to redirect to after authorization (null for Pin authorization)</param>
        /// <param name="forceLogin">Should user be forced to log in to authorize this app</param>
        /// <param name="authorizationCallback">Lambda to let program perform redirect to authorization page</param>
        /// <param name="authenticationCompleteCallback">Lambda to invoke to let user know when authorization completes</param>
        public void GetRequestTokenAsync(
            Uri oauthRequestTokenUrl, 
            Uri oauthAuthorizeUrl, 
            string twitterCallbackUrl, 
            AuthAccessType authAccessType,
            bool forceLogin, 
            Action<string> authorizationCallback, 
            Action<TwitterAsyncResponse<object>> authenticationCompleteCallback)
        {
            var req = GetHttpGetRequest(oauthRequestTokenUrl, twitterCallbackUrl, authAccessType);

            req.BeginGetResponse(
                new AsyncCallback(
                    ar =>
                    {
                        var twitterResponse = new TwitterAsyncResponse<object>();

                        try
                        {
                            var res = req.EndGetResponse(ar) as HttpWebResponse;

                            string requestTokenResponse = GetHttpResponse(res);

                            string authorizationUrl = PrepareAuthorizeUrl(oauthAuthorizeUrl.ToString(), forceLogin, requestTokenResponse);

                            authorizationCallback(authorizationUrl);
                        }
                        catch (TwitterQueryException tqe)
                        {
                            twitterResponse.Status = TwitterErrorStatus.TwitterApiError;
                            twitterResponse.Message = "Error while communicating with Twitter. Please see Error property for details.";
                            twitterResponse.Exception = tqe;
                        }
                        catch (Exception ex)
                        {
                            twitterResponse.Status = TwitterErrorStatus.TwitterApiError;
                            twitterResponse.Message = "Error during LINQ to Twitter processing. Please see Error property for details.";
                            twitterResponse.Exception = ex;
                        }
                        finally
                        {
                            if (authenticationCompleteCallback != null)
                            {
                                authenticationCompleteCallback(twitterResponse); 
                            }
                        }
                    }), null);
        }
示例#16
0
        public HttpWebRequest GetHttpGetRequest(Uri oauthUrl, string callbackUrl, AuthAccessType authAccessType)
        {
            string signedUrl = null;
            string queryString = null;
            string callback = callbackUrl ?? string.Empty;
            var request = new Request(oauthUrl.ToString());
            GetOAuthQueryString(HttpMethod.GET, request, callback, out signedUrl, out queryString);
            
            var finalUrl = ProxyUrl + request.FullUrl;

            var req = System.Net.WebRequest.Create(finalUrl) as HttpWebRequest;
            req.Headers[HttpRequestHeader.Authorization] = PrepareAuthHeader(queryString);
            req.Method = HttpMethod.GET.ToString();

#if !SILVERLIGHT || WINDOWS_PHONE
            req.Headers[HttpRequestHeader.AcceptEncoding] = "deflate,gzip";
#endif

#if !SILVERLIGHT && !NETFX_CORE
            req.ServicePoint.Expect100Continue = false;
            req.UserAgent = OAuthUserAgent;
            if (Proxy != null)
                req.Proxy = Proxy;
#endif
            return req;
        }
示例#17
0
 public PinAuthorizer(bool forceLogin, AuthAccessType accessType, string preFillScreenName)
     : base(forceLogin, accessType, preFillScreenName) { }
示例#18
0
 public PinAuthorizer(bool forceLogin, AuthAccessType accessType) 
     : base(forceLogin, accessType, null) { }
示例#19
0
 public void GetRequestTokenAsync(Uri oauthRequestTokenUrl, Uri oauthAuthorizeUrl, string twitterCallbackUrl, AuthAccessType authAccessType, bool forceLogin, Action <string> authorizationCallback, Action <TwitterAsyncResponse <object> > authenticationCompleteCallback)
 {
     authenticationCompleteCallback(new TwitterAsyncResponse <object>());
 }
示例#20
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 AuthorizationLinkGet(string requestToken, string authorizeUrl, string callback, bool forceLogin, AuthAccessType authAccessToken)
        {
            var request = new Request(requestToken);

            if (authAccessToken != AuthAccessType.NoChange)
            {
                request.RequestParameters.Add(
                    new QueryParameter(OAuthXAccessTypeKey, authAccessToken.ToString().ToLower()));
            }

            var response = OAuthWebRequest(HttpMethod.GET, request, null, EncodeToProtectMultiByteCharUrl(callback));

            return PrepareAuthorizeUrl(authorizeUrl, forceLogin, response);
        }
示例#21
0
 public void GetAccessTokenAsync(string verifier, Uri oauthAccessTokenUrl, string twitterCallbackUrl, AuthAccessType authAccessType, Action <TwitterAsyncResponse <UserIdentifier> > authenticationCompleteCallback)
 {
     authenticationCompleteCallback(new TwitterAsyncResponse <UserIdentifier>());
 }
示例#22
0
 public AspNetAuthorizer(bool forceLogin, AuthAccessType accessType)
     : base(forceLogin, accessType, null)
 {
 }
示例#23
0
 public PinAuthorizer(bool forceLogin, AuthAccessType accessType)
     : base(forceLogin, accessType, string.Empty)
 {
 }