UNPKG

@cognigy/rest-api-client

Version:

Cognigy REST-Client

75 lines 3.93 kB
"use strict"; var __rest = (this && this.__rest) || function (s, e) { var t = {}; for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) t[p] = s[p]; if (s != null && typeof Object.getOwnPropertySymbols === "function") for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) { if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) t[p[i]] = s[p[i]]; } return t; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.AuthenticationAPI = void 0; const GenericAPIFn_1 = require("../GenericAPIFn"); /* Authentication Methods */ const ApiKeyAuthentication_1 = require("./ApiKey/ApiKeyAuthentication"); const BasicAuthentication_1 = require("./BasicAuthentication/BasicAuthentication"); const OAuth2Authentication_1 = require("./OAuth2/OAuth2Authentication"); const JwtTokenAuthentication_1 = require("./JWT/JwtTokenAuthentication"); const rest_1 = require("../shared/helper/rest"); function AuthenticationAPI(instance) { const self = instance; return { setCredentials: (credentials) => { switch (credentials.type) { case "ApiKey": self.authenticationHandler = new ApiKeyAuthentication_1.ApiKeyAuthentication(credentials, self); break; case "Basic": self.authenticationHandler = new BasicAuthentication_1.BasicAuthentication(credentials, self); break; case "OAuth2": self.authenticationHandler = new OAuth2Authentication_1.OAuth2Authentication(credentials, self); break; case "JWT": self.authenticationHandler = new JwtTokenAuthentication_1.default(credentials, self); break; } }, login: async (data) => { var _a; return (_a = self.authenticationHandler) === null || _a === void 0 ? void 0 : _a.login(data); }, logout: async () => { var _a; return (_a = self.authenticationHandler) === null || _a === void 0 ? void 0 : _a.logout(); }, getAccessToken: async () => { var _a; return (_a = self.authenticationHandler) === null || _a === void 0 ? void 0 : _a.getAccessToken(); }, getRefreshToken: () => { var _a; return (_a = self.authenticationHandler) === null || _a === void 0 ? void 0 : _a.getRefreshToken(); }, isLoggedIn: async () => { var _a; return (_a = self.authenticationHandler) === null || _a === void 0 ? void 0 : _a.isLoggedIn(); }, getRealtimeToken: (options) => (0, GenericAPIFn_1.GenericAPIFn)("/auth/realtimetoken", "POST", self)(undefined, options), webfinger: (args, options) => (0, GenericAPIFn_1.GenericAPIFn)(`/.well-known/webfinger?${(0, rest_1.stringifyQuery)(args)}`, "GET", self)(undefined, Object.assign({ withAuthentication: false }, options)), getAuthorizationCode: async (data) => { var _a; return (_a = self.authenticationHandler) === null || _a === void 0 ? void 0 : _a.getAuthorizationCode(data); }, exchangeOneTimeTokenForRefreshToken: (_a, options) => { var { loginToken } = _a, args = __rest(_a, ["loginToken"]); return (0, GenericAPIFn_1.GenericAPIFn)(`/auth/exchangetoken?${(0, rest_1.stringifyQuery)({ loginToken })}`, "GET", self)(args, Object.assign({ withAuthentication: false, withCredentials: true }, options)); }, generateManagementUIAuthToken: (args, options) => (0, GenericAPIFn_1.GenericAPIFn)("/new/management/auth/token", "POST", self)(args, options) }; } exports.AuthenticationAPI = AuthenticationAPI; //# sourceMappingURL=AuthenticationAPI.js.map