bitbucket
Version:
Bitbucket API client for Browser and Node.js
3 lines (2 loc) • 1.17 kB
JavaScript
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):((e=e||self).Bitbucket=e.Bitbucket||{},e.Bitbucket.Plugin=e.Bitbucket.Plugin||{},e.Bitbucket.Plugin.authenticate=t())}(this,function(){"use strict";var e=function(e){return new Buffer(e).toString("base64")};return function(t,a){if(!a.auth){var n={client:t,auth:void 0};t.authenticate=function(e,t){if(t){switch(t.type){case"apppassword":case"basic":if(!t.username||!t.password)throw new Error("Basic authentication requires both a username and password to be set");break;case"token":if(!t.token)throw new Error("Token authentication requires a token to be set");break;default:throw new Error("Invalid authentication type, must be 'apppassword', 'basic' or 'token'")}e.auth=t}else delete e.auth}.bind(null,n),t.requestHook.before(function(t,a){if(t.auth)switch(t.auth.type){case"apppassword":case"basic":a.headers.authorization="Basic ".concat(e("".concat(t.auth.username,":").concat(t.auth.password)));break;case"token":a.headers.authorization="Bearer ".concat(t.auth.token)}}.bind(null,n))}}});
//# sourceMappingURL=authenticate.js.map