Last active
January 28, 2017 06:07
-
-
Save shanewholloway/ebcd702910974be34b98a7e20970ceb0 to your computer and use it in GitHub Desktop.
create image data url from otpauth:// url
This file contains hidden or 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 speakeasy = require('speakeasy') | |
const totp_obj = { label: 'gist-totp-demo', algorithm: 'sha256', | |
secret: 'some secret string', encoding: 'base64'} | |
const otp_url = speakeasy.otpauthURL(totp_obj) | |
const qr_image = require('qr-image') | |
const png_buffer = qr_image.imageSync(otp_url, {type: 'png'}) | |
const svg = qr_image.imageSync(otp_url, {type: 'svg'}) | |
const svg_buffer = Buffer.from(svg) | |
const png_data_url = `data:image/png;base64,${png_buffer.toString('base64')}` | |
const svg_data_url = `data:image/svg;base64,${svg_buffer.toString('base64')}` | |
console.log(` | |
### PNG URL | |
 | |
### SVG URL | |
 | |
### SVG Raw | |
\`\`\`xml | |
${svg} | |
\`\`\` | |
`) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
PNG URL
SVG URL
SVG Raw