Unable to find implementation of microsoft login for windows form applications
#documentation doesn't exist
Unable to find the implementation of Microsoft login for windows form applications.
How can I integrate Microsoft account login in C# windows application? I have tried going through the documentation but all the steps are for either web or ASP.NET core.
https://docs.microsoft.com/en-us/aspnet/core/security/authentication/social/microsoft-logins?view=aspnetcore-2.2
I just want to login into my windows application using Microsoft account and get skype username.
Have a look at our wiki, particularly at the Interactive flow. MSAL will pop-up a WinForms panel that hosts a browser for your users to log in. When they login, you get given a access token that you can use to access protected APIs, like the Graph.
I am not sure how you'd find the skype username though.
Can you provide a little more explicit guidance where winforms is documented in the wiki please? I can get wpf to work but not winforms, and can't find an example. I have tried with and without the following:- AcquireTokenByUsernamePassword(), AcquireTokenInteractive(), WithParentActivityOrWindow(form.Handle).
and WithParentActivityOrWindow(new WindowInteropHelper(form).Handle) gives the error "cannot convert from 'System.Windows.Forms.Form' to 'System.Windows.Window'"
WithParentActivityOrWindow(form) should work since your form is a Window. We don't take the handle object directly.
I am not sure my Form is a "Window" as per the error at the end. My form is a subclass of System.Windows.Forms.Form.
No doubt this will be me not getting these Guids aligned once again, however at the moment it just "hangs" without raising an exception, and without showing a UI.
@pritchie99 : do you want to share a small repro solution (attach a zip file) ?
You don't need to use WithParentActivityOrWindow(form) except if you want to pop-up browser to be centered on a window. Please try without it first.
A small repro would be helpful.
Thank you all - File|New has worked with UI shown so presumably the case is related to artefacts from my old Winforms app.
Ran into the same here and was breaking my head over it for hours. I was using an (old-style) Windows Forms with .NET Framework application to make the call and the login screen never appeared. Until the light bulb above my head went on when I read in the Wiki that you need to call it on the UI thread as it will spawn a window to log in. I was using .Wait() to go from a synchronous button click to an asynchronous method where I would run these commands, thus away from the UI thread, thus the UI never showed up. Solution for me was to simply change the signature of the click handler to: private async void SignInButton_Click(object sender, RoutedEventArgs e) and get rid of the Wait() and Result. Works like a charm now.
Hi,
I am facing the same issue of unable to get microsoft login in windows form applications. Can someone please provide the steps on how to proceed on this issue?
@pritchie99 Could you please let me know the steps you performed I am facing the same issue
@KrishnaAgrawal5 - I answered on the other thread you opened. Let's continue the conversation there.