我们如何在Google puppeteer的无头Chrome中传递身份验证令牌? [英] How do we pass authentication token in headless chrome in google puppeteer?

查看:966
本文介绍了我们如何在Google puppeteer的无头Chrome中传递身份验证令牌?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在伪造者的标头中传递身份验证令牌(JWT),以便在我的应用程序中使用无头chrome的pdf视图吗? 我们正在使用react作为前端UI.使用puppeteer,我们能够生成pdf,但是我们需要使用JWT授权到pdf的链接 我们如何在标头中传递jwt,puppeteer是否支持标头中的Auth令牌? 请帮忙.

I want to pass authentication token(JWT) in puppeteer headers, for the pdf view with headless chrome in my application? We are using react as our front-end UI. And using puppeteer we are able to generate pdf, but the link to pdf we need to authorize using JWT How do we pass the jwt in headers, does puppeteer support Auth token in headers? Please help.

谢谢

推荐答案

要在请求中传递其他标头,可以使用函数

To pass additional headers in the request, you can use the function page.setExtraHTTPHeaders.

上面链接的文档中的语录:

Quote from the docs linked above:

额外的HTTP标头将随页面启动的每个请求一起发送.

The extra HTTP headers will be sent with every request the page initiates.

示例:

page.setExtraHTTPHeaders({
    'Token': '...', 
});

随后所有后续请求都将具有带有设置值的附加标头Token.

All following requests will then have the additional header Token with the set value.

这篇关于我们如何在Google puppeteer的无头Chrome中传递身份验证令牌?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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