Created
May 21, 2019 17:57
-
-
Save anshulrgoyal/1a0eb8475211bb7410e75c8aed9e192f to your computer and use it in GitHub Desktop.
Access token validation
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
/** | |
* 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