Implement nostr api

This commit is contained in:
2023-07-04 11:30:04 +01:00
parent 5de1c96b20
commit 013008dcf9
9 changed files with 129 additions and 17 deletions

View File

@ -1,3 +1,6 @@
using System.Security.Claims;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Authorization.Infrastructure;
using Microsoft.EntityFrameworkCore;
using Nostr.Client.Client;
using NostrStreamer.Database;
@ -21,6 +24,22 @@ internal static class Program
services.AddControllers();
services.AddSingleton(config);
// nostr auth
services.AddTransient<NostrAuthHandler>();
services.AddAuthentication(o =>
{
o.DefaultChallengeScheme = NostrAuth.Scheme;
o.AddScheme<NostrAuthHandler>(NostrAuth.Scheme, "Nostr");
});
services.AddAuthorization(o =>
{
o.DefaultPolicy = new AuthorizationPolicy(new[]
{
new ClaimsAuthorizationRequirement(ClaimTypes.Name, null)
}, new[] {NostrAuth.Scheme});
});
// nostr services
services.AddSingleton<NostrMultiWebsocketClient>();
services.AddSingleton<INostrClient>(s => s.GetRequiredService<NostrMultiWebsocketClient>());
@ -39,6 +58,7 @@ internal static class Program
}
app.UseCors(o => o.AllowAnyHeader().AllowAnyMethod().AllowAnyOrigin());
app.UseAuthorization();
app.MapControllers();
await app.RunAsync();