OIDC client with local HTTP listener stuck #194
Replies: 2 comments 5 replies
-
Based on the sample you're looking at, I suggest adding a As a bonus, I would also start the task before opening the browser, and await the task afterwards to ensure that we're listening for the response before the response potentially already happened: // start the task before opening the browser in case we return immediately when the user still has an active session
var contextTask = http.GetContextAsync();
// open system browser to start authentication
Process.Start(new ProcessStartInfo
{
FileName = state.StartUrl,
UseShellExecute = true,
});
HttpListenerContext? context = null;
try
{
// wait for the authorization response.
context = await contextTask.WaitAsync(TimeSpan.FromMinutes(10));
}
catch (TimeoutException)
{
}
if (context is null)
{
Console.WriteLine("\n\nError:\n{0}", "The operation timed out while waiting for the authorization response.");
return;
} That said, while using the
|
Beta Was this translation helpful? Give feedback.
-
Thanks for your detailed answer!
|
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
I've been playing around with this example: https://github.com/DuendeSoftware/foss/blob/main/identity-model-oidc-client/samples/HttpSysConsoleClient/HttpSysConsoleClient/Program.cs#L55
It's a pretty slick approach to start a local webserver and then redirect there. It works very well, only when we close the browser instead of logging in, the code is stuck at line 55
It's waiting to get a feedback via HTTP listener and never receives a message. The only idea is to put this inside another thread and then wait for the process to close. If it does, we stop the HTTP listener and exit with an error code, otherwise if we get an HTTP request, we terminate the process somehow and return the login result.
It feels a bit hacky, any better ideas?
Beta Was this translation helpful? Give feedback.
All reactions