Added client library
This commit is contained in:
@@ -8,6 +8,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ApplicationLayer", "Applica
|
|||||||
EndProject
|
EndProject
|
||||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Infrastructure", "Infrastructure\Infrastructure.csproj", "{2BE88B8B-10CE-48AA-9884-ABEE4A4487F7}"
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Infrastructure", "Infrastructure\Infrastructure.csproj", "{2BE88B8B-10CE-48AA-9884-ABEE4A4487F7}"
|
||||||
EndProject
|
EndProject
|
||||||
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "VisaApiClient", "VisaApiClient\VisaApiClient.csproj", "{46172CC0-8935-4158-9B7F-50FCCBDB6F67}"
|
||||||
|
EndProject
|
||||||
Global
|
Global
|
||||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||||
Debug|Any CPU = Debug|Any CPU
|
Debug|Any CPU = Debug|Any CPU
|
||||||
@@ -30,5 +32,9 @@ Global
|
|||||||
{2BE88B8B-10CE-48AA-9884-ABEE4A4487F7}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
{2BE88B8B-10CE-48AA-9884-ABEE4A4487F7}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
{2BE88B8B-10CE-48AA-9884-ABEE4A4487F7}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
{2BE88B8B-10CE-48AA-9884-ABEE4A4487F7}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
{2BE88B8B-10CE-48AA-9884-ABEE4A4487F7}.Release|Any CPU.Build.0 = Release|Any CPU
|
{2BE88B8B-10CE-48AA-9884-ABEE4A4487F7}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
|
{46172CC0-8935-4158-9B7F-50FCCBDB6F67}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
|
{46172CC0-8935-4158-9B7F-50FCCBDB6F67}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
|
{46172CC0-8935-4158-9B7F-50FCCBDB6F67}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
|
{46172CC0-8935-4158-9B7F-50FCCBDB6F67}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
EndGlobalSection
|
EndGlobalSection
|
||||||
EndGlobal
|
EndGlobal
|
||||||
|
|||||||
2060
SchengenVisaApi/VisaApiClient/Client.cs
Normal file
2060
SchengenVisaApi/VisaApiClient/Client.cs
Normal file
File diff suppressed because it is too large
Load Diff
39
SchengenVisaApi/VisaApiClient/ClientBase.cs
Normal file
39
SchengenVisaApi/VisaApiClient/ClientBase.cs
Normal file
@@ -0,0 +1,39 @@
|
|||||||
|
using System.Text;
|
||||||
|
|
||||||
|
namespace VisaApiClient
|
||||||
|
{
|
||||||
|
public class ClientBase
|
||||||
|
{
|
||||||
|
private const string LoginPath = "users/login";
|
||||||
|
|
||||||
|
protected string? AuthToken { get; private set; }
|
||||||
|
|
||||||
|
protected void SetAuthToken(string token)
|
||||||
|
{
|
||||||
|
AuthToken = token;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected Task<HttpRequestMessage> CreateHttpRequestMessageAsync(CancellationToken cancellationToken)
|
||||||
|
{
|
||||||
|
var msg = new HttpRequestMessage();
|
||||||
|
msg.Headers.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("Bearer", AuthToken);
|
||||||
|
return Task.FromResult(msg);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
protected async Task PrepareRequestAsync(HttpClient client, HttpRequestMessage request, string url, CancellationToken cancellationToken)
|
||||||
|
=> await Task.CompletedTask;
|
||||||
|
|
||||||
|
protected async Task PrepareRequestAsync(HttpClient client, HttpRequestMessage request, StringBuilder urlBuilder, CancellationToken cancellationToken)
|
||||||
|
=> await Task.CompletedTask;
|
||||||
|
|
||||||
|
protected async Task ProcessResponseAsync(HttpClient client, HttpResponseMessage response, CancellationToken cancellationToken)
|
||||||
|
{
|
||||||
|
if (response.RequestMessage!.RequestUri!.AbsolutePath == LoginPath)
|
||||||
|
{
|
||||||
|
var token = await response.Content.ReadAsStringAsync(cancellationToken);
|
||||||
|
SetAuthToken(token);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
13
SchengenVisaApi/VisaApiClient/VisaApiClient.csproj
Normal file
13
SchengenVisaApi/VisaApiClient/VisaApiClient.csproj
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
|
<PropertyGroup>
|
||||||
|
<TargetFramework>net8.0</TargetFramework>
|
||||||
|
<ImplicitUsings>enable</ImplicitUsings>
|
||||||
|
<Nullable>enable</Nullable>
|
||||||
|
</PropertyGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
</Project>
|
||||||
Reference in New Issue
Block a user