github.com/jfrog/frogbot@v1.1.1-0.20231221090046-821a26f50338/action/node_modules/@actions/http-client/lib/auth.js (about) 1 "use strict"; 2 var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { 3 function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } 4 return new (P || (P = Promise))(function (resolve, reject) { 5 function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } 6 function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } 7 function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } 8 step((generator = generator.apply(thisArg, _arguments || [])).next()); 9 }); 10 }; 11 Object.defineProperty(exports, "__esModule", { value: true }); 12 exports.PersonalAccessTokenCredentialHandler = exports.BearerCredentialHandler = exports.BasicCredentialHandler = void 0; 13 class BasicCredentialHandler { 14 constructor(username, password) { 15 this.username = username; 16 this.password = password; 17 } 18 prepareRequest(options) { 19 if (!options.headers) { 20 throw Error('The request has no headers'); 21 } 22 options.headers['Authorization'] = `Basic ${Buffer.from(`${this.username}:${this.password}`).toString('base64')}`; 23 } 24 // This handler cannot handle 401 25 canHandleAuthentication() { 26 return false; 27 } 28 handleAuthentication() { 29 return __awaiter(this, void 0, void 0, function* () { 30 throw new Error('not implemented'); 31 }); 32 } 33 } 34 exports.BasicCredentialHandler = BasicCredentialHandler; 35 class BearerCredentialHandler { 36 constructor(token) { 37 this.token = token; 38 } 39 // currently implements pre-authorization 40 // TODO: support preAuth = false where it hooks on 401 41 prepareRequest(options) { 42 if (!options.headers) { 43 throw Error('The request has no headers'); 44 } 45 options.headers['Authorization'] = `Bearer ${this.token}`; 46 } 47 // This handler cannot handle 401 48 canHandleAuthentication() { 49 return false; 50 } 51 handleAuthentication() { 52 return __awaiter(this, void 0, void 0, function* () { 53 throw new Error('not implemented'); 54 }); 55 } 56 } 57 exports.BearerCredentialHandler = BearerCredentialHandler; 58 class PersonalAccessTokenCredentialHandler { 59 constructor(token) { 60 this.token = token; 61 } 62 // currently implements pre-authorization 63 // TODO: support preAuth = false where it hooks on 401 64 prepareRequest(options) { 65 if (!options.headers) { 66 throw Error('The request has no headers'); 67 } 68 options.headers['Authorization'] = `Basic ${Buffer.from(`PAT:${this.token}`).toString('base64')}`; 69 } 70 // This handler cannot handle 401 71 canHandleAuthentication() { 72 return false; 73 } 74 handleAuthentication() { 75 return __awaiter(this, void 0, void 0, function* () { 76 throw new Error('not implemented'); 77 }); 78 } 79 } 80 exports.PersonalAccessTokenCredentialHandler = PersonalAccessTokenCredentialHandler; 81 //# sourceMappingURL=auth.js.map