-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
91 additions
and
34 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 7 additions & 0 deletions
7
sources/Clients.Identity.Api.Shared/Authentications/LoginProxyRequest.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
namespace MadWorldNL.Clients.Identity.Api.Shared.Authentications; | ||
|
||
public class LoginProxyRequest | ||
{ | ||
public string Email { get; set; } = string.Empty; | ||
public string Password { get; set; } = string.Empty; | ||
} |
17 changes: 17 additions & 0 deletions
17
sources/Clients.Identity.Api.Shared/Builders/WebApplicationBuilderExtensions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,28 @@ | ||
using MadWorldNL.Clients.Identity.Api.Shared.Services; | ||
using MadWorldNL.Clients.Identity.Api.Shared.Settings; | ||
using Microsoft.AspNetCore.Builder; | ||
using Microsoft.Extensions.Configuration; | ||
using Microsoft.Extensions.DependencyInjection; | ||
using Server.Presentation.Grpc.Authentication.V1; | ||
|
||
namespace MadWorldNL.Clients.Identity.Api.Shared.Builders; | ||
|
||
public static class WebApplicationBuilderExtensions | ||
{ | ||
public static void AddIdentity(this WebApplicationBuilder builder) | ||
{ | ||
var identitySettings = builder.Configuration.GetSection(IdentitySettings.Entry); | ||
|
||
builder.Services.AddOptions<IdentitySettings>() | ||
.Bind(identitySettings) | ||
.ValidateDataAnnotations(); | ||
|
||
builder.Services.AddGrpcClient<Authentication.AuthenticationClient>(option => | ||
{ | ||
var identityHost = identitySettings.GetValue<string>(nameof(IdentitySettings.Host))!; | ||
option.Address = new Uri(identityHost); | ||
}); | ||
|
||
builder.Services.AddScoped<AuthenticationService>(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 17 additions & 1 deletion
18
sources/Clients.Identity.Api.Shared/Endpoints/EndpointsExtensions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,27 @@ | ||
using MadWorldNL.Clients.Identity.Api.Shared.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; | ||
|
||
public static class EndpointsExtensions | ||
{ | ||
public static void AddIdentityEndpoints(this WebApplication app) | ||
{ | ||
|
||
app.AddAuthenticationEndpoints(); | ||
} | ||
|
||
private static void AddAuthenticationEndpoints(this WebApplication app) | ||
{ | ||
var authenticationEndpoints = app.MapGroup("/Authentication") | ||
.WithTags("Authentication"); | ||
|
||
authenticationEndpoints.MapPost("/Login", | ||
([AsParameters] LoginProxyRequest request, [FromServices] AuthenticationService authenticationService) => | ||
authenticationService.AuthenticateAsync(request)) | ||
.WithName("Login"); | ||
} | ||
} |
30 changes: 30 additions & 0 deletions
30
sources/Clients.Identity.Api.Shared/Services/AuthenticationService.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
using MadWorldNL.Clients.Identity.Api.Shared.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 | ||
{ | ||
private readonly Authentication.AuthenticationClient _client; | ||
private readonly IdentitySettings _identitySettings; | ||
|
||
public AuthenticationService(Authentication.AuthenticationClient client, IOptions<IdentitySettings> identitySettings) | ||
{ | ||
_client = client; | ||
_identitySettings = identitySettings.Value; | ||
} | ||
|
||
public async Task<LoginResponse> AuthenticateAsync(LoginProxyRequest proxyRequest) | ||
{ | ||
var request = new LoginRequest | ||
{ | ||
Audience = _identitySettings.Audience, | ||
Username = proxyRequest.Email, | ||
Password = proxyRequest.Password | ||
}; | ||
|
||
return await _client.LoginAsync(request); | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
sources/Clients.Identity.Api.Shared/Settings/IdentitySettings.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
namespace MadWorldNL.Clients.Identity.Api.Shared.Settings; | ||
|
||
public class IdentitySettings | ||
{ | ||
public const string Entry = "Identity"; | ||
|
||
public string Audience { get; set; } = string.Empty; | ||
public string Host { get; set; } = string.Empty; | ||
} |