Login Issue

jagbirsingh
Hi,

Since Friday morning - 13 August 2021 , the login API is returning an issue in the redirect URL.

I am using the below code as suggested by AjitAshokan on github . and it worked pretty well until 16 th July 2021 and now again having the Redirect url issues.
I am generating random ports every time my application requires login but then it is not working .

Please follow the comment in the code below // not working now where it stucks after successful login.

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);


I believe it has something to do with the Redirect code possibly written in the KiteZerodha javascript on kite.zerodha.com

as C#/VB code is dependent on this code to return good request context which in this case is not happening.



Please help as it stopped my work since Friday morning.

Note: The same I reported on 16th July 2021 but It started working on 20th July 2020 and I closed that discussion.

Thank you.
Tagged:
This discussion has been closed.