Created
October 31, 2018 21:47
-
-
Save kamicut/7fdccf0fa02ce6d3c32aa08818f45a93 to your computer and use it in GitHub Desktop.
auth with openstreetmap
This file contains 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
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