Is there a way to signin Xero api using oauth2 in c# desktop application?

Viewed 915

There are several .Net sample codes that using oauth2 to signin Xero, but all of them is working with browser (most of the sample code for C# is for ASP.NET MVC).

I am going to develop a desktop application using Xero Api but Xero official tutorial said that mobile or desktop application should use PKCE flow instead of using ClientID/Secret scheme.

And in this PKCE flow, user should interact with browser to get Authorization code.

I want to know if there is any way to signin without user interaction.

2 Answers

Xero api signin was just migrated to use OAuth2.0 and it should interact with browser at least once. Once you get refresh_token using offline_access scope, you will use this token to get access token. Unfortunately they don't support custom url scheme. Hope this will be helpful for you.

I had the same problem, and there were no examples of how to do this.

As mentioned you need to create a refresh token (which does mean you have to open a browser at some point), but after that you can keep refreshing the token to get new access tokens. A refresh token can be used only once so you must store the new refresh token after each use. You must make sure to only allow one program/thread to refreshes the token at a time. Refresh tokens will expire after 60 days if they're not refreshed.

I created a worked example on github to show how to do this.

Since I produced this Xero have sent me a link to a new desktop based program which replaces their XOAuth console program for generating the refresh token.

Now that .Net 5 is available you could look at embedding Edge into the application for when you have to log into Xero

Related