File tree Expand file tree Collapse file tree 1 file changed +10
-3
lines changed Expand file tree Collapse file tree 1 file changed +10
-3
lines changed Original file line number Diff line number Diff line change @@ -404,20 +404,28 @@ var Client = module.exports = function(config) {
404
404
* key: "clientID",
405
405
* secret: "clientSecret"
406
406
* });
407
+ *
408
+ * // or token
409
+ * github.authenticate({
410
+ * type: "token",
411
+ * token: "userToken",
412
+ * });
407
413
**/
408
414
this . authenticate = function ( options ) {
409
415
if ( ! options ) {
410
416
this . auth = false ;
411
417
return ;
412
418
}
413
- if ( ! options . type || "basic|oauth|client" . indexOf ( options . type ) === - 1 )
419
+ if ( ! options . type || "basic|oauth|client|token " . indexOf ( options . type ) === - 1 )
414
420
throw new Error ( "Invalid authentication type, must be 'basic', 'oauth' or 'client'" ) ;
415
421
if ( options . type == "basic" && ( ! options . username || ! options . password ) )
416
422
throw new Error ( "Basic authentication requires both a username and password to be set" ) ;
417
423
if ( options . type == "oauth" ) {
418
424
if ( ! options . token && ! ( options . key && options . secret ) )
419
425
throw new Error ( "OAuth2 authentication requires a token or key & secret to be set" ) ;
420
426
}
427
+ if ( options . type == "token" && ! options . token )
428
+ throw new Error ( "Token authentication requires a token to be set" ) ;
421
429
422
430
this . auth = options ;
423
431
} ;
@@ -702,8 +710,7 @@ var Client = module.exports = function(config) {
702
710
}
703
711
break ;
704
712
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 ;
707
714
break ;
708
715
case "basic" :
709
716
basic = new Buffer ( this . auth . username + ":" + this . auth . password , "ascii" ) . toString ( "base64" ) ;
You can’t perform that action at this time.
0 commit comments