Program.cs 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. using Fido2NetLib;
  2. using Microsoft.AspNetCore.Mvc;
  3. using Passwordless;
  4. var builder = WebApplication.CreateBuilder(args);
  5. // Add services to the container.
  6. // Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
  7. builder.Services.AddEndpointsApiExplorer();
  8. builder.Services.AddSwaggerGen();
  9. builder.Services.AddFido2(options =>
  10. {
  11. options.ServerDomain = "localhost";
  12. options.ServerName = "FIDO2 Test";
  13. options.Origins = ["http://localhost:5172"];
  14. options.TimestampDriftTolerance = 300000;
  15. });
  16. builder.Services.AddTransient<CredentialManager>();
  17. var app = builder.Build();
  18. // Configure the HTTP request pipeline.
  19. if (app.Environment.IsDevelopment())
  20. {
  21. app.UseSwagger();
  22. app.UseSwaggerUI();
  23. }
  24. app.UseStaticFiles();
  25. app.UseHttpsRedirection();
  26. app.MapGet("/buildCredentialOptions", ([FromQuery] string login, CredentialManager credMan) =>
  27. credMan.BuildCredentialOptions(login))
  28. .WithName("BuildCredentialOptions")
  29. .WithOpenApi();
  30. app.MapGet("/registerCredential", async ([FromQuery] string login, [FromBody] AuthenticatorAttestationRawResponse attestationResponse, CredentialManager credMan) =>
  31. await credMan.RegisterCredential(login, attestationResponse))
  32. .WithName("RegisterCredential")
  33. .WithOpenApi();
  34. app.Run();