Skip to content

Commit

Permalink
Add contracts project
Browse files Browse the repository at this point in the history
  • Loading branch information
oveldman committed Apr 1, 2024
1 parent 13004c6 commit 960f1a3
Show file tree
Hide file tree
Showing 7 changed files with 47 additions and 17 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace MadWorldNL.Clients.Identity.Api.Shared.Authentications;
namespace MadWorldNL.Clients.Identity.Api.Contracts.Authentications;

public class LoginProxyRequest
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
namespace MadWorldNL.Clients.Identity.Api.Contracts.Authentications;

public class LoginProxyResponse
{
public bool IsSuccess { get; set; }
public string AccessToken { get; set; } = string.Empty;
public DateTime Expiration { get; set; }
public string RefreshToken { get; set; } = string.Empty;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<RootNamespace>MadWorldNL.Clients.Identity.Api.Contracts</RootNamespace>
<AssemblyName>$(RootNamespace)</AssemblyName>
</PropertyGroup>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\Clients.Identity.Api.Contracts\Clients.Identity.Api.Contracts.csproj" />
<ProjectReference Include="..\ClientSdk.Grpc\ClientSdk.Grpc.csproj" />
</ItemGroup>

Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
using MadWorldNL.Clients.Identity.Api.Shared.Authentications;
using MadWorldNL.Clients.Identity.Api.Contracts.Authentications;
using MadWorldNL.Clients.Identity.Api.Shared.Services;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Server.Presentation.Grpc.Authentication.V1;

namespace MadWorldNL.Clients.Identity.Api.Shared.Endpoints;

Expand All @@ -20,7 +19,7 @@ private static void AddAuthenticationEndpoints(this WebApplication app)
.WithTags("Authentication");

authenticationEndpoints.MapPost("/Login",
([AsParameters] LoginProxyRequest request, [FromServices] AuthenticationService authenticationService) =>
([FromBody] LoginProxyRequest request, [FromServices] AuthenticationService authenticationService) =>
authenticationService.AuthenticateAsync(request))
.WithName("Login");
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,22 +1,17 @@
using MadWorldNL.Clients.Identity.Api.Shared.Authentications;
using MadWorldNL.Clients.Identity.Api.Contracts.Authentications;
using MadWorldNL.Clients.Identity.Api.Shared.Settings;
using Microsoft.Extensions.Options;
using Server.Presentation.Grpc.Authentication.V1;

namespace MadWorldNL.Clients.Identity.Api.Shared.Services;

public sealed class AuthenticationService
public sealed class AuthenticationService(
Authentication.AuthenticationClient client,
IOptions<IdentitySettings> identitySettings)
{
private readonly Authentication.AuthenticationClient _client;
private readonly IdentitySettings _identitySettings;
private readonly IdentitySettings _identitySettings = identitySettings.Value;

public AuthenticationService(Authentication.AuthenticationClient client, IOptions<IdentitySettings> identitySettings)
{
_client = client;
_identitySettings = identitySettings.Value;
}

public async Task<LoginResponse> AuthenticateAsync(LoginProxyRequest proxyRequest)
public async Task<LoginProxyResponse> AuthenticateAsync(LoginProxyRequest proxyRequest)
{
var request = new LoginRequest
{
Expand All @@ -25,6 +20,14 @@ public async Task<LoginResponse> AuthenticateAsync(LoginProxyRequest proxyReques
Password = proxyRequest.Password
};

return await _client.LoginAsync(request);
var response = await client.LoginAsync(request);

return new LoginProxyResponse()
{
IsSuccess = response.IsSuccess,
AccessToken = response.AccessToken,
Expiration = response.Expiration.ToDateTime(),
RefreshToken = response.RefreshToken
};
}
}
12 changes: 11 additions & 1 deletion sources/MadWorldNL.Identity.sln
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Clients.Admin.BFF", "Client
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Clients.Identity.Api.Shared", "Clients.Identity.Api.Shared\Clients.Identity.Api.Shared.csproj", "{7F925140-B483-461E-9740-646E40771F4E}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Shared", "Shared", "{F11E5F0F-DE3D-466E-AB4E-3AEE0BE5A5ED}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Clients.Identity.Api.Contracts", "Clients.Identity.Api.Contracts\Clients.Identity.Api.Contracts.csproj", "{6EE2F699-9915-4D62-96DB-5361C5094193}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand All @@ -68,7 +72,9 @@ Global
{18DCD2E1-CF25-4FAA-816A-3CFB316DD39F} = {FD69CCDE-B746-4AAF-B04C-9628249B7AD1}
{2CBE9479-2507-4235-AA27-E0DD7C898B7B} = {FD69CCDE-B746-4AAF-B04C-9628249B7AD1}
{E7111595-76B0-4A1D-AD45-819C7311887B} = {FD69CCDE-B746-4AAF-B04C-9628249B7AD1}
{7F925140-B483-461E-9740-646E40771F4E} = {FD69CCDE-B746-4AAF-B04C-9628249B7AD1}
{F11E5F0F-DE3D-466E-AB4E-3AEE0BE5A5ED} = {FD69CCDE-B746-4AAF-B04C-9628249B7AD1}
{7F925140-B483-461E-9740-646E40771F4E} = {F11E5F0F-DE3D-466E-AB4E-3AEE0BE5A5ED}
{6EE2F699-9915-4D62-96DB-5361C5094193} = {F11E5F0F-DE3D-466E-AB4E-3AEE0BE5A5ED}
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{2B04007E-B2D9-4E8B-82D2-C553CD5F3DA2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
Expand Down Expand Up @@ -111,5 +117,9 @@ Global
{7F925140-B483-461E-9740-646E40771F4E}.Debug|Any CPU.Build.0 = Debug|Any CPU
{7F925140-B483-461E-9740-646E40771F4E}.Release|Any CPU.ActiveCfg = Release|Any CPU
{7F925140-B483-461E-9740-646E40771F4E}.Release|Any CPU.Build.0 = Release|Any CPU
{6EE2F699-9915-4D62-96DB-5361C5094193}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{6EE2F699-9915-4D62-96DB-5361C5094193}.Debug|Any CPU.Build.0 = Debug|Any CPU
{6EE2F699-9915-4D62-96DB-5361C5094193}.Release|Any CPU.ActiveCfg = Release|Any CPU
{6EE2F699-9915-4D62-96DB-5361C5094193}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
EndGlobal

0 comments on commit 960f1a3

Please sign in to comment.