Xero - beautiful accounting software

Xero Developer Help Center

Xero Developer Community

Community > Wrapper libraries >

OAuth2.0 with WinForms

Started by Alex Brouwer -   in Wrapper libraries

I have a number of WinForms applications that I need to maintain. I understand OAuth1.0 will no longer be support in March next year, problem I have is that Xero's examples use MVC. It's a technology I have no experience in and have no idea on how to make this new authentication system work in WinForms.

Does anyone have any experience doing this? Where does one start! lol
Hi Alex

OAuth2 with desktop apps is definitely possible.

Without getting too detailed, you have two options:

1) Embed a local web server that can host the redirect and callback pages. .NET Core has one that will work well, however this will require a separate project to be created.
This is probably best run as a Windows Service, which can be started and stopped by your Win Forms app.

You also need to spawn a web browser from within your app to display the above pages to the user.

More details:
- https://docs.microsoft.com/en-us/aspnet/core/fundamentals/host/generic-host?view=aspnetcore-3.1
- https://docs.microsoft.com/en-us/dotnet/framework/winforms/controls/webbrowser-control-windows-forms

2) Host the authentication pages as a regular web app. Send the user there to authenticate.

You could spawn a browser from your app or open the system browser and have your app register a url handler to facilitate returning to your app after authorisation.

Host an API in this web app that your Win Forms app can interact with and retrieve the Xero tokens.

The first approach is more secure because the user's tokens don't leave their machines, but it may be open to more impacts from the user's machine config.

The second approach involves managing the separate web app and its security but the user experience overall is probably better.

Further info that is somewhat related

Hope that helps!

Joe Niland  

Alex saw your other thread so looks like you're making progress! Did you get it working?

Joe Niland