Cross origin GET from local file://

拈花ヽ惹草 提交于 2019-12-23 10:06:15

问题


I'm trying to build an html file to monitor some things on a remote site- specifically, github.com. I'd like to be able to keep it to just that flat file, making the requests straight from the JS to github's API. My thought process went like this:

  1. Let's use jsonp, since I only need read access, so sticking with GETs should be fine.
    • That fails because you can't do basic authentication with jsonp.
  2. Ok, I'll use Github's OAuth instead of basic authentication!
    • That fails because the browser doesn't like me redirecting to a local resource: Not allowed to load local resource: file:///Users/... for understandable security reasons.
  3. Ok, I'll load Github's oauth in an iFrame, then get the resulting url (which should contain the oauth code I need).
    • That fails because you apparently can't access anything about a child iframe if it's on another domain, so unless I redirect back to file:///whatever, I can't get the final url. And, of course, I can't redirect to file:///whatever because of the ``Not allowed to load local resource` again.
  4. Ok, I'll use Cross-Origin Resource Sharing (going back to basic auth again)!
    • That fails because CORS from a file:/// url send the origin header as null, which servers won't accept

So, any suggestions as to how to successfully authenticate to this api from a single, local html file- either as a way around the above tacts, or another idea entirely?


回答1:


If you are using google chrome you could try running it with the

--allow-file-access-from-files

switch enabled.



来源:https://stackoverflow.com/questions/8192159/cross-origin-get-from-local-file

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!