A Xero PUBLIC application obtains a 30 minute access token using three-legged oAuth1.0.
This sample application uses the standard oauth npm to authenticate with Xero and access the API endpoints.
Three-legged oAuth 1.0 requires that the application (the oAuth consumer) provides endpoints (views) for the user to initiate the authentication and redirect to and from Xero. For this example I've used hapi.js, but if you express or koa there's only subtle differences with the request and response arguments.
There's a lot of comments in the code, but for an explanation see my blog.
-
Clone the repo
-
Install the packages
npm init
-
Run it (the defaults are localhost on port 8001)
node src/server.js
-
Browse to http://localhost:8001/ and authenticate with Xero.
Here's what you'll want to change if you copy the code:
- Your consumer token and secret generated by Xero
- The two end-point URLs
- The callback URL
- For the endpoint's you need to access, create functions that invoke the endpoint via the oauth module (eg. oauth.get()) and work with the Resposne object.