call api key in repo genaric
This commit is contained in:
parent
451d5d28bc
commit
169b3428e7
3 changed files with 40 additions and 24 deletions
|
|
@ -20,7 +20,6 @@ namespace BMA.EHR.Application.Repositories
|
|||
private readonly IApplicationDBContext _dbContext;
|
||||
private readonly DbSet<T> _dbSet;
|
||||
private readonly IHttpContextAccessor _httpContextAccessor;
|
||||
private readonly IConfiguration _configuration;
|
||||
|
||||
#endregion
|
||||
|
||||
|
|
@ -53,14 +52,14 @@ namespace BMA.EHR.Application.Repositories
|
|||
|
||||
#region " For Call External API "
|
||||
|
||||
protected async Task<string> GetExternalAPIAsync(string apiPath, string accessToken)
|
||||
protected async Task<string> GetExternalAPIAsync(string apiPath, string accessToken, string apiKey)
|
||||
{
|
||||
try
|
||||
{
|
||||
using (var client = new HttpClient())
|
||||
{
|
||||
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", accessToken.Replace("Bearer ", ""));
|
||||
client.DefaultRequestHeaders.Add("api_key", _configuration["API_KEY"]);
|
||||
client.DefaultRequestHeaders.Add("api_key", apiKey);
|
||||
var _res = await client.GetAsync(apiPath);
|
||||
if (_res.IsSuccessStatusCode)
|
||||
{
|
||||
|
|
@ -77,7 +76,7 @@ namespace BMA.EHR.Application.Repositories
|
|||
}
|
||||
}
|
||||
|
||||
protected async Task<string> PostExternalAPIAsync(string apiPath, string accessToken, object? body)
|
||||
protected async Task<string> PostExternalAPIAsync(string apiPath, string accessToken, object? body, string apiKey)
|
||||
{
|
||||
try
|
||||
{
|
||||
|
|
@ -88,7 +87,7 @@ namespace BMA.EHR.Application.Repositories
|
|||
using (var client = new HttpClient())
|
||||
{
|
||||
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", accessToken.Replace("Bearer ", ""));
|
||||
client.DefaultRequestHeaders.Add("api_key", _configuration["API_KEY"]);
|
||||
client.DefaultRequestHeaders.Add("api_key", apiKey);
|
||||
var _res = await client.PostAsync(apiPath, stringContent);
|
||||
if (_res.IsSuccessStatusCode)
|
||||
{
|
||||
|
|
@ -105,7 +104,7 @@ namespace BMA.EHR.Application.Repositories
|
|||
}
|
||||
}
|
||||
|
||||
protected async Task<bool> PostExternalAPIBooleanAsync(string apiPath, string accessToken, object? body)
|
||||
protected async Task<bool> PostExternalAPIBooleanAsync(string apiPath, string accessToken, object? body, string apiKey)
|
||||
{
|
||||
try
|
||||
{
|
||||
|
|
@ -116,7 +115,7 @@ namespace BMA.EHR.Application.Repositories
|
|||
using (var client = new HttpClient())
|
||||
{
|
||||
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", accessToken.Replace("Bearer ", ""));
|
||||
client.DefaultRequestHeaders.Add("api_key", _configuration["API_KEY"]);
|
||||
client.DefaultRequestHeaders.Add("api_key", apiKey);
|
||||
var _res = await client.PostAsync(apiPath, stringContent);
|
||||
return _res.IsSuccessStatusCode;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue