/// <summary> /// Initializes a new instance of the <see cref="SimpleConsumerTokenManager"/> class. /// </summary> /// <param name="consumerKey">The consumer key.</param> /// <param name="consumerSecret">The consumer secret.</param> /// <param name="tokenManager">The OAuth token manager.</param> public SimpleConsumerTokenManager(string consumerKey, string consumerSecret, IOAuthTokenManager tokenManager) { Requires.NotNullOrEmpty(consumerKey, "consumerKey"); Requires.NotNullOrEmpty(consumerSecret, "consumerSecret"); Requires.NotNull(tokenManager, "oAuthTokenManager"); this.ConsumerKey = consumerKey; this.ConsumerSecret = consumerSecret; this.tokenManager = tokenManager; }
public ZoteroClient(string consumerKey, string consumerSecret, IOAuthTokenManager tokenManager) : base("Zotero", ZoteroServiceDescription, new SimpleConsumerTokenManager(consumerKey, consumerSecret, tokenManager)) { this.consumerKey = consumerKey; this.consumerSecret = consumerSecret; }
/// <summary> /// Initializes a new instance of the <see cref="SimpleConsumerTokenManager"/> class. /// </summary> /// <param name="consumerKey">The consumer key.</param> /// <param name="consumerSecret">The consumer secret.</param> /// <param name="tokenManager">The OAuth token manager.</param> public SimpleConsumerTokenManager(string consumerKey, string consumerSecret, IOAuthTokenManager tokenManager) { Requires.NotNullOrEmpty(consumerKey, "consumerKey"); Requires.NotNullOrEmpty(consumerSecret, "consumerSecret"); Requires.NotNull(tokenManager, "oAuthTokenManager"); this.ConsumerKey = consumerKey; this.ConsumerSecret = consumerSecret; this.tokenManager = tokenManager; }
/// <summary> /// Initializes a new instance of the <see cref="LinkedInClient"/> class. /// </summary> /// <param name="consumerKey">The consumer key.</param> /// <param name="consumerSecret">The consumer secret.</param> /// <param name="tokenManager">The token manager.</param> public LinkedInClient(string consumerKey, string consumerSecret, IOAuthTokenManager tokenManager) : base("linkedIn", LinkedInServiceDescription, new SimpleConsumerTokenManager(consumerKey, consumerSecret, tokenManager)) { }
public BitBucketAuthenticationClient(string consumerKey, string consumerSecret, IOAuthTokenManager tokenManager) : base("BitBucket", BitBucketServiceDescription, new SimpleConsumerTokenManager(consumerKey, consumerSecret, tokenManager)) { _consumerKey = consumerKey; _consumerSecret = consumerSecret; }
/// <summary> /// Initializes a new instance of the <see cref="TwitterClient"/> class. /// </summary> /// <param name="consumerKey">The consumer key.</param> /// <param name="consumerSecret">The consumer secret.</param> /// <param name="tokenManager">The token manager.</param> public TwitterClientEx(string consumerKey, string consumerSecret, IOAuthTokenManager tokenManager) : base("twitter", TwitterServiceDescription, new SimpleConsumerTokenManager(consumerKey, consumerSecret, tokenManager)) { }
/// <summary> /// Initializes a new instance of the <see cref="TwitterClient"/> class. /// </summary> /// <param name="consumerKey">The consumer key.</param> /// <param name="consumerSecret">The consumer secret.</param> /// <param name="tokenManager">The token manager.</param> public TwitterClient(string consumerKey, string consumerSecret, IOAuthTokenManager tokenManager) : base("twitter", TwitterServiceDescription, new SimpleConsumerTokenManager(consumerKey, consumerSecret, tokenManager)) { }
public AvansOAuthClient(string consumerKey, string consumerSecret, IOAuthTokenManager tokenManager) : base("avans", AvansServiceDescription, new SimpleConsumerTokenManager(consumerKey, consumerSecret, tokenManager)) { }
public AvansOAuthClient(string consumerKey, string consumerSecret, IOAuthTokenManager tokenManager) : base("avans", AvansServiceDescription, new SimpleConsumerTokenManager(consumerKey, consumerSecret, tokenManager)) { }
/// <summary> /// Initializes a new instance of the <see cref="TrelloClient"/> class. /// </summary> /// <param name="consumerKey">The consumer key. This is your Trello API key.</param> /// <param name="consumerSecret">The consumer secret. This is your Trello API Secret.</param> /// <param name="tokenManager">The token manager.</param> public TrelloClient(string consumerKey, string consumerSecret, IOAuthTokenManager tokenManager) : base(_providerName, TrelloServiceDescription, new SimpleConsumerTokenManager(consumerKey, consumerSecret, tokenManager)) { _consumerKey = consumerKey; }
/// <summary> /// Initializes a new instance of the <see cref="TrelloClient"/> class. /// </summary> /// <param name="consumerKey">The consumer key. This is your Trello API key.</param> /// <param name="consumerSecret">The consumer secret. This is your Trello API Secret.</param> /// <param name="tokenManager">The token manager.</param> public TrelloClient(string consumerKey, string consumerSecret, IOAuthTokenManager tokenManager) : base(_providerName, TrelloServiceDescription, new SimpleConsumerTokenManager(consumerKey, consumerSecret, tokenManager)) { _consumerKey = consumerKey; }
/// <summary> /// Initializes a new instance of the <see cref="LinkedInClient"/> class. /// </summary> /// <param name="consumerKey">The consumer key.</param> /// <param name="consumerSecret">The consumer secret.</param> /// <param name="tokenManager">The token manager.</param> public LinkedInClient(string consumerKey, string consumerSecret, IOAuthTokenManager tokenManager) : base("linkedIn", LinkedInServiceDescription, new SimpleConsumerTokenManager(consumerKey, consumerSecret, tokenManager)) { }
GetFirstSalesforceObjectPageAsync <T>(int partyId, Func <Task <ResponseBase <SalesforceQueryResponseData <T>, IList <SalesforceError> > > > getFirstPageFunc, ISalesforceServiceClientV2 svcSalesforce, IOAuthTokenManager oauthTokenManager, ILogTrace logTrace) { var domain = $"GetFirstSalesforce{typeof(T).Name}Page"; var startedAt = DateTime.UtcNow; // send request to get the first batch from Salesforce var res = await getFirstPageFunc(); logTrace?.Add(LogLevel.Info, domain, "First try", startedAt); // success case if (res.Status == HttpStatusCode.OK) { return(res); } // error case var errorCode = res.Error?.FirstOrDefault()?.ErrorCode; if (errorCode == null) { throw new Exception($"{domain} - Status {res.Status} - Message {res.ErrorString}"); } if (errorCode != "INVALID_SESSION_ID") { throw new Exception( $"{domain} - Status {res.Status} - Code {errorCode} - Message {res.ErrorString}" ); } logTrace?.Add(LogLevel.Info, domain, "AccessToken expired"); // try to refresh token startedAt = DateTime.UtcNow; var oauthToken = await oauthTokenManager.RefreshAccessTokenAsync <SalesforceOAuthError>( new RefreshAccessTokenRequest { PartyId = partyId, MaxRetries = 5, RetryWaitSecondsIfFailed = 5 }, logTrace); if (oauthToken == null) { logTrace?.Add(LogLevel.Warning, domain, "Refresh Token Failed.", startedAt); throw new IgnoreProcessingMessageException("Refresh Token Failed.", $"Failed to RefreshAccessToken for partyId = {partyId}"); } logTrace?.Add(LogLevel.Info, domain, "AccessToken refreshed", startedAt); // update the access token in svcSalesforce svcSalesforce.AccessToken = oauthToken.AccessToken; // try again startedAt = DateTime.UtcNow; res = await getFirstPageFunc(); logTrace?.Add(LogLevel.Info, domain, "Task retried", startedAt); // success case if (res.Status == HttpStatusCode.OK) { return(res); } // error case throw new Exception($"{domain} - Status {res.Status} - Code {errorCode} - Message {res.ErrorString}"); }
/// <summary>Gets all salesforce objects asynchronous.</summary> /// <typeparam name="T"></typeparam> /// <param name="partyId">The party identifier.</param> /// <param name="getFirstPageFunc">The get first page function.</param> /// <param name="svcSalesforce">The SVC salesforce.</param> /// <param name="oauthTokenManager">The oauth token manager.</param> /// <param name="logTrace">The log trace.</param> /// <returns></returns> public static async Task <IList <T> > GetAllSalesforceObjectsAsync <T>(int partyId, Func <Task <ResponseBase <SalesforceQueryResponseData <T>, IList <SalesforceError> > > > getFirstPageFunc, ISalesforceServiceClientV2 svcSalesforce, IOAuthTokenManager oauthTokenManager, ILogTrace logTrace) { var startedAt = DateTime.UtcNow; // send request to get the first batch from Salesforce var firstTopicsRes = await GetFirstSalesforceObjectPageAsync(partyId, getFirstPageFunc, svcSalesforce, oauthTokenManager, logTrace); var sfObjects = firstTopicsRes.Data.Records; // repeat until all the topics are retrieved, just in case, usually there won't be more than 1000 topics var nextRecordUrl = firstTopicsRes.Data.NextRecordsUrl; while (nextRecordUrl != null) { var nextTopicsRes = await svcSalesforce.GetNextPageAsync(firstTopicsRes.Data); nextRecordUrl = nextTopicsRes.Data.NextRecordsUrl; sfObjects = sfObjects.Concat(nextTopicsRes.Data.Records).ToList(); } logTrace?.Add(LogLevel.Info, $"GetAllSalesforce{typeof(T).Name}Async() - Done", $"{typeof(T).Name}s #{sfObjects.Count}", startedAt); return(sfObjects.ToList()); }