-
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
11 changed files
with
101 additions
and
0 deletions.
There are no files selected for viewing
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,14 @@ | ||
using Microsoft.AspNetCore.Components.Web; | ||
using Microsoft.AspNetCore.Components.WebAssembly.Hosting; | ||
using MadWorldNL.Clients.Admin.Web; | ||
using MadWorldNL.Clients.Identity.Blazor.Shared.Extensions; | ||
|
||
var builder = WebAssemblyHostBuilder.CreateDefault(args); | ||
builder.RootComponents.Add<App>("#app"); | ||
builder.RootComponents.Add<HeadOutlet>("head::after"); | ||
|
||
builder.AddIdentity(); | ||
|
||
builder.Services.AddScoped(sp => new HttpClient { BaseAddress = new Uri(builder.HostEnvironment.BaseAddress) }); | ||
|
||
await builder.Build().RunAsync(); |
5 changes: 5 additions & 0 deletions
5
sources/Clients.Admin.Web/wwwroot/appsettings.Development.json
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,5 @@ | ||
{ | ||
"Identity": { | ||
"Host": "https://localhost:7047/" | ||
} | ||
} |
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,5 @@ | ||
{ | ||
"Identity": { | ||
"Host": "https://localhost:7047/" | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
sources/Clients.Identity.Blazor.Shared/Authentications/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,22 @@ | ||
using System.Net.Http.Json; | ||
using MadWorldNL.Clients.Identity.Api.Contracts.Authentications; | ||
using MadWorldNL.Clients.Identity.Blazor.Shared.Settings; | ||
|
||
namespace MadWorldNL.Clients.Identity.Blazor.Shared.Authentications; | ||
|
||
public class AuthenticationService : IAuthenticationService | ||
{ | ||
private const string Endpoint = "Authentication"; | ||
|
||
private readonly HttpClient _client; | ||
public AuthenticationService(IHttpClientFactory clientFactory) | ||
{ | ||
_client = clientFactory.CreateClient(ApiTypes.AnonymousIdentity); | ||
} | ||
|
||
public async Task<LoginProxyResponse> LoginAsync(LoginProxyRequest request) | ||
{ | ||
var response = await _client.PostAsJsonAsync(Endpoint, request); | ||
return await response.Content.ReadFromJsonAsync<LoginProxyResponse>() ?? new LoginProxyResponse(); | ||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
sources/Clients.Identity.Blazor.Shared/Authentications/IAuthenticationService.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,8 @@ | ||
using MadWorldNL.Clients.Identity.Api.Contracts.Authentications; | ||
|
||
namespace MadWorldNL.Clients.Identity.Blazor.Shared.Authentications; | ||
|
||
public interface IAuthenticationService | ||
{ | ||
Task<LoginProxyResponse> LoginAsync(LoginProxyRequest request); | ||
} |
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
35 changes: 35 additions & 0 deletions
35
sources/Clients.Identity.Blazor.Shared/Extensions/WebAssemblyHostBuilderExtensions.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,35 @@ | ||
using MadWorldNL.Clients.Identity.Blazor.Shared.Authentications; | ||
using MadWorldNL.Clients.Identity.Blazor.Shared.Settings; | ||
using Microsoft.AspNetCore.Components.WebAssembly.Hosting; | ||
using Microsoft.Extensions.DependencyInjection; | ||
using Microsoft.Extensions.Options; | ||
|
||
namespace MadWorldNL.Clients.Identity.Blazor.Shared.Extensions; | ||
|
||
public static class WebAssemblyHostBuilderExtensions | ||
{ | ||
public static void AddIdentity(this WebAssemblyHostBuilder builder) | ||
{ | ||
builder.Services.AddOptions<IdentitySettings>() | ||
.Bind(builder.Configuration.GetSection(IdentitySettings.Entry)); | ||
|
||
builder.Services.AddScoped<IAuthenticationService, AuthenticationService>(); | ||
|
||
builder.AddIdentityClients(); | ||
} | ||
|
||
private static void AddIdentityClients(this WebAssemblyHostBuilder builder) | ||
{ | ||
builder.Services.AddHttpClient(ApiTypes.AnonymousIdentity, (serviceProvider, client) => | ||
{ | ||
var identitySettingsOption = serviceProvider.GetService<IOptions<IdentitySettings>>()!; | ||
client.BaseAddress = new Uri(identitySettingsOption.Value.Host!); | ||
}); | ||
|
||
builder.Services.AddHttpClient(ApiTypes.Identity, (serviceProvider, client) => | ||
{ | ||
var identitySettingsOption = serviceProvider.GetService<IOptions<IdentitySettings>>()!; | ||
client.BaseAddress = new Uri(identitySettingsOption.Value.Host!); | ||
}); | ||
} | ||
} |
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.Blazor.Shared.Settings; | ||
|
||
public static class ApiTypes | ||
{ | ||
public const string AnonymousIdentity = nameof(AnonymousIdentity); | ||
public const string Identity = nameof(Identity); | ||
} |
7 changes: 7 additions & 0 deletions
7
sources/Clients.Identity.Blazor.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,7 @@ | ||
namespace MadWorldNL.Clients.Identity.Blazor.Shared.Settings; | ||
|
||
public class IdentitySettings | ||
{ | ||
public const string Entry = "Identity"; | ||
public string Host { get; set; } = string.Empty; | ||
} |
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,6 @@ | ||
namespace MadWorldNL.Clients.Identity.Blazor.Shared.pages; | ||
|
||
public partial class Login | ||
{ | ||
|
||
} |
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