【问题标题】:confirmation token invalid in production确认令牌在生产中无效
【发布时间】:2015-06-23 19:24:17
【问题描述】:

我尝试了 stackoverflow 上已经建议的解决方案,但没有成功。这是情况。我正在使用 Devise 构建一个 Rails 应用程序进行身份验证。在开发过程中,我能够通过电子邮件链接获得确认以正常工作。我注册了,发送了一封电子邮件,我点击了将我重定向到应用程序的链接,我,用户,得到了确认。但是,在 Heroku 平台上的生产中,这种用户注册确认方法失败了。具体来说,我收到消息

“1 个错误禁止保存此用户。

确认令牌无效”

在 Heroku 日志中,当我收到“确认令牌无效”时,我注意到创建用户时生成的确认令牌 (ee438ce80d3cc139df595771f8e058cc2eb7a91b33429d30c1ae6e4b3b00721f) 与 Devise 发送的“确认我的帐户”链接中的确认令牌不同:http://bloccit.herokuapp.com/users/confirmation?confirmation_token=GvdY2xffANGxEndv8Nc_

我试图与对方,(在URL与ee438ce80d3cc139df595771f8e058cc2eb7a91b33429d30c1ae6e4b3b00721f替换GvdY2xffANGxEndv8Nc_在生产数据库,并且还“ee438ce80d3cc139df595771f8e058cc2eb7a91b33429d30c1ae6e4b3b00721f”与“GvdY2xffANGxEndv8Nc_”)的替换标记仍然没有运气! P>

然后,我了解到人们在 devise/mailer/confirmation_instructions.html.erb 视图中进行了一些修改。我尝试并更改了文件

来自

<p>Welcome <%= @email %>!</p>

<p>You can confirm your account email through the link below:</p>

<p><%= link_to 'Confirm my account', confirmation_url(@resource, confirmation_token: @token) %></p>

到

<p>Welcome <%= @email %>!</p>

<p>You can confirm your account email through the link below:</p>

<p><%= link_to 'Confirm my account', confirmation_url(@resource, :confirmation_token => @resource.confirmation_token) %></p>

另外,我阅读了 Devise 文档,其中指出不再建议进行确认注册。但是,文档继续,如果您想使用它,请在 devise.rb 文件中包含以下设置:

config.allow_insecure_sign_in_after_confirmation = true

我按照说明对我提到的视图进行了更改。然后提交到 git,并重新部署到 Heroku。我发现这在用户对象实例和“确认我的帐户”中生成了相同的确认令牌。查看 Heroku 日志:

2015-04-17T03:53:40.460157+00:00 app[web.1]: 用户负载 (1.1ms) SELECT "users".* FROM "users" WHERE "users"."confirmation_token" = $1 ORDER通过“用户”。“id”ASC 限制 1 [[“confirmation_token”,“aa160f928b848bb06d9c5a681dafdc00333904d9e012dd95b1b344d9c7aff20c”]]
... 2015-04-17T03:53:40.905542+00:00 应用 [web.1]:

您可以通过以下链接确认您的帐户电子邮件:


2015-04-17T03:53:40.905533+00:00 app[web.1]: 内容类型: text/html;
2015-04-17T03:53:40.905544+00:00 应用[web.1]:
2015-04-17T03:53:40.905545+00:00 应用[web.1]:

&lt;a href="http://bloccit.herokuapp.com/users/confirmation?confirmation_token=aa160f928b848bb06d9c5a681dafdc00333904d9e012dd95b1b344d9c7aff20c"&gt;Confirm my account&lt;/a&gt;&lt;/p&gt;

但是,我收到了与上面提到的相同的错误“确认令牌无效”。

我已经为此工作了两个多晚上。我也不明白为什么开发没有错误,但生产错误啊!

病毒

【问题讨论】:

  • 看起来我的一些东西被剥离了。
  • 看起来我的一些东西被剥离了——从
  • 从

    更改为

    @resource.confirmation_token) %>

  • 为了更好的可读性,这里是确认我的帐户链接:bloccit.herokuapp.com/users/…">
  • Devise 的版本是多少?

标签: ruby-on-rails heroku devise


【解决方案1】:

您的config.action_mailer.default_url_options 设置为{ host: 'bloccit.herokuapp.com' }。这是 Bloc 提供的示例项目。为了使确认令牌起作用,您只需将其设置为{ host: 'your_app_name.herokuapp.com' }。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-10-08
    • 2018-03-19
    相关资源
    最近更新 更多