Xero - beautiful accounting software

Xero Developer Help Center

Xero Developer Community

Community > API Authentication >

Has anybody managed to get OAuth working using ASP.NET ?

Started by Tim Sheppard -   in API Authentication

We originally integrated our online payroll MyPAYE with Xero nearly 2 years ago using API 1.0 We are now trying to upgrade to API 2.0 so that we can use the new Journal posting features, but we are struggling to adapt the Xero demo C# program for use in a SaaS to SaaS web environment.

The Xero demo surprisingly is written as a Windows console app and runs in a command prompt box. If I edit the Consumer key etc to the values for MyPAYE, the sample app will allow me to talk to my Xero test account. However as soon as I try to adapt the code for use in web page, I can get the Xero User login to work and retrieve the oAuth verification code from the web callback, but I cannot get the access token to work - I just get 403 - Forbidden errors.

If I edit the Xero console app to create a new OAuthConsumerContext and OAuthSession after the OAuth verification code is entered and then create a new request token and insert the original (saved) values from the request token used to initiate the Xero authentication process, which is basically what I do in the callback web page, then the console app works. I presume I need to save and restore another OAuth parameter from the session used to initiate the authentication, but I cannot work out what this is.

Any suggestions would be appreciated
@Tim - check out our .NET MVC web app example on Github . We'll get that code samples page tidied up so it's easier to find!
 

Tony Rule (Xero Staff)  

Tony

At least when looking for a needle in a haystack, you can use a metal detector to find it.

Just downloaded the complete solution, but the new Xero.ScreencastWeb is built in VS 2010 whilst the rest is VS 2008. If you allow VS 2010 to convert the VS 2008 projects, they won't compile becasue ClientCertEnabledConsumerRequestFactory is obsolete and VS 2008 won't open the Xero.ScreencastWeb project

Thanks guys, that really helps !!

If it wasn't for our rapidly growing Xero user base on MyPAYE, I'd have given up weeks ago.
 

Tim Sheppard  

After much banging of head against a brick wall, I finally found the problem. We program in VB.NET and we had used the ability of Visual Studio to handle solutions containing both VB (our code) and C# (the DevDefined.OAuth code) projects. Normally this works fine, but the ConsumerRequest call in the DevDefined library has a complex structure involving extensions to the ConsumerRequest class and whilst the C# call converts happily to VB and compiles, the compiled code behaves differently to the compiled C# code, hence our access denied problem. Adding a further C# project to wrap the ConsumerRequest call and allow VB to pass its parameter conventionally solves the issue.
 

Tim Sheppard  

Hi,

Does someone have an example for asp.net site, not asp.net MVC?

I have never worked with MVC before and I am battling a bit to get my head around it to work for my asp.net page.

Many Thanks
Bennie
 

Bennie Matthee  

Hi Guys,
I am an asp.net vb.net programmer & was up against the same problem. Have created a stub that should get you going...you can find it on github here:
https://github.com/SuperRoo/Xero_Asp_VB_Net_Connection_Example/

this uses vs2010 & I installed the package from the package manager (command: Install-Package XeroAPI.Net)...don't use the source code in the examples
 

Roger Burke  

Hi All,

All the examples mentioned above uses XeroAPI.Net which is no longer officially supported. Is there any web example based on Xero-Net which is officially supported ?
 

Zia Khan  

I too am trying to get a footbold on the authentication in ASP.NET and once sorted can post some working samples for the comminity.

Can anyone help as once you get past authentication its usually fairly straight forward.
PS I have already authenticated with Google Calendar/Drive so will tey using this code and Xero modifying it but in the meantime if anyone can help then it would really be appreciated.
 

Simon Richardson  

Can anyone provide a sample for winforms C# integration with XERO public app ?

Please let me know as soon as possible.
 

Anil Anjana