Program.cs 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  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.Run();