Skip to content

Commit

Permalink
Start with bff
Browse files Browse the repository at this point in the history
  • Loading branch information
oveldman committed Mar 31, 2024
1 parent 0c57393 commit 13004c6
Show file tree
Hide file tree
Showing 10 changed files with 91 additions and 34 deletions.
6 changes: 0 additions & 6 deletions sources/Clients.Admin.BFF/Clients.Admin.BFF.http

This file was deleted.

27 changes: 1 addition & 26 deletions sources/Clients.Admin.BFF/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,29 +22,4 @@
app.UseHttpsRedirection();
app.AddIdentityEndpoints();

var summaries = new[]
{
"Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching"
};

app.MapGet("/weatherforecast", () =>
{
var forecast = Enumerable.Range(1, 5).Select(index =>
new WeatherForecast
(
DateOnly.FromDateTime(DateTime.Now.AddDays(index)),
Random.Shared.Next(-20, 55),
summaries[Random.Shared.Next(summaries.Length)]
))
.ToArray();
return forecast;
})
.WithName("GetWeatherForecast")
.WithOpenApi();

app.Run();

record WeatherForecast(DateOnly Date, int TemperatureC, string? Summary)
{
public int TemperatureF => 32 + (int)(TemperatureC / 0.5556);
}
app.Run();
4 changes: 4 additions & 0 deletions sources/Clients.Admin.BFF/appsettings.Development.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
{
"Identity": {
"Audience": "https://admin.mad-world.nl",
"Host": " http://localhost:5266"
},
"Logging": {
"LogLevel": {
"Default": "Information",
Expand Down
4 changes: 4 additions & 0 deletions sources/Clients.Admin.BFF/appsettings.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
{
"Identity": {
"Audience": "https://admin.mad-world.nl",
"Host": " http://localhost:5266"
},
"Logging": {
"LogLevel": {
"Default": "Information",
Expand Down
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;
}
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>();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,12 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Grpc.AspNetCore" />
<PackageReference Include="Microsoft.AspNetCore.OpenApi" />
</ItemGroup>

<ItemGroup>
<Folder Include="Services\" />
<ProjectReference Include="..\ClientSdk.Grpc\ClientSdk.Grpc.csproj" />
</ItemGroup>

</Project>
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");
}
}
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);
}
}
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;
}

0 comments on commit 13004c6

Please sign in to comment.