asp.net mvc - .NET MVC Swashbuckle gated by Basic Auth -


is there way gate swashbuckle documentation page behind basic auth attribute? right username , password can see documentation page.

the swashbuckle configured

globalconfiguration.configuration.enableswagger 

and

.enableswaggerui 

but creates own messagehandler there no me attach basic auth attribute implemented actionfilterattribute.

i not want basic auth applied entire site, swagger endpoints

if got correctly, case might similar (image) (image). here's have done & worked:

 public class addauthorizationheaderparameteroperationfilter: ioperationfilter  {      public void apply(operation operation, schemaregistry schemaregistry, apidescription apidescription)      {          var filterpipeline = apidescription.actiondescriptor.getfilterpipeline();          var isauthorized = filterpipeline.select(filterinfo => filterinfo.instance).any(filter => filter iauthorizationfilter);            var allowanonymous = apidescription.actiondescriptor.getcustomattributes<allowanonymousattribute>().any();          var basicauthenticator = apidescription.actiondescriptor.getcustomattributes<mybasicauthenticator>().any();                                //because attribute might @ controller or action method                      var mytokenauthenticator = apidescription.getcontrollerandactionattributes<mytokenauthenticator>().any();   		          //actionname: controllers          if (isauthorized != null)          {              if (operation != null)              {                  if (operation.parameters == null)                  {                      operation.parameters = new list<parameter>();                  }                  if (mytokenauthenticator)                  {                                             operation.parameters.add(new parameter()                      {                          name = "authorization",                          @in = "header",                          description = "id obtained service method authenticate. ex: mytoken id",                          required = true,                          type = "string"                                                  });                  }                  if (basicauthenticator)                  {                      operation.parameters.add(new parameter()                      {                          name = "authorization",                          @in = "header",                          type = "string",                                                        description = "basic http authentication. ex: basic (email:password).tobase64",                          @required = true                      });                                          }              }          }      }  }

similar issues: swashbuckle q.


Comments

Popular posts from this blog

c++ - Difference between pre and post decrement in recursive function argument -

php - Nothing but 'run(); ' when browsing to my local project, how do I fix this? -

php - How can I echo out this array? -