Azure Ad integration in Azure functions with swagger

Viewed 221

I am using Azure functions V3 with swagger UI. I am using the below code in my start up

builder.AddSwashBuckle(Assembly.GetExecutingAssembly(),opts => {
                opts.SpecVersion = Microsoft.OpenApi.OpenApiSpecVersion.OpenApi3_0;
                opts.Title = "Platform Data Operations";
      


            });

I have configured the Azure Ad authentication for my app in the azure portal. Set up the permissions and redirect Uri.I am able to login successfully from the browser after calling the redirect URI. Can some one help me with how to integrate in the code.

1 Answers

You can follow the sample code below,

 builder.AddSwashBuckle(Assembly.GetExecutingAssembly(), opts =>
        {
            opts.SpecVersion = OpenApiSpecVersion.OpenApi3_0;
            opts.ConfigureSwaggerGen = (x =>
            {
                x.DocumentFilter<CustomSwaggerDocumentAttribute>();
                x.EnableAnnotations();
                x.CustomOperationIds(apiDesc =>
                {
                    return apiDesc.TryGetMethodInfo(out MethodInfo methodInfo)
                        ? methodInfo.Name
                        : new Guid().ToString();
                });
            });
            // remove code as query parameter
            opts.AddCodeParameter = false;
            opts.PrependOperationWithRoutePrefix = true;
            opts.Title = "Sample Function API Swagger";
        });
Related