Skip to content

Authentication broken in Scalar.AspNetCore version 2.10.0 #7261

@meenzen

Description

@meenzen

What happens?

NSwag Security Config:

builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerDocument(settings =>
{
    settings.AddSecurity(
        "bearer",
        [],
        new OpenApiSecurityScheme
        {
            Type = OpenApiSecuritySchemeType.OAuth2,
            Description = "Azure AD",
            Flow = OpenApiOAuth2Flow.Implicit,
            Flows = new OpenApiOAuthFlows
            {
                Implicit = new OpenApiOAuthFlow
                {
                    Scopes = new Dictionary<string, string>
                    {
                        {
                            $"api://{builder.Configuration["AzureAd:ClientId"]}/Api.Access",
                            "Access to the API. Some endpoints may additionally require group permissions."
                        },
                    },
                    AuthorizationUrl =
                        $"https://login.microsoftonline.com/{builder.Configuration["AzureAd:TenantId"]}/oauth2/v2.0/authorize",
                    TokenUrl =
                        $"https://login.microsoftonline.com/{builder.Configuration["AzureAd:TenantId"]}/oauth2/v2.0/token",
                },
            },
        }
    );
});

Scalar Config:

app.UseOpenApi(options =>
{
    options.Path = "/openapi/{documentName}.json";
});
app.MapScalarApiReference(options =>
        options
            .AddPreferredSecuritySchemes("bearer")
            .AddImplicitFlow(
                "bearer",
                oauth =>
                {
                    oauth.ClientId = builder.Configuration["AzureAd:ClientId"];
                    oauth.SelectedScopes = [$"api://{builder.Configuration["AzureAd:ClientId"]}/"];
                }
            )
            .SortTagsAlphabetically()
            .SortOperationsByMethod()
    )
    .AllowAnonymous();

Auth url and scopes are missing:

Image

What did you expect to happen?

Auth still works like it did in 2.9.0, as you can see the auth url and scopes are configured correctly:

Image

OpenAPI Document

No response

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions