我正在了解如何以正确的方式为 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/