【问题标题】:Rails API JWT Token Authentication working in Dev but not in ProdRails API JWT 令牌身份验证在 Dev 中工作,但在 Prod 中不工作
【发布时间】:2021-12-06 10:23:15
【问题描述】:

我已经基于 tutorial 为我的 Rails API 构建了一个基于 JWT 令牌的身份验证。 Rails 服务器在开发模式下运行,一切正常。当我在生产模式下运行 rails 服务器时,出现以下错误:

Started GET "/profiles" for 10.71.232.74 at 2021-10-19 15:17:37 +0200
Processing by ProfilesController#index as */*
Filter chain halted as :authenticate_request rendered or redirected
Completed 401 Unauthorized in 0ms (Views: 0.1ms | ActiveRecord: 0.0ms | Allocations: 150)

我现在想知道服务器的 Dev 和 Prod 模式之间的区别在哪里。我对两者都使用相同的数据库,所以我的环境除了服务器的模式没有区别。

【问题讨论】:

  • 您是否已将 prod ip 地址列入白名单?

标签: ruby-on-rails jwt


【解决方案1】:

该问题与 JWT 令牌生成有关。 Rails 无法访问 secret_key_base(复制/粘贴错误)。在开发模式下,服务器只是在后台做了一些魔术来生成令牌,所以它确实有效。在生产中它没有。 在将 secret_key_base 提供给 Rails 之后,它就起作用了。 总的来说,rails 中的错误消息误导了我。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-03-08
    • 2018-10-25
    • 2020-04-01
    • 2020-06-03
    • 1970-01-01
    • 2022-01-24
    • 1970-01-01
    • 2020-07-16
    相关资源
    最近更新 更多