2020-01-28 13:07:56 +08:00
|
|
|
"use strict";
|
|
|
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
|
class BasicCredentialHandler {
|
|
|
|
constructor(username, password) {
|
|
|
|
this.username = username;
|
|
|
|
this.password = password;
|
|
|
|
}
|
|
|
|
prepareRequest(options) {
|
2020-07-05 03:43:39 +08:00
|
|
|
options.headers['Authorization'] =
|
|
|
|
'Basic ' +
|
|
|
|
Buffer.from(this.username + ':' + this.password).toString('base64');
|
2020-01-28 13:07:56 +08:00
|
|
|
}
|
|
|
|
// This handler cannot handle 401
|
|
|
|
canHandleAuthentication(response) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
handleAuthentication(httpClient, requestInfo, objs) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
exports.BasicCredentialHandler = BasicCredentialHandler;
|
|
|
|
class BearerCredentialHandler {
|
|
|
|
constructor(token) {
|
|
|
|
this.token = token;
|
|
|
|
}
|
|
|
|
// currently implements pre-authorization
|
|
|
|
// TODO: support preAuth = false where it hooks on 401
|
|
|
|
prepareRequest(options) {
|
|
|
|
options.headers['Authorization'] = 'Bearer ' + this.token;
|
|
|
|
}
|
|
|
|
// This handler cannot handle 401
|
|
|
|
canHandleAuthentication(response) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
handleAuthentication(httpClient, requestInfo, objs) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
exports.BearerCredentialHandler = BearerCredentialHandler;
|
|
|
|
class PersonalAccessTokenCredentialHandler {
|
|
|
|
constructor(token) {
|
|
|
|
this.token = token;
|
|
|
|
}
|
|
|
|
// currently implements pre-authorization
|
|
|
|
// TODO: support preAuth = false where it hooks on 401
|
|
|
|
prepareRequest(options) {
|
2020-07-05 03:43:39 +08:00
|
|
|
options.headers['Authorization'] =
|
|
|
|
'Basic ' + Buffer.from('PAT:' + this.token).toString('base64');
|
2020-01-28 13:07:56 +08:00
|
|
|
}
|
|
|
|
// This handler cannot handle 401
|
|
|
|
canHandleAuthentication(response) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
handleAuthentication(httpClient, requestInfo, objs) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
exports.PersonalAccessTokenCredentialHandler = PersonalAccessTokenCredentialHandler;
|