Кодировка
This commit is contained in:
parent
b129f22b73
commit
9659b7bc8c
@ -9,12 +9,12 @@ using System.Text.Json;
|
||||
namespace DD.Persistence.Client.Helpers;
|
||||
|
||||
/// <summary>
|
||||
/// Êëàññ, ïîçâîëÿþùèé ãåíåðèðîâàòü api-token
|
||||
/// Класс, позволяющий генерировать api-token
|
||||
/// </summary>
|
||||
public static class ApiTokenHelper
|
||||
{
|
||||
/// <summary>
|
||||
/// Ìåòîä àâòîðèàöèè
|
||||
/// Метод авторизации
|
||||
/// </summary>
|
||||
/// <param name="httpClient"></param>
|
||||
/// <param name="configuration"></param>
|
||||
@ -30,14 +30,14 @@ public static class ApiTokenHelper
|
||||
var keycloakGetTokenUrl = configuration.GetSection("KeycloakGetTokenUrl").Get<string>() ?? string.Empty;
|
||||
|
||||
var jwtToken = needUseKeyCloak
|
||||
? authUser.CreateKeyCloakJwtToken(keycloakGetTokenUrl)
|
||||
? authUser.CreateKeyCloakJwtToken(keycloakGetTokenUrl, httpClient)
|
||||
: authUser.CreateDefaultJwtToken();
|
||||
|
||||
httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", jwtToken);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Àâòîðèçàöèÿ ÷åðåç ñîáñòâåííûé jwt-òîêåí
|
||||
/// Авторизация через собственный jwt-токен
|
||||
/// </summary>
|
||||
/// <param name="authUser"></param>
|
||||
/// <returns></returns>
|
||||
@ -68,14 +68,13 @@ public static class ApiTokenHelper
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Àâòîðèçàöèÿ ÷åðåç jwt-òîêåí keycloak
|
||||
/// Авторизация через jwt-токен keycloak
|
||||
/// </summary>
|
||||
/// <param name="authUser"></param>
|
||||
/// <param name="keycloakGetTokenUrl"></param>
|
||||
/// <returns></returns>
|
||||
private static string CreateKeyCloakJwtToken(this AuthUser authUser, string keycloakGetTokenUrl)
|
||||
private static string CreateKeyCloakJwtToken(this AuthUser authUser, string keycloakGetTokenUrl, HttpClient httpClient)
|
||||
{
|
||||
var sharedClient = new HttpClient();
|
||||
var parameters = new Dictionary<string, string> {
|
||||
{ "username", authUser.Username },
|
||||
{ "password", authUser.Password },
|
||||
@ -84,7 +83,7 @@ public static class ApiTokenHelper
|
||||
};
|
||||
var encodedContent = new FormUrlEncodedContent(parameters);
|
||||
|
||||
using HttpResponseMessage response = sharedClient.PostAsync(keycloakGetTokenUrl, encodedContent).GetAwaiter().GetResult();
|
||||
using HttpResponseMessage response = httpClient.PostAsync(keycloakGetTokenUrl, encodedContent).GetAwaiter().GetResult();
|
||||
|
||||
if (response.IsSuccessStatusCode == true)
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user