protected async Task <ActionResult <Api.OAuthClientSecretResponse> > Post(Api.OAuthClientSecretRequest party) { try { if (!await ModelState.TryValidateObjectAsync(party)) { return(BadRequest(ModelState)); } var oauthDownParty = await tenantService.GetAsync <TParty>(await DownParty.IdFormat(RouteBinding, party.PartyName)); var secret = new OAuthClientSecret(); await secretHashLogic.AddSecretHashAsync(secret, party.Secret); if (oauthDownParty.Client.Secrets == null) { oauthDownParty.Client.Secrets = new List <OAuthClientSecret>(); } oauthDownParty.Client.Secrets.Add(secret); await tenantService.UpdateAsync(oauthDownParty); return(Created(mapper.Map <Api.OAuthClientSecretResponse>(secret).Set(s => s.Name = new[] { oauthDownParty.Name, s.Name }.ToDotList()))); } catch (CosmosDataException ex) { if (ex.StatusCode == HttpStatusCode.Conflict) { logger.Warning(ex, $"Create secret on client '{typeof(TParty).Name}' by name '{party.PartyName}'."); return(Conflict(typeof(TParty).Name, party.PartyName)); } throw; } }
protected async Task <ActionResult> Post(Api.OAuthClientSecretRequest secretRequest) { try { if (!await ModelState.TryValidateObjectAsync(secretRequest)) { return(BadRequest(ModelState)); } secretRequest.PartyName = secretRequest.PartyName?.ToLower(); var oauthDownParty = await tenantRepository.GetAsync <TParty>(await DownParty.IdFormatAsync(RouteBinding, secretRequest.PartyName)); foreach (var s in secretRequest.Secrets) { var secret = new OAuthClientSecret(); await secretHashLogic.AddSecretHashAsync(secret, s); if (oauthDownParty.Client.Secrets == null) { oauthDownParty.Client.Secrets = new List <OAuthClientSecret>(); } oauthDownParty.Client.Secrets.Add(secret); } secretRequest.Secrets = oauthDownParty.Client.Secrets.Select(s => s.Id).ToList(); if (!await ModelState.TryValidateObjectAsync(secretRequest)) { return(BadRequest(ModelState)); } await tenantRepository.UpdateAsync(oauthDownParty); return(Created(new Api.OAuthDownParty { Name = secretRequest.PartyName })); } catch (CosmosDataException ex) { if (ex.StatusCode == HttpStatusCode.Conflict) { logger.Warning(ex, $"Conflict, Create secret on client '{typeof(TParty).Name}' by name '{secretRequest.PartyName}'."); return(Conflict(typeof(TParty).Name, secretRequest.PartyName)); } throw; } }
public async Task <ActionResult <Api.OidcDownParty> > PostOidcClientSecretDownParty([FromBody] Api.OAuthClientSecretRequest secretRequest) => await Post(secretRequest);
public async Task <ActionResult <Api.OAuthClientSecretResponse> > PostOidcClientSecretDownParty([FromBody] Api.OAuthClientSecretRequest party) => await Post(party);