【问题标题】:Rails: make authentication to swagger API via devise or otherRails:通过设计或其他方式对 swagger API 进行身份验证
【发布时间】:2020-09-14 06:53:24
【问题描述】:

我的目标是登录 Swagger API 以访问端点。未来使用授权令牌。

我尝试将设计线放在 ApplicationController 中:

before_action :authenticate_user!

但是当加载 http://localhost:3000/api-docs/index.html 时 - 系统允许在没有身份验证的情况下访问 API。

我尝试在 /config/initializers/rswag-ui.rb 中取消注释:

  c.basic_auth_enabled = true
  c.basic_auth_credentials 'username', 'password'

但不是这个。

此外,它也没有从 Swagger.io 官方文档中找到实现承载身份验证的正确方法。我不知道它是否连接到设计,我是否需要使用它。

通过我的用户的登录名和密码登录API,哪种方式好? 谢谢。

【问题讨论】:

    标签: ruby-on-rails api authentication devise swagger


    【解决方案1】:

    使用 rswag-ui,您只需要取消注释这些行。不需要其他身份验证(如设计)。

    # /config/initializers/rswag-ui.rb
    
    c.basic_auth_enabled = true
    c.basic_auth_credentials 'username', 'password'
    
    

    我刚刚在我的项目中做了它,它立即起作用了,所以我想我不妨回答一下。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-12-08
      • 2012-02-09
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多