小编Cri*_*n18的帖子

使用 HttpListener 对 Windows 桌面应用程序进行 OAuth 2.0 授权

我正在用 C# 编写一个带有外部身份验证(Google、Facebook)的 Windows 桌面应用程序。

我正在使用 HttpListener 来允许用户通过带有 ASP.NET Web API 的外部身份验证服务获取 Barer 令牌,但为此需要管理员权限,我想在没有管理员模式的情况下运行。

我的参考资料是适用于 Windows 的示例桌面应用程序

这是来自 C# 的外部身份验证提供程序的最佳实践吗?或者有另一种方法可以做到这一点?

这是我通过外部提供商获取 Barer 令牌的代码:

public static async Task<string> RequestExternalAccessToken(string provider)
{
    // Creates a redirect URI using an available port on the loopback address.
    string redirectURI = string.Format("http://{0}:{1}/", IPAddress.Loopback, GetRandomUnusedPort());

    // Creates an HttpListener to listen for requests on that redirect URI.
    var http = new HttpListener();
    http.Prefixes.Add(redirectURI);
    http.Start();

    // Creates the OAuth 2.0 authorization request.
    string authorizationRequest = …
Run Code Online (Sandbox Code Playgroud)

c# httplistener google-authentication oauth-2.0 asp.net-web-api

2
推荐指数
1
解决办法
2869
查看次数