elsa-workflows / elsa-workflows/elsa-gitbook

API Admin Key Creation

Open
#40 2 comments 0 reactions 0 assignees View on GitHub
triaged
Dominant language
C#
Stars
9
Forks
30
Avg merge
49m
Merged PRs (30d)
32

Description

[There seems to be a discrepancy between the documentation and the actual behavior of the system](https://github.com/elsa-workflows/elsa-studio/issues/28). When following the steps outlined in the [Elsa-Server documentation](https://v3.elsaworkflows.io/docs/installation/elsa-server) to set up an Elsa server, the step to create a new admin results in a 401 Unauthorized error. This is unexpected as the documentation mentions that requests from localhost should be allowed.

The request in question is:
```
curl --location 'https://localhost:5001/elsa/api/identity/applications' \\
--header 'Content-Type: application/json' \\
--data '{
"name": "Postman",
"roles": ["admin"]
}'
```

Additionally, the provided `Program.cs` configuration is as follows:
```
using Elsa.Extensions;
using osisa.SmartWeb2.Api.Workflows;

var builder = WebApplication.CreateBuilder(args);

// Add services to the container.
builder.Services.AddControllers();
builder.Services.AddElsa(elsa =>
elsa
// Configure identity so that we can create a default admin user.
.UseIdentity(identity =>
{
var configuration = builder.Configuration;
var identitySection = configuration.GetSection("Identity");
var identityTokenSection = identitySection.GetSection("Tokens");

identity.IdentityOptions = options => identitySection.Bind(options);
identity.TokenOptions = options => identityTokenSection.Bind(options);
identity.UseConfigurationBasedUserProvider(options => identitySection.Bind(options));
identity.UseConfigurationBasedApplicationProvider(options => identitySection.Bind(options));
identity.UseConfigurationBasedRoleProvider(options => identitySection.Bind(options));
})

// Use default authentication (JWT + API Key).
.UseDefaultAuthentication(auth => auth.UseAdminApiKey())

// EXPOSE API ENDPOINTS
.UseWorkflowsApi()

// REGISTER WORKFLOWS AS HTTP ENDPOINTS under /workflows/{name}
.UseWorkflowRuntime(
runtime => runtime
.AddWorkflow())
.UseHttp()
);

// Configure CORS to allow designer app hosted on a different origin to invoke the APIs.
builder.Services.AddCors(cors => cors.AddDefaultPolicy(policy => policy.AllowAnyOrigin().AllowAnyHeader().AllowAnyMethod()));

var app = builder.Build();

// Configure the HTTP request pipeline.
app.UseHttpsRedirection();
app.UseAuthorization();
// ENABLE CORS
app.UseCors();
// ENABLE AUTHENTICATION
app.UseAuthentication();
// ENABLE WORKFLOWS API
app.UseWorkflowsApi();
// REGISTER CONTROLLERS AS HTTP ENDPOINTS
app.MapControllers();
// ENABLE WORKFLOWS TO BE USED AS HTTP ENDPOINTS
app.UseWorkflows();
app.Run();
```

It would be beneficial for users if the documentation could be updated to reflect the correct steps or provide additional troubleshooting steps for this issue.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.