使用Omniauth和Rails + React - CORS问题

时间:2018-03-29 19:40:03

标签: ruby-on-rails reactjs redirect cors shopify

我正在尝试使用shopify策略在我的rails / react应用中使用omniauth进行身份验证。

将用户发送到omniauth路径后:

SessionsController

def authenticate
  redirect_to "/auth/shopify?shop=#{params[:shop]}"
end

Omniauth正在向我的浏览器发送302重定向:

Rails Output

(shopify) Setup endpoint detected, running now.
(shopify) Request phase initiated.
127.0.0.1 - - [29/Mar/2018:15:02:40 DST] "GET /auth/shopify?shop=xxx.myshopify.com HTTP/1.1" 302 280
http://localhost:8082/ -> /auth/shopify?shop=xxx.myshopify.com

在此之后,我的浏览器中出现CORS错误:

Failed to load https://x.myshopify.com/admin/oauth/authorize?client_id=x&redirect_uri=http%3A%2F%2Flocalhost%3A3000%2Fauth%2Fshopify%2Fcallback&response_type=code&scope=read_products&state=x: 
Redirect from 'https://x.myshopify.com/admin/oauth/authorize?client_id=x&redirect_uri=http%3A%2F%2Flocalhost%3A3000%2Fauth%2Fshopify%2Fcallback&response_type=code&scope=read_products&state=x' 
to 'https://x.myshopify.com/admin/auth/login' has been blocked by CORS policy: 
No 'Access-Control-Allow-Origin' header is present on the requested resource. 
Origin 'null' is therefore not allowed access.

这会导致我的提取请求失败而没有错误对象中的任何内容。

如何防止此错误?

0 个答案:

没有答案