如何使用 OAuth 2.0 和来自 C# 可执行文件的 `authentication_code` 授权流类型进行身份验证?

How to authenticate using OAuth 2.0 with `authentication_code` grant flow type from a C# executable?

我正在使用 C# 命令行 tool which automates some deployment tasks by sending requests to the API of an on-premise installation (in this specific case UiPath Orchestrator)。

我一直用到现在bearer token authentication, which is being phased-out and need to move to OAuth 2.0 for authentication on the respective on-premise setup

到目前为止,我已经找到了一些关于如何使用带有 client_credentials grant flow 类型的 OAuth 2.0 进行身份验证的示例,并且我自己已经能够成功实施它:

问题是在我的特定情况下 client_credentials grant flow 类型允许用户访问太多资源,需要改用 authorization_code grant flow 类型,允许用户仅访问允许的资源。

希望 authorization_code grant flow 类型的一些 simple/basic 代码片段,因为到目前为止只找到了以下示例,我正在努力完全理解但不确定这些是否适用于我的具体情况:

控制台应用程序使用系统浏览器进行交互式登录,方式与桌面应用程序相同。有两种侦听登录响应的选项,反映在这些小的 C# 代码示例中:

有关概念的更多信息,以及您可以 运行 在本地使用的几个 Node.js 应用程序,请参阅我的桌面博客文章,从 here 开始。