Skip to content

Commit cb47d1c

Browse files
committed
Merge pull request octokit#174 from groupsky/support_token_authentication
fixed token authentication
2 parents 56d79e5 + 8611ffa commit cb47d1c

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

index.js

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -404,20 +404,28 @@ var Client = module.exports = function(config) {
404404
* key: "clientID",
405405
* secret: "clientSecret"
406406
* });
407+
*
408+
* // or token
409+
* github.authenticate({
410+
* type: "token",
411+
* token: "userToken",
412+
* });
407413
**/
408414
this.authenticate = function(options) {
409415
if (!options) {
410416
this.auth = false;
411417
return;
412418
}
413-
if (!options.type || "basic|oauth|client".indexOf(options.type) === -1)
419+
if (!options.type || "basic|oauth|client|token".indexOf(options.type) === -1)
414420
throw new Error("Invalid authentication type, must be 'basic', 'oauth' or 'client'");
415421
if (options.type == "basic" && (!options.username || !options.password))
416422
throw new Error("Basic authentication requires both a username and password to be set");
417423
if (options.type == "oauth") {
418424
if (!options.token && !(options.key && options.secret))
419425
throw new Error("OAuth2 authentication requires a token or key & secret to be set");
420426
}
427+
if (options.type == "token" && !options.token)
428+
throw new Error("Token authentication requires a token to be set");
421429

422430
this.auth = options;
423431
};
@@ -702,8 +710,7 @@ var Client = module.exports = function(config) {
702710
}
703711
break;
704712
case "token":
705-
basic = new Buffer(this.auth.username + "/token:" + this.auth.token, "ascii").toString("base64");
706-
headers.authorization = "Basic " + basic;
713+
headers.authorization = "token " + this.auth.token;
707714
break;
708715
case "basic":
709716
basic = new Buffer(this.auth.username + ":" + this.auth.password, "ascii").toString("base64");

0 commit comments

Comments
 (0)