public async Task Enrich(JwsPayload jwsPayload, OpenIdClient client) { var subject = jwsPayload.GetClaimValue(Jwt.Constants.UserClaims.Subject); using (var httpClient = new HttpClient()) { var request = new HttpRequestMessage { RequestUri = new Uri(_httpClaimsSourceOptions.Url), Method = HttpMethod.Get, // Content = new StringContent(JsonConvert.SerializeObject(new { sub = subject }), Encoding.UTF8, "application/json") }; if (!string.IsNullOrWhiteSpace(_httpClaimsSourceOptions.ApiToken)) { request.Headers.Add("Authorization", $"Bearer {_httpClaimsSourceOptions.ApiToken}"); } var result = await httpClient.SendAsync(request).ConfigureAwait(false); var json = await result.Content.ReadAsStringAsync().ConfigureAwait(false); var kvp = result.Content.Headers.FirstOrDefault(k => k.Key == "Content-Type"); if (!kvp.Equals(default(KeyValuePair <string, IEnumerable <string> >)) && !string.IsNullOrWhiteSpace(kvp.Key) && result.IsSuccessStatusCode) { string jwt = null; JwsPayload jObj = null; if (kvp.Value.Any(v => v.Contains("application/json"))) { jObj = JsonConvert.DeserializeObject <JwsPayload>(json); jwt = await _jwtBuilder.BuildClientToken(client, jObj, client.IdTokenSignedResponseAlg, client.IdTokenEncryptedResponseAlg, client.IdTokenEncryptedResponseEnc); } else if (kvp.Value.Any(v => v.Contains("application/jwt"))) { throw new NotImplementedException(); /* * jwt = json; * jObj = Extract(json); */ } if (!string.IsNullOrWhiteSpace(jwt)) { ClaimsSourceHelper.AddAggregate(jwsPayload, jObj, jwt, _httpClaimsSourceOptions.Name); } } } }
public Task Enrich(JwsPayload jwsPayload, OpenIdClient openidClient, CancellationToken cancellationToken) { ClaimsSourceHelper.AddDistribute(jwsPayload, _distributeHttpClaimsSourceOptions.Name, _distributeHttpClaimsSourceOptions.Url, _distributeHttpClaimsSourceOptions.ApiToken, _distributeHttpClaimsSourceOptions.ClaimNames); return(Task.FromResult(0)); }