Example #1
0
        public static void EnableAzureAdB2cOAuth2(this SwaggerUiConfig c, string clientId, string policyName, string clientSecret = null, string realm = null, string appName = "Swagger UI", bool enableDiscoveryUrlSelector = true, IDictionary <string, string> additionalParameters = null)
        {
            var additionalParams = new Dictionary <string, string>
            {
                { "p", policyName },
                { "response_mode", "fragment" }
            };

            if (additionalParameters != null)
            {
                foreach (var additionalParameter in additionalParameters)
                {
                    additionalParams.Add(additionalParameter.Key, additionalParameter.Value);
                }
            }
            c.EnableOAuth2Support(
                clientId,
                clientSecret,
                realm,
                appName,
                additionalQueryStringParams: additionalParams
                );
            if (enableDiscoveryUrlSelector)
            {
                c.EnableDiscoveryUrlSelector();
            }
        }
        private static void ConfigureSwagger(IAppBuilder app)
        {
            var http = new HttpConfiguration();

            var swaggerUiConfig = new SwaggerUiConfig(new[] { "v2" }, m => "");

            swaggerUiConfig.EnableDiscoveryUrlSelector();

            //swaggerUiConfig.EnableApiKeySupport("Authorization", "header");
            //swaggerUiConfig.InjectJavaScript(typeof(Application).Assembly, "BlackCoffeeTalk.Bootstrap.ClientResources.swaggerExtensions.js");

            http.Routes.MapHttpRoute("swagger_ui_shortcut", "", null, null, new RedirectHandler(r => r.RequestUri.AbsoluteUri.TrimEnd('/'), "index"));
            http.Routes.MapHttpRoute("swagger_ui", "{*assetPath}", null, new { assetPath = ".+" }, new SwaggerUiHandler(swaggerUiConfig));


            app.UseWebApi(http);
        }
 /// <summary>
 /// Configures the UI elements / front end functionality of swagger
 /// </summary>
 /// <param name="uiConfig"></param>
 private static void ConfigureSwaggerUI(SwaggerUiConfig uiConfig)
 {
     uiConfig.DocExpansion(DocExpansion.None);
     uiConfig.DisableValidator();
     uiConfig.EnableDiscoveryUrlSelector();
 }