// A promisey wrapper for api requests function request(host, access_token) { var query_string_data = querystring.stringify({ access_token: access_token, attribute_name: 'uuid' // we only need to pull the uuid for this access token to make sure it matches }); return httpsRequest.get({ host: host, path: '/entity?' + query_string_data }); }
function buildUrl (opts) { const url = defineCollectionUrl(opts); const queryString = { hl: opts.lang, gl: opts.country }; if (opts.age) { queryString.age = opts.age; } const fullURL = `${url}?${qs.stringify(queryString)}`; debug('Initial Request URL: %s', fullURL); return fullURL; }
function buildUrl (opts) { const { lang, devId, country } = opts; const url = `${BASE_URL}/store/apps`; const path = isNaN(opts.devId) ? `/developer` : `/dev`; const queryString = { id: devId, hl: lang, gl: country }; const fullURL = `${url}${path}?${qs.stringify(queryString)}`; debug('Initial request: %s', fullURL); return fullURL; }
async loadSourceMap(sourceMapURL, compiledURL) { try { let payload; if (sourceMapURL.startsWith('data:')) { const [metadata, ...other] = sourceMapURL.split(','); const urlPayload = other.join(','); const isBase64 = metadata.endsWith(';base64'); payload = JSON.parse(Buffer.from(isBase64 ? urlPayload : querystring.unescape(urlPayload), isBase64 ? 'base64' : 'utf8').toString('utf8')); } else { const fileURL = new URL(sourceMapURL); const content = await fsReadFile(fileURL, 'utf8'); payload = JSON.parse(content); } await removeSourceContentIfMatch(sourceMapURL, compiledURL, payload); return {payload}; } catch (e) { return {error: e.stack}; } }
http.createServer(function (req, res) { var url = URL.parse(req.url, true), uri = decodeURIComponent(url.pathname), postData = ''; if (paths[uri] !== undefined) { if (req.method === 'POST') { req.on('data', function (chunk) { postData += chunk.toString(); }); req.on('end', function () { if (!req.headers['content-type'] || req.headers['content-type'].indexOf('multipart') !== 0) postData = qs.parse(postData); paths[uri](url, req, res, postData); }); } else { paths[uri](url, req, res); } } else { res.writeHead(404); res.end(); } })
// A promise wrapper for requests to the OAuth2 token introspection endpoint. function requestTokenInfo(options, access_token) { if (!options || !options.tokenIntrospectionEndpointUrl) { throw new Parse.Error(Parse.Error.OBJECT_NOT_FOUND, MISSING_URL); } const parsedUrl = url.parse(options.tokenIntrospectionEndpointUrl); const postData = querystring.stringify({ token: access_token }); const headers = { 'Content-Type': 'application/x-www-form-urlencoded', 'Content-Length': Buffer.byteLength(postData) }; if (options.authorizationHeader) { headers['Authorization'] = options.authorizationHeader; } const postOptions = { hostname: parsedUrl.hostname, path: parsedUrl.pathname, method: 'POST', headers: headers }; return httpsRequest.request(postOptions, postData); }
const generateOAuthToken = (code: string, redirect_uri: string): Promise<?SlackData> => { return axios .post( 'https://slack.com/api/oauth.access', querystring.stringify({ code: code, scope: 'users:read.email,users:read,chat:write,bot,chat:write:bot,channels:read,groups:read', client_id: '201769987287.271382863153', client_secret: SLACK_SECRET, redirect_uri, }) ) .then(response => { // if the response is valid if (response.data && response.data.ok) { return { access_token: response.data.access_token, team_id: response.data.team_id, team_name: response.data.team_name, scope: response.data.scope, }; } }) .catch(error => { console.error('\n\nerror', error); return null; }); }
opts.country = opts.country || 'us'; const qs = queryString.stringify({ id: opts.appId, hl: opts.lang,
// A promisey wrapper for weibo graph requests. function graphRequest(access_token) { var postData = querystring.stringify({ access_token: access_token, }); var options = { hostname: 'api.weibo.com', path: '/oauth2/get_token_info', method: 'POST', headers: { 'Content-Type': 'application/x-www-form-urlencoded', 'Content-Length': Buffer.byteLength(postData), }, }; return httpsRequest.request(options, postData); }
/** * Set query-string as an object. * * @function Request#query * @param {Object} obj set querystring and query object for request. * @return {void} */ set query(obj) { this.querystring = querystring.stringify(obj); }
// A promisey wrapper for api requests function apiRequest(api_key, auth_token) { var post_data = querystring.stringify({ token: auth_token, apiKey: api_key, format: 'json' }); var post_options = { host: 'rpxnow.com', path: '/api/v2/auth_info', method: 'POST', headers: { 'Content-Type': 'application/x-www-form-urlencoded', 'Content-Length': post_data.length } }; return httpsRequest.request(post_options, post_data); }
// A promisey wrapper for api requests function request(host, access_token) { var query_string_data = querystring.stringify({ access_token: access_token, attribute_name: 'uuid', // we only need to pull the uuid for this access token to make sure it matches }); return httpsRequest.get({ host: host, path: '/entity?' + query_string_data }); }
// A promisey wrapper for weibo graph requests. function graphRequest(access_token) { var postData = querystring.stringify({ access_token: access_token }); var options = { hostname: 'api.weibo.com', path: '/oauth2/get_token_info', method: 'POST', headers: { 'Content-Type': 'application/x-www-form-urlencoded', 'Content-Length': Buffer.byteLength(postData) } }; return httpsRequest.request(options, postData); }
// A promisey wrapper for api requests function apiRequest(api_key, auth_token) { var post_data = querystring.stringify({ token: auth_token, apiKey: api_key, format: 'json', }); var post_options = { host: 'rpxnow.com', path: '/api/v2/auth_info', method: 'POST', headers: { 'Content-Type': 'application/x-www-form-urlencoded', 'Content-Length': post_data.length, }, }; return httpsRequest.request(post_options, post_data); }
// A promise wrapper for requests to the OAuth2 token introspection endpoint. function requestTokenInfo(options, access_token) { if (!options || !options.tokenIntrospectionEndpointUrl) { throw new Parse.Error(Parse.Error.OBJECT_NOT_FOUND, MISSING_URL); } const parsedUrl = url.parse(options.tokenIntrospectionEndpointUrl); const postData = querystring.stringify({ token: access_token, }); const headers = { 'Content-Type': 'application/x-www-form-urlencoded', 'Content-Length': Buffer.byteLength(postData), }; if (options.authorizationHeader) { headers['Authorization'] = options.authorizationHeader; } const postOptions = { hostname: parsedUrl.hostname, path: parsedUrl.pathname, method: 'POST', headers: headers, }; return httpsRequest.request(postOptions, postData); }