简体   繁体   English

在node.js CLI中获取浏览器响应或回调

[英]Get browser response or callback in node.js CLI

Snyk asks for authentication when user uses it on first time. 用户首次使用时,Snyk要求进行身份验证。 It looks like this: 看起来像这样:

  1. User types snyk auth in cmd. 用户在cmd中键入snyk auth
  2. Tab opens in browser with log in page. 在带有登录页面的浏览器中打开选项卡。
  3. Log in. 登录。
  4. Snyk receives response that I have logged in and proceeds next. Snyk收到我已登录的响应,然后继续。

1 - 3 is obvious for me how it works. 1-3对我来说很明显。 But I don't understand how node knows that I have logged in. It has something to do with HTTP headers I guess but still I have no idea how it should look like in a code. 但是我不明白节点如何知道我已经登录。我猜它与HTTP标头有关,但我仍然不知道它在代码中的外观。 I have tried to find my answer in cli/commands/auth.js but code is too complicated to me. 我试图在cli / commands / auth.js中找到答案,但是代码对我来说太复杂了。

You can create a temporary http server with a callback route for authentication; 您可以创建一个带有回调路由的临时http服务器进行身份验证; just like you do in a simple ordinary web application. 就像在一个简单的普通Web应用程序中一样。
After the authentication, you can save the received information (eg in a file) and stop the http server. 认证之后,您可以保存接收到的信息(例如,保存在文件中)并停止http服务器。

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

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