bugyo-cloud-client
Version:
HTTP client for Bugyo Cloud
68 lines • 2.88 kB
JavaScript
;
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.Authenticate = void 0;
const querystring_1 = __importDefault(require("querystring"));
const bugyo_cloud_client_1 = require("../bugyo-cloud-client");
const url_utils_1 = require("../utils/url-utils");
const base_endpoint_1 = require("./base/base-endpoint");
class Authenticate extends base_endpoint_1.BaseEndpoint {
/**
* 認証します
*
* @param client
* @param token
* @param authInfo
*/
invoke(client, token, authInfo) {
return __awaiter(this, void 0, void 0, function* () {
const url = (0, url_utils_1.produceUrl)("Authenticate", client.param);
const data = this.createData(token, authInfo);
const config = {
headers: {
"Content-Type": "application/x-www-form-urlencoded",
},
};
this.logger.debug("Trying to POST, url=%s", url, data, config);
const resp = yield client.session.post(url, data, config);
this.throwIfNgStatus(resp);
this.logger.info("Authenticate succeed.");
return this.parseResponse(resp);
});
}
createData(token, authInfo) {
return querystring_1.default.stringify({
btnLogin: null,
OBCID: authInfo.loginId,
Password_d1: null,
Password_d2: null,
Password_d3: null,
Password: authInfo.password,
__RequestVerificationToken: token,
"X-Requested-With": "XMLHttpRequest",
});
}
parseResponse(resp) {
if ("RedirectURL" in resp.data) {
return resp.data["RedirectURL"];
}
else {
const content = resp.data;
this.logger.error("Response is not to be expected.", content);
throw new bugyo_cloud_client_1.BugyoCloudClientError("Response is not to be expected.");
}
}
}
exports.Authenticate = Authenticate;
//# sourceMappingURL=authenticate.js.map