Configure your own API in Swagger
# package-development
r
Anyone knows why swagger (and maybe API general ) only works when deriving and API controller from ManagementApiControllerBase in V14? No authentication header is set when I do otherwise..
j
Here's an example composer that configures its own API and "borrows" the bearer token of the management API:
Copy code
public class BellissimaApiComposer : IComposer
{
    public void Compose(IUmbracoBuilder builder)
    {
        builder.Services.ConfigureOptions<ConfigureSwaggerGenOptions>();
    }

    private class MyBackOfficeSecurityRequirementsOperationFilter : BackOfficeSecurityRequirementsOperationFilterBase
    {
        protected override string ApiName => Constants.ApiNameV1;
    }

    internal class ConfigureSwaggerGenOptions : IConfigureOptions<SwaggerGenOptions>
    {
        public void Configure(SwaggerGenOptions options)
        {
            options.SwaggerDoc(
                Constants.ApiNameV1,
                new OpenApiInfo
                {
                    Title = "Bellissima Management Api",
                    Version = "Latest",
                    Description = "Bellissima Management Api",
                });

            options.OperationFilter<MyBackOfficeSecurityRequirementsOperationFilter>();
        }
    }
}
The secret is this line:
options.OperationFilter<MyBackOfficeSecurityRequirementsOperationFilter>();
r
Thank you Jacob that was it! Was about to pull my (last) hair out
19 Views