auth.js 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. class BasicCredentialHandler {
  4. constructor(username, password) {
  5. this.username = username;
  6. this.password = password;
  7. }
  8. prepareRequest(options) {
  9. options.headers['Authorization'] = 'Basic ' + Buffer.from(this.username + ':' + this.password).toString('base64');
  10. }
  11. // This handler cannot handle 401
  12. canHandleAuthentication(response) {
  13. return false;
  14. }
  15. handleAuthentication(httpClient, requestInfo, objs) {
  16. return null;
  17. }
  18. }
  19. exports.BasicCredentialHandler = BasicCredentialHandler;
  20. class BearerCredentialHandler {
  21. constructor(token) {
  22. this.token = token;
  23. }
  24. // currently implements pre-authorization
  25. // TODO: support preAuth = false where it hooks on 401
  26. prepareRequest(options) {
  27. options.headers['Authorization'] = 'Bearer ' + this.token;
  28. }
  29. // This handler cannot handle 401
  30. canHandleAuthentication(response) {
  31. return false;
  32. }
  33. handleAuthentication(httpClient, requestInfo, objs) {
  34. return null;
  35. }
  36. }
  37. exports.BearerCredentialHandler = BearerCredentialHandler;
  38. class PersonalAccessTokenCredentialHandler {
  39. constructor(token) {
  40. this.token = token;
  41. }
  42. // currently implements pre-authorization
  43. // TODO: support preAuth = false where it hooks on 401
  44. prepareRequest(options) {
  45. options.headers['Authorization'] = 'Basic ' + Buffer.from('PAT:' + this.token).toString('base64');
  46. }
  47. // This handler cannot handle 401
  48. canHandleAuthentication(response) {
  49. return false;
  50. }
  51. handleAuthentication(httpClient, requestInfo, objs) {
  52. return null;
  53. }
  54. }
  55. exports.PersonalAccessTokenCredentialHandler = PersonalAccessTokenCredentialHandler;