我试图从C#WPF应用程序登录到我的AWS Cognito用户池,以接收我的API网关的身份验证令牌。
我正在使用其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转到新的空白页:
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,等待用户登录并返回访问令牌吗?