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); }
/// <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); }
/// <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(); }
public void GetRequestTokenAsync(Uri oauthRequestTokenUrl, Uri oauthAuthorizeUrl, string twitterCallbackUrl, AuthAccessType authAccessType, bool forceLogin, Action<string> authorizationCallback, Action<TwitterAsyncResponse<object>> authenticationCompleteCallback) { authenticationCompleteCallback(new TwitterAsyncResponse<object>()); }
public string AuthorizationLinkGet(string requestToken, string authorizeUrl, string callback, bool forceLogin, AuthAccessType authAccessType) { throw new NotImplementedException(); }
public void GetAccessTokenAsync(string verifier, Uri oauthAccessTokenUrl, string twitterCallbackUrl, AuthAccessType authAccessType, Action<TwitterAsyncResponse<UserIdentifier>> authenticationCompleteCallback) { authenticationCompleteCallback(new TwitterAsyncResponse<UserIdentifier>()); }
public AspNetAuthorizer(bool forceLogin, AuthAccessType accessType, string preFillScreenName) : base(forceLogin, accessType, preFillScreenName) { }
/// <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); }
/// <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)); }
/// <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 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; }
public PinAuthorizer(bool forceLogin, AuthAccessType accessType, string preFillScreenName) : base(forceLogin, accessType, preFillScreenName) { }
public PinAuthorizer(bool forceLogin, AuthAccessType accessType) : base(forceLogin, accessType, null) { }
public void GetRequestTokenAsync(Uri oauthRequestTokenUrl, Uri oauthAuthorizeUrl, string twitterCallbackUrl, AuthAccessType authAccessType, bool forceLogin, Action <string> authorizationCallback, Action <TwitterAsyncResponse <object> > authenticationCompleteCallback) { authenticationCompleteCallback(new TwitterAsyncResponse <object>()); }
/// <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); }
public void GetAccessTokenAsync(string verifier, Uri oauthAccessTokenUrl, string twitterCallbackUrl, AuthAccessType authAccessType, Action <TwitterAsyncResponse <UserIdentifier> > authenticationCompleteCallback) { authenticationCompleteCallback(new TwitterAsyncResponse <UserIdentifier>()); }
public AspNetAuthorizer(bool forceLogin, AuthAccessType accessType) : base(forceLogin, accessType, null) { }
public PinAuthorizer(bool forceLogin, AuthAccessType accessType) : base(forceLogin, accessType, string.Empty) { }