Update CompleteTask endpoint to use permissions instead of policy

This commit is contained in:
Sipke Schoorstra 2023-04-22 20:43:54 +02:00
parent 9b5c95b72f
commit eb2c866fc0
6 changed files with 9 additions and 13 deletions

View file

@ -21,7 +21,7 @@ public class Complete : ElsaEndpoint<Request, Response>
public override void Configure()
{
Post("/tasks/{taskId}/complete");
Policies("CompleteTask");
ConfigurePermissions("tasks:complete");
}
/// <inheritdoc />

View file

@ -26,11 +26,6 @@ public class WorkflowsApiFeature : FeatureBase
{
}
/// <summary>
/// A delegate that configures the policy requirements for the /tasks/{taskId}/complete API endpoint.
/// </summary>
public Action<AuthorizationPolicyBuilder> CompleteTaskPolicy { get; set; } = policy => policy.RequireAuthenticatedUser();
/// <inheritdoc />
public override void Configure()
{
@ -40,7 +35,6 @@ public class WorkflowsApiFeature : FeatureBase
/// <inheritdoc />
public override void Apply()
{
Services.AddAuthorization(auth => auth.AddPolicy("CompleteTask", CompleteTaskPolicy));
Services.AddSingleton<ISerializationOptionsConfigurator, SerializationConfigurator>();
Module.AddFastEndpointsFromModule();
}

View file

@ -1,3 +1,4 @@
using System.Net.Http.Headers;
using Elsa.Samples.Webhooks.ExternalApp.Jobs;
var builder = WebApplication.CreateBuilder(args);
@ -8,7 +9,8 @@ builder.Services.AddControllers();
// Configure the background worker with an HTTP client that can report workflow task completion.
builder.Services.AddHttpClient<DeliverFoodJob>(httpClient =>
{
httpClient.BaseAddress = new Uri("https://localhost:7164/elsa/api/");
httpClient.BaseAddress = new Uri("https://localhost:5001/elsa/api/");
httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("ApiKey", Guid.Empty.ToString()); // Use the admin API key.
});
var app = builder.Build();

View file

@ -24,8 +24,8 @@ builder.Services.AddElsa(elsa =>
options.AccessTokenLifetime = TimeSpan.FromDays(1);
};
})
.UseWorkflowsApi(api => api.CompleteTaskPolicy = policy => policy.RequireAssertion(_ => true)) // Allows anonymous requests. Will be replaced with an API key scheme.
.UseDefaultAuthentication()
.UseWorkflowsApi()
.UseDefaultAuthentication(auth => auth.UseAdminApiKey())
.UseWebhooks(webhooks => webhooks.WebhookOptions = options => builder.Configuration.GetSection("Webhooks").Bind(options));
});

View file

@ -2,7 +2,7 @@
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
"Microsoft.AspNetCore": "Debug"
}
},
"AllowedHosts": "*",
@ -12,7 +12,7 @@
"EventTypes": [
"RunTask"
],
"Url": "https://localhost:7100/webhooks/run-task"
"Url": "https://localhost:5002/webhooks/run-task"
}
]
}

View file

@ -1 +1 @@
POST https://localhost:7164/workflows/hungry
POST https://localhost:5001/workflows/hungry