public IEnumerable<IOAuthQueryParameter> GenerateApplicationParameters( IConsumerCredentials temporaryCredentials, IAuthenticationToken authenticationToken = null, IEnumerable<IOAuthQueryParameter> additionalParameters = null) { var headers = GenerateConsumerParameters(temporaryCredentials).ToList(); // Add Header for authenticated connection to a Twitter Application if (authenticationToken != null && !string.IsNullOrEmpty(authenticationToken.AuthorizationKey) && !string.IsNullOrEmpty(authenticationToken.AuthorizationSecret)) { headers.Add(new OAuthQueryParameter("oauth_token", StringFormater.UrlEncode(authenticationToken.AuthorizationKey), true, true, false)); headers.Add(new OAuthQueryParameter("oauth_token_secret", StringFormater.UrlEncode(authenticationToken.AuthorizationSecret), false, false, true)); } else { headers.Add(new OAuthQueryParameter("oauth_token", "", false, false, true)); } if (additionalParameters != null) { headers.AddRange(additionalParameters); } return headers; }
protected void CopyPropertiesToClone(IConsumerCredentials clone) { clone.ApplicationOnlyBearerToken = ApplicationOnlyBearerToken; clone.AuthorizationKey = AuthorizationKey; clone.AuthorizationSecret = AuthorizationSecret; clone.VerifierCode = VerifierCode; }
public IEnumerable <IOAuthQueryParameter> GenerateApplicationParameters( IConsumerCredentials temporaryCredentials, IAuthenticationToken authenticationToken = null, IEnumerable <IOAuthQueryParameter> additionalParameters = null) { var headers = GenerateConsumerParameters(temporaryCredentials).ToList(); // Add Header for authenticated connection to a Twitter Application if (authenticationToken != null && !string.IsNullOrEmpty(authenticationToken.AuthorizationKey) && !string.IsNullOrEmpty(authenticationToken.AuthorizationSecret)) { headers.Add(new OAuthQueryParameter("oauth_token", StringFormater.UrlEncode(authenticationToken.AuthorizationKey), true, true, false)); headers.Add(new OAuthQueryParameter("oauth_token_secret", StringFormater.UrlEncode(authenticationToken.AuthorizationSecret), false, false, true)); } else { headers.Add(new OAuthQueryParameter("oauth_token", "", false, false, true)); } if (additionalParameters != null) { headers.AddRange(additionalParameters); } return(headers); }
public ITwitterCredentials GenerateToken(IConsumerCredentials appCredentials) { var callbackParameter = _oAuthWebRequestGenerator.GenerateParameter("oauth_verifier", appCredentials.VerifierCode, true, true, false); try { var authHandler = new AuthHttpHandler(callbackParameter); var response = _twitterRequestHandler.ExecuteQuery(Resources.OAuthRequestAccessToken, HttpMethod.POST, authHandler, new TwitterCredentials(appCredentials)); if (response == null) { return(null); } Match responseInformation = Regex.Match(response, "oauth_token=(?<oauth_token>(?:\\w|\\-)*)&oauth_token_secret=(?<oauth_token_secret>(?:\\w)*)&user_id=(?<user_id>(?:\\d)*)&screen_name=(?<screen_name>(?:\\w)*)"); var credentials = new TwitterCredentials(); credentials.AccessToken = responseInformation.Groups["oauth_token"].Value; credentials.AccessTokenSecret = responseInformation.Groups["oauth_token_secret"].Value; credentials.ConsumerKey = appCredentials.ConsumerKey; credentials.ConsumerSecret = appCredentials.ConsumerSecret; return(credentials); } catch (TwitterException ex) { LogExceptionOrThrow(ex); } return(null); }
public TwitterCredentials(IConsumerCredentials credentials) : base("", "") { if (credentials != null) { ConsumerKey = credentials.ConsumerKey; ConsumerSecret = credentials.ConsumerSecret; ApplicationOnlyBearerToken = credentials.ApplicationOnlyBearerToken; } }
public static string GetBearerTokenAuthorizationHeader(IConsumerCredentials credentials) { string concatenatedCredentials = StringFormater.UrlEncode(credentials.ConsumerKey) + ":" + StringFormater.UrlEncode(credentials.ConsumerSecret); byte[] credBytes = Encoding.UTF8.GetBytes(concatenatedCredentials); string base64Credentials = Convert.ToBase64String(credBytes); return("Basic " + base64Credentials); }
public static string GetBearerTokenAuthorizationHeader(IConsumerCredentials credentials) { string concatenatedCredentials = StringFormater.UrlEncode(credentials.ConsumerKey) + ":" + StringFormater.UrlEncode(credentials.ConsumerSecret); byte[] credBytes = Encoding.UTF8.GetBytes(concatenatedCredentials); string base64Credentials = Convert.ToBase64String(credBytes); return "Basic " + base64Credentials; }
public TwitterCredentials(IConsumerCredentials credentials) : base("", "") { if (credentials != null) { ConsumerKey = credentials.ConsumerKey; ConsumerSecret = credentials.ConsumerSecret; AuthorizationKey = credentials.AuthorizationKey; AuthorizationSecret = credentials.AuthorizationSecret; VerifierCode = credentials.VerifierCode; } }
// Step 1 - Generate Authorization URL public IAuthenticationContext InitAuthenticationProcess(IConsumerCredentials appCredentials, string callbackURL, string credsIdentifier) { try { var authContext = new AuthenticationContext(appCredentials); var token = authContext.Token; if (string.IsNullOrEmpty(callbackURL)) { callbackURL = Resources.OAuth_PINCode_CallbackURL; } else if (credsIdentifier != null) { _credentialsStore.CallbackAuthenticationContextStore.Add(credsIdentifier, authContext); callbackURL = callbackURL.AddParameterToQuery(Resources.RedirectRequest_CredsParamId, credsIdentifier); } var callbackParameter = _oAuthWebRequestGenerator.GenerateParameter("oauth_callback", callbackURL, true, true, false); var authHandler = new AuthHttpHandler(callbackParameter, authContext.Token); var requestTokenResponse = _twitterRequestHandler.ExecuteQuery( Resources.OAuthRequestToken, HttpMethod.POST, authHandler, new TwitterCredentials(appCredentials)); if (!string.IsNullOrEmpty(requestTokenResponse) && requestTokenResponse != Resources.OAuthRequestToken) { Match tokenInformation = Regex.Match(requestTokenResponse, Resources.OAuthTokenRequestRegex); bool callbackConfirmed; if (!bool.TryParse(tokenInformation.Groups["oauth_callback_confirmed"].Value, out callbackConfirmed) || !callbackConfirmed) { return(null); } token.AuthorizationKey = tokenInformation.Groups["oauth_token"].Value; token.AuthorizationSecret = tokenInformation.Groups["oauth_token_secret"].Value; authContext.AuthorizationURL = string.Format("{0}?oauth_token={1}", Resources.OAuthRequestAuthorize, token.AuthorizationKey); authContext.Token.AuthorizationUniqueIdentifier = credsIdentifier; return(authContext); } } catch (TwitterException ex) { LogExceptionOrThrow(ex); } return(null); }
public IEnumerable <IOAuthQueryParameter> GenerateConsumerParameters(IConsumerCredentials consumerCredentials) { var consumerHeaders = new List <IOAuthQueryParameter>(); // Add Header for every connection to a Twitter Application if (consumerCredentials != null && !String.IsNullOrEmpty(consumerCredentials.ConsumerKey) && !String.IsNullOrEmpty(consumerCredentials.ConsumerSecret)) { consumerHeaders.Add(new OAuthQueryParameter("oauth_consumer_key", StringFormater.UrlEncode(consumerCredentials.ConsumerKey), true, true, false)); consumerHeaders.Add(new OAuthQueryParameter("oauth_consumer_secret", StringFormater.UrlEncode(consumerCredentials.ConsumerSecret), false, false, true)); } return(consumerHeaders); }
public async Task <bool> TryToReplyToCrcChallenge(IWebhooksRequest request, IConsumerCredentials credentials) { var crcToken = request.GetQuery()["crc_token"]; if (crcToken.IsNullOrEmpty()) { return(false); } await ReplyToCrcChallengeRequest(crcToken[0], request, credentials).ConfigureAwait(false); return(true); }
public async Task <bool> CRCChallenge(HttpContext context, IConsumerCredentials credentials) { var crcToken = context.Request.Query["crc_token"]; if (!crcToken.IsNullOrEmpty()) { await ReplyToCRCChallengeRequest(crcToken, context, credentials); return(true); } return(false); }
// Step 1 - Generate Authorization URL public IAuthenticationContext InitAuthenticationProcess(IConsumerCredentials appCredentials, string callbackURL, bool updateQueryIsAuthorized) { try { var authContext = new AuthenticationContext(appCredentials); var token = authContext.Token; if (string.IsNullOrEmpty(callbackURL)) { callbackURL = Resources.OAuth_PINCode_CallbackURL; } else if (updateQueryIsAuthorized) { var credsIdentifier = Guid.NewGuid(); _credentialsStore.CallbackAuthenticationContextStore.Add(credsIdentifier, authContext); callbackURL = callbackURL.AddParameterToQuery(Resources.RedirectRequest_CredsParamId, credsIdentifier.ToString()); } var callbackParameter = _oAuthWebRequestGenerator.GenerateParameter("oauth_callback", callbackURL, true, true, false); var authHandler = new AuthHttpHandler(callbackParameter, authContext.Token); var requestTokenResponse = _twitterRequestHandler.ExecuteQuery(Resources.OAuthRequestToken, HttpMethod.POST, authHandler, new TwitterCredentials(appCredentials)); if (!string.IsNullOrEmpty(requestTokenResponse) && requestTokenResponse != Resources.OAuthRequestToken) { Match tokenInformation = Regex.Match(requestTokenResponse, Resources.OAuthTokenRequestRegex); bool callbackConfirmed = Boolean.Parse(tokenInformation.Groups["oauth_callback_confirmed"].Value); if (!callbackConfirmed) { return null; } token.AuthorizationKey = tokenInformation.Groups["oauth_token"].Value; token.AuthorizationSecret = tokenInformation.Groups["oauth_token_secret"].Value; authContext.AuthorizationURL = string.Format("{0}?oauth_token={1}", Resources.OAuthRequestAuthorize, token.AuthorizationKey); return authContext; } } catch (TwitterException ex) { LogExceptionOrThrow(ex); } return null; }
public IEnumerable<IOAuthQueryParameter> GenerateConsumerParameters(IConsumerCredentials consumerCredentials) { var consumerHeaders = new List<IOAuthQueryParameter>(); // Add Header for every connection to a Twitter Application if (consumerCredentials != null && !string.IsNullOrEmpty(consumerCredentials.ConsumerKey) && !string.IsNullOrEmpty(consumerCredentials.ConsumerSecret)) { consumerHeaders.Add(new OAuthQueryParameter("oauth_consumer_key", StringFormater.UrlEncode(consumerCredentials.ConsumerKey), true, true, false)); consumerHeaders.Add(new OAuthQueryParameter("oauth_consumer_secret", StringFormater.UrlEncode(consumerCredentials.ConsumerSecret), false, false, true)); } return consumerHeaders; }
public ITwitterCredentials GetCredentialsFromCallbackURL(string callbackURL, IConsumerCredentials appCredentials) { Match urlInformation = Regex.Match(callbackURL, Resources.OAuthToken_GetVerifierCode_Regex); String responseOAuthToken = urlInformation.Groups["oauth_token"].Value; String verifierCode = urlInformation.Groups["oauth_verifier"].Value; // Check that the callback URL response passed in is for our current credentials.... if (String.Equals(responseOAuthToken, appCredentials.AuthorizationKey)) { GetCredentialsFromVerifierCode(verifierCode, appCredentials); } return(null); }
public bool TryGetValue(string identifier, out IConsumerCredentials creds) { creds = null; if (string.IsNullOrEmpty(identifier)) { return false; } Guid id; if (!Guid.TryParse(identifier, out id)) { return false; } return TryGetValue(id, out creds); }
// Step 1 - Generate Authorization URL public string GetAuthorizationURL(IConsumerCredentials appCredentials, string callbackURL, bool updateQueryIsAuthorized) { try { if (string.IsNullOrEmpty(callbackURL)) { callbackURL = Resources.OAuth_PINCode_CallbackURL; } else if (updateQueryIsAuthorized) { var credsIdentifier = Guid.NewGuid(); _credentialsStore.CallbackCredentialsStore.Add(credsIdentifier, appCredentials); callbackURL = callbackURL.AddParameterToQuery(Resources.RedirectRequest_CredsParamId, credsIdentifier.ToString()); } var callbackParameter = _oAuthWebRequestGenerator.GenerateParameter("oauth_callback", callbackURL, true, true, false); var authHandler = new AuthHttpHandler(callbackParameter); var requestTokenResponse = _twitterRequestHandler.ExecuteQuery(Resources.OAuthRequestToken, HttpMethod.POST, authHandler, new TwitterCredentials(appCredentials)); if (!string.IsNullOrEmpty(requestTokenResponse) && requestTokenResponse != Resources.OAuthRequestToken) { Match tokenInformation = Regex.Match(requestTokenResponse, Resources.OAuthTokenRequestRegex); bool callbackConfirmed = Boolean.Parse(tokenInformation.Groups["oauth_callback_confirmed"].Value); if (!callbackConfirmed) { return(null); } appCredentials.AuthorizationKey = tokenInformation.Groups["oauth_token"].Value; appCredentials.AuthorizationSecret = tokenInformation.Groups["oauth_token_secret"].Value; return(String.Format("{0}?oauth_token={1}", Resources.OAuthRequestAuthorize, appCredentials.AuthorizationKey)); } } catch (TwitterException ex) { LogExceptionOrThrow(ex); } return(null); }
public bool TryGetValue(string identifier, out IConsumerCredentials creds) { creds = null; if (string.IsNullOrEmpty(identifier)) { return(false); } Guid id; if (!Guid.TryParse(identifier, out id)) { return(false); } return(TryGetValue(id, out creds)); }
// Step 2 - Generate User Credentials public ITwitterCredentials GetCredentialsFromVerifierCode(string verifierCode, IConsumerCredentials appCredentials) { try { var callbackParameter = _oAuthWebRequestGenerator.GenerateParameter("oauth_verifier", verifierCode, true, true, false); var authHandler = new AuthHttpHandler(callbackParameter); var response = _twitterRequestHandler.ExecuteQuery(Resources.OAuthRequestAccessToken, HttpMethod.POST, authHandler, new TwitterCredentials(appCredentials)); if (response == null) { return null; } Match responseInformation = Regex.Match(response, Resources.OAuthTokenAccessRegex); if (responseInformation.Groups["oauth_token"] == null || responseInformation.Groups["oauth_token_secret"] == null) { return null; } var credentials = new TwitterCredentials( appCredentials.ConsumerKey, appCredentials.ConsumerSecret, responseInformation.Groups["oauth_token"].Value, responseInformation.Groups["oauth_token_secret"].Value); return credentials; } catch (TwitterException ex) { if (_exceptionHandler.LogExceptions) { _exceptionHandler.AddTwitterException(ex); } if (!_exceptionHandler.SwallowWebExceptions) { throw; } } return null; }
private static IConsumerCredentials GetCrentialsFromId(string identifier, IConsumerCredentials appCredentials) { if (appCredentials == null || string.IsNullOrEmpty(appCredentials.AuthorizationKey) || string.IsNullOrEmpty(appCredentials.AuthorizationSecret)) { IConsumerCredentials creds; if (_credentialsStore.TryGetValue(identifier, out creds)) { appCredentials = creds; } else { if (appCredentials == null) { throw new ArgumentException("The credentials are required as the URL does not contain the credentials identifier."); } throw new ArgumentException("The credentials needs the AuthorizationKey and AuthorizationSecret to be set up as the URL does not contain the credentials identifier."); } } return(appCredentials); }
// ############## Step 1 - Authorization URL ############### public static IAuthenticationContext InitAuthentication(IConsumerCredentials appCredentials, string callbackURL = null) { return(_webTokenFactory.InitAuthenticationProcess(appCredentials, callbackURL, Guid.NewGuid().ToString())); }
public bool TryGetValue(Guid identifier, out IConsumerCredentials creds) { return _callbackCredentialsStore.TryGetValue(identifier, out creds); }
private static async Task ReplyToCRCChallengeRequest(string crcToken, HttpContext context, IConsumerCredentials credentials) { context.Response.ContentType = "application/json; charset=utf-8"; var crcResponseToken = CreateToken(crcToken, credentials.ConsumerSecret); var response = new { response_token = $"sha256={crcResponseToken}" }; await context.Response.WriteAsync(JsonConvert.SerializeObject(response)); }
/// <summary> /// Get the credentials from a PIN CODE/OAUTH VERIFIER provided by twitter.com to the user. /// /// This method generates the credentials from the ConsumerCredentials used to get the Authentication URL. /// </summary> /// <param name="verifierCode"> /// - PIN CODE Authentication : User enters the pin given on twitter.com /// - URL REDIRECT : Use the value of the 'oauth_verifier' url parameter. /// </param> /// <param name="authorizationId"> /// Authorization Id used to store the credentials before a redirect. /// This can be retrieved from the callback request 'authorization_id' parameter. /// </param> /// <param name="appCredentials"> /// If this parameter is set, the authorizationId will be used only if this object misses some required information. /// </param> public static ITwitterCredentials GetCredentialsFromVerifierCode(string verifierCode, string authorizationId, IConsumerCredentials appCredentials = null) { appCredentials = GetCrentialsFromId(authorizationId, appCredentials); return(_credentialsCreator.GetCredentialsFromVerifierCode(verifierCode, appCredentials)); }
protected void CopyPropertiesToClone(IConsumerCredentials clone) { clone.ApplicationOnlyBearerToken = ApplicationOnlyBearerToken; }
public bool TryGetValue(Guid identifier, out IConsumerCredentials creds) { return(_callbackCredentialsStore.TryGetValue(identifier, out creds)); }
public ITwitterCredentials GenerateToken(IConsumerCredentials appCredentials) { var callbackParameter = _oAuthWebRequestGenerator.GenerateParameter("oauth_verifier", appCredentials.VerifierCode, true, true, false); try { var authHandler = new AuthHttpHandler(callbackParameter); var response = _twitterRequestHandler.ExecuteQuery(Resources.OAuthRequestAccessToken, HttpMethod.POST, authHandler, new TwitterCredentials(appCredentials)); if (response == null) { return null; } Match responseInformation = Regex.Match(response, "oauth_token=(?<oauth_token>(?:\\w|\\-)*)&oauth_token_secret=(?<oauth_token_secret>(?:\\w)*)&user_id=(?<user_id>(?:\\d)*)&screen_name=(?<screen_name>(?:\\w)*)"); var credentials = new TwitterCredentials(); credentials.AccessToken = responseInformation.Groups["oauth_token"].Value; credentials.AccessTokenSecret = responseInformation.Groups["oauth_token_secret"].Value; credentials.ConsumerKey = appCredentials.ConsumerKey; credentials.ConsumerSecret = appCredentials.ConsumerSecret; return credentials; } catch (TwitterException ex) { LogExceptionOrThrow(ex); } return null; }
public ITwitterCredentials GetCredentialsFromCallbackURL(string callbackURL, IConsumerCredentials appCredentials) { Match urlInformation = Regex.Match(callbackURL, Resources.OAuthToken_GetVerifierCode_Regex); String responseOAuthToken = urlInformation.Groups["oauth_token"].Value; String verifierCode = urlInformation.Groups["oauth_verifier"].Value; // Check that the callback URL response passed in is for our current credentials.... if (String.Equals(responseOAuthToken, appCredentials.AuthorizationKey)) { GetCredentialsFromVerifierCode(verifierCode, appCredentials); } return null; }
/// <summary> /// Return an authentication context object containing an url that will let the user authenticate on twitter. /// If the callback url is null, the user will be redirected to PIN CODE authentication. /// If the callback url is defined, the user will be redirected to CALLBACK authentication. /// /// The 'authorization_id' parameter is added by Tweetinvi to simplify the retrieval of information to /// generate the credentials. Strict mode removes this parameter from your query and let you handle it your own way. /// </summary> public static IAuthenticationContext InitAuthentication_StrictMode(IConsumerCredentials appCredentials, string callbackURL = null) { return(_webTokenFactory.InitAuthenticationProcess(appCredentials, callbackURL, false)); }
public ITwitterCredentials GetCredentialsFromVerifierCode(string verifierCode, IConsumerCredentials appCredentials) { appCredentials.VerifierCode = verifierCode; return GenerateToken(appCredentials); }
public static IAuthenticationContext BeginCreateClient(IConsumerCredentials consumerCredentials) { return(AuthFlow.InitAuthentication(consumerCredentials)); }
// ############## Step 2 - Get the token from URL or pin code ############### /// <summary> /// Get the credentials from a PIN CODE/OAUTH VERIFIER provided by twitter.com to the user. /// /// This method generates the credentials from the ConsumerCredentials used to get the Authentication URL. /// </summary> /// <param name="verifierCode"> /// - PIN CODE Authentication : User enters the pin given on twitter.com /// - URL REDIRECT : Use the value of the 'oauth_verifier' url parameter. /// </param> /// <param name="appCredentials">Use the same credentials as the one given as a parameter to get the Authentication URL.</param> public static ITwitterCredentials GetCredentialsFromVerifierCode(string verifierCode, IConsumerCredentials appCredentials) { return(_credentialsCreator.GetCredentialsFromVerifierCode(verifierCode, appCredentials)); }
public AuthenticationContext(IConsumerCredentials consumerCredentials) { Token = new AuthenticationToken(); Token.ConsumerCredentials = consumerCredentials.Clone(); }
/// <summary> /// Get the credentials from a PIN CODE/OAUTH VERIFIER provided by twitter.com to the user. /// /// This method generates the credentials from the ConsumerCredentials used to get the Authentication URL. /// </summary> /// <param name="verifierCode"> /// - PIN CODE Authentication : User enters the pin given on twitter.com /// - URL REDIRECT : Use the value of the 'oauth_verifier' url parameter. /// </param> /// <param name="authorizationId"> /// Authorization Id used to store the credentials before a redirect. /// This can be retrieved from the callback request 'authorization_id' parameter. /// </param> /// <param name="appCredentials"> /// If this parameter is set, the authorizationId will be used only if this object misses some required information. /// </param> public static ITwitterCredentials GetCredentialsFromVerifierCode(string verifierCode, string authorizationId, IConsumerCredentials appCredentials = null) { appCredentials = GetCrentialsFromId(authorizationId, appCredentials); return _credentialsCreator.GetCredentialsFromVerifierCode(verifierCode, appCredentials); }
/// <summary> /// Return an authentication context object containing an url that will let the user authenticate on twitter. /// If the callback url is null, the user will be redirected to PIN CODE authentication. /// If the callback url is defined, the user will be redirected to CALLBACK authentication. /// /// The 'authorization_id' parameter is added by Tweetinvi to simplify the retrieval of information to /// generate the credentials. Strict mode removes this parameter from your query and let you handle it your own way. /// </summary> public static IAuthenticationContext InitAuthentication_StrictMode(IConsumerCredentials appCredentials, string callbackURL = null) { return _webTokenFactory.InitAuthenticationProcess(appCredentials, callbackURL, false); }
/// <summary> /// Get the credentials from an entire callback URL. /// Please note that the appCredentials needs to contain the AuthorizationKey and AuthorizationSecret set up as they were before the redirect. /// </summary> /// <param name="callbackURL">Provide the entire URL (including the params) of the received callback request.</param> /// <param name="appCredentials"> /// If this parameter is set, the credentials information will be extracted from it, /// otherwise, Tweetinvi will attempt to access the credentials associated with the 'authorization_id' parameter. /// </param> public static ITwitterCredentials GetCredentialsFromCallbackURL(string callbackURL, IConsumerCredentials appCredentials = null) { string verifierCode = _webTokenCreator.GetVerifierCodeFromCallbackURL(callbackURL); var credentialsId = callbackURL.GetURLParameter("authorization_id"); appCredentials = GetCrentialsFromId(credentialsId, appCredentials); return GetCredentialsFromVerifierCode(verifierCode, appCredentials); }
// Step 2 - Generate User Credentials public ITwitterCredentials GetCredentialsFromVerifierCode(string verifierCode, IConsumerCredentials appCredentials) { try { var callbackParameter = _oAuthWebRequestGenerator.GenerateParameter("oauth_verifier", verifierCode, true, true, false); var authHandler = new AuthHttpHandler(callbackParameter); var response = _twitterRequestHandler.ExecuteQuery(Resources.OAuthRequestAccessToken, HttpMethod.POST, authHandler, new TwitterCredentials(appCredentials)); if (response == null) { return(null); } Match responseInformation = Regex.Match(response, Resources.OAuthTokenAccessRegex); if (responseInformation.Groups["oauth_token"] == null || responseInformation.Groups["oauth_token_secret"] == null) { return(null); } var credentials = new TwitterCredentials( appCredentials.ConsumerKey, appCredentials.ConsumerSecret, responseInformation.Groups["oauth_token"].Value, responseInformation.Groups["oauth_token_secret"].Value); return(credentials); } catch (TwitterException ex) { if (_exceptionHandler.LogExceptions) { _exceptionHandler.AddTwitterException(ex); } if (!_exceptionHandler.SwallowWebExceptions) { throw; } } return(null); }
private static IConsumerCredentials GetCrentialsFromId(string identifier, IConsumerCredentials appCredentials) { if (appCredentials == null || string.IsNullOrEmpty(appCredentials.AuthorizationKey) || string.IsNullOrEmpty(appCredentials.AuthorizationSecret)) { IConsumerCredentials creds; if (_credentialsStore.TryGetValue(identifier, out creds)) { appCredentials = creds; } else { if (appCredentials == null) { throw new ArgumentException("The credentials are required as the URL does not contain the credentials identifier."); } throw new ArgumentException("The credentials needs the AuthorizationKey and AuthorizationSecret to be set up as the URL does not contain the credentials identifier."); } } return appCredentials; }
/// <summary> /// Return an URL that will let the user authenticate on twitter. /// If the callback url is null, the user will be redirected to PIN CODE authentication. /// If the callback url is defined, the user will be redirected to CALLBACK authentication. /// /// The 'authorization_id' parameter is added by Tweetinvi to simplify the retrieval of information to /// generate the credentials. Strict Mode removes this parameter from your query and let you handle it your way. /// </summary> public static string GetAuthorizationURL_StrictMode(IConsumerCredentials appCredentials, string callbackURL = null) { return _webTokenCreator.GetAuthorizationURL(appCredentials, callbackURL, false); }
public TwitterInvalidCredentialsException(IConsumerCredentials credentials) : base("The consumer key and consumer secret must be defined!") { Credentials = credentials; }
// ############## Step 2 - Get the token from URL or pin code ############### /// <summary> /// Get the credentials from a PIN CODE/OAUTH VERIFIER provided by twitter.com to the user. /// /// This method generates the credentials from the ConsumerCredentials used to get the Authentication URL. /// </summary> /// <param name="verifierCode"> /// - PIN CODE Authentication : User enters the pin given on twitter.com /// - URL REDIRECT : Use the value of the 'oauth_verifier' url parameter. /// </param> /// <param name="appCredentials">Use the same credentials as the one given as a parameter to get the Authentication URL.</param> public static ITwitterCredentials GetCredentialsFromVerifierCode(string verifierCode, IConsumerCredentials appCredentials) { return _credentialsCreator.GetCredentialsFromVerifierCode(verifierCode, appCredentials); }
/// <summary> /// Get the credentials from an entire callback URL. /// Please note that the appCredentials needs to contain the AuthorizationKey and AuthorizationSecret set up as they were before the redirect. /// </summary> /// <param name="callbackURL">Provide the entire URL (including the params) of the received callback request.</param> /// <param name="appCredentials"> /// If this parameter is set, the credentials information will be extracted from it, /// otherwise, Tweetinvi will attempt to access the credentials associated with the 'authorization_id' parameter. /// </param> public static ITwitterCredentials GetCredentialsFromCallbackURL(string callbackURL, IConsumerCredentials appCredentials = null) { string verifierCode = _webTokenCreator.GetVerifierCodeFromCallbackURL(callbackURL); var credentialsId = callbackURL.GetURLParameter("authorization_id"); appCredentials = GetCrentialsFromId(credentialsId, appCredentials); return(GetCredentialsFromVerifierCode(verifierCode, appCredentials)); }
/// <summary> /// Return an authentication context object containing an url that will let the user authenticate on twitter. /// If the callback url is null, the user will be redirected to PIN CODE authentication. /// If the callback url is defined, the user will be redirected to CALLBACK authentication. /// </summary> public static IAuthenticationContext InitAuthentication(IConsumerCredentials appCredentials, string callbackURL, string authenticationIdentifier) { return(_webTokenFactory.InitAuthenticationProcess(appCredentials, callbackURL, authenticationIdentifier)); }
/// <summary> /// Return an URL that will let the user authenticate on twitter. /// If the callback url is null, the user will be redirected to PIN CODE authentication. /// If the callback url is defined, the user will be redirected to CALLBACK authentication. /// /// The 'authorization_id' parameter is added by Tweetinvi to simplify the retrieval of information to /// generate the credentials. Strict Mode removes this parameter from your query and let you handle it your way. /// </summary> public static string GetAuthorizationURL_StrictMode(IConsumerCredentials appCredentials, string callbackURL = null) { return(_webTokenCreator.GetAuthorizationURL(appCredentials, callbackURL, false)); }
public ITwitterCredentials GetCredentialsFromVerifierCode(string verifierCode, IConsumerCredentials appCredentials) { appCredentials.VerifierCode = verifierCode; return(GenerateToken(appCredentials)); }
private async Task ReplyToCrcChallengeRequestAsync(string crcToken, IWebhooksRequest request, IConsumerCredentials credentials) { var crcResponseInfo = _webhooksHelper.CreateCrcResponseToken(crcToken, credentials.ConsumerSecret); await request.WriteInResponseAsync(crcResponseInfo.Json, crcResponseInfo.ContentType).ConfigureAwait(false); }