使用C#WPF应用程序登录AWS Cognito用户池

时间:2020-06-24 13:58:38

标签: c# wpf amazon-web-services http amazon-cognito

我试图从C#WPF应用程序登录到我的AWS Cognito用户池,以接收我的API网关的身份验证令牌。

这是我的App客户端设置: enter image description here

我正在使用其URL如下的Amazon Hosted UI:

https://<my_domain>.auth.us-east-1.amazoncognito.com/login?client_id=<my_client_id>&response_type=token&scope=email+openid+profile&redirect_uri=http://localhost:5000

运行此URL时,我看到此网页: enter image description here

完成登录过程后,我将使用以下新URL转到新的空白页:

http://localhost:5000/#access_token=<SOME_VERY_LONG_TOKEN>&token_type=Bearer&expires_in=3600

我需要获取的身份验证令牌位于新网址的此处

但是,我找不到任何方法可以在WPF项目中使用C#代码获取此令牌。 这是我使用的C#代码:

        string authorizationRequest = @"https://<my_domain>.auth.us-east-1.amazoncognito.com/login?client_id=<client_id>&response_type=token&scope=openid+profile+email&redirect_uri=http://localhost:5000";
        string redirectURI = "http://localhost:5000/";

        // 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.
        Process.Start(authorizationRequest); // Opens Google Chrome with the login page
        HttpListenerContext context = await http.GetContextAsync();
        var response = context.Response;
        http.Stop();

我无法从http响应中获取令牌,因为响应为空。

任何人都可以提供C#代码来接收托管UI URL,等待用户登录并返回访问令牌吗?

0 个答案:

没有答案