Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Need a way to use OidcClient from a worker thread #122

Open
jzkirtley opened this issue Apr 6, 2022 · 2 comments
Open

Need a way to use OidcClient from a worker thread #122

jzkirtley opened this issue Apr 6, 2022 · 2 comments

Comments

@jzkirtley
Copy link

I am currently attempting to use OIDC authentication in a legacy Winforms app. The login process is extremely arcane (it can happen in the background or through user action, and authentication can take a number of different forms). Much of the login code predates the async/await model in .net, and involves worker threads that occasionally post information back to the main UI thread (for example, status updates)

Because of this, I need to be able to call OidcClient.Login Synchronously. However, attempting to simply force synchronization don't work. Specifically:

            loginResult = oidcClient.LoginAsync(loginRequest).Result;

throws an exception:
InnerException = {"Cannot change thread mode after it is set. (Exception from HRESULT: 0x80010106 (RPC_E_CHANGED_MODE))"}

I believe I can generate a simple test case if necessary, assuming there's a good generic OAuth server running somewhere I could use as a test bed.

@jzkirtley
Copy link
Author

Any workarounds would be appreciated. Attempts to call OidcClient.LoginAsync from an invoked callback in the UI thread deadlock (which makes sense). Rewriting my entire login process to use async/await is basically a nonstarter as it's literally thousands of lines of legacy code.

@leastprivilege
Copy link
Contributor

Sorry - no idea. Feel free to grab the source code and change it in any way you need.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants