UNPKG

@zowe/core-for-zowe-sdk

Version:

Core libraries shared by Zowe SDK packages

64 lines 3.04 kB
"use strict"; /* * This program and the accompanying materials are made available under the terms of the * Eclipse Public License v2.0 which accompanies this distribution, and is available at * https://www.eclipse.org/legal/epl-v20.html * * SPDX-License-Identifier: EPL-2.0 * * Copyright Contributors to the Zowe Project. * */ 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()); }); }; Object.defineProperty(exports, "__esModule", { value: true }); exports.Login = void 0; const imperative_1 = require("@zowe/imperative"); const ZosmfRestClient_1 = require("../rest/ZosmfRestClient"); const LoginConstants_1 = require("./LoginConstants"); /** * Class to handle logging onto APIML. * @export * @class Login */ class Login { /** * Perform APIML login to obtain LTPA2 or other token types. * @static * @param {AbstractSession} session * @returns * @memberof Login */ static apimlLogin(session) { return __awaiter(this, void 0, void 0, function* () { imperative_1.Logger.getAppLogger().trace("Login.login()"); imperative_1.ImperativeExpect.toNotBeNullOrUndefined(session, "Required session must be defined"); imperative_1.ImperativeExpect.toMatchRegExp(session.ISession.tokenType, "^apimlAuthenticationToken.*", `Token type (${session.ISession.tokenType}) for API ML token login must start with 'apimlAuthenticationToken'.`); imperative_1.AuthOrder.makingRequestForToken(session.ISession); const client = new ZosmfRestClient_1.ZosmfRestClient(session); yield client.request({ request: "POST", resource: LoginConstants_1.LoginConstants.APIML_V1_RESOURCE }); if (client.response.statusCode !== imperative_1.RestConstants.HTTP_STATUS_204) { throw new imperative_1.ImperativeError(client.populateError({ msg: `REST API Failure with HTTP(S) status ${client.response.statusCode}`, causeErrors: client.dataString, source: imperative_1.SessConstants.HTTP_PROTOCOL })); } session.ISession.user = session.ISession.password = session.ISession.base64EncodedAuth = undefined; // return token to the caller return session.ISession.tokenValue; }); } } exports.Login = Login; //# sourceMappingURL=Login.js.map