Skip to content

Instantly share code, notes, and snippets.

@atesgoral
Created April 22, 2016 23:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save atesgoral/f07a36050b5e83d73aadad1cb00d5764 to your computer and use it in GitHub Desktop.
Save atesgoral/f07a36050b5e83d73aadad1cb00d5764 to your computer and use it in GitHub Desktop.
GitHub TOTP token generation
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