Created
June 10, 2015 06:31
-
-
Save jeromyevans/4ef8239cdc95f34426e7 to your computer and use it in GitHub Desktop.
Request the Xero Access Token
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Perform the callback leg of the three-legged oAuth. | |
// Given the auth_token and auth_verifier from xero, request the AccessToken | |
exports.requestXeroAccessToken = function(request, reply) { | |
var oAuthToken = request.query["oauth_token"]; | |
var oAuthVerifier = request.query["oauth_verifier"]; | |
var org = request.query["org"]; | |
var oAuthData = request.session.get('oauth'); | |
if (!oAuthData) { | |
return reply.view('failed'); | |
} | |
oAuthData.verifier = oAuthVerifier; | |
oauth.getOAuthAccessToken( | |
oAuthData.token, | |
oAuthData.token_secret, | |
oAuthData.verifier, | |
function (error, oauth_access_token, oauth_access_token_secret, results) { | |
if (error) { | |
console.log(oAuthData); | |
console.log(error); | |
return reply("Authentication Failure!"); | |
} | |
request.session.set('oauth', { | |
token: oAuthData.token, // todo: necessary to retain? | |
token_secret: oAuthData.token_secret, // todo: necessary to retain? | |
verifier: oAuthData.verifier, // todo: necessary to retain? | |
access_token: oauth_access_token, | |
access_token_secret: oauth_access_token_secret | |
}); | |
// now that we have authenticated we can access restricted endpoints | |
// via oauth.get() etc. | |
// snip | |
return reply.view('success'); | |
} | |
); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment