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 = "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(); |
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 | |
.AddFastEndpoints() | |
.SwaggerDocument(); | |
var app = bld.Build(); | |
app.UseFastEndpoints() | |
.UseSwaggerGen(); | |
app.Run(); |
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 builder = WebApplication.CreateBuilder(); | |
builder.Services.AddTransient<IAuthorizationHandler, TestHandler>(); //Register your handler | |
builder.Services.AddFastEndpoints(); | |
builder.Services.AddJWTBearerAuth("xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"); | |
builder.Services.AddAuthorization(o => | |
{ | |
//Set the default policy to use your requirements (so you don't have to set the policy on each endpoint) | |
o.DefaultPolicy = new AuthorizationPolicyBuilder() | |
.RequireAuthenticatedUser() | |
.AddRequirements(new OperationAuthorizationRequirement()) //Using built-in requirement for testing here |
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
[ | |
JsonPolymorphic(TypeDiscriminatorPropertyName = "_t"), | |
JsonDerivedType(typeof(MultiChoiceQuestionRequest), "mcq"), | |
JsonDerivedType(typeof(RatingQuestionRequest), "rq") | |
] | |
public class BaseQuestionRequest | |
{ | |
public int Id { get; set; } | |
} |
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 CreateToken : EndpointWithoutRequest | |
{ | |
public override void Configure() | |
{ | |
Get("token"); | |
AllowAnonymous(); | |
} | |
public override async Task HandleAsync(CancellationToken ct) | |
{ |
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.AddFastEndpoints( | |
o => o.Assemblies = new[] | |
{ | |
typeof(SomeAssemblyName).Assembly, | |
typeof(AnotherAssemblyName).Assembly | |
}); | |
//this also enables bypassing the default blacklist of assemblies: https://github.com/FastEndpoints/FastEndpoints/blob/main/Src/Library/Main/EndpointData.cs#L28-L48 |
NewerOlder