Last active
July 11, 2019 09:51
-
-
Save FlyInk13/aa4768136779151328194d8c1da19200 to your computer and use it in GitHub Desktop.
Документация: https://vk.cc/9AjsnM
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
const {createHmac} = require('crypto'); | |
const querystring = require('querystring'); | |
const sha256 = (string, pwd) => createHmac('sha256', pwd).update(string).digest('base64'); | |
function checkSign(url, clientSecret) { | |
const parsedSearch = querystring.parse(url); | |
const checkSumRaw = Object | |
.keys(parsedSearch) | |
.filter((key) => /^vk_/.test(key)) | |
.sort() | |
.map((key) => { | |
const val = parsedSearch[key]; | |
return key + '=' + val; | |
}) | |
.join('&'); | |
const checkSum = sha256(checkSumRaw, clientSecret) | |
.replace(/\+/g, '-') | |
.replace(/\//g, '_') | |
.replace(/=/g, ''); | |
return checkSum == parsedSearch['sign']; | |
} | |
module.exports = checkSign; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment