/// <summary> /// Does the authentication module supports pre-authentication? /// </summary> /// <param name="client">Client executing this request</param> /// <param name="request">Request to authenticate</param> /// <param name="credentials">The credentials to be used for the authentication</param> /// <returns>true when the authentication module supports pre-authentication</returns> public bool CanPreAuthenticate(IRestClient client, IRestRequest request, ICredentials credentials) { var cred = credentials?.GetCredential(client.BuildUri(request, false), AuthenticationMethod); if (cred == null) return false; return true; }
public AnswerFactoryDockableWindow(object hook) { this.InitializeComponent(); this.client = new RestClient(Settings.Default.baseUrl); this.GetToken(); this.Hook = hook; this.selectionTypecomboBox.SelectedIndex = 0; this.ProjIdRepo = CreateProjIdDataTable(); this.projectDataView = new DataView(this.ProjIdRepo); this.projectNameDataGridView.DataSource = this.projectDataView; var dataGridViewColumn = this.projectNameDataGridView.Columns["Id"]; if (dataGridViewColumn != null) { dataGridViewColumn.Visible = false; } this.RecipeRepo = CreateRecipeInfoDataDatable(); this.recipeStatusDataGridView.DataSource = this.RecipeRepo; var recipeGridDataCol0 = this.recipeStatusDataGridView.Columns["Recipe Name"]; if (recipeGridDataCol0 != null) { recipeGridDataCol0.AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; } var recipeGridDataCol1 = this.recipeStatusDataGridView.Columns["Status"]; if (recipeGridDataCol1 != null) { recipeGridDataCol1.AutoSizeMode = DataGridViewAutoSizeColumnMode.DisplayedCells; } this.selectedAois = new List<string>(); }
public GameUpdater(IRestClient restClient, string basePath, IVersionProvider versionProvider) { this._restClient = restClient; this._basePath = basePath; _versionProvider = versionProvider; this.SetupCurrentCulture(); }
/// <summary> /// Create the client /// </summary> /// <param name="client">The REST client that wants to create the HTTP client</param> /// <param name="request">The REST request for which the HTTP client is created</param> /// <returns>A new HttpClient object</returns> /// <remarks> /// The DefaultHttpClientFactory contains some helpful protected methods that helps gathering /// the data required for a proper configuration of the HttpClient. /// </remarks> public virtual IHttpClient CreateClient(IRestClient client, IRestRequest request) { var headers = new GenericHttpHeaders(); var httpClient = new DefaultHttpClient(this, headers) { BaseAddress = GetBaseAddress(client) }; if (client.Timeout.HasValue) { httpClient.Timeout = client.Timeout.Value; } var proxy = GetProxy(client); if (proxy != null) { httpClient.Proxy = new RequestProxyWrapper(proxy); } var cookieContainer = GetCookies(client, request); if (cookieContainer != null) { httpClient.CookieContainer = cookieContainer; } if (_setCredentials) { var credentials = client.Credentials; if (credentials != null) { httpClient.Credentials = credentials; } } return httpClient; }
public VideoResource(IRestClient client) : base(client) { resource = "videos"; creatableAttributes = new string[] {"encoding_profile_ids", "encoding_profile_tags", "skip_default_encoding_profiles", "use_original_as_transcoding"}; accessableAttributes = new string[] {"title", "description", "tags", "image_id"}; }
public void Authenticate(IRestClient client, IRestRequest request) { var token = Convert.ToBase64String(Encoding.UTF8.GetBytes(string.Format("{0}:{1}", _username, _password))); var authorizationHeader = string.Format("Basic {0}", token); client.Parameters.Add(new Parameter {Name = "Authorization", Value = authorizationHeader, Type = ParameterType.Header}); }
public NestApi(string accessToken) { _client = new RestClient() { AccessToken = accessToken, }; }
public PluginLoader( ILogger logger, IRestClient restClient) { _logger = logger; _restClient = restClient; }
public static void MoveObjects(IRestClient restClient, long[] pFileIds, long pFromId, long pToId, TransactionResponse transaction = null) { if (pFileIds == null || pFileIds.Length == 0) return; var createRequest = new RestRequest("api/rest/object/move/{id}", Method.POST); if (transaction != null) createRequest.AddParameter("transactionId", transaction.TransactionId); for (var i = 0; i < pFileIds.Length; i++) { if (i == 0) createRequest.AddUrlSegment("id", pFileIds[i].ToString("D")); else createRequest.AddParameter("id", pFileIds[i].ToString("D")); } createRequest.AddParameter("target", pToId.ToString("D")); createRequest.AddParameter("parameters", createRequest.JsonSerializer.Serialize(new { parent = new[] {pFromId.ToString("D")}, inheritAcl = true })); var tmpResponse = restClient.Execute<RestResponseBaseExt>(createRequest); ThrowIfNotSuccessful(tmpResponse); }
public DrainCommand(IApplicationConfiguration applicationConfiguration, IAccessTokenConfiguration accessTokenConfiguration, TextWriter writer) : base(applicationConfiguration) { _accessToken = accessTokenConfiguration.GetAccessToken(); _restClient = new RestClient(AppHarborBaseUrl); _writer = writer; }
public static void Logout(IRestClient restClient) { var request = new RestRequest("api/rest/session/logout", Method.POST); var responseData = restClient.Execute<RestResponseBaseExt>(request); //Dont throw Exception as it doesnt matter if Logout has worked //ThrowIfNotSuccessful(responseData); }
public void Authenticate(IRestClient client, IRestRequest request) { DateTime signingDate = DateTime.UtcNow; SetContentMd5(request); SetContentSha256(request); SetHostHeader(client, request); SetDateHeader(request, signingDate); SortedDictionary<string, string> headersToSign = GetHeadersToSign(request); string signedHeaders = GetSignedHeaders(headersToSign); string region = Regions.GetRegion(client.BaseUrl.Host); string canonicalRequest = GetCanonicalRequest(client, request, headersToSign); byte[] canonicalRequestBytes = System.Text.Encoding.UTF8.GetBytes(canonicalRequest); string canonicalRequestHash = BytesToHex(ComputeSha256(canonicalRequestBytes)); string stringToSign = GetStringToSign(region, canonicalRequestHash, signingDate); byte[] signingKey = GenerateSigningKey(region, signingDate); byte[] stringToSignBytes = System.Text.Encoding.UTF8.GetBytes(stringToSign); byte[] signatureBytes = SignHmac(signingKey, stringToSignBytes); string signature = BytesToHex(signatureBytes); string authorization = GetAuthorizationHeader(signedHeaders, signature, signingDate, region); request.AddHeader("Authorization", authorization); }
public TwitterClient(IRestClient client, string consumerKey, string consumerSecret, string callback) : base(client) { Encode = true; Statuses = new Statuses(this); Account = new Account(this); DirectMessages = new DirectMessages(this); Favourites = new Favourites(this); Block = new Block(this); Friendships = new Friendship(this); Lists = new List(this); Search = new Search(this); Users = new Users(this); FriendsAndFollowers = new FriendsAndFollowers(this); OAuthBase = "https://api.twitter.com/oauth/"; TokenRequestUrl = "request_token"; TokenAuthUrl = "authorize"; TokenAccessUrl = "access_token"; Authority = "https://api.twitter.com/"; Version = "1"; #if !SILVERLIGHT ServicePointManager.Expect100Continue = false; #endif Credentials = new OAuthCredentials { ConsumerKey = consumerKey, ConsumerSecret = consumerSecret, }; if (!string.IsNullOrEmpty(callback)) ((OAuthCredentials)Credentials).CallbackUrl = callback; }
public override void Authenticate(IRestClient client, IRestRequest request) { if (!string.IsNullOrWhiteSpace(AccessToken)) { request.AddHeader("authorization", string.Format("bearer {0}", AccessToken)); } }
public void Authenticate(IRestClient client, IRestRequest request) { if(!request.Parameters.Any(p => p.Name.Equals("Authorization", StringComparison.OrdinalIgnoreCase))) { request.AddParameter("Authorization", "SuTToken " + _token, ParameterType.HttpHeader); } }
public SyncStatusReport(TableSet tableSet) { this.tableSet = tableSet; sourceDB = new QueryRunner(tableSet.SourceConnectionStringName); destinationDB = new QueryRunner(tableSet.DestinationConnectionStringName); restClient = new RestClient(BaseUrl); }
public void Initialize(ProviderConfiguration providerConfiguration, IList<string> scope = null, IRestClient restClient = null) { if (providerConfiguration == null) { throw new ArgumentNullException("providerConfiguration"); } if (providerConfiguration.Providers == null) { throw new ArgumentException("providerConfiguration.Providers"); } foreach (ProviderKey provider in providerConfiguration.Providers) { IAuthenticationProvider authenticationProvider; switch (provider.Name.ToLowerInvariant()) { case "facebook": authenticationProvider = new FacebookProvider(provider, scope, restClient); break; case "google": authenticationProvider = new GoogleProvider(provider, scope, restClient); break; case "twitter": authenticationProvider = new TwitterProvider(provider, restClient); break; default: throw new ApplicationException( "Unhandled ProviderName found - unable to know which Provider Type to create."); } AddProvider(authenticationProvider); } }
/// <summary> /// </summary> /// <param name="apiBaseUrl">API base url. https://api.vk.com/. </param> /// <param name="authToken">Access token you receive after successful authentication.</param> public VkApiSession(string apiBaseUrl, VkAuthToken authToken) { this.AuthToken = authToken; this.RestClient = new RestClient(apiBaseUrl) { Authenticator = new AccessTokenAuthenticator(this.AuthToken.Value) }; }
protected UserRepository(string apiKey, IRestClient restClient, IUserResponseParser parser, IPageCalculator pageCalculator) { this.apiKey = apiKey; this.restClient = restClient; this.parser = parser; this.pageCalculator = pageCalculator; }
public When(IRestClient client, IRestRequest request, IRestResponse response) { this.client = client; this.request = request; this.response = response; data = new Object(); }
public IssueResource(IRestClient client) : base(client) { resource = "issues"; //creatableAttributes = new string[] { "encoding_profile_ids", "encoding_profile_tags", "skip_default_encoding_profiles", "use_original_as_transcoding" }; accessableAttributes = new string[] {"title", "state", "labels"}; }
public void SetUp() { twitterClient = Substitute.For<IBaseTwitterClient>(); searchClient = Substitute.For<IRestClient>(); search = new Search(twitterClient, s => searchClient); }
public AuthenticationService(ProviderConfiguration providerConfiguration, IList<string> scope = null, IRestClient restClient = null) { Condition.Requires(providerConfiguration).IsNotNull(); Condition.Requires(providerConfiguration.Providers).IsNotNull(); var redirectUri = string.Format("{0}?{1}=", providerConfiguration.CallbackUri, providerConfiguration.CallbackQuerystringKey); foreach (ProviderKey provider in providerConfiguration.Providers) { var providerSpecificRedirectUri = new Uri((redirectUri + provider.Name).ToLower()); IAuthenticationProvider authenticationProvider; switch (provider.Name) { case ProviderType.Facebook: authenticationProvider = new FacebookProvider(provider, providerSpecificRedirectUri, scope, restClient); break; case ProviderType.Google: authenticationProvider = new GoogleProvider(provider, providerSpecificRedirectUri, scope, restClient); break; case ProviderType.Twitter: authenticationProvider = new TwitterProvider(provider, providerSpecificRedirectUri, restClient); break; default: throw new ApplicationException( "Unhandled ProviderType found - unable to know which Provider Type to create."); } AddProvider(authenticationProvider); } }
public DispatcherService(ServiceSettings settings, IRestClient restClient, ILogger logger) { Settings = settings; _restClient = restClient; _logger = logger; }
public GoogleProvider(string clientId, string clientSecret, IList<string> scope = null, IRestClient restClient = null) { if (string.IsNullOrEmpty(clientId)) { throw new ArgumentNullException("clientId"); } if (string.IsNullOrEmpty(clientSecret)) { throw new ArgumentNullException("clientSecret"); } _clientId = clientId; _clientSecret = clientSecret; // Optionals. _scope = scope == null || scope.Count <= 0 ? new List<string> { "https://www.googleapis.com/auth/userinfo.profile", "https://www.googleapis.com/auth/userinfo.email" } : scope; _restClient = restClient ?? new RestClient("https://accounts.google.com"); }
public void Authenticate(IRestClient client, IRestRequest request) { if (request.Parameters.Exists(p => p.Name.Equals("Cookie", StringComparison.InvariantCultureIgnoreCase))) return; request.AddParameter("cookie", _authHeader, ParameterType.HttpHeader); }
public HabitRPGClient(string baseurl, string apiuser, string apitoken) { _baseUrl = baseurl; _apiUser = apiuser; _apiToken = apitoken; _restClient = new RestClient(baseurl); }
/// <summary> /// Modifies the request to ensure that the authentication requirements are met. /// </summary> /// <param name="client">Client executing this request</param> /// <param name="request">Request to authenticate</param> public void Authenticate(IRestClient client, IRestRequest request) { // only add the Authorization parameter if it hasn't been added by a previous Execute if (request.Parameters.Any(p => p.Name != null && p.Name.Equals("Authorization", StringComparison.OrdinalIgnoreCase))) return; request.AddParameter("Authorization", this._authHeader, ParameterType.HttpHeader); }
public ResultsPresenter(IResultsView view, Dispatcher dispatcher) { View = view; Dispatcher = dispatcher; RestClient = RestClientFactory.GetDefault(); View.ResultSelected += ResultSelected; }
public LgEloquaContext(IRestClient restClient) : base(restClient) { BadContacts = new DbSet<BadContact>(restClient); LgContacts = new DbSet<LgContact>(restClient); ExtendedContacts = new DbSet<ExtendedContact>(restClient); }
public ApiRequestBuilder(IRestClient restClient) { _restClient = restClient; }
protected virtual void CheckCallResult(HttpStatusCode code, IRestClient client, IRestRequest request) { }
public UploadRepository(IRestClient client) : base(client) { }
/// <summary> /// Initializes a new instance of the <see cref="SitefinityDataViewComponent"/> class. /// </summary> /// <param name="service">The rest service.</param> public SitefinityDataModel(IRestClient service) { this.service = service; }
/// <summary> /// 调用所有OpenAPI时,除了各接口私有的参数外,所有OpenAPI都需要传入基于OAuth2.0协议的通用参数 /// 将这些通用参数加入RestRequest /// </summary> /// <param name="client"></param> /// <param name="request"></param> public override void Authenticate(IRestClient client, IRestRequest request) { request.AddParameter("access_token", AccessToken, ParameterType.GetOrPost); request.AddParameter("openid", openId, ParameterType.GetOrPost); request.AddParameter("oauth_consumer_key", consumerKey, ParameterType.GetOrPost); }
public HttpClientTest() { _configMock = new Mock <IConfig>(); _httpClient = new HttpClient(new DelegatingHandlerStub()); _restClient = new RestClient(_configMock.Object, _httpClient); }
public PostcodeLookup(IPostcodeLookupConfig config) { lookupClient = config.RestClient; }
/// <inheritdoc /> public MFWSClientProxy(IRestClient restClient) : base(restClient) { }
private void AddOAuthData(IRestClient client, IRestRequest request, OAuthWorkflow workflow) { var url = client.BuildUri(request, false).ToString(); OAuthWebQueryInfo oauth; var method = request.Method.ToString(); var parameters = new WebParameterCollection(); // include all GET and POST parameters before generating the signature // according to the RFC 5849 - The OAuth 1.0 Protocol // http://tools.ietf.org/html/rfc5849#section-3.4.1 // if this change causes trouble we need to introduce a flag indicating the specific OAuth implementation level, // or implement a seperate class for each OAuth version var useMultiPart = request.ContentCollectionMode == ContentCollectionMode.MultiPart || (request.ContentCollectionMode == ContentCollectionMode.MultiPartForFileParameters && (client.DefaultParameters.GetFileParameters().Any() || request.Parameters.GetFileParameters().Any())); var requestParameters = client.MergeParameters(request).OtherParameters; var effectiveMethod = client.GetEffectiveHttpMethod(request); if (effectiveMethod == Method.GET) { var filteredParams = requestParameters.Where(x => x.Type == ParameterType.GetOrPost || x.Type == ParameterType.QueryString); foreach (var p in filteredParams) { parameters.Add(new WebParameter(p.Name, p.Value.ToString(), WebParameterType.Query)); } } else if (!useMultiPart && effectiveMethod == Method.POST) { foreach (var p in requestParameters.Where(x => x.Type == ParameterType.QueryString)) { parameters.Add(new WebParameter(p.Name, p.Value.ToString(), WebParameterType.Query)); } foreach (var p in requestParameters.Where(x => x.Type == ParameterType.GetOrPost)) { parameters.Add(new WebParameter(p.Name, p.Value.ToString(), WebParameterType.Post)); } } else { // if we are sending a multipart request, only the "oauth_" parameters should be included in the signature foreach (var p in requestParameters.Where(p => p.Name != null && p.Name.StartsWith("oauth_", StringComparison.Ordinal))) { parameters.Add(new WebParameter(p.Name, p.Value.ToString(), WebParameterType.Internal)); } } switch (Type) { case OAuthType.RequestToken: workflow.RequestTokenUrl = url; oauth = workflow.BuildRequestTokenInfo(method, parameters); break; case OAuthType.AccessToken: workflow.AccessTokenUrl = url; oauth = workflow.BuildAccessTokenInfo(method, parameters); break; case OAuthType.ClientAuthentication: workflow.AccessTokenUrl = url; oauth = workflow.BuildClientAuthAccessTokenInfo(method, parameters); break; case OAuthType.ProtectedResource: oauth = workflow.BuildProtectedResourceInfo(method, parameters, url); break; default: throw new ArgumentOutOfRangeException(); } switch (ParameterHandling) { case OAuthParameterHandling.HttpAuthorizationHeader: parameters.Add("oauth_signature", oauth.Signature, WebParameterType.Internal); request.AddHeader("Authorization", GetAuthorizationHeader(parameters)); break; case OAuthParameterHandling.UrlOrPostParameters: parameters.Add("oauth_signature", oauth.Signature, WebParameterType.Internal); foreach (var parameter in parameters.Where( parameter => !string.IsNullOrEmpty(parameter.Name) && (parameter.Name.StartsWith("oauth_") || parameter.Name.StartsWith("x_auth_")))) { var v = parameter.Value; v = Uri.UnescapeDataString(v.Replace('+', ' ')); request.AddOrUpdateParameter(parameter.Name, v); } break; default: throw new ArgumentOutOfRangeException(); } }
public QuickSearchConfiguration(IRestClient restClient) { RestClient = restClient; _apiBase = ArtifactoryBuilder.ApiBase + "/search"; }
public PostService2(IRestClient client, IApiConfig apiConfig) { _apiConfig = apiConfig; _client = client; }
/// <summary> /// Does the authentication module supports pre-authentication? /// </summary> /// <param name="client">Client executing this request</param> /// <param name="request">Request to authenticate</param> /// <param name="credentials">The credentials to be used for the authentication</param> /// <returns>true when the authentication module supports pre-authentication</returns> public bool CanPreAuthenticate(IRestClient client, IRestRequest request, ICredentials credentials) { return(true); }
protected virtual IRestClient Mature(IRestClient client) { return(client); }
private static Task <IRestResponse <T> > ExecuteBasic <T>(IRestClient client, IRestRequest request, CancellationToken cancellationToken) { return(client.ExecuteTaskAsync <T>(request, cancellationToken)); }
public new Response Execute(IRestClient client) { return(Execute <Response>(client)); }
public UserResource(IRestClient client) { Client = client; }
private async Task <IRestResponse> GetResponse(IRestRequest request, CancellationToken cancellationToken, IRestClient client = null) { client = client ?? Client; var response = await TimeLimiter.Perform(async() => await ExecuteBasic(client, request, cancellationToken), cancellationToken); if (response.ErrorException != null) { throw new WebClientException(_ErrorMessage, response.ErrorException); } return(response); }
private async Task <IRestResponse <T> > GetResponse <T>(IRestRequest request, CancellationToken cancellationToken, IRestClient client = null) { request.JsonSerializer = NewtonsoftJsonSerializer.Default; client = client ?? Client; var response = await TimeLimiter.Perform(async() => await ExecuteBasic <T>(client, request, cancellationToken), cancellationToken); if (response.ErrorException != null) { throw new WebClientException(_ErrorMessage, response.ErrorException); } CheckCallResult(response.StatusCode, client, request); return(response); }
public FileSystemClient(ILogger log, FileSystemCrawlJobData filesystemCrawlJobData, IRestClient client) // TODO: pass on any extra dependencies { if (filesystemCrawlJobData == null) { throw new ArgumentNullException(nameof(filesystemCrawlJobData)); } if (client == null) { throw new ArgumentNullException(nameof(client)); } _log = log ?? throw new ArgumentNullException(nameof(log)); _filesystemCrawlJobData = filesystemCrawlJobData; // TODO use info from filesystemCrawlJobData to instantiate the connection client.BaseUrl = new Uri(s_baseUri); // client.AddDefaultParameter("api_key", filesystemCrawlJobData.ApiKey, ParameterType.QueryString); }
public StudentIdentificationSystemDescriptorsApi(IRestClient client) { this.client = client; }
public PartnerClientMessageWriter(IRestClient restClient, IPartnerClientMessageLoader loader, IClientStageRepository clientStageRepository) : base(restClient, loader, clientStageRepository) { }
public MetaWeatherOrchestration(IRestClient restClient, IConfiguration configuration) { _restClient = restClient; _configuration = configuration; }
public DisabilityCategoryTypesApi(IRestClient client) { this.client = client; }
public ContributorRepository(IRestClient restClient) { this.restClient = restClient ?? throw new ArgumentNullException("restClient"); }
/// <summary> /// This method applies the list of features to the specified REST API request. /// </summary> /// <param name="client">This parameter is currently unused.</param> /// <param name="request">The REST API request that will have the features applied.</param> /// <remarks> /// The specific features will be added as a special header to the REST API request. /// </remarks> public void Handle(IRestClient client, IRestRequest request) { request.AddHeader("X-FS-Feature-Tag", this.experiments); }
private RestRequestExecutor( IRestClient client) { _client = client; }
public DataStaxEnterpriseSearch(ISession session, TaskCache <string, PreparedStatement> statementCache, IRestClient restClient) { if (session == null) { throw new ArgumentNullException("session"); } if (statementCache == null) { throw new ArgumentNullException("statementCache"); } _session = session; _statementCache = statementCache; _restClient = restClient; }
public BudgetsApi(IRestClient client) { this.client = client; }
private async Task <T> ExecuteAsync <T>(IRestClient client, IRestRequest request) { var response = await client.Execute <T>(request); return(response.Data); }
public void Authenticate(IRestClient client, IRestRequest request) { request.Credentials = credentials; }