Skip to content

Commit

Permalink
Add client support for bearer token authentication
Browse files Browse the repository at this point in the history
  • Loading branch information
elisherer committed Feb 13, 2017
1 parent 8242800 commit 9dc0976
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions lib/client.js
Expand Up @@ -501,13 +501,16 @@ Request.prototype.accept = function(type){
* Set Authorization field value with `user` and `pass`.
*
* @param {String} user
* @param {String} pass
* @param {Object} options with 'type' property 'auto' or 'basic' (default 'basic')
* @param {String} [pass] optional in case of using 'bearer' as type
* @param {Object} options with 'type' property 'auto', 'basic' or 'bearer' (default 'basic')
* @return {Request} for chaining
* @api public
*/

Request.prototype.auth = function(user, pass, options){
if (typeof pass === 'object' && pass !== null) { // pass is optional and can substitute for options
options = pass;
}
if (!options) {
options = {
type: 'function' === typeof btoa ? 'basic' : 'auto',
Expand All @@ -523,6 +526,10 @@ Request.prototype.auth = function(user, pass, options){
this.username = user;
this.password = pass;
break;

case 'bearer': // usage would be .auth(accessToken, { type: 'bearer' })
this.set('Authorization', 'Bearer ' + user);
break;
}
return this;
};
Expand Down

0 comments on commit 9dc0976

Please sign in to comment.