permission สรรหา
This commit is contained in:
parent
6f60af960f
commit
1b9bc7dc97
3 changed files with 114 additions and 2 deletions
62
Repositories/PermissionRepository.cs
Normal file
62
Repositories/PermissionRepository.cs
Normal file
|
|
@ -0,0 +1,62 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using BMA.EHR.Recruit.Service.Data;
|
||||
using BMA.EHR.Recruit.Service.Models.Recruits;
|
||||
using BMA.EHR.Recruit.Service.Core;
|
||||
using BMA.EHR.MetaData.Service.Models;
|
||||
using BMA.EHR.Domain.Models.Placement;
|
||||
using BMA.EHR.Recurit.Service.Data;
|
||||
using System.Security.Claims;
|
||||
using System.Net.Http.Headers;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace BMA.EHR.Recruit.Service.Services
|
||||
{
|
||||
public class PermissionRepository
|
||||
{
|
||||
private readonly IHttpContextAccessor _httpContextAccessor;
|
||||
private readonly IConfiguration _configuration;
|
||||
|
||||
public PermissionRepository(IHttpContextAccessor httpContextAccessor,
|
||||
IConfiguration configuration)
|
||||
{
|
||||
_httpContextAccessor = httpContextAccessor;
|
||||
_configuration = configuration;
|
||||
}
|
||||
|
||||
#region " Properties "
|
||||
|
||||
private string? AccessToken => _httpContextAccessor?.HttpContext?.Request.Headers["Authorization"];
|
||||
|
||||
#endregion
|
||||
|
||||
#region " Methods "
|
||||
|
||||
public async Task<dynamic> GetPermissionAPIAsync(string action, string system)
|
||||
{
|
||||
try
|
||||
{
|
||||
var apiPath = $"{_configuration["API"]}/org/permission/dotnet/{action}/{system}";
|
||||
|
||||
using (var client = new HttpClient())
|
||||
{
|
||||
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", AccessToken.Replace("Bearer ", ""));
|
||||
client.DefaultRequestHeaders.Add("api_key", _configuration["API_KEY"]);
|
||||
var req = await client.GetAsync(apiPath);
|
||||
var res = await req.Content.ReadAsStringAsync();
|
||||
return res;
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue