background_scripts/bgscript-xhrs.js
// A generic post request for an access token. The request body may need to be reformatted depending on the API being queried.
A generic post request for an access token. The request body may need to be reformatted depending on the API being queried.
A generic post request for an access token . The request body may need to be reformatted depending on the API being queried .
function xhrMeetupTokenRequest(code, grantType, refreshToken) {
	return new Promise((resolve, reject) => {
		let xhr = new XMLHttpRequest();
		xhr.open("POST", gATEP, true);
		xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
		xhr.onload = function() {
			if (xhr.status >= 200 && xhr.status < 300) {
				return resolve(xhr.response);
			} else {
				reject(
					Error({
						status: xhr.status,
						statusTextInElse: xhr.statusText
					})
				);
			}
		};
		xhr.onerror = function() {
			reject(
				Error({
					status: xhr.status,
					statusText: xhr.statusText
				})
			);
		};
		let requestBody = refreshToken
			? `client_id=${mCK}&client_secret=${mCS}&grant_type=${grantType}&refresh_token=${refreshToken}&scope=rsvp`
			: `client_id=${mCK}&client_secret=${mCS}&grant_type=${grantType}&redirect_uri=${redirect_Uri}&code=${code}&scope=rsvp`;
		xhr.send(requestBody);
	});
}
function xhrMeetupTokenRequest ( code , grantType , refreshToken ) { return new Promise ( ( resolve , reject ) => { let xhr = new XMLHttpRequest ( ) ; xhr . open ( "POST" , gATEP , true ) ; xhr . setRequestHeader ( "Content-Type" , "application/x-www-form-urlencoded" ) ; xhr . onload = function ( ) { if ( xhr . status >= 200 && xhr . status < 300 ) { return resolve ( xhr . response ) ; } else { reject ( Error ( { status : xhr . status , statusTextInElse : xhr . statusText } ) ) ; } } ; xhr . onerror = function ( ) { reject ( Error ( { status : xhr . status , statusText : xhr . statusText } ) ) ; } ; let requestBody = refreshToken ? ` ${ mCK } ${ mCS } ${ grantType } ${ refreshToken } ` : ` ${ mCK } ${ mCS } ${ grantType } ${ redirect_Uri } ${ code } ` ; xhr . send ( requestBody ) ; } ) ; }
A generic post request for an access token.
A generic post request for an access token .