Created
April 22, 2016 23:46
-
-
Save atesgoral/f07a36050b5e83d73aadad1cb00d5764 to your computer and use it in GitHub Desktop.
GitHub TOTP token generation
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 GitHubApi = require('github'); | |
const speakeasy = require('speakeasy'); | |
github.authenticate({ | |
type: 'basic', | |
username: process.env.GITHUB_USERNAME, | |
password: process.env.GITHUB_PASSWORD | |
}); | |
const token = speakeasy.totp({ | |
secret: process.env.TOTP_SECRET, // The secret GitHub presents when attempting to enable an authenticator (e.g. Google Authenticator) | |
encoding: 'base32', | |
step: 30 | |
}); | |
// Then things like: | |
github.authorization.create({ | |
scopes: [ 'repo' ], | |
note: 'Some Script', | |
note_url: 'http://example.com', | |
headers: { | |
'X-GitHub-OTP': token | |
} | |
}, (err, res) => { | |
if (err) throw err; | |
console.log(res); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment