lichunqiang / yii2-swagger

yii2 with swagger-php
https://packagist.org/packages/light/yii2-swagger
MIT License
151 stars 47 forks source link

Add in header basic auth. #4

Closed ihippik closed 7 years ago

ihippik commented 8 years ago
  function addAuthorization() {
    var username = encodeURIComponent($('#input_username').val());
    var password = encodeURIComponent($('#input_password').val());
    if (username && username.trim() != "" && password && password.trim() != "") {
      var basicAuth = new SwaggerClient.PasswordAuthorization('basic', username, password);
      window.swaggerUi.api.clientAuthorizations.add("basicAuth", basicAuth);
    }
  }
  $('#input_username').change(addAuthorization);
  $('#input_password').change(addAuthorization);
lichunqiang commented 8 years ago

hi @ihippik what's your purpose?can you explain? thanks.

you want to have an enhancement, PR is welcome.

ihippik commented 8 years ago

Without this function, and two fields for name and password, I could not add headers basic auth. Although I had in my json:

                "security": [
                    {
                        "basicAuth": []
                    }
                ]

...

    "securityDefinitions": {
        "basicAuth": {
            "type": "basic",
            "description": "HTTP Basic Authentication. Works over `HTTP` and `HTTPS`"
        }
    },

... but I can not add these headers in the UI.

lichunqiang commented 8 years ago

Got it, PR is welcome.

lichunqiang commented 7 years ago

Hi, this resolve in new version. You can have a try.