Skip to content

Commit

Permalink
ook inloggen afdwingen op minimal api endpoints
Browse files Browse the repository at this point in the history
  • Loading branch information
felixcicatt committed Nov 28, 2024
1 parent 49778ca commit 69e872d
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 8 deletions.
3 changes: 2 additions & 1 deletion ODPC.Server/Authentication/AuthenticationExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,8 @@ public static void AddAuth(this IServiceCollection services, Action<AuthOptions>
});
}
services.AddAuthorizationBuilder()
.AddPolicy(AdminPolicy.Name, policy => policy.RequireRole(authOptions.AdminRole));
.AddPolicy(AdminPolicy.Name, policy => policy.RequireRole(authOptions.AdminRole))
.AddFallbackPolicy("LoggedIn", policy => policy.RequireAuthenticatedUser());
services.AddDistributedMemoryCache();
services.AddOpenIdConnectAccessTokenManagement();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,11 @@ public async Task ExecuteResultAsync(ActionContext context)

var config = context.HttpContext.RequestServices.GetRequiredService<IConfiguration>();
using var client = context.HttpContext.RequestServices.GetRequiredService<IOdrcClientFactory>().Create(reason);
var timeoutInMinutes = int.TryParse(config["ODRC_DOWNLOAD_TIMEOUT_MINUTES"], out var m)
var timeoutInMinutes = int.TryParse(config["DOWNLOAD_TIMEOUT_MINUTES"], out var m)
? m
: 10;
client.Timeout = TimeSpan.FromMinutes(timeoutInMinutes);
using var requestMessage = new HttpRequestMessage(HttpMethod.Get, path) { Version = new Version(2, 0) };
using var httpResponse = await client.GetAsync(path, HttpCompletionOption.ResponseHeadersRead, token); ;
using var httpResponse = await client.GetAsync(path, HttpCompletionOption.ResponseHeadersRead, token);

response.StatusCode = (int)httpResponse.StatusCode;
response.Headers.ContentLength = httpResponse.Content.Headers.ContentLength;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public static void Map(IEndpointRouteBuilder builder) => builder.MapPut(
async (HttpRequest request, IOdrcClientFactory clientFactory, IConfiguration config, CancellationToken token) =>
{
using var client = clientFactory.Create("Upload bestandsdeel");
var timeoutInMinutes = int.TryParse(config["ODRC_UPLOAD_TIMEOUT_MINUTES"], out var m)
var timeoutInMinutes = int.TryParse(config["UPLOAD_TIMEOUT_MINUTES"], out var m)
? m
: 10;
client.Timeout = TimeSpan.FromMinutes(timeoutInMinutes);
Expand Down
2 changes: 1 addition & 1 deletion ODPC.Server/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ string GetRequiredConfig(string key)

app.UseAuthorization();

app.MapControllers().RequireAuthorization();
app.MapControllers();

app.MapOdpcAuthEndpoints();
app.MapHealthChecks("/healthz").AllowAnonymous();
Expand Down
4 changes: 2 additions & 2 deletions ODPC.Server/appsettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,6 @@
"ODRC_BASE_URL": "",
"ODRC_API_KEY": "",
"OIDC_ADMIN_ROLE": "",
"ODRC_UPLOAD_TIMEOUT_MINUTES": "",
"ODRC_DOWNLOAD_TIMEOUT_MINUTES": ""
"UPLOAD_TIMEOUT_MINUTES": "",
"DOWNLOAD_TIMEOUT_MINUTES": ""
}

0 comments on commit 69e872d

Please sign in to comment.