通过设置cookie打开带有Phantom.Js的受密码保护的网站(Passport.js) [英] Opening password protected site (Passport.js) with Phantom.Js by setting cookie

查看:555
本文介绍了通过设置cookie打开带有Phantom.Js的受密码保护的网站(Passport.js)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用 Phantom.js 脚本访问我的 Express.js 应用的护照保护页面。

I am trying to access a passport protected page of my Express.js app with a Phantom.js script.

如何在不知道护照的情况下模拟已登录的用户?

How can I simulate a logged in user without knowing the passport?

我使用护照.js 作为具有 LocalStrategy MongoStore 的安全库,以保护 mongo 数据库中的会话。我想知道我是否可以在会话集合中创建记录,并使用 Phantom.js phantom.addCookie ))模拟没有用户密码的特定登录用户?

I am using Passport.js as a auth library with LocalStrategy and MongoStore to safe the sessions in the mongo database. I am wondering if I can create a record in the sessions collection and set a generated cookie with Phantom.js (phantom.addCookie(...)) to simulate a specific logged in user without the password of the user?

我可以生成

Can I generate the content of the of the connect.sid cookie for a specific user in the backend and add it to phantom.js in order to simulate a logged in user?

我发现Passport.js使用 Cookie-Signature 节点模块来签署Cookie内容,并假设 Express.js 使用 连接 会话中间件来处理cookie和会话创建, HTTP标头。

I figured out that Passport.js uses the Cookie-Signature node module to sign the cookie content and I assume Express.js uses the Connect cookie and session middleware to handle the cookie and session creation and insert them into the HTTP headers.

推荐答案

使用javascript,您应该能够填写您的登录字段并提交。 (模拟用户登录,而不是尝试重新创建登录Cookie)

using javascript, you should be able to fill in your login fields and submit. (simulating a user login, not trying to recreate a login cookie)

这可能是您最好的选择。

that would probably be your best bet.

如何填写表单,请参阅:
如何填写表单字段并使用javascript提交?
使用javascript 自动填写表单

for how to fill in forms, see: How to fill in form field, and submit, using javascript? Automatic form fill using javascript

这篇关于通过设置cookie打开带有Phantom.Js的受密码保护的网站(Passport.js)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆