【问题标题】:Headers are not been sending Basic Auth for swagger-lume标头没有为 swagger-lume 发送基本身份验证
【发布时间】:2016-07-20 14:18:32
【问题描述】:

我在 Lumen 中有 Basic Auth Api。对于该 API,我使用以下 url 集成了 Swagger-ui:https://github.com/DarkaOnLine/SwaggerLume

在 swagger ui 中启用自定义标题。我们对以下 2 个文件进行了更改

1. swagger-lume.php

     'headers' => [
        /*
        |--------------------------------------------------------------------------
        | Uncomment to add response headers when swagger is generated
        |--------------------------------------------------------------------------
         */
        /*"view" => [
        'Content-Type' => 'text/plain'
        ],*/
        /*
        |--------------------------------------------------------------------------
        | Uncomment to add request headers when swagger performs requests
        |--------------------------------------------------------------------------
         */
        "request" => [
    'Authorization ' => 'Basic  YWRtaW46YWRtaW4='
    ],
    ],

2。生成的index.blade.php代码如下

  basicAuth=  "Basic " + btoa("admin:admin");
swaggerUi.api.clientAuthorizations.add("key", new SwaggerClient.ApiKeyAuthorization("Authorization", basicAuth, "header"));

但是标头没有在请求中发送。请查看下图以供参考

请提出建议,如何解决此问题。

【问题讨论】:

    标签: php swagger swagger-ui lumen swagger-2.0


    【解决方案1】:

    我在 api 文件的注释语法中定义了许多安全定义。我发现问题来自 json 文件。删除下面的注释语法,然后在 ajax 调用中接受标头。

    ...,
    "securityDefinitions":{
        "administrator":{
            "type":"basic",
            "description":"The administrator."
        },
        "supervisor":{
            "type":"basic",
            "description":"A supervisor."
        },
        "customer":{
            "type":"basic",
            "description":"A customer."
        }
    },
    ...
    

    【讨论】:

      猜你喜欢
      • 2022-10-25
      • 1970-01-01
      • 2015-03-13
      • 1970-01-01
      • 1970-01-01
      • 2013-08-18
      • 1970-01-01
      • 2020-06-08
      • 1970-01-01
      相关资源
      最近更新 更多