Adding Basic Authorization for Swagger-UI

前端 未结 4 1362
鱼传尺愫
鱼传尺愫 2020-11-30 11:14

I have currently deployed a swagger project but I am having trouble adding some basic authorization to it. Currenty when you click on the \"Try it out!\" button you are requ

4条回答
  •  青春惊慌失措
    2020-11-30 11:39

    I had a similar problem, the suggested answers are correct in my case I end up adding something in the index.html like:

    var myAuth = "Basic " + btoa("user:password");
    window.authorizations.add("key", neSwaggerClient.ApiKeyAuthorization("Authorization", myAuth, "header"));
    

    I added this on either the marked method addApiKeyAuthorization or you can create another method but call it after the window.swaggerUi.load();

    But if you have your swagger-ui running as "stand alone" with something like gulp or grunt you may require to configure the services to accept all OPTIONS request.

    I struggle a little with that, I hope it helps someone.

    Regards

提交回复
热议问题