This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[HttpGet("publish"), AllowAnonymous] | |
sealed class MyEndpoint : EndpointWithoutRequest | |
{ | |
public override async Task HandleAsync(CancellationToken c) | |
{ | |
var evnt = new MyEvent { Message = "hello!" }; | |
await PublishAsync(evnt); | |
await SendAsync("all good!"); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var bld = WebApplication.CreateBuilder(args); | |
bld.Services | |
.SwaggerDocument() | |
.AddFastEndpoints(); | |
var app = bld.Build(); | |
app.UseFastEndpoints( | |
c => | |
{ | |
c.Errors.UseProblemDetails(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.Text.Json.Serialization; | |
var bld = WebApplication.CreateBuilder(args); | |
bld.Services | |
.SwaggerDocument(o => o.UseOneOfForPolymorphism = true) //enable the setting | |
.AddFastEndpoints(); | |
var app = bld.Build(); | |
app.UseFastEndpoints() | |
.UseSwaggerGen(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var bld = WebApplication.CreateBuilder(args); | |
bld.Services | |
.AddAuthenticationJwtBearer( | |
s => s.SigningKey = "...", | |
o => | |
{ | |
o.Events = new() | |
{ | |
OnChallenge = | |
async ctx => |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class MyDbContext(DbContextOptions<MyDbContext> opts) : IdentityDbContext<IdentityUser>(opts); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using Testcontainers.MongoDb; | |
public class Sut : AppFixture<Program> | |
{ | |
const string Database = "TestingDB"; | |
const string RootUsername = "root"; | |
const string RootPassword = "password"; | |
MongoDbContainer _container = null!; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<meta charset="UTF-8"> | |
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | |
<title>Streaming Response Viewer</title> | |
<script> | |
async function streamResponse(url) { | |
const response = await fetch(url); | |
const reader = response.body.getReader(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
bld.Services.AddAuthenticationJwtBearer( | |
s => | |
{ | |
s.SigningKey = "base64 encoded public key"; | |
s.SigningStyle = TokenSigningStyle.Asymmetric; | |
s.KeyIsPemEncoded = true; // only if public key is in PEM format | |
}, | |
b => | |
{ | |
b.TokenValidationParameters.ValidIssuer = "issuer"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class BasicAuth(IOptionsMonitor<AuthenticationSchemeOptions> options, | |
ILoggerFactory logger, | |
UrlEncoder encoder) | |
: AuthenticationHandler<AuthenticationSchemeOptions>(options, logger, encoder) | |
{ | |
internal const string SchemeName = "Basic"; | |
protected override Task<AuthenticateResult> HandleAuthenticateAsync() | |
{ | |
if (IsPublicEndpoint() || !Request.Headers.ContainsKey("Authorization")) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
app.UseSwaggerGen( | |
s => | |
{ | |
//where to serve swagger.json files from | |
s.Path = "/PREFIX/swagger/{documentName}/swagger.json"; | |
//api endpoint server base path customization | |
s.PostProcess = (document, request) => | |
{ | |
document.Servers.Clear(); |
NewerOlder