{"id":395,"date":"2019-05-24T10:27:35","date_gmt":"2019-05-24T01:27:35","guid":{"rendered":"http:\/\/localhost:8000\/?p=395"},"modified":"2021-01-23T12:13:41","modified_gmt":"2021-01-23T03:13:41","slug":"302-redirect-cors","status":"publish","type":"post","link":"http:\/\/localhost:8000\/2019\/05\/302-redirect-cors.html","title":{"rendered":"\u5225\u30c9\u30e1\u30a4\u30f3\u3078\u306e302 redirect\u3092\u8fd4\u3059API\u3092\u547c\u3073\u51fa\u3059\u3068CORS\u30a8\u30e9\u30fc"},"content":{"rendered":"
\u5225\u30c9\u30e1\u30a4\u30f3\u3078\u306e302 redirect\u3092\u8fd4\u3059\u5225\u30c9\u30e1\u30a4\u30f3\u306eAPI\u3092\u547c\u3073\u51fa\u3059\u3068CORS\u30a8\u30e9\u30fc\u304c\u767a\u751f\u3059\u308b\u3053\u3068\u304c\u308f\u304b\u3063\u305f\u3002<\/p>\n
\u8aac\u660e\u304c\u96e3\u3057\u3044\u306e\u3060\u304c\u3001\u81ea\u5206\u306e\u5177\u4f53\u7684\u306a\u30b1\u30fc\u30b9\u3092\u66f8\u304f\u3068\u3001<\/p>\n
\u3068\u3044\u3046\u6d41\u308c\u3067\u3001\u4ee5\u4e0b\u306e\u30a8\u30e9\u30fc\u304c\u767a\u751f\u3057\u305f\u3002<\/p>\n
Access to XMLHttpRequest at 'https:\/\/accounts.google.com\/o\/oauth2\/auth?client_id=**********.apps.googleusercontent.com&redirect_uri=http%3A%2F%2Flocalhost%3A8080%2Flogin&scope=profile&state=**********&response_type=code&response_mode=query' (redirected from 'http:\/\/localhost:8080\/hoge') from origin 'null' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.<\/code><\/pre>\n\u30a8\u30e9\u30fc\u767a\u751f\u306e\u30e1\u30ab\u30cb\u30ba\u30e0<\/h2>\n
\u51e6\u7406\u306e\u6d41\u308c\u306f\u4ee5\u4e0b\u306e\u3088\u3046\u306a\u611f\u3058\u3002\u8af8\u60aa\u306e\u6839\u6e90\u306f\u30d6\u30e9\u30a6\u30b6\u304c\u30c9\u30e1\u30a4\u30f3C\u306b\u30ea\u30c0\u30a4\u30ec\u30af\u30c8\u3059\u308b\u969b\u306bOrigin: null<\/code>\u30d8\u30c3\u30c0\u30fc\u3092\u8a2d\u5b9a\u3059\u308b\u3053\u3068\u306e\u3088\u3046\u3060\u3002<\/p>\n\n- \u30c9\u30e1\u30a4\u30f3A\u304b\u3089\u30c9\u30e1\u30a4\u30f3B\u306eAPI\u3092request\u3059\u308b<\/li>\n
- \u30c9\u30e1\u30a4\u30f3B\u306f\u3001
Access-Control-Allow-Origin: *<\/code>\u3092\u8a2d\u5b9a\u3057\u305f\u3046\u3048\u3067\u3001Location\u306b\u30c9\u30e1\u30a4\u30f3C\u306eURL\u3092\u6307\u5b9a\u3057\u3066response\u3092\u8fd4\u3059<\/li>\n- \u5168\u3066\u306eOrigin\u304c\u8a31\u53ef\u3055\u308c\u3066\u3044\u308b\u305f\u3081CORS\u30a8\u30e9\u30fc\u306f\u767a\u751f\u3057\u306a\u3044<\/li>\n
- \u30d6\u30e9\u30a6\u30b6\u306f\u3001\u30c9\u30e1\u30a4\u30f3C\u306b\u30ea\u30c0\u30a4\u30ec\u30af\u30c8\u3059\u308b\u3002\u3053\u306e\u969b\u3001
Origin: null<\/code>\u30d8\u30c3\u30c0\u30fc\u304c\u8a2d\u5b9a\u3055\u308c\u308b<\/b><\/li>\n- \u30c9\u30e1\u30a4\u30f3C\u306f\u3001
Access-Control-Allow-Origin<\/code>\u30d8\u30c3\u30c0\u30fc\u3092\u3064\u3051\u305a\u306b\u3001response\u3092\u8fd4\u3059<\/li>\n- \u30d6\u30e9\u30a6\u30b6\u306f\u3001\u5192\u982d\u306b\u66f8\u3044\u305fCORS\u30a8\u30e9\u30fc\u3092\u767a\u751f\u3055\u305b\u308b<\/li>\n<\/ol>\n
<\u30b7\u30fc\u30b1\u30f3\u30b9\u56f3>
\n<\/p>\n
\u3053\u306e\u554f\u984c\u306b\u5bfe\u3059\u308b\u56de\u907f\u65b9\u6cd5\u306f\u898b\u3064\u304b\u3089\u306a\u304b\u3063\u305f<\/h2>\n
\u7d50\u8ad6\u3001Issue\u306f\u767a\u898b\u3059\u308b\u3082\u306e\u306e\u5bfe\u5fdc\u65b9\u6cd5\u307e\u3067\u8a00\u53ca\u3055\u308c\u3066\u3044\u308b\u3082\u306e\u306f\u306a\u304b\u3063\u305f\u3002<\/p>\n
\n- https:\/\/stackoverflow.com\/questions\/51743710\/origin-null-is-therefore-not-allowed-access<\/a><\/li>\n
- https:\/\/stackoverflow.com\/questions\/30193851\/ajax-call-following-302-redirect-sets-origin-to-null<\/a><\/li>\n
- https:\/\/stackoverflow.com\/questions\/25499169\/why-does-my-redirected-cors-request-fail<\/a><\/li>\n
- https:\/\/w3c.github.io\/webappsec-cors-for-developers\/#avoid-returning-access-control-allow-origin-null<\/a><\/li>\n<\/ul>\n
\u5bfe\u5fdc\u6848\uff11\uff1a\u30c9\u30e1\u30a4\u30f3\u3092\u7d71\u4e00\u3059\u308b -> \u7d50\u5c40\u89e3\u6c7a\u3057\u306a\u304b\u3063\u305f<\/h3>\n
\u30c9\u30e1\u30a4\u30f3A\u3068\u30c9\u30e1\u30a4\u30f3B\u304cCross Origin\u306e\u72b6\u614b\u3067\u30ea\u30c0\u30a4\u30ec\u30af\u30c8\u6642\u306bOrigin: null<\/code>\u30d8\u30c3\u30c0\u30fc\u3092\u3064\u3051\u306a\u3044\u3088\u3046\u306b\u3059\u308b\u3053\u3068\u306f\u3067\u304d\u306a\u305d\u3046\u306a\u306e\u3067\u3001\u30c9\u30e1\u30a4\u30f3A\u3068\u30c9\u30e1\u30a4\u30f3B\u306e\u30c9\u30e1\u30a4\u30f3\u3092\u4e00\u81f4\u3055\u305b\u308b\u3053\u3068\u306b\u3057\u305f\u3002\u8a73\u7d30\u306f\u5225\u8a18\u4e8b\u3092\u66f8\u3044\u305f\u306e\u3067\u305d\u3061\u3089\u3092\u53c2\u7167\u306e\u3053\u3068\u3002
\n\u30ed\u30fc\u30ab\u30eb\u74b0\u5883\u3067\u958b\u767a\u4e2d\u306e\u8907\u6570\u30a2\u30d7\u30ea\u30b5\u30fc\u30d0\u306e\u30c9\u30e1\u30a4\u30f3\u3092Nginx\u3067\u7d71\u4e00\u3059\u308b<\/a><\/p>\n\u3057\u304b\u3057\u3001\u7d50\u679c\u3068\u3057\u3066\u554f\u984c\u306f\u89e3\u6c7a\u3057\u306a\u304b\u3063\u305f<\/b>\u3002\u30ea\u30d0\u30fc\u30b9\u30d7\u30ed\u30ad\u30b7\u3092\u7acb\u3066\u308b\u3053\u3068\u3067\u3001\u30c9\u30e1\u30a4\u30f3\u3092\u7d71\u4e00\u3059\u308b\u3053\u3068\u306f\u3067\u304d\u305f\u3082\u306e\u306e\u3001\u4ee5\u4e0b\u306e\u30a8\u30e9\u30fc\u304c\u5f15\u304d\u7d9a\u304d\u767a\u751f\u3057\u305f\u306e\u3067\u3042\u308b\u3002<\/p>\nAccess to XMLHttpRequest at 'https:\/\/accounts.google.com\/o\/oauth2\/auth?client_id=**********.apps.googleusercontent.com&redirect_uri=http%3A%2F%2Frinoguchi.io%2Flogin&scope=profile&state=**********&response_type=code&response_mode=query' (redirected from 'http:\/\/rinoguchi.io\/hoge') from origin 'http:\/\/rinoguchi.io' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.<\/code><\/pre>\n\u7406\u7531\u3068\u3057\u3066\u306f\u3001 \u30c9\u30e1\u30a4\u30f3\u304c\u4e00\u81f4\u3057\u305f\u3089\u30ea\u30c0\u30a4\u30ec\u30af\u30c8\u6642\u306bOrigin<\/code>\u30d8\u30c3\u30c0\u30fc\u3092\u3064\u3051\u306a\u304f\u306a\u308b\u306e\u3060\u3068\u601d\u3063\u3066\u3044\u305f\u304c\u3001Origin: http:\/\/rinoguchi.io<\/code>\u304c\u8a2d\u5b9a\u3055\u308c\u3066\u3044\u308b\u305f\u3081\u306e\u3088\u3046\u3060\u3002
\nGoogle API<\/a>\u306e\u8a2d\u5b9a\u3067\u627f\u8a8d\u6e08\u307f\u30c9\u30e1\u30a4\u30f3\u306brinoguchi.io<\/code>\u3092\u8ffd\u52a0\u3057\u3066\u307f\u305f\u306e\u3060\u304c\u3001Access-Control-Allow-Origin<\/code>\u3092\u8a2d\u5b9a\u3057\u3066\u304f\u308c\u308b\u3053\u3068\u3082\u306a\u304f\u5f71\u97ff\u306f\u306a\u304b\u3063\u305f\u3002<\/p>\n\u5bfe\u5fdc\u6848\uff12\uff1a\u5225\u30c9\u30e1\u30a4\u30f3\u3078\u306e302 Redirect\u3092\u3084\u3081\u308b -> \u3053\u308c\u3067\u89e3\u6c7a<\/h2>\n
\u8272\u3005\u8abf\u3079\u3066\u3044\u308b\u3068\u3001\u3069\u3046\u3084\u3089\u5225\u30c9\u30e1\u30a4\u30f3\u3078302 Redirect\u3092\u3059\u308b\u3068Allow-Origin\u3092\u8a2d\u5b9a\u3057\u306a\u3044\u9650\u308a\u306f\u3001CROS\u30a8\u30e9\u30fc\u306b\u3055\u308c\u3066\u3057\u307e\u3046\u3088\u3046\u3060\u3063\u305f\u3002\u306a\u306e\u3067\u3001\u3068\u3066\u3082\u9762\u5012\u3060\u3063\u305f\u304c\u3001302\u30ea\u30c0\u30a4\u30ec\u30af\u30c8\u3092\u884c\u308f\u306a\u3044\u5f62\u306b\u51e6\u7406\u3092\u7d44\u307f\u66ff\u3048\u308b\u3053\u3068\u306b\u3057\u305f\u3002\u8a73\u7d30\u306f\u5225\u8a18\u4e8b\u3092\u66f8\u3044\u305f\u306e\u3067\u3001\u3053\u3061\u3089\u3092\u53c2\u7167\u306e\u3053\u3068\u3002
\nKtor\u3067\u69cb\u7bc9\u3057\u305fAPI\u30b5\u30fc\u30d0\u306eGoogle OAuth\u8a8d\u8a3c\u51e6\u7406\u306e\u5168\u4f53\u50cf<\/a><\/p>\n\u3053\u306e\u5bfe\u5fdc\u306b\u3088\u308a\u3001\u3084\u3063\u3068CORS\u30a8\u30e9\u30fc\u3092\u8d77\u3053\u3055\u305aGoogle OAuth\u8a8d\u8a3c\u3092\u884c\u3046\u3053\u3068\u304c\u3067\u304d\u308b\u69d8\u306b\u306a\u3063\u305f\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"
\u5225\u30c9\u30e1\u30a4\u30f3\u3078\u306e302 redirect\u3092\u8fd4\u3059\u5225\u30c9\u30e1\u30a4\u30f3\u306eAPI\u3092\u547c\u3073\u51fa\u3059\u3068CORS\u30a8\u30e9\u30fc\u304c\u767a\u751f\u3059\u308b\u3053\u3068\u304c\u308f\u304b\u3063\u305f\u3002 \u8aac\u660e\u304c\u96e3\u3057\u3044\u306e\u3060\u304c\u3001\u81ea\u5206\u306e\u5177\u4f53\u7684\u306a\u30b1\u30fc\u30b9\u3092\u66f8\u304f\u3068\u3001 \u30c9\u30e1\u30a4\u30f3A\uff08\u30d5\u30ed\u30f3\u30c8\u30a8\u30f3\u30c9\u30b5\u30fc\u30d0\uff09\u304b\u3089\u30c9\u30e1\u30a4\u30f3B\uff08\u30d0\u30c3\u30af\u30a8\u30f3\u30c9API\u30b5\u30fc\u30d0\uff09\u306eAPI\u3092\u547c\u3073\u51fa\u3059 API\u304cGoogle OAuth\u8a8d\u8a3c\u306e\u305f\u3081\u306b\u30c9\u30e1\u30a4\u30f3C\uff08account.google.com\uff09\u3078\u306e302 Redirect\u3092\u8fd4\u3059 CORS\u30a8\u30e9\u30fc\u767a\u751f \u3068\u3044\u3046\u6d41\u308c\u3067\u3001\u4ee5\u4e0b\u306e\u30a8\u30e9\u30fc\u304c\u767a\u751f\u3057\u305f\u3002 Access to XMLHttpRequest at 'https:\/\/accounts.google.com\/o\/oauth2\/auth?client_id=**********.apps.googleusercontent.com&redirect_uri=http%3A%2F%2Flocalhost%3A8080%2F <\/span>Continue Reading<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[34],"tags":[],"_links":{"self":[{"href":"http:\/\/localhost:8000\/wp-json\/wp\/v2\/posts\/395"}],"collection":[{"href":"http:\/\/localhost:8000\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/localhost:8000\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/localhost:8000\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/localhost:8000\/wp-json\/wp\/v2\/comments?post=395"}],"version-history":[{"count":1,"href":"http:\/\/localhost:8000\/wp-json\/wp\/v2\/posts\/395\/revisions"}],"predecessor-version":[{"id":397,"href":"http:\/\/localhost:8000\/wp-json\/wp\/v2\/posts\/395\/revisions\/397"}],"wp:attachment":[{"href":"http:\/\/localhost:8000\/wp-json\/wp\/v2\/media?parent=395"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/localhost:8000\/wp-json\/wp\/v2\/categories?post=395"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/localhost:8000\/wp-json\/wp\/v2\/tags?post=395"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}