Skip to content

Instantly share code, notes, and snippets.

@anshulrgoyal
Created May 21, 2019 17:57
Show Gist options
  • Save anshulrgoyal/1a0eb8475211bb7410e75c8aed9e192f to your computer and use it in GitHub Desktop.
Save anshulrgoyal/1a0eb8475211bb7410e75c8aed9e192f to your computer and use it in GitHub Desktop.
Access token validation
/**
* validateToken - validate the token supplied by the frontend
* @param {String} token the token supplied by the front end
* @param {String} ffid the ffid of the user
*/
async function validateToken(token, ffid) {
const data = await request.get(
`https://graph.facebook.com/debug_token?input_token=${token}&access_token=${
config.FB.APP_ID
}|${config.FB.APP_SECERET}`
);
const { data: parsedData } = JSON.parse(data);
if (parsedData.is_valid) {
if (ffid === parsedData.user_id) {
return true;
} else {
return false;
}
} else {
return false;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment