简体   繁体   English

使用浏览器中保存的JavaScript和cookie获取网站的HTML代码

[英]GET a website's HTML code using JavaScript and cookies saved in the browser

I'm writing a Chrome Packaged App, that is supposed to interact with a website (that I do not own), and retrieve some HTML code from it. 我正在编写一个Chrome打包的应用程序,该程序应该与一个网站(我不拥有)进行交互,并从中检索一些HTML代码。 I'm using jQuery get() to retrieve the source code, but the problem is that the user is logged in that website and there is some info that isn't available unless you're logged in. 我正在使用jQuery get()来检索源代码,但问题是用户已登录该网站,并且除非您登录,否则有些信息是不可用的。

So I want the app to retrieve the page as it would be if the user would be logged in (in Chrome). 因此,我希望该应用程序检索该页面,就像用户将登录(在Chrome中)一样。

I know it isn't really that good of an idea to make a Chrome App that is dependent on the browser's cookies (the app should be able to run by itself), but I don't know of any other way I could do this, and even if I'd figure out how to log into the website through the app, users would think it was a phisher (the app will be closed source). 我知道制作一个依赖于浏览器cookie的Chrome应用并不是一个好主意(该应用应能够独立运行),但是我不知道有什么其他方法可以做到这一点,即使我想出了如何通过该应用程序登录该网站,用户也会认为这是网络钓鱼(该应用程序将是封闭源代码)。 So yeah, relying on the browser cookies. 是的,依靠浏览器cookie。

As far as I know, and I'm pretty sure I would know, there's no way to send the cookies with an HTTP request from a Chrome App. 据我所知,而且我相当确定,我无法通过Chrome应用发送带有HTTP请求的Cookie。

In the old days, prior to OAuth, it was typical for a user who wanted an app to access a web site to tell the app his/her login and password, through a setup page or the equivalent. 在过去,在使用OAuth之前,通常是希望用户通过设置页面或等效页面访问应用程序以告知应用程序其登录名和密码的网站的用户。 Then the app would login. 然后该应用程序将登录。

This is much improved with OAuth, but the web site you're trying to access it may not support it. OAuth对此功能进行了很大的改进,但是您尝试访问它的网站可能不支持它。 If it does, then that's the way to go. 如果是这样,那就是要走的路。 If not, you have no choice but to ask the user for his/her login credentials, and then to store those for reuse. 如果没有,您别无选择,只能要求用户提供他/她的登录凭据,然后将其存储以备重用。 Not in a cookie, as Chrome Apps can't access cookies, but in local storage. Chrome浏览器无法访问Cookie,因此不在Cookie中,而是在本地存储中。 (There's a specific Chrome App API for local storage.) You probably should encrypt the password, and perhaps the login as well. (有一个特定的Chrome App API用于本地存储。)您可能应该加密密码,以及登录名。 Note that in this case it can't be a one-way hash, but rather a normal encrypt/decrypt. 请注意,在这种情况下,它不能是单向哈希,而是普通的加密/解密。

(If you are using OAuth, use the Chrome App identity API, which makes OAUth2 very easy, and OAuth1 possible but far from easy.) (如果您使用的是OAuth,请使用Chrome App身份API,这使OAUth2非常容易,而OAuth1则可行,但远非易事。)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM