Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,10 @@ await InvokeAsync(async () =>
private async Task RestartHideTimer()
{
await Abort();
_ = HideAfterDelayAsync();
_ = HideAfterDelay();
}

private async Task HideAfterDelayAsync()
private async Task HideAfterDelay()
{
try
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ private async Task SetNavPanelItems(ClaimsPrincipal authUser)

//#if (module == "Admin")

var (dashboard, manageProductCatalog) = await (authorizationService.IsAuthorizedAsync(authUser!, AppFeatures.AdminPanel.Dashboard),
authorizationService.IsAuthorizedAsync(authUser!, AppFeatures.AdminPanel.ManageProductCatalog));
var (dashboard, manageProductCatalog) = await (authorizationService.IsAuthorized(authUser!, AppFeatures.AdminPanel.Dashboard),
authorizationService.IsAuthorized(authUser!, AppFeatures.AdminPanel.ManageProductCatalog));

if (dashboard || manageProductCatalog)
{
Expand Down Expand Up @@ -67,7 +67,7 @@ private async Task SetNavPanelItems(ClaimsPrincipal authUser)
//#endif

//#if (sample == true)
if (await authorizationService.IsAuthorizedAsync(authUser!, AppFeatures.Todo.ManageTodo))
if (await authorizationService.IsAuthorized(authUser!, AppFeatures.Todo.ManageTodo))
{
navPanelItems.Add(new()
{
Expand Down Expand Up @@ -101,9 +101,9 @@ private async Task SetNavPanelItems(ClaimsPrincipal authUser)
Url = PageUrls.About,
});

var (manageRoles, manageUsers, manageAiPrompt) = await (authorizationService.IsAuthorizedAsync(authUser!, AppFeatures.Management.ManageRoles),
authorizationService.IsAuthorizedAsync(authUser!, AppFeatures.Management.ManageUsers),
authorizationService.IsAuthorizedAsync(authUser!, AppFeatures.Management.ManageAiPrompt));
var (manageRoles, manageUsers, manageAiPrompt) = await (authorizationService.IsAuthorized(authUser!, AppFeatures.Management.ManageRoles),
authorizationService.IsAuthorized(authUser!, AppFeatures.Management.ManageUsers),
authorizationService.IsAuthorized(authUser!, AppFeatures.Management.ManageAiPrompt));

if (manageRoles || manageUsers || manageAiPrompt)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ private async Task SocialSignIn(string provider)

var redirectUrl = await identityController.GetSocialSignInUri(provider, GetReturnUrl(), port is -1 ? null : port, CurrentCancellationToken);

await externalNavigationService.NavigateToAsync(redirectUrl);
await externalNavigationService.NavigateTo(redirectUrl);
}
catch (KnownException e)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ private async Task SocialSignUp(string provider)

var redirectUrl = await identityController.GetSocialSignInUri(provider, ReturnUrlQueryString, port is -1 ? null : port, CurrentCancellationToken);

await externalNavigationService.NavigateToAsync(redirectUrl);
await externalNavigationService.NavigateTo(redirectUrl);
}
catch (KnownException e)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ protected override async Task OnAfterFirstRenderAsync()

var user = (await AuthenticationStateTask).User;

lacksValidPrivilege = (await AuthorizationService.IsAuthorizedAsync(user, AuthPolicies.PRIVILEGED_ACCESS)) is false;
lacksValidPrivilege = (await AuthorizationService.IsAuthorized(user, AuthPolicies.PRIVILEGED_ACCESS)) is false;
}
finally
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,19 @@ protected override async Task OnInitAsync()
{
await base.OnInitAsync();

_ = keyboard.Add(ButilKeyCodes.KeyF, () => searchBox.FocusAsync(), ButilModifiers.Ctrl);

selectedFilter = nameof(AppStrings.All);
selectedSort = nameof(AppStrings.Alphabetical);

await LoadTodoItems();
}

protected override async Task OnAfterFirstRenderAsync()
{
await keyboard.Add(ButilKeyCodes.KeyF, () => searchBox.FocusAsync(), ButilModifiers.Ctrl);

await base.OnAfterFirstRenderAsync();
}

private async Task LoadTodoItems(bool showLoading = true)
{
if (showLoading)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ public override async Task<AuthenticationState> GetAuthenticationStateAsync()
public async Task<bool> TryEnterElevatedAccessMode(CancellationToken cancellationToken)
{
var user = IAuthTokenProvider.ParseAccessToken(await tokenProvider.GetAccessToken(), validateExpiry: true);
var hasElevatedAccess = await authorizationService.IsAuthorizedAsync(user, AuthPolicies.ELEVATED_ACCESS);
var hasElevatedAccess = await authorizationService.IsAuthorized(user, AuthPolicies.ELEVATED_ACCESS);
if (hasElevatedAccess)
return true;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
// Check out Client.web/wwwroot/web-interop-app.html's comments.
public interface IExternalNavigationService
{
Task NavigateToAsync(string url);
Task NavigateTo(string url);
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public partial class DefaultExternalNavigationService : IExternalNavigationServi
private string? lastOpenedWindowId = null;
private Action? pubSubUnsubscribe;

public async Task NavigateToAsync(string url)
public async Task NavigateTo(string url)
{
if (AppPlatform.IsBlazorHybrid)
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
using Boilerplate.Client.Core.Styles;
using Boilerplate.Client.Core.Styles;

namespace Boilerplate.Client.Maui.Services;

public partial class MauiExternalNavigationService : IExternalNavigationService
{
public async Task NavigateToAsync(string url)
public async Task NavigateTo(string url)
{
var isDark = Application.Current!.UserAppTheme == AppTheme.Dark;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public override async ValueTask<JsonElement> GetWebAuthnCredential(JsonElement o

((MauiLocalHttpServer)localHttpServer).WebAuthnService = this;

await externalNavigationService.NavigateToAsync($"http://localhost:{localHttpServer.Port}/{PageUrls.WebInteropApp}?actionName=GetWebAuthnCredential");
await externalNavigationService.NavigateTo($"http://localhost:{localHttpServer.Port}/{PageUrls.WebInteropApp}?actionName=GetWebAuthnCredential");

return await GetWebAuthnCredentialTcs.Task;
}
Expand All @@ -30,7 +30,7 @@ public override async ValueTask<JsonElement> CreateWebAuthnCredential(JsonElemen

((MauiLocalHttpServer)localHttpServer).WebAuthnService = this;

await externalNavigationService.NavigateToAsync($"http://localhost:{localHttpServer.Port}/{PageUrls.WebInteropApp}?actionName=CreateWebAuthnCredential");
await externalNavigationService.NavigateTo($"http://localhost:{localHttpServer.Port}/{PageUrls.WebInteropApp}?actionName=CreateWebAuthnCredential");

return await CreateWebAuthnCredentialTcs.Task;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public override async ValueTask<JsonElement> GetWebAuthnCredential(JsonElement o

((WindowsLocalHttpServer)localHttpServer).WebAuthnService = this;

await externalNavigationService.NavigateToAsync($"http://localhost:{localHttpServer.Port}/{PageUrls.WebInteropApp}?actionName=GetWebAuthnCredential");
await externalNavigationService.NavigateTo($"http://localhost:{localHttpServer.Port}/{PageUrls.WebInteropApp}?actionName=GetWebAuthnCredential");

return await GetWebAuthnCredentialTcs.Task;
}
Expand All @@ -32,7 +32,7 @@ public override async ValueTask<JsonElement> CreateWebAuthnCredential(JsonElemen

((WindowsLocalHttpServer)localHttpServer).WebAuthnService = this;

await externalNavigationService.NavigateToAsync($"http://localhost:{localHttpServer.Port}/{PageUrls.WebInteropApp}?actionName=CreateWebAuthnCredential");
await externalNavigationService.NavigateTo($"http://localhost:{localHttpServer.Port}/{PageUrls.WebInteropApp}?actionName=CreateWebAuthnCredential");

return await CreateWebAuthnCredentialTcs.Task;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public partial class IdentityController
public async Task SendResetPasswordToken(SendResetPasswordTokenRequestDto request, CancellationToken cancellationToken)
{
request.PhoneNumber = phoneService.NormalizePhoneNumber(request.PhoneNumber);
var user = await userManager.FindUserAsync(request)
var user = await userManager.FindUser(request)
?? throw new ResourceNotFoundException(Localizer[nameof(AppStrings.UserNotFound)]).WithData("Identifier", request);

if (await userConfirmation.IsConfirmedAsync(userManager, user) is false)
Expand Down Expand Up @@ -80,7 +80,7 @@ public async Task SendResetPasswordToken(SendResetPasswordTokenRequestDto reques
public async Task ResetPassword(ResetPasswordRequestDto request, CancellationToken cancellationToken)
{
request.PhoneNumber = phoneService.NormalizePhoneNumber(request.PhoneNumber);
var user = await userManager.FindUserAsync(request) ?? throw new ResourceNotFoundException(Localizer[nameof(AppStrings.UserNotFound)]).WithData("Identifier", request);
var user = await userManager.FindUser(request) ?? throw new ResourceNotFoundException(Localizer[nameof(AppStrings.UserNotFound)]).WithData("Identifier", request);

var expired = (DateTimeOffset.Now - user.ResetPasswordTokenRequestedOn) > AppSettings.Identity.ResetPasswordTokenLifetime;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public async Task<ActionResult> SocialSignInCallback(string? returnUrl = null, i

if (user is null && (string.IsNullOrEmpty(email) is false || string.IsNullOrEmpty(phoneNumber) is false))
{
user = await userManager.FindUserAsync(new() { Email = email, PhoneNumber = phoneNumber });
user = await userManager.FindUser(new() { Email = email, PhoneNumber = phoneNumber });
}

if (user is null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public async Task SignUp(SignUpRequestDto request, CancellationToken cancellatio
//#endif

// Attempt to locate an existing user using either their email address or phone number. The enforcement of a unique username policy is integral to the aspnetcore identity framework.
var existingUser = await userManager.FindUserAsync(new() { Email = request.Email, PhoneNumber = request.PhoneNumber });
var existingUser = await userManager.FindUser(new() { Email = request.Email, PhoneNumber = request.PhoneNumber });
if (existingUser is not null)
{

Expand Down Expand Up @@ -91,7 +91,7 @@ public async Task SignIn(SignInRequestDto request, CancellationToken cancellatio
{
request.PhoneNumber = phoneService.NormalizePhoneNumber(request.PhoneNumber);

var user = await userManager.FindUserAsync(request)
var user = await userManager.FindUser(request)
?? await userManager.CreateUserWithDemoRole(request, request.Password); // Check out SignInModalService for more details

await SignIn(request, user, cancellationToken);
Expand All @@ -114,7 +114,7 @@ private async Task SignIn(SignInRequestDto request, User user, CancellationToken
bool isOtpSignIn = string.IsNullOrEmpty(request.Otp) is false;

var (signInResult, firstStepAuthenticationMethod) = isOtpSignIn
? await signInManager.OtpSignInAsync(user, request.Otp!)
? await signInManager.OtpSignIn(user, request.Otp!)
: (await signInManager.PasswordSignInAsync(user, request.Password!, isPersistent: false, lockoutOnFailure: true), authenticationMethod: "Password");

if (signInResult.IsNotAllowed && await userConfirmation.IsConfirmedAsync(userManager, user) is false)
Expand Down Expand Up @@ -302,7 +302,7 @@ public async Task<ActionResult<TokenResponseDto>> Refresh(RefreshTokenRequestDto
public async Task SendOtp(IdentityRequestDto request, string? returnUrl = null, CancellationToken cancellationToken = default)
{
request.PhoneNumber = phoneService.NormalizePhoneNumber(request.PhoneNumber);
var user = await userManager.FindUserAsync(request)
var user = await userManager.FindUser(request)
?? await userManager.CreateUserWithDemoRole(request); // Check out SignInModalService for more details

if (await userConfirmation.IsConfirmedAsync(userManager, user) is false)
Expand Down Expand Up @@ -363,7 +363,7 @@ public async Task SendTwoFactorToken(SignInRequestDto request, CancellationToken
{
request.PhoneNumber = phoneService.NormalizePhoneNumber(request.PhoneNumber);

var user = await userManager.FindUserAsync(request)
var user = await userManager.FindUser(request)
?? throw new ResourceNotFoundException(Localizer[nameof(AppStrings.UserNotFound)]).WithData("Identifier", request);

await SendTwoFactorToken(request, user, cancellationToken);
Expand All @@ -377,7 +377,7 @@ private async Task SendTwoFactorToken(SignInRequestDto request, User user, Cance
bool isOtpSignIn = string.IsNullOrEmpty(request.Otp) is false;

var (signInResult, firstStepAuthenticationMethod) = isOtpSignIn
? await signInManager.OtpSignInAsync(user, request.Otp!)
? await signInManager.OtpSignIn(user, request.Otp!)
: (await signInManager.PasswordSignInAsync(user!, request.Password!, isPersistent: false, lockoutOnFailure: true), authenticationMethod: "Password");

if (signInResult.RequiresTwoFactor is false)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public async Task<RoleDto> Create(RoleDto roleDto, CancellationToken cancellatio
[Authorize(Policy = AuthPolicies.ELEVATED_ACCESS)]
public async Task<RoleDto> Update(RoleDto roleDto, CancellationToken cancellationToken)
{
var role = await GetRoleByIdAsync(roleDto.Id, cancellationToken);
var role = await GetRoleById(roleDto.Id, cancellationToken);

if (AppRoles.IsBuiltInRole(role.Name!))
throw new BadRequestException(Localizer[nameof(AppStrings.CanNotChangeBuiltInRole), role.Name!]);
Expand All @@ -97,7 +97,7 @@ public async Task<RoleDto> Update(RoleDto roleDto, CancellationToken cancellatio
[Authorize(Policy = AuthPolicies.ELEVATED_ACCESS)]
public async Task Delete(Guid roleId, string concurrencyStamp, CancellationToken cancellationToken)
{
var role = await GetRoleByIdAsync(roleId, cancellationToken);
var role = await GetRoleById(roleId, cancellationToken);

if (AppRoles.IsBuiltInRole(role.Name!))
throw new BadRequestException(Localizer[nameof(AppStrings.CanNotChangeBuiltInRole), role.Name!]);
Expand All @@ -114,7 +114,7 @@ public async Task AddClaims(Guid roleId, List<ClaimDto> claims, CancellationToke
{
List<RoleClaim> entities = [];

var role = await GetRoleByIdAsync(roleId, cancellationToken);
var role = await GetRoleById(roleId, cancellationToken);

if (role.Name == AppRoles.SuperAdmin)
throw new BadRequestException(Localizer[nameof(AppStrings.UserCantChangeSuperAdminRoleClaimsErrorMessage)]);
Expand All @@ -132,7 +132,7 @@ public async Task AddClaims(Guid roleId, List<ClaimDto> claims, CancellationToke
[Authorize(Policy = AuthPolicies.ELEVATED_ACCESS)]
public async Task UpdateClaims(Guid roleId, List<ClaimDto> claims, CancellationToken cancellationToken)
{
var role = await GetRoleByIdAsync(roleId, cancellationToken);
var role = await GetRoleById(roleId, cancellationToken);

if (role.Name == AppRoles.SuperAdmin)
throw new BadRequestException(Localizer[nameof(AppStrings.UserCantChangeSuperAdminRoleClaimsErrorMessage)]);
Expand All @@ -155,7 +155,7 @@ public async Task UpdateClaims(Guid roleId, List<ClaimDto> claims, CancellationT
[Authorize(Policy = AuthPolicies.ELEVATED_ACCESS)]
public async Task DeleteClaims(Guid roleId, List<ClaimDto> claims, CancellationToken cancellationToken)
{
var role = await GetRoleByIdAsync(roleId, cancellationToken);
var role = await GetRoleById(roleId, cancellationToken);

if (role.Name == AppRoles.SuperAdmin)
throw new BadRequestException(Localizer[nameof(AppStrings.UserCantChangeSuperAdminRoleClaimsErrorMessage)]);
Expand Down Expand Up @@ -210,7 +210,7 @@ public async Task ToggleUserRole(UserRoleDto dto, CancellationToken cancellation
[Authorize(Policy = AuthPolicies.ELEVATED_ACCESS)]
public async Task RemoveAllUsersFromRole(Guid roleId, CancellationToken cancellationToken)
{
var role = await GetRoleByIdAsync(roleId, cancellationToken);
var role = await GetRoleById(roleId, cancellationToken);

await DbContext.UserRoles.Where(ur => ur.RoleId == roleId).ExecuteDeleteAsync(cancellationToken);
}
Expand Down Expand Up @@ -246,7 +246,7 @@ await pushNotificationService.RequestPush(new()
//#endif


private async Task<Role> GetRoleByIdAsync(Guid id, CancellationToken cancellationToken)
private async Task<Role> GetRoleById(Guid id, CancellationToken cancellationToken)
{
var role = await roleManager.Roles.FirstOrDefaultAsync(r => r.Id == id, cancellationToken)
?? throw new ResourceNotFoundException();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public async Task Delete(Guid userId, CancellationToken cancellationToken)
if (User.GetUserId() == userId)
throw new BadRequestException(Localizer[nameof(AppStrings.UserCantRemoveItselfErrorMessage)]);

var user = await GetUserByIdAsync(userId, cancellationToken);
var user = await GetUserById(userId, cancellationToken);

if (await userManager.IsInRoleAsync(user, AppRoles.SuperAdmin))
{
Expand Down Expand Up @@ -118,7 +118,7 @@ public async Task RevokeAllUserSessions(Guid userId, CancellationToken cancellat
}


private async Task<User> GetUserByIdAsync(Guid id, CancellationToken cancellationToken)
private async Task<User> GetUserById(Guid id, CancellationToken cancellationToken)
{
var user = await userManager.Users.FirstOrDefaultAsync(r => r.Id == id, cancellationToken)
?? throw new ResourceNotFoundException();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ namespace Microsoft.AspNetCore.Identity;
public static partial class SignInManagerExtensions
{
/// <summary>
/// The app invokes <see cref="OtpSignInAsync"/> in the following scenarios:
/// The app invokes <see cref="OtpSignIn"/> in the following scenarios:
///
/// 1. When the user opts to sign in using a 6-digit code received via SMS.
/// 2. When the user chooses to sign in using a 6-digit code sent via email, typically within a magic link.
Expand All @@ -22,7 +22,7 @@ public static partial class SignInManagerExtensions
/// to avoid sending a second step to the same communication channel: For successful two-step authentication, the user must use a different method for the second step.
/// </summary>

public static async Task<(SignInResult signInResult, string? authenticationMethod)> OtpSignInAsync(this SignInManager<User> signInManager, User user, string otp)
public static async Task<(SignInResult signInResult, string? authenticationMethod)> OtpSignIn(this SignInManager<User> signInManager, User user, string otp)
{
var appSettings = signInManager.Context.RequestServices.GetRequiredService<ServerApiSettings>();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ namespace Microsoft.AspNetCore.Identity;

public static partial class UserManagerExtensions
{
public static async Task<User?> FindUserAsync(this UserManager<User> userManager, IdentityRequestDto identity)
public static async Task<User?> FindUser(this UserManager<User> userManager, IdentityRequestDto identity)
{
User? user = default;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ public partial class AppIdentityOptions : IdentityOptions
public TimeSpan TwoFactorTokenLifetime { get; set; }

/// <summary>
/// <see cref="SignInManagerExtensions.OtpSignInAsync(SignInManager{Models.Identity.User}, Models.Identity.User, string)"/>
/// <see cref="SignInManagerExtensions.OtpSignIn(SignInManager{Models.Identity.User}, Models.Identity.User, string)"/>
/// </summary>
public TimeSpan OtpTokenLifetime { get; set; }

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using Boilerplate.Server.Api.Models.Identity;
using Boilerplate.Server.Api.Models.Identity;

namespace Boilerplate.Server.Api.Services.Identity;

Expand Down
Loading
Loading