Last active
May 23, 2019 15:09
-
-
Save yaasita/7a3823c899d6ec2e89f793542bd02dbc to your computer and use it in GitHub Desktop.
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
node_modules |
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
{ | |
"name": "work", | |
"version": "1.0.0", | |
"lockfileVersion": 1, | |
"requires": true, | |
"dependencies": { | |
"base64url": { | |
"version": "3.0.1", | |
"resolved": "https://registry.npmjs.org/base64url/-/base64url-3.0.1.tgz", | |
"integrity": "sha512-ir1UPr3dkwexU7FdV8qBBbNDRUhMmIekYMFZfi+C/sLNnRESKPl23nB9b2pltqfOQNnGzsDdId90AEtG5tCx4A==" | |
}, | |
"js-sha256": { | |
"version": "0.9.0", | |
"resolved": "https://registry.npmjs.org/js-sha256/-/js-sha256-0.9.0.tgz", | |
"integrity": "sha512-sga3MHh9sgQN2+pJ9VYZ+1LPwXOxuBJBA5nrR5/ofPfuiJBE2hnjsaN8se8JznOmGLN2p49Pe5U/ttafcs/apA==" | |
} | |
} | |
} |
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
{ | |
"name": "work", | |
"version": "1.0.0", | |
"description": "", | |
"main": "pkce.js", | |
"scripts": { | |
"test": "echo \"Error: no test specified\" && exit 1" | |
}, | |
"keywords": [], | |
"author": "", | |
"license": "ISC", | |
"dependencies": { | |
"base64url": "^3.0.1", | |
"js-sha256": "^0.9.0" | |
} | |
} |
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
"use strict"; | |
const base64url = require("base64url"); | |
const sha256 = require("js-sha256"); | |
// 参考: https://tools.ietf.org/html/rfc7636#appendix-B | |
(async () => { | |
const code_verifier = get_code_verifier(); | |
const code_challenge = get_code_challenge(code_verifier); | |
console.log( | |
`code_verifier = ${code_verifier}\nのとき\ncode_challenge = ${code_challenge}\nです` | |
); | |
})(); | |
function get_code_challenge(str) { | |
const hash = sha256.arrayBuffer(str); | |
return base64url(hash); | |
} | |
function get_code_verifier() { | |
let buf = Buffer.alloc(32); | |
for (let i = 0; i < buf.length; i++) { | |
const random_num = Math.floor(Math.random() * 256); | |
buf.writeUInt8(random_num, i); | |
} | |
return base64url(buf); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment