c# - 是否允许 native 应用程序客户端使用重定向 URI 中的任何随机可用端口?

标签 c# oauth-2.0 google-oauth

我正在了解如何以正确的方式为 Windows 实现 OAuth 2.0 native 应用程序。我偶然发现了这个example用 C# 编写。 但这就是这个例子让我烦恼的地方:

// Creates a redirect URI using an available port on the loopback address.
string redirectUri = $"http://{IPAddress.Loopback}:{GetRandomUnusedPort()}/";

我读过的有关 OAuth 2.0 的所有内容都明确指出,redirect_uri 必须在 OAuth 服务器上预先注册,并且不能是动态的。 这个例子是错误的还是我遗漏了什么?

最佳答案

根据OAuth for Native Apps您应该能够注册一个静态重定向 URI,如下所示:

  • http://localhost/callback

然后在运行时您应该能够使用各种重定向 URL,如下所示:

  • http://localhost:8001/callback
  • http://localhost:8002/callback
  • http://localhost:8003/callback

不过,我很少看到这种支持,更常见的是您需要注册三个左右的特定 URL。您需要测试您的提供商才能确定。

关于c# - 是否允许 native 应用程序客户端使用重定向 URI 中的任何随机可用端口?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66057903/

相关文章:

c# - 根据子集合总和的比较执行单个查询

c# - 如何在c#中从Eventhub接收最新消息

c# - 为什么 C# 不对泛型进行 "simple"类型推断?

angularjs - Identity Server 身份验证无需请求用户许可

google-apps-script - OAuth 同意屏幕 - 能够删除应用程序 Logo : old solution is no longer working

c# - ExecuteStoreQuery 和 ExecuteStoreCommand 有什么区别

node.js - 从 Electron 浏览器窗口获取 json

oauth-2.0 - [OAuth][Keycloak] invalid_grant session 在尝试使用 refresh_token 时未激活

android - 401 Unauthorized error.将授权码升级为凭证对象失败

ruby-on-rails - 网站如何撤销/断开 OAuth 访问权限?