我有一個配置了端口3000上運行的Passport的環回API服務器。我的UI由來自端口3080的react JS組成。我想用Google實現身份驗證。對於這一點,從我反應過來的應用程序,我想提出一個呼叫 localhost:3000/auth/google
但這一呼聲沒有得到重定向因爲CORS錯誤的谷歌:在StrongLoop支持的ReactJS應用程序上啓用CORS
Fetch API cannot load http://localhost:3000/auth/google. Redirect from 'http://localhost:3000/auth/google' to 'https://accounts.google.com/o/oauth2/auth?response_type=code&redirect_uri=h…d=584602753475-1kk345gd8trcn31pbg1v2gncajhpakk8.apps.googleusercontent.com' has been blocked by CORS policy: Request requires preflight, which is disallowed to follow cross-origin redirect.
當我打http://localhost:3000/auth/google
URL從一個新的瀏覽器標籤,一切工作正常。
任何人都可以告訴我應該在哪裏啓用cors?
編輯
我能看到的是,瀏覽器正在一個選項請求到localhost:3000/auth /中谷歌
這是我得到的時候我做了一個選項,捲曲要求: HTTP/1.1 204 No Content X-Powered-By: Express Vary: Origin Access-Control-Allow-Credentials: true Access-Control-Allow-Methods: GET,HEAD,PUT,PATCH,POST,DELETE Access-Control-Max-Age: 86400 Date: Mon, 20 Feb 2017 14:05:53 GMT Connection: keep-alive
感謝您的回覆。我在我的JS獲取請求中有這部分。瀏覽器向「http:// localhost:3000/auth/google」發出一個選項請求。這是事情被阻止的地方。 –
您測試了選項請求嗎? http://stackoverflow.com/questions/14481850/how-to-send-a-http-options-request-from-the-command-line – philipp
我嘗試了一個選項請求。響應是:'HTTP/1.1 204無內容 X-Powered-By:Express Vary:Origin Access-Control-Allow-Credentials:true Access-Control-Allow-Methods:GET,HEAD,PUT,PATCH,POST ,刪除 訪問控制最大年齡:86400 日期:2017年2月20日星期一14:05:53 GMT 連接:保持活動狀態 –