Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Getting AuthenticationStub to override multiple schemas #135

Closed
egil opened this issue Feb 6, 2023 · 1 comment
Closed

Getting AuthenticationStub to override multiple schemas #135

egil opened this issue Feb 6, 2023 · 1 comment

Comments

@egil
Copy link

egil commented Feb 6, 2023

I have the following authentication configuration in my api/app, which AuthenticationStub does not seem to be able to override.

var authBuilder = services.AddAuthentication(options =>
{
    options.DefaultScheme = "MultiSchemaAuth";
    options.DefaultChallengeScheme = OpenIdConnectDefaults.AuthenticationScheme;
}).AddPolicyScheme("MultiSchemaAuth", "MultiSchemaAuth", options =>
{
    options.ForwardDefaultSelector = context =>
    {
        // API uses JwtBearer to authenticate, all other URLS uses OpenIdConnect.
        return context.Request.Path.StartsWithSegments("/v2/api", StringComparison.OrdinalIgnoreCase)
            ? JwtBearerDefaults.AuthenticationScheme
            : OpenIdConnectDefaults.AuthenticationScheme;
    };
});
authBuilder.AddMicrosoftIdentityWebApi(Configuration.GetSection("AzureAd"), jwtBearerScheme: JwtBearerDefaults.AuthenticationScheme);
authBuilder.AddMicrosoftIdentityWebApp(Configuration.GetSection("AzureAd"), openIdConnectScheme: OpenIdConnectDefaults.AuthenticationScheme);

Previously, when I just had the following authentication configuration, AuthenticationStub was able to override:

services
    .AddAuthentication(JwtBearerDefaults.AuthenticationScheme)
    .AddMicrosoftIdentityWebApi(Configuration);

I realize this is may not an Alba-related question, but I figured that this might be an excellent place to get some help either way, and it could be there is something that can be changed in AuthenticationStub to my current auth scenario work.

Thanks for en excellent library!

@egil
Copy link
Author

egil commented Feb 7, 2023

Never mind, I'm an idiot. I had explicitly set an authentication schema on my controllers ([Authorize(AuthenticationSchemes = JwtBearerDefaults.AuthenticationScheme)]), so yeah, that's why it didn't work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant