public CrayonApiClient(HttpClient httpClient) { _httpClient = httpClient; _jsonSerializerSettings = new JsonSerializerSettings { MissingMemberHandling = MissingMemberHandling.Ignore, NullValueHandling = NullValueHandling.Include, DefaultValueHandling = DefaultValueHandling.Include, Formatting = Formatting.Indented }; _assemblyVersion = typeof(CrayonApiClient).GetTypeInfo().Assembly.GetName().Version.ToString(); Addresses = new AddressResource(this); AgreementProducts = new AgreementProductResource(this); Agreements = new AgreementResource(this); BillingStatements = new BillingStatementResource(this); BlogItems = new BlogItemResource(this); Clients = new ClientResource(this); CustomerTenants = new CustomerTenantResource(this); InvoiceProfiles = new InvoiceProfileResource(this); Me = new MeResource(this); OrganizationAccess = new OrganizationAccessResource(this); Organizations = new OrganizationResource(this); Publishers = new PublisherResource(this); Programs = new ProgramResource(this); Regions = new RegionResource(this); Secrets = new SecretResource(this); Subscriptions = new SubscriptionResource(this); Tokens = new TokenResource(this); UsageRecords = new UsageRecordResource(this); Users = new UserResource(this); }
/// <inheritdoc /> /// <summary> /// Create a new client <b>Permissions Needed:</b> CLIENTS_ADMIN /// </summary> /// <param name="clientResource">The client resource object</param> public void CreateClient(ClientResource clientResource) { mWebCallEvent.WebPath = "/auth/clients"; if (!string.IsNullOrEmpty(mWebCallEvent.WebPath)) { mWebCallEvent.WebPath = mWebCallEvent.WebPath.Replace("{format}", "json"); } mWebCallEvent.HeaderParams.Clear(); mWebCallEvent.QueryParams.Clear(); mWebCallEvent.AuthSettings.Clear(); mWebCallEvent.PostBody = null; mWebCallEvent.PostBody = KnetikClient.Serialize(clientResource); // http body (model) parameter // authentication settings mWebCallEvent.AuthSettings.Add("oauth2_client_credentials_grant"); // authentication settings mWebCallEvent.AuthSettings.Add("oauth2_password_grant"); // make the HTTP request mCreateClientStartTime = DateTime.Now; mWebCallEvent.Context = mCreateClientResponseContext; mWebCallEvent.RequestType = KnetikRequestType.POST; KnetikLogger.LogRequest(mCreateClientStartTime, "CreateClient", "Sending server request..."); KnetikGlobalEventSystem.Publish(mWebCallEvent); }
public Register(ClientResource clientResource, RegisterInitialModel registerInitialModel, IAESCrypter aesCrypter) { this.aesCrypter = aesCrypter; this.clientResource = clientResource; this.addMinuteExpiredTime = registerInitialModel.AddMinuteExpiredTime; this.authServerAuthenApiUrl = registerInitialModel.AuthServerAuthenApiUrl; this.protectedAuthenApiUrl = registerInitialModel.ProtectedAuthenApiUrl; }
public void ReturnFileResourceResultWithResource() { var contextMock = new Mock <IResourceContext>(); var resource = new ClientResource(); var result = resource.Execute(contextMock.Object); Assert.NotNull(result); }
public void ReturnStatusCodeResourceResultWithMissingResource() { var contextMock = new Mock <IResourceContext>(); var resource = new ClientResource { ResourceName = "wrong" }; var result = resource.Execute(contextMock.Object); Assert.NotNull(result as StatusCodeResourceResult); }
public IActionResult Post([FromBody] ClientResource clientResource) { if (!ModelState.IsValid) { return(NotFound()); } var clientDto = _mapper.Map <ClientDTO>(clientResource); _service.Add(clientDto); return(Ok()); }
public IActionResult Put(int id, [FromBody] ClientResource clientResource) { if (!ModelState.IsValid) { return(NotFound()); } var clientDto = _mapper.Map <ClientDTO>(clientResource); clientDto.Id = id; _service.Update(clientDto); return(Ok()); }
private void OnUpdateClientResponse(KnetikRestResponse response) { if (!string.IsNullOrEmpty(response.Error)) { throw new KnetikException("Error calling UpdateClient: " + response.Error); } UpdateClientData = (ClientResource)KnetikClient.Deserialize(response.Content, typeof(ClientResource), response.Headers); KnetikLogger.LogResponse(mUpdateClientStartTime, "UpdateClient", string.Format("Response received successfully:\n{0}", UpdateClientData)); if (UpdateClientComplete != null) { UpdateClientComplete(response.ResponseCode, UpdateClientData); } }
public IActionResult SignUp(ClientCreateViewModel clientCreateViewModel) { var account = new AccountResource() { Login = clientCreateViewModel.Login, Phone = clientCreateViewModel.Phone, Email = clientCreateViewModel.Email, Password = clientCreateViewModel.Password }; var jsonResponse = _client.GetStringAsync("api/accounts").Result; var oldAccounts = JsonConvert.DeserializeObject <List <AccountResource> >(jsonResponse); if (oldAccounts.Any(account => account.Login == clientCreateViewModel.Login)) { return(Redirect("/site/vertical/pages-register.html")); } var json = JsonConvert.SerializeObject(account); var data = new StringContent(json, Encoding.UTF8, "application/json"); var result = _client.PostAsync("api/accounts", data).Result; if (result.StatusCode == System.Net.HttpStatusCode.OK) { var accountsJson = _client.GetStringAsync("api/accounts").Result; var accounts = JsonConvert.DeserializeObject <List <AccountResource> >(accountsJson); var accountGet = accounts.Where(a => a.Login == clientCreateViewModel.Login && a.Phone == clientCreateViewModel.Phone && a.Email == clientCreateViewModel.Email).FirstOrDefault(); var client = new ClientResource() { AccountId = accountGet.Id, Name = clientCreateViewModel.Name }; var clientJson = JsonConvert.SerializeObject(client); var clientData = new StringContent(clientJson, Encoding.UTF8, "application/json"); var clientResult = _client.PostAsync("api/clients", clientData).Result; if (clientResult.StatusCode == System.Net.HttpStatusCode.OK) { return(Redirect("/site/vertical/pages-login.html")); } } return(Redirect("/site/vertical/pages-register.html")); }
static void Main(string[] args) { Console.WriteLine("Hello World!"); ClientResource clientResource = new ClientResource() { ClientId = "6365724719934223450001", ClientKey = "A25AD6A46FD945C7647AD34A993E01AF", ClientIV = "5687EC92759818B5", ClientName = "Sample", ProtectedServers = new List <ClientToProtectedServerData>(), }; RegisterInitialModel registerInitialModel = new RegisterInitialModel() { AddMinuteExpiredTime = 30, AuthServerAuthenApiUrl = "http://localhost:21383/api/RegisterService/Authen/", ProtectedAuthenApiUrl = "http://localhost:21383/api/RegisterService/CheckClientRequest", }; Register register = new Register(clientResource, registerInitialModel, new LocalMachineAESCrypter()); var apiResult = register.Authenticate(); if (apiResult == false) { Console.WriteLine(apiResult.ResultMessage); //Auth Server 驗證失敗 Environment.Exit(1); } List <string> cypherTextList = apiResult.Value.CypherTextList; List <AuthClientCypherTextModel> authClientCyphersTextList = new List <AuthClientCypherTextModel>(); cypherTextList.ForEach(x => authClientCyphersTextList.Add(register.DecryptAuthServerResp(x))); //當需要去Protected Server溝通時 取出相對應的 AuthClientCypherTextModel AuthClientCypherTextModel authClient = authClientCyphersTextList.Where(x => x.ProtectedId == "目標Protected Server Id").Single(); //先去 Protected Server 取得驗證相關資料 AuthorizeValueModel authorizeValueModel = register.SendCypherTextToProtectedResourceForVerify(authClient, "目標Protected Server Id"); PostSampleData postSampleData = new PostSampleData() { Data = "Sample1", Data2 = "Sample2" }; //取得 afterPostAuthorizeValueModel 後,更新 AuthorizeValueModel 供下次呼叫此 Protected Server 使用 var afterPostAuthorizeValueModel = register.SendRequestAndAuthorizeByPost <PostSampleData>("目標Protected Server URL", authorizeValueModel, postSampleData); }
public async Task <IActionResult> UpdateClient(int id, [FromBody] ClientResource clientResource) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var client = await context.Clients.FindAsync(id); if (client == null) { return(NotFound()); } mapper.Map <ClientResource, Client>(clientResource, client); await context.SaveChangesAsync(); var result = mapper.Map <Client, ClientResource>(client); return(Ok(result)); }
public bool Add(ResourceType type, string data, bool renderTag = false) { if (type == ResourceType.ScriptFile || type == ResourceType.StyleFile) { var ldata = data.ToLower(CultureInfo.InvariantCulture); var isAddedAlready = Resources.Any(t => t.Data.ToLower() == ldata); if (isAddedAlready) { return(false); } } var item = new ClientResource { Type = type, Data = data, RenderTag = renderTag, }; Resources.Add(item); return(true); }
/// <inheritdoc /> /// <summary> /// Update a client <b>Permissions Needed:</b> CLIENTS_ADMIN /// </summary> /// <param name="clientKey">The key of the client</param> /// <param name="clientResource">The client resource object</param> public void UpdateClient(string clientKey, ClientResource clientResource) { // verify the required parameter 'clientKey' is set if (clientKey == null) { throw new KnetikException(400, "Missing required parameter 'clientKey' when calling UpdateClient"); } mWebCallEvent.WebPath = "/auth/clients/{client_key}"; if (!string.IsNullOrEmpty(mWebCallEvent.WebPath)) { mWebCallEvent.WebPath = mWebCallEvent.WebPath.Replace("{format}", "json"); } mWebCallEvent.WebPath = mWebCallEvent.WebPath.Replace("{" + "client_key" + "}", KnetikClient.ParameterToString(clientKey)); mWebCallEvent.HeaderParams.Clear(); mWebCallEvent.QueryParams.Clear(); mWebCallEvent.AuthSettings.Clear(); mWebCallEvent.PostBody = null; mWebCallEvent.PostBody = KnetikClient.Serialize(clientResource); // http body (model) parameter // authentication settings mWebCallEvent.AuthSettings.Add("oauth2_client_credentials_grant"); // authentication settings mWebCallEvent.AuthSettings.Add("oauth2_password_grant"); // make the HTTP request mUpdateClientStartTime = DateTime.Now; mWebCallEvent.Context = mUpdateClientResponseContext; mWebCallEvent.RequestType = KnetikRequestType.PUT; KnetikLogger.LogRequest(mUpdateClientStartTime, "UpdateClient", "Sending server request..."); KnetikGlobalEventSystem.Publish(mWebCallEvent); }
public override ActionResult Index(CustomFormContainerBlock currentBlock) { var contextMode = ControllerContext.RequestContext.GetContextMode(); var isDefaultOrPreview = (contextMode == ContextMode.Default) || (contextMode == ContextMode.Preview); if (isDefaultOrPreview) { var instance = ServiceLocator.Current.GetInstance <IRequiredClientResourceList>(); var webResourceUrl = ModuleHelper.GetWebResourceUrl(typeof(FormContainerBlockController), "EPiServer.Forms.ClientResources.ViewMode.EPiServerForms.css"); var clientResource = new ClientResource { Name = "EPiServerForms.css", Dependencies = new List <string> { "EPiServerForms_prerequisite.js" }, ResourceType = ClientResourceType.Html, InlineContent = "<link rel='stylesheet' type='text/css' data-epiforms-resource='EPiServerForms.css' href='" + webResourceUrl + "' />" }; instance.Require(clientResource).AtHeader(); if (!EPiServerFormsSection.Instance.WorkInNonJSMode) { InitJs(instance); } } currentBlock.BuildFormModel(); var result = PartialView("Blocks/EPiServerForms/CustomFormContainerBlock", currentBlock); if ((currentBlock.Form != null) && isDefaultOrPreview) { var expectedFormGuid = GetExpectedFormGuid(); var currentStepIndex = GetCurrentStepIndex(currentBlock, expectedFormGuid); var formSubmissionId = GetFormSubmissionId(currentBlock); ViewBag.IsStepValidToDisplay = currentStepIndex.HasValue && _stepValidationHandler.Service.IsStepValidToDisplay( new FormIdentity(), currentBlock, currentStepIndex.Value, formSubmissionId); SetCurrentStepIndex(currentStepIndex); ViewBag.FormSubmissionId = formSubmissionId; ViewBag.ValidationFail = false; ViewBag.Submittable = false; ViewBag.Message = this.GetParamValue("__FormMessage"); ViewBag.FormFinalized = IsFormFinalized(currentBlock, expectedFormGuid); if (currentBlock.Form.IsMalFormSteps()) { ViewBag.Message = FormsExtensions.LocalizationService.GetString( "/episerver/forms/viewmode/malformstepconfigruation"); return(result); } if (IsFormFinalized()) { return(result); } var submittableStatus = currentBlock.Form.GetSubmittableStatus(ControllerContext.HttpContext); ViewBag.Submittable = submittableStatus.Submittable; if (!submittableStatus.Submittable) { ViewBag.Message = submittableStatus.Message; return(result); } ViewBag.ValidationFail = IsValidationFail(currentBlock, expectedFormGuid); } return(result); }
public void ProvideProperName() { var resource = new ClientResource(); Assert.Equal("glimpse_client", resource.Name); }
public void ReturnOneParameterKeys() { var resource = new ClientResource(); Assert.Equal(1, resource.Parameters.Count()); }
public void ThrowExceptionWithNullParameters() { var resource = new ClientResource(); Assert.Throws <ArgumentNullException>(() => resource.Execute(null)); }