/// <exception cref="GPClientException"></exception> public GPConnector GetAppToken(string scope) { var restRequest = new RestRequest(@"/oauth2/token", Method.POST); restRequest.RequestFormat = DataFormat.Json; restRequest.AddHeader("Accept", "application/json"); //restRequest.JsonSerializer = new JsonCustomSerializer<T>(); //new JsonSerializer(); //// not found //restRequest.JsonSerializer = new RestSharpJsonNetSerializer(); // chtělo opět chtělo newtonsoft 12.0.0.0 //restRequest.JsonSerializer = new RestSharp.Serializers.Newtonsoft.Json.NewtonsoftJsonSerializer(); // Tady mě to prvně donutilo nainstalovat RestSharp.Serializers.NewtonsoftJson a poté opět chtělo newtonsoft 12.0.0.0 //restRequest.JsonSerializer = new RestSharp.Serializers.NewtonsoftJson.JsonNetSerializer(); // //restRequest.JsonSerializer = new SunamoRestJsonSerializer(); #if NETSTANDARD restRequest.JsonSerializer = new SunamoRestJsonTextSerializer(); #endif restRequest.JsonSerializer.ContentType = "application/x-www-form-urlencoded"; restRequest.AddParameter("application/x-www-form-urlencoded", "grant_type=client_credentials&scope=" + scope, ParameterType.RequestBody); var authenticator = new HttpBasicAuthenticator(ClientID, ClientSecret); authenticator.Authenticate(Client, restRequest); var response = Client.Execute(restRequest); OnIncomingDataEvent(response); AccessToken = ProcessResponse <AccessToken>(response); return(this); }
private static T Post <T>(string resource, string jsonBody = "", HttpBasicAuthenticator authenticator = null, string token = "") where T : BaseApiModel, new() { client.Authenticator = authenticator; RestRequest request = new RestRequest(resource, Method.POST); request.RequestFormat = DataFormat.Json; if (!string.IsNullOrEmpty(token)) { request.AddHeader("x-access-token", token); } if (!string.IsNullOrEmpty(jsonBody)) { request.AddParameter("application/json", jsonBody, ParameterType.RequestBody); } var response = client.Execute(request); try { return(JsonConvert.DeserializeObject <T>(response.Content)); } catch { T errorModel = new T(); errorModel.result = "bad"; errorModel.message = "Critical error"; return(errorModel); } }
public static Token Create(string username, string password) { var client = new RestClient(Server.BaseUrl); var request = new RestRequest("tokens", Method.POST); var authenticator = new HttpBasicAuthenticator(username, password); authenticator.Authenticate(client, request); var response = client.Execute(request); if (response != null && response.StatusCode == System.Net.HttpStatusCode.OK) { var json = response.Content; if (!string.IsNullOrEmpty(json)) { var obj = Json.Convert.FromJson <Token>(json); if (obj != null) { return(obj); } } } return(null); }
private static RestClient GetClient(HttpBasicAuthenticator basicAuthenticator) { return(new RestClient(BaseURL) { Authenticator = basicAuthenticator }); }
public void Setup() { username = "******"; password = "******"; authenticator = new HttpBasicAuthenticator(username, password); }
public Client(string organisation, string personalAccessToken) { if (string.IsNullOrWhiteSpace(organisation)) { throw new ArgumentNullException(nameof(organisation), "Organisation is required"); } if (string.IsNullOrWhiteSpace(personalAccessToken)) { throw new ArgumentNullException(nameof(personalAccessToken), "PAT is required"); } var opts = new JsonSerializerOptions() { PropertyNameCaseInsensitive = true, PropertyNamingPolicy = JsonNamingPolicy.CamelCase }; // set Feed URL _feedClient = new RestClient($"https://feeds.dev.azure.com/{organisation}") .UseSystemTextJson(opts); // set Pkgs URL _pkgsClient = new RestClient($"https://pkgs.dev.azure.com/{organisation}") .UseSystemTextJson(opts); // set access using PAT var auth = new HttpBasicAuthenticator("", personalAccessToken); _feedClient.Authenticator = auth; _pkgsClient.Authenticator = auth; }
public bool CheckJobSuccessful(int jobId) { try { var client = new RestClient(this.TowerURI); client.RemoteCertificateValidationCallback = (sender, certificate, chain, sslPolicyErrors) => true; var authenticator = new HttpBasicAuthenticator(this.TowerUser, this.TowerPassword); var request = new RestRequest("jobs/" + jobId + "/", Method.GET); authenticator.Authenticate(client, request); IRestResponse response = client.Execute(request); if (response.StatusCode == HttpStatusCode.OK) { var content = JObject.Parse(response.Content); return(!content.Value <bool>("failed")); } else { return(false); } } catch (Exception ex) { Console.WriteLine(ex.Message); return(false); } }
public Form1() { InitializeComponent(); restClient = new RestClient("http://localhost:8888"); authenticator = new HttpBasicAuthenticator("demo", "demo"); f1 = this; }
public string GetToken(string apiName) { HttpBasicAuthenticator auth = null; switch (apiName) { case "SpeechToText": auth = new HttpBasicAuthenticator("BASIC", Headers["SpeechToTextAuth"]); break; case "TextToSpeech": auth = new HttpBasicAuthenticator("BASIC", Headers["TextToSpeechAuth"]); break; case "Convo": auth = new HttpBasicAuthenticator("BASIC", Headers["ConvoAuth"]); break; } IRestResponse <object> response = GenericRestSharp <object>("https://stream.watsonplatform.net/authorization/api/v1/token?url=https://stream.watsonplatform.net/speech-to-text/api", null, null, auth); if (response.Data == null) { throw new Exception(response.Content); } return(response.Content); }
public IBitbucketClient AuthentificateWithLogin(string username, string password) { var authentificator = new HttpBasicAuthenticator(username, password); var bitbucketClient = new BitbucketClient(authentificator); return(bitbucketClient); }
public void SubmitterSet_Put() { AUTH = new HttpBasicAuthenticator(ousername, opassword); prepareData(); var client = new RestClient(basic_url + "({id})"); client.Authenticator = AUTH; Int32 id = 1000; var request = new RestRequest("", Method.PUT); request.RequestFormat = DataFormat.Json; request.AddUrlSegment("id", id.ToString()); SubmitterSet submitterSet = new SubmitterSet(); submitterSet.ID = id; submitterSet.Name = "SubmitterSetTest" + "({id})"; submitterSet.Org = "submitterSet for test"; submitterSet.Company = "submitterSet for test"; submitterSet.Address = "submitterSet for test"; submitterSet.Phone = "submitterSet for test"; submitterSet.Mobile = "submitterSet for test"; submitterSet.Email = "submitterSet for test"; request.AddJsonBody(submitterSet); // execute the request IRestResponse response = client.Execute(request); var content = response.Content; // raw content as string var status = response.StatusCode; Console.WriteLine(content); Assert.AreEqual(STATUS_PUT, status.ToString()); cleanData(id); }
public void prepareData() { AUTH = new HttpBasicAuthenticator(ousername, opassword); var client = new RestClient(basic_url); client.Authenticator = AUTH; var request = new RestRequest("", Method.POST); request.RequestFormat = DataFormat.Json; Int32 id = 1000; SubmitterSet submitterSet = new SubmitterSet(); submitterSet.ID = id; submitterSet.Name = "SubmitterSetTest" + "({id})"; submitterSet.Org = "submitterSet for test"; submitterSet.Company = "submitterSet for test"; submitterSet.Address = "submitterSet for test"; submitterSet.Phone = "submitterSet for test"; submitterSet.Mobile = "submitterSet for test"; submitterSet.Email = "submitterSet for test"; request.AddJsonBody(submitterSet); IRestResponse response = client.Execute(request); var status = response.StatusCode; if (status.ToString() != STATUS_POST) { Console.WriteLine("Prepare data failed"); } }
public BaseClient(string site, string user, string password, string baseUrl) : base(baseUrl) { Authenticator = new HttpBasicAuthenticator(site + "\\" + user, password); AddHandler("text/plain", new JsonDeserializer()); SimpleJson.CurrentJsonSerializerStrategy = new CamelCaseSerializer(); }
public void Setup() { _username = "******"; _password = "******"; _authenticator = new HttpBasicAuthenticator(_username, _password); }
static void Main(string[] args) { var TEAMCITY_URL = ConfigurationManager.AppSettings["TEAMCITY_URL"]; var TEAMCITY_USERNAME = ConfigurationManager.AppSettings["TEAMCITY_USERNAME"]; var TEAMCITY_PASSWORD = ConfigurationManager.AppSettings["TEAMCITY_PASSWORD"]; var client = new RestClient(TEAMCITY_URL); var start = 0; var count = 100; // TeamCity's limit var done = false; var authenticator = new HttpBasicAuthenticator(TEAMCITY_USERNAME, TEAMCITY_PASSWORD); var failingBuilds = new Dictionary <string, build>(); // Collect a list of build config/branch name combinations with a failing build while (!done) { var request = new RestRequest("builds", Method.GET); request.AddQueryParameter("locator", $"status:FAILURE,branch:default:any,start:{start},count:{count}"); request.AddQueryParameter("fields", "count,nextHref,build(webUrl,buildTypeId,number,branchName,buildType(id,name,project))"); request.AddHeader("Content-Type", "application/json"); request.AddHeader("Accept", "application/json"); authenticator.Authenticate(client, request); var response = client.Execute(request); var builds = JsonConvert.DeserializeObject <builds>(response.Content); foreach (var build in builds.build.Where(p => p.buildType.project.archived == false && IsRelevantBranchName(p.branchName))) { var key = build.buildType.id + build.branchName; if (!failingBuilds.ContainsKey(key)) { failingBuilds.Add(key, build); } } start += count; done = builds.count == 0; } // For each build config/branch combination, get the last build and see if it succeeded var file = File.CreateText(@"moo.csv"); foreach (var build in failingBuilds.Values) { var request = new RestRequest($"buildTypes/id:{build.buildType.id}/builds/branch:name:{build.branchName}", Method.GET); request.AddHeader("Content-Type", "application/json"); request.AddHeader("Accept", "application/json"); authenticator.Authenticate(client, request); var response = client.Execute(request); var lastBuild = JsonConvert.DeserializeObject <build>(response.Content); if (lastBuild.status.ToLower() != "success") { file.WriteLine( $"{build.buildType.project.name},{build.buildType.name},{build.branchName},{build.webUrl}"); } } file.Close(); Console.WriteLine("\n\nPress a key..."); Console.ReadKey(); }
public HttpBasicAuthenticatorTests() { _username = "******"; _password = "******"; _authenticator = new HttpBasicAuthenticator(_username, _password); }
public UsersRestClient() : base(new Uri("https://dev.tikforce.com/users-dev/")) { var authenticator = new HttpBasicAuthenticator("tikmeapi", "_x36pgY;9!]ZC8]A"); RestClient.Authenticator = authenticator; RestClient.AddDefaultHeader("Authorization-Token", "8CE494A8-0DFF-4DEC-B1F7-972BDA43F0C1"); RestClient.AddDefaultHeader("Ocp-Apim-Subscription-Key", "b423ac3302e844db922c637450a1cc34"); }
public static IRestResponse Execute(RestRequest request, HttpBasicAuthenticator basicAuthenticator) { var client = GetClient(basicAuthenticator); client.AddHandler("application/json", NewtonsoftJsonSerializer.Default); return(client.Execute(request)); }
public TFLAPI(string id, string key) { appID = id; appKey = key; authenticator = new HttpBasicAuthenticator(appID, appKey); client = new RestClient(); client.BaseUrl = new System.Uri("https://api.tfl.gov.uk"); client.Authenticator = authenticator; }
private OAuthToken ExecuteRequest(IRestRequest request, string clientId, string clientSecret) { IAuthenticator authenticator = new HttpBasicAuthenticator(clientId, clientSecret); IRestResponse <OAuthToken> response = ExecuteRequest <OAuthToken>(request, authenticator); ProcessResponse(response); return(response.Data); }
public BitcoinClient(ConnectionInfo connInfo) { HttpBasicAuthenticator auth = new HttpBasicAuthenticator(connInfo.Username, connInfo.Password); _client = new RestClient(connInfo.Url) { Authenticator = auth }; }
public void SetUp() { IAuthenticator authenticator = new HttpBasicAuthenticator(c_jiraUsername, c_jiraPassword); _restClient = new JiraRestClient(c_jiraUrl, authenticator); _service = new JiraProjectVersionService(_restClient); _versionFinder = new JiraProjectVersionFinder(_restClient); _issueService = new JiraIssueService(_restClient); _repairer = new JiraProjectVersionRepairer(_service, _versionFinder); }
//bool IgnoreSSLIssues??? //string AccessToken - Authentificator //connectionTimeOut - Timeout // ReadWriteTimeout public virtual ArtifactoryRestClientConfiguration SetRestClient(IRestClient restClient) { if (restClient == null) { throw new ArgumentNullException(nameof(restClient)); } var authenticator = new HttpBasicAuthenticator(UserName, Password); return(new ArtifactoryRestClientConfiguration(restClient, authenticator, Url, UserAgent)); }
protected BaseRest(string hostUrl) { AssertCtor(HostUrl = hostUrl); _userName = string.Empty; _password = string.Empty; if (!string.IsNullOrEmpty(_userName)) { _auth = new HttpBasicAuthenticator(_userName, _password); _authWeb = new NetworkCredential(_userName, _password); } }
public TableAPIClient(String sNowURL, String userName, string password) { HttpBasicAuthenticator credentials = new HttpBasicAuthenticator(userName, password); _TableName = string.Empty; _sNowURL = sNowURL; ServiceNowClient = new RestClient() { Authenticator = credentials }; }
public void Authenticator_CanBeSet() { //Arrange var restsharp = Rest.On().Respond; var newAuthenticator = new HttpBasicAuthenticator("user", "password"); //Act restsharp.Authenticator = newAuthenticator; //Assert Assert.AreEqual(newAuthenticator, restsharp.Authenticator); }
public void Evaluate(int SpreadMax) { // Set the slice counts of our outputs. FOutputAuthentication.SliceCount = SpreadMax; // start doing stuff foreach spread item for (int i = 0; i < SpreadMax; i++) { //client[i] = new RestClient(); FOutputAuthentication[i] = new HttpBasicAuthenticator(FInputUsername[i], FInputPassword[i]); } }
internal RestAPIRequest(string username, string apikey, string baseUrl, string apiVersion) { ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12; _auth = new HttpBasicAuthenticator(username, apikey); var version = Assembly.GetExecutingAssembly().GetName().Version; _userAgent = "DataSift/v" + apiVersion + " Dotnet/v" + version.ToString(); _baseUrl = baseUrl; _apiVersion = apiVersion; }
public static User Get(string username, string password) { var client = new RestClient(Server.BaseUrl); var request = new RestRequest("user", Method.GET); var authenticator = new HttpBasicAuthenticator(username, password); authenticator.Authenticate(client, request); var response = client.Execute(request); return(GetResponse(response)); }
private static HttpBasicAuthenticator GetAuthentication() { string AccountNumber = ConfigurationManager.AppSettings["AccountNumber"]; string APIKey = ConfigurationManager.AppSettings["APIKey"]; if (string.IsNullOrEmpty(AccountNumber) || string.IsNullOrEmpty(APIKey)) { return(null); } HttpBasicAuthenticator a = new HttpBasicAuthenticator(AccountNumber, APIKey); return(a); }
public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { if (value == null || value.ToString() == "") return null; RestClient client = new RestClient(); var request = new RestRequest(value.ToString(), Method.GET); try {//workaround because I use a class for this XD string exeConfigPath = this.GetType().Assembly.Location; string dir = Path.GetDirectoryName(exeConfigPath); string[] files = System.IO.Directory.GetFiles(dir, "*.config"); string mainassembly = ""; foreach (var f in files) { if (!f.Contains(this.GetType().Assembly.FullName) && !f.Contains("vshost")) { mainassembly = f.Substring(0, f.Length - 7); break; } } string username = UserSettings.Get("username"); string password = DataProtector.DecryptData(UserSettings.Get("password")); if (string.IsNullOrWhiteSpace(username) || string.IsNullOrWhiteSpace(password)) return null; HttpBasicAuthenticator user = new HttpBasicAuthenticator(username, password); client.Authenticator = user; } catch (Exception ex1) { MessageBox.Show("exception: " + ex1); } // var response = client.Execute(request); return LoadImage(response.RawBytes); }