bitbucket
Version:
Bitbucket API client for Browser and Node.js
3 lines (2 loc) • 1.2 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";function e(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}function t(e,t){var a;if(e.auth)switch(e.auth.type){case"apppassword":case"basic":t.headers.authorization="Basic ".concat((a="".concat(e.auth.username,":").concat(e.auth.password),"undefined"!=typeof Buffer?Buffer.from(a).toString("base64"):btoa(a)));break;case"token":t.headers.authorization="Bearer ".concat(e.auth.token)}}return function(a,n){if(!n.auth){var o={client:a,auth:void 0};a.authenticate=e.bind(null,o),a.requestHook.before(t.bind(null,o))}}}));
//# sourceMappingURL=authenticate.js.map