Adding Basic Authorization for Swagger-UI

前端 未结 4 1361
鱼传尺愫
鱼传尺愫 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:40

    The correct setting for Basic authentication Header is:

    Authorization: Basic username:password
    

    The String username:password needs to be encoded using RFC2045-MIME a variant of Base64. See more details here: https://en.wikipedia.org/wiki/Basic_access_authentication#Client_side

    Then, to configure this header, you should do:

    Considering that the Base64 encoding for username:password is dXNlcm5hbWU6cGFzc3dvcmQ=

    swaggerUi.api.clientAuthorizations.add("key", new SwaggerClient.ApiKeyAuthorization("Authorization", "Basic dXNlcm5hbWU6cGFzc3dvcmQ=", "header"));
    

    Read more about this here: https://github.com/swagger-api/swagger-ui

提交回复
热议问题