Program.cs 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  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.AddMemoryCache();
  17. builder.Services.AddTransient<OptionsCache>();
  18. builder.Services.AddTransient<CredentialManager>();
  19. var app = builder.Build();
  20. // Configure the HTTP request pipeline.
  21. if (app.Environment.IsDevelopment())
  22. {
  23. app.UseSwagger();
  24. app.UseSwaggerUI();
  25. }
  26. app.UseStaticFiles();
  27. app.UseHttpsRedirection();
  28. app.MapGet("/buildCredentialOptions", ([FromQuery] string login, CredentialManager credMan) =>
  29. credMan.BuildCredentialOptions(login))
  30. .WithName("BuildCredentialOptions")
  31. .WithOpenApi();
  32. app.MapPost("/registerCredential", async ([FromQuery] string login, [FromBody] AuthenticatorAttestationRawResponse attestationResponse, CredentialManager credMan) =>
  33. await credMan.RegisterCredential(login, attestationResponse))
  34. .WithName("RegisterCredential")
  35. .WithOpenApi();
  36. app.MapGet("/buildAssertionOptions", async ([FromQuery] string login, CredentialManager credMan) =>
  37. await credMan.BuildAssertionOptions(login))
  38. .WithName("BuildAssertionOptions")
  39. .WithOpenApi();
  40. app.MapPost("/verifyCredential", async ([FromBody] AuthenticatorAssertionRawResponse assertionResponse, CredentialManager credMan) =>
  41. await credMan.VerifyCredential(assertionResponse))
  42. .WithName("VerifyCredential")
  43. .WithOpenApi();
  44. app.Run();