【问题标题】:Show protected methods in SWAGGER (RESTLER 3)在 SWAGGER (RESTLER 3) 中显示受保护的方法
【发布时间】:2013-10-30 21:07:22
【问题描述】:

我正在制作一个 API,我真的很喜欢方法的 SWAGGER 接口,但是我的所有 API 请求都需要通过 Basic Auth 进行保护和验证。因此,这些受保护的方法或类中的任何一个都可用于 SWAGGER。有什么方法可以显示吗?

【问题讨论】:

    标签: php restler


    【解决方案1】:

    将以下内容放在 index.php 中将启用受保护方法的列表

    use \Luracast\Restler\Resources;
    
    Resources::$hideProtected = false;
    

    从 swagger 访问 Basic Auth 保护的 api 就可以了。但是验证和通过基本身份验证需要在 swagger ui 方面完成一些工作

    【讨论】:

    • Soy 我想我在 __isAllowed 期间总是会在使用 SWAGGER 时得到 FALSE。抱歉,我不能让它成为代码块样式:(
    • 参见github.com/wordnik/swagger-ui#header-parameters,您现在可以轻松地使用 Swagger UI 2 进行基本身份验证!
    • 你是对的。我使用#input_apiKey 示例,但我总是得到 TypeError: window.authorizations is undefined in Console after unfocusing from the input field。
    【解决方案2】:

    我在 SWAGGER 文档上阅读了此内容,但是……我需要动态发送使用 SWAGGER UI 输入字段键入的用户和密码……然后将它们转换为基本身份验证。所以实际上问题是如何将 user&pwd 字段添加到每个 SWAGGER 请求中,并将它们设置为通过 Basic Auth 标头发送。

        // add a new ApiKeyAuthorization when the api-key changes in the ui.
    $('#input_apiKey').change(function() {
      var key = $('#input_apiKey')[0].value;
      if(key && key.trim() != "") {
        window.authorizations.add("key", new ApiKeyAuthorization("api_key", key, "header"));
      }
    })
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-03-31
      • 2016-02-19
      • 1970-01-01
      • 2010-10-30
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多