Xero - beautiful accounting software

Xero Developer Help Center

Xero Developer Community

Community > Wrapper libraries >

C# and how to use oauth_verifier

Started by vinay doshi -   in Wrapper libraries

I am trying out the C# wrapper for Xero, and following the github example from here: https://github.com/XeroAPI/Xero-Net

I am trying to create a public application in asp.net webforms. For this I simply added a webform to a VS project and added the nuget package for XERO.

In the webform I added just 1 button, on whose click I am trying to do an authentication.
protected void Button1_Click(object sender, EventArgs e)
{

var user = new ApiUser { Name = Environment.MachineName };

// Public Application Sample
public_app_api = new XeroCoreApi("https://api.xero.com",
new PublicAuthenticator("https://api.xero.com", "https://api.xero.com",
"http://localhost:59597",
new MemoryTokenStore()),
new Consumer(your_consumerkey, your_consumersecret),
user,
new DefaultMapper(), new DefaultMapper());

var public_contacts = public_app_api.Contacts.Find().ToList();
int count = public_contacts.Count;

}

}


When I run this, my localhost page opens up. I click on the button, and the point at which the debugger hits this line
var public_contacts = public_app_api.Contacts.Find().ToList();

I get a "Authorise Application" Window from Xero, and I click on "Authorise".

All of this works fine, and then I get redirected to a page as follows
http://localhost:59597/?oauth_token=8FVOVQGO3EQ66NMZQCC4Y6UYNL095T&oauth_verifier=3150317&org=4ccM4CgImqw1FO4nti%24bs0

I am never able to retrieve the Contacts from Xero as that line never executes. Am I supposed to do something with the oauth_verifier OR the org details that were returned in the URL above?

Any help will be appreciated.
Hi,
You need to verify the oauth_token. You need 2 token stores. And you need a postback page to deal with all of that.

I have a working ASP example we are selling for $100

Kind Regards

Remember we consult on a per hour basis. Contact us if your need us to fix the problem. $35 per hour.

We can do a 30 min free consultation via Skype. Click Here

Henzard Kruger
Certified Xero Advisor and Full Stack developer
Picahoo cc - 0711304241 - henzard@picahoo.co.za
Skype: henzard, Gtalk: henzardkruger@gmail.com
Quality is remembered long after the price is forgotten

I abide by the 3 message rule. After 3 messages we skype.
 

Henzard Kruger  

Hi , I have got to the same point.
I'm working with a C# forms application,
I use xeroCoreAPI and get the xero screen to open, user to logon, authorise for 30 minutes and the pin displayed.

I display a c# form to accept the pin.

I am then trying to pass the oauth_verifier to https://api.xero.com/oauth/Authorize
But the response is always 401 unauthorised

Can you point me in the right direction please?

 

Karen Gibbons  

Working with c# form you will need to use a private application
 

Henzard Kruger  

The application needs to be used across many Xero logons/organisations, so I thought that required a public or partner app. I went for public as while we're gold partners for Xero we aren't on the developer side. The application has to be a windows form based as it also connects to desktop based package.
 

Karen Gibbons  

Hi,

You will never get you application approved if your don't have a website to deal with the logins. You will need to have a middle ware website to deal with the postback if you will have any chance to get approved. Alternatively you can just educate your clients on private apps but getting onto the marketplace with a desktop app might be a first. If you add me to skype I will be happy to explain what you need and why.
 

Henzard Kruger  

Hi
I was going to have them enter the pin number and have it give access that way, reading other posts that seemed to be a possibility.
I am booked out with other clients today and part of Monday, I will add you to Skype when I'm next in the office and give you a call
Thanks for replying
Karen
 

Karen Gibbons  

Hi,

That sounds great looking forward to it
 

Henzard Kruger