我正在用rails 7创建一个新的应用程序。我想为用户添加一种通过蒸汽注册的方式。我使用了在rails 6上工作的代码,但是在rails 7上,我收到了一个错误。
Access to fetch at 'https://steamcommunity.com/openid/login?openid.ax.theKeyIamHidingforStackOverflow'
(redirected from 'http://localhost:3000/auth/Steam')
from origin 'http://localhost:3000' has been blocked by
CORS policy: Response to preflight request doesn't pass access control
check: No 'Access-Control-Allow-Origin' header is present on the requested resource.
If an opaque response serves your needs, set the
request's mode to 'no-cors' to fetch the resource with CORS disabled.点击https://steamcommunity.com/openid/login?fooBar,我得到流,也重定向到我的应用程序,我是注册的。我试图在config/initializers/cors.rb中设置cors,例如:
Rails.application.config.middleware.insert_before 0, Rack::Cors do
allow do
origins 'https://steamcommunity.com'
resource '*', headers: :any, methods: [:get, :post]
end
end但这行不通。在尝试重定向到第三方网站之前,我是否需要允许访问它们?
为了保护重定向,rails 7上有什么变化吗?
这是发送到服务器的帖子。
= form_tag '/auth/Steam', method: :post do
= submit_tag 'Steam'诚挚的问候
丹尼斯
发布于 2022-08-05 06:40:51
要解决这个问题,我们需要在发出Ajax请求时禁用turbo,方法是使用如下形式:
= form_tag '/auth/steam', method: :post, data: { turbo: false } do
= submit_tag 'Steam'此表单包含禁用data: { turbo: false }的turbo。
https://stackoverflow.com/questions/73238186
复制相似问题