Open douglasg14b opened 6 months ago
The exception you're encountering indicates that there is an attempt to add an authentication scheme with the name "Bearer" more than once. This can happen if AddAuthentication
is called multiple times with the same scheme or if different parts of the code are trying to configure the same authentication scheme independently.
To resolve this issue, you should ensure that the "Bearer" scheme is only added once throughout your application's startup configuration. Here are some steps you can take:
AddAuthentication
and AddJwtBearer
to see if the "Bearer" scheme is being added more than once.Without seeing the actual code, it's difficult to provide a precise solution. However, the general approach is to review and consolidate your authentication configuration to prevent duplicate scheme registrations.
If you continue to have trouble, please provide more details about your startup configuration, especially around the authentication and authorization setup, so that a more specific solution can be provided.
This comment was generated by Glime.
From what I'm reading, perhaps elsa
should chose a more specific name for it's authentication schema? 🤔
Most applications are, by default, going to be using JwtBearerDefaults.AuthenticationScheme
since that's what is automatically configured for them if they have setup JWT auth. Which means the canonical JWT auth setup is in conflict with elsa
.
This call can specify the schema name: https://github.com/elsa-workflows/elsa-core/blob/8289ae2cdfe54bfa848c1a89060de30ea44c33fc/src/modules/Elsa.Identity/Features/DefaultAuthenticationFeature.cs#L68
That may not be a bad idea. Originally, the default configuration is just there to get started quickly, but usually you'll want to handle authentication yourself, in which case you may not want to use the default setup other than perhaps as an example. However, that also means you'd need to handle setting up the claims identity such that it has the permissions claim. If we just offer a default setup using a different scheme, then perhaps it can work side by side with an application specific scheme (which probably is called Bearer as you mentioned)
That's a good point actually 🤔 , I have not yet integrated my auth scheme into Elsa. Actually, I have no idea how even!
I agree that most will move away from the default, but to ease the onboarding pain the default may want to be named something different to avoid the conflcit!
If elsa is not explicitly specifying the Authorization scheme to use, then I don't think it will work at all if an existing default one exists. Regardless of it one was to integrate their own identity or not no?
The IdentityFeature
also appears tosupply defaults for some of these services, how can this be changed?
.AddScoped<ISecretHasher, DefaultSecretHasher>()
.AddScoped<IAccessTokenIssuer, DefaultAccessTokenIssuer>()
.AddScoped<IUserCredentialsValidator, DefaultUserCredentialsValidator>()
.AddScoped<IApplicationCredentialsValidator, DefaultApplicationCredentialsValidator>()
.AddScoped<IApiKeyGenerator>(sp => sp.GetRequiredService<DefaultApiKeyGeneratorAndParser>())
.AddScoped<IApiKeyParser>(sp => sp.GetRequiredService<DefaultApiKeyGeneratorAndParser>())
.AddScoped<IClientIdGenerator, DefaultClientIdGenerator>()
.AddScoped<ISecretGenerator, DefaultSecretGenerator>()
.AddScoped<IRandomStringGenerator, DefaultRandomStringGenerator>()
.AddScoped<DefaultApiKeyGeneratorAndParser>()
The IdentityFeature also appears tosupply defaults for some of these services, how can this be changed?
In your project after all registrations you can replace any of service descriptor. It's the easiest way without any changes to elsa-core library.
When you want to integrate Elsa with your own authentication I think you don't need Elsa.Identity package at all. You would like to add some Elsa claims to your user by default (e.g. based on role). It's possible that you will have to support some contracts from Elsa.Identity package. However FastEndpoints uses default asp.net authentication mechanism so the main goal is to authenticate user with some Elsa claims.
Description
When trying to startup after following the Server docs. I receive the following exception:
I'm honestly not sure what else needs to be fiddled with here to make this work :/