是否可以从 vscode 扩展中对 OAuth 2.0 API 进行身份验证

问题描述:

我的团队编写了一个监控系统,我们最近将监控的定义迁移到了 git 存储库中.这些定义由一些 json 和 powershell 文件组成.VSCode 是编辑和处理 git 的理想场景.问题是在开发监控时,能够在测试环境中执行它是很好的.以前所有编辑都是通过 Web 界面完成的,我们允许通过 AzureAD 和 OAuth2.0 保护的 API 对测试机器临时执行 powershell.

My team writes a monitoring system which we have recently migrated the definitions of our monitoring into a git repo. These definitions are comprised of some json and powershell files. VSCode is an ideal scenario for editing and dealing with git. The problem is while developing the monitoring it is nice to be able to execute it against a test environment. Previously all editing was done through a web interface and we allowed ad hoc execution of the powershell against test machines through an API which is secured with AzureAD and OAuth2.0.

VS Code 扩展无法访问完整的电子 API,并且您无法创建 BrowserWindow 来处理通常的 OAuth 重定向流.有没有办法解决这个限制并允许用户对我们的 api 进行身份验证,以便我们可以调用它?

VS Code extensions don't have access to the full electron api and you are restricted from creating a BrowserWindow to handle the usual OAuth redirect flow. Is there a way to work around this limitation and allow a user to auth to our api so that we can make calls to it?

任何想法或可能的解决方法都很棒.

Any ideas or possible workarounds would be awesome.

为无法打开 Web 浏览器进行身份验证的应用程序获取用户令牌的支持方式是OAuth 设备流程".这是有关如何使用 AAD 实现它的博客的链接.

The supported way to get a user token for an application that doesn't have the ability to open a Web Browser to auth is the "OAuth Device Flow". Here is a link to a blog about how to implement it with AAD.

https://joonasw.net/view/device-code-flow