Skip to content

Instantly share code, notes, and snippets.

@kamicut
Created October 31, 2018 21:47
Show Gist options
  • Save kamicut/7fdccf0fa02ce6d3c32aa08818f45a93 to your computer and use it in GitHub Desktop.
Save kamicut/7fdccf0fa02ce6d3c32aa08818f45a93 to your computer and use it in GitHub Desktop.
auth with openstreetmap
function(token, tokenSecret, ctx, cb) {
var OAuth = new require("oauth").OAuth;
var parser = require('xml2json');
var oauth = new OAuth(ctx.requestTokenURL, ctx.accessTokenURL, ctx.client_id, ctx.client_secret, "1.0", null, "HMAC-SHA1");
oauth.get("https://api.openstreetmap.org/api/0.6/user/details", token, tokenSecret, function(e, xml, r) {
console.log(xml);
if (e) return cb(e);
if (r.statusCode !== 200) return cb(new Error("StatusCode: " + r.statusCode));
try {
var jsonResp = JSON.parse(parser.toJson(xml));
var user = jsonResp.user;
cb(null, user);
}
catch (e) {
console.log(e);
cb(new UnauthorizedError("[+] fetchUserProfile: OSM fetch script failed. Check Webtask logs"));
}
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment