It looks like you're new here. If you want to get involved, click one of these buttons!
kite = new Kite(MyAPIKey, Debug: true, Pool:20);
kite.EnableLogging(false);
// Generate a redirect url for local http server
string redirectURL = string.Format("https://{0}:{1}/", IPAddress.Loopback, GetRandomUnusedPort());
string loginURL = string.Format("{0}&redirect_url={1}", kite.GetLoginURL(), redirectURL);
var http = new HttpListener();
http.Prefixes.Add(redirectURL);
http.Start();
Process.Start(new ProcessStartInfo(loginURL) { UseShellExecute = true });
// not working now
var context = Task.Run(async () => await http.GetContextAsync()).Result;
// Send a response back to browser
var response = context.Response;
string responseString = string.Format("Please return to the app");
var buffer = System.Text.Encoding.UTF8.GetBytes(responseString);
response.ContentLength64 = buffer.Length;
var responseOutput = response.OutputStream;
Task responseTask = responseOutput.WriteAsync(buffer, 0, buffer.Length).ContinueWith((task) =>
{
responseOutput.Close();
http.Stop();
});
var requestToken = context.Request.QueryString.Get("request_token");
if (requestToken == null)
{
//Console.WriteLine("Login was not completed");
return;
}
//Use request token to generate access token
User user = kite.GenerateSession(requestToken, MySecret);
// Store this locally and reuse it. This is valid for one day
kite.SetAccessToken(user.AccessToken);
Note : Issue reported on 16th July 2021 lasted till next day Morning only and after 5:30 am on 17th July 2021 it started working appropriately. But this time since 13th August 2021 issue is persisting and my work is stuck.
http://127.0.0.1:12345
and change code tostring redirectURL = string.Format("http://{0}:{1}/", IPAddress.Loopback, 12345);
Make sure not to use "https" for this setup because the "HttpListener" cannot handle SSL without proper certificates.
To help you I am attaching one more snapshot of issue using firefox.
GetRandomUnusedPort
logic and it will be fine.Thanks for the fix. It’s working now . We can close the thread .