nettoyage des warning, ajout de localization
All checks were successful
Generation data pour merge sur master / reviewProcess (pull_request) Successful in 1m21s
Generation data pour merge sur master / generateData (pull_request) Successful in 1m31s
Generation data pour merge sur master / generateData (push) Has been skipped
Generation data pour merge sur master / reviewProcess (push) Successful in 1m16s

This commit was merged in pull request #22.
This commit is contained in:
2024-09-09 23:16:34 +02:00
parent cd4788b2b0
commit 0cde51e01c
21 changed files with 376 additions and 122 deletions

View File

@@ -45,7 +45,7 @@ internal static class IdentityComponentsEndpointRouteBuilderExtensions
SignInManager<ApplicationUser> signInManager,
[FromForm] string returnUrl) =>
{
await signInManager.SignOutAsync();
await signInManager.SignOutAsync().ConfigureAwait(true);
return TypedResults.LocalRedirect($"~/{returnUrl}");
});
@@ -57,7 +57,7 @@ internal static class IdentityComponentsEndpointRouteBuilderExtensions
[FromForm] string provider) =>
{
// Clear the existing external cookie to ensure a clean login process
await context.SignOutAsync(IdentityConstants.ExternalScheme);
await context.SignOutAsync(IdentityConstants.ExternalScheme).ConfigureAwait(false);
var redirectUrl = UriHelper.BuildRelative(
context.Request.PathBase,
@@ -76,13 +76,13 @@ internal static class IdentityComponentsEndpointRouteBuilderExtensions
[FromServices] UserManager<ApplicationUser> userManager,
[FromServices] AuthenticationStateProvider authenticationStateProvider) =>
{
var user = await userManager.GetUserAsync(context.User);
var user = await userManager.GetUserAsync(context.User).ConfigureAwait(false);
if (user is null)
{
return Results.NotFound($"Unable to load user with ID '{userManager.GetUserId(context.User)}'.");
}
var userId = await userManager.GetUserIdAsync(user);
var userId = await userManager.GetUserIdAsync(user).ConfigureAwait(false);
downloadLogger.LogInformation("User with ID '{UserId}' asked for their personal data.", userId);
// Only include personal data for download
@@ -94,13 +94,13 @@ internal static class IdentityComponentsEndpointRouteBuilderExtensions
personalData.Add(p.Name, p.GetValue(user)?.ToString() ?? "null");
}
var logins = await userManager.GetLoginsAsync(user);
var logins = await userManager.GetLoginsAsync(user).ConfigureAwait(false);
foreach (var l in logins)
{
personalData.Add($"{l.LoginProvider} external login provider key", l.ProviderKey);
}
personalData.Add("Authenticator Key", (await userManager.GetAuthenticatorKeyAsync(user))!);
personalData.Add("Authenticator Key", (await userManager.GetAuthenticatorKeyAsync(user).ConfigureAwait(false))!);
var fileBytes = JsonSerializer.SerializeToUtf8Bytes(personalData);
context.Response.Headers.TryAdd("Content-Disposition", "attachment; filename=PersonalData.json");

View File

@@ -4,10 +4,12 @@ using LudikZoneBlazor.Data;
namespace LudikZoneBlazor.Components.Account;
// Remove the "else if (EmailSender is IdentityNoOpEmailSender)" block from RegisterConfirmation.razor after updating with a real implementation.
#pragma warning disable CA1812 // Elle est instanciée en Injection de dependance
/// <summary> Remove the "else if (EmailSender is IdentityNoOpEmailSender)" block from RegisterConfirmation.razor after updating with a real implementation. </summary>
internal sealed class IdentityNoOpEmailSender : IEmailSender<ApplicationUser>
{
private readonly IEmailSender emailSender = new NoOpEmailSender();
private readonly NoOpEmailSender emailSender = new NoOpEmailSender();
public Task SendConfirmationLinkAsync(ApplicationUser user, string email, string confirmationLink) =>
emailSender.SendEmailAsync(email, "Confirm your email", $"Please confirm your account by <a href='{confirmationLink}'>clicking here</a>.");
@@ -18,3 +20,5 @@ internal sealed class IdentityNoOpEmailSender : IEmailSender<ApplicationUser>
public Task SendPasswordResetCodeAsync(ApplicationUser user, string email, string resetCode) =>
emailSender.SendEmailAsync(email, "Reset your password", $"Please reset your password using the following code: {resetCode}");
}
#pragma warning restore CA1812

View File

@@ -3,6 +3,8 @@ using Microsoft.AspNetCore.Components;
namespace LudikZoneBlazor.Components.Account;
#pragma warning disable CA1812 // Elle est instanciée en Injection de dependance
internal sealed class IdentityRedirectManager(NavigationManager navigationManager)
{
public const string StatusCookieName = "Identity.StatusMessage";
@@ -56,3 +58,5 @@ internal sealed class IdentityRedirectManager(NavigationManager navigationManage
public void RedirectToCurrentPageWithStatus(string message, HttpContext context)
=> RedirectToWithStatus(CurrentPath, message, context);
}
#pragma warning restore CA1812

View File

@@ -7,6 +7,8 @@ using LudikZoneBlazor.Data;
namespace LudikZoneBlazor.Components.Account;
#pragma warning disable CA1812 // Elle est instanciée en Injection de dependance
// This is a server-side AuthenticationStateProvider that revalidates the security stamp for the connected user
// every 30 minutes an interactive circuit is connected.
internal sealed class IdentityRevalidatingAuthenticationStateProvider(
@@ -21,14 +23,14 @@ internal sealed class IdentityRevalidatingAuthenticationStateProvider(
AuthenticationState authenticationState, CancellationToken cancellationToken)
{
// Get the user manager from a new scope to ensure it fetches fresh data
await using var scope = scopeFactory.CreateAsyncScope();
using AsyncServiceScope scope = scopeFactory.CreateAsyncScope();
var userManager = scope.ServiceProvider.GetRequiredService<UserManager<ApplicationUser>>();
return await ValidateSecurityStampAsync(userManager, authenticationState.User);
return await ValidateSecurityStampAsync(userManager, authenticationState.User).ConfigureAwait(false);
}
private async Task<bool> ValidateSecurityStampAsync(UserManager<ApplicationUser> userManager, ClaimsPrincipal principal)
{
var user = await userManager.GetUserAsync(principal);
var user = await userManager.GetUserAsync(principal).ConfigureAwait(false);
if (user is null)
{
return false;
@@ -40,8 +42,10 @@ internal sealed class IdentityRevalidatingAuthenticationStateProvider(
else
{
var principalStamp = principal.FindFirstValue(options.Value.ClaimsIdentity.SecurityStampClaimType);
var userStamp = await userManager.GetSecurityStampAsync(user);
var userStamp = await userManager.GetSecurityStampAsync(user).ConfigureAwait(false);
return principalStamp == userStamp;
}
}
}
#pragma warning restore CA1812

View File

@@ -3,11 +3,13 @@ using LudikZoneBlazor.Data;
namespace LudikZoneBlazor.Components.Account;
#pragma warning disable CA1812 // Elle est instanciée en Injection de dependance
internal sealed class IdentityUserAccessor(UserManager<ApplicationUser> userManager, IdentityRedirectManager redirectManager)
{
public async Task<ApplicationUser> GetRequiredUserAsync(HttpContext context)
{
var user = await userManager.GetUserAsync(context.User);
var user = await userManager.GetUserAsync(context.User).ConfigureAwait(false);
if (user is null)
{
@@ -17,3 +19,5 @@ internal sealed class IdentityUserAccessor(UserManager<ApplicationUser> userMana
return user;
}
}
#pragma warning restore CA1812