Skip to content

Instantly share code, notes, and snippets.

@steffentchr
Last active February 14, 2018 10:27
Show Gist options
  • Save steffentchr/cf4f95aafcd16c5e1d14bcfbda7e7197 to your computer and use it in GitHub Desktop.
Save steffentchr/cf4f95aafcd16c5e1d14bcfbda7e7197 to your computer and use it in GitHub Desktop.
Session signing on TwentyThree with Node, request and oauth-1.0a
const request = require('request');
const crypto = require('crypto');
const OAuth = require('oauth-1.0a');
const domain = '<domain>';
const key = '<consumer_key>';
const secret = '<consumer_secret>';
const access_token = '<access_token>';
const access_secret = '<access_token_secret>';
const token = {
key: access_token,
secret: access_secret
};
const oauth = OAuth({
consumer: { key, secret },
signature_method: 'HMAC-SHA1',
hash_function(base_string, key) {
return crypto.createHmac('sha1', key).update(base_string).digest('base64');
}
});
const request_data = {
url: 'http://'+domain+'/api/session/get-token.json',
method: 'GET',
data: {}
};
request({
url: request_data.url,
method: request_data.method,
form: request_data.data,
headers: oauth.toHeader(oauth.authorize(request_data, token))
}, function(error, response, body) {
var session_token = JSON.parse(body).sessiontoken.access_token;
console.log("\nTo log in, Visit:\n http://"+domain+"/api/session/redeem-token?session_token="+session_token+"\n\n");
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment