Skip to content

Instantly share code, notes, and snippets.

View jpd21122012's full-sized avatar
:octocat:

Ing. Jorge Perales Díaz jpd21122012

:octocat:
View GitHub Profile
<PackageReference Include="CommunityToolkit.Maui" Version="8.0.0" />
dotnet new maui -n NfcMauiApp
cd NfcMauiApp
// In your LoginViewModel
private async Task OnLoginClicked()
{
// ... auth logic
await _navigationService.NavigateToAsync("//Dashboard");
}
// A simple navigation service in Core/Infrastructure/
public class NavigationService : INavigationService
{
builder.Services.AddTransient<LoginPage>(); // Register the page
builder.Services.AddTransient<LoginViewModel>(); // Register the ViewModel
// Register the concrete service that implements the feature's interface
builder.Services.AddSingleton<IAuthService, AuthService>();
// Features/Authentication/LoginViewModel.cs
public partial class LoginViewModel : ObservableObject
{
private readonly IAuthService _authService;
private readonly INavigationService _navigationService;
[ObservableProperty]
private string _userName;
[ObservableProperty]
// Features/Authentication/IAuthService.cs
public interface IAuthService
{
Task<bool> LoginAsync(string username, string password);
Task<bool> LogoutAsync();
}
MyMauiApp/
├── Features/
│ ├── Authentication/
│ │ ├── LoginPage.xaml
│ │ ├── LoginPage.xaml.cs
│ │ ├── LoginViewModel.cs
│ │ ├── LoginCommand.cs
│ │ └── IAuthService.cs // Feature-specific interface
│ ├── Dashboard/
│ │ ├── DashboardPage.xaml
MyMauiApp/
├── Views/
├── ViewModels/
├── Models/
├── Services/
└── Repositories/
var isAuthenticated = await BiometricAuthenticationService.AuthenticateAsync();
if (isAuthenticated)
{
// Proceed to load the private key and sign
}
[HttpPost("verifyLogin")]
public async Task<IActionResult> VerifyLogin([FromBody] LoginVerificationRequest request)
{
// 1. Find the user and their stored public key
var user = await _context.Users.FirstOrDefaultAsync(u => u.Username == request.Username);
if (user == null) return Unauthorized();
// 2. Recreate the original challenge that was sent to this user
// (You would need to store this challenge temporarily with an expiry)
byte[] challengeBytes = GetStoredChallengeForUser(user.Username);