public async Task <BaseResponse> ExecuteAsync(Uri scopesUri, ScopeResponse scope, string authorizationHeaderValue = null) { if (scopesUri == null) { throw new ArgumentNullException(nameof(scopesUri)); } if (scope == null) { throw new ArgumentNullException(nameof(scope)); } var httpClient = _httpClientFactory.GetHttpClient(); var serializedJson = JObject.FromObject(scope).ToString(); var body = new StringContent(serializedJson, Encoding.UTF8, "application/json"); var request = new HttpRequestMessage { Method = HttpMethod.Post, RequestUri = scopesUri, Content = body }; if (!string.IsNullOrWhiteSpace(authorizationHeaderValue)) { request.Headers.Add("Authorization", "Bearer " + authorizationHeaderValue); } var httpResult = await httpClient.SendAsync(request); var content = await httpResult.Content.ReadAsStringAsync().ConfigureAwait(false); try { httpResult.EnsureSuccessStatusCode(); } catch (Exception) { return(new BaseResponse { ContainsError = true, Error = JsonConvert.DeserializeObject <ErrorResponse>(content), HttpStatus = httpResult.StatusCode }); } return(new BaseResponse()); }
public async Task <ActionResult> Update([FromBody] ScopeResponse request) { if (request == null) { throw new ArgumentNullException(nameof(request)); } if (!await _scopeActions.UpdateScope(request.ToParameter())) { return(new StatusCodeResult(StatusCodes.Status500InternalServerError)); } await _representationManager.AddOrUpdateRepresentationAsync(this, ScopeStoreName + request.Name, false); return(new NoContentResult()); }
public static Scope ToParameter(this ScopeResponse scopeResponse) { if (scopeResponse == null) { throw new ArgumentNullException(nameof(scopeResponse)); } return(new Scope { Description = scopeResponse.Description, IsDisplayedInConsent = scopeResponse.IsDisplayedInConsent, IsExposed = scopeResponse.IsExposed, IsOpenIdScope = scopeResponse.IsOpenIdScope, Name = scopeResponse.Name, Type = scopeResponse.Type, Claims = scopeResponse.Claims }); }
public async Task <BaseResponse> ResolveUpdate(Uri wellKnownConfigurationUri, ScopeResponse client, string authorizationHeaderValue = null) { var configuration = await _configurationClient.GetConfiguration(wellKnownConfigurationUri).ConfigureAwait(false); return(await _updateScopeOperation.ExecuteAsync(new Uri(configuration.Content.ScopesEndpoint), client, authorizationHeaderValue).ConfigureAwait(false)); }