From 8d32e2653e0ff510a13a5b26fcfc0dec6eefc634 Mon Sep 17 00:00:00 2001 From: Dmitri Dimitrioglo Date: Tue, 9 May 2017 22:09:32 +0300 Subject: [PATCH] Working with two-factor authentication As mentioned in github API: ``` In addition to the Basic Authentication credentials, you must send the user's authentication code (i.e., one-time password) in the X-GitHub-OTP header. ``` And we will be able to use it like this: ``` const github = new GitHub({ username: 'ddimitrioglo', password: 'xxxxxxxxxxxx', otp: '888999' // <= One-Time-Password }); let me = github.getUser(); me.listRepos((err, repos) => { console.log(repos); }); ``` --- lib/Requestable.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/lib/Requestable.js b/lib/Requestable.js index bad111ac..10413986 100644 --- a/lib/Requestable.js +++ b/lib/Requestable.js @@ -54,6 +54,7 @@ class Requestable { token: auth.token, username: auth.username, password: auth.password, + otp: auth.otp || null }; this.__AcceptHeader = AcceptHeader || 'v3'; @@ -102,6 +103,10 @@ class Requestable { if (this.__authorizationHeader) { headers.Authorization = this.__authorizationHeader; } + + if (this.__auth.otp) { + headers['X-GitHub-OTP'] = this.__auth.otp; + } return headers; }