Added userinfo endpoint usage and api now properly creates necessary claims to start doing database stuff

This commit is contained in:
2021-10-18 11:06:44 -04:00
parent 320d939c76
commit 9e6c7f33a5
13 changed files with 129 additions and 88 deletions

View File

@@ -7,6 +7,7 @@ using System.Threading.Tasks;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.Logging;
using Newtonsoft.Json;
using WebAPI.Data.Dto.OIDC;
namespace WebAPI.Data
{
@@ -49,6 +50,21 @@ namespace WebAPI.Data
var responsecontent = await response.Content.ReadAsStringAsync();
return JsonConvert.DeserializeObject<IntrospectionResponse>(responsecontent).Active;
}
public async Task<OIDCUserInfoResponse> GetTokenDetails(string accessToken)
{
HttpRequestMessage requestMessage =
new HttpRequestMessage(HttpMethod.Get, $"https://{AppSettings.OIDCUserInfoEndpoint}");
requestMessage.Headers.Authorization = new AuthenticationHeaderValue("Bearer", accessToken);
HttpResponseMessage response = await _httpClient.SendAsync(requestMessage);
if (!response.IsSuccessStatusCode)
{
return null;
}
var responsecontent = await response.Content.ReadAsStringAsync();
return JsonConvert.DeserializeObject<OIDCUserInfoResponse>(responsecontent);
}
}
}