UNPKG

@cocalc/server

Version:

CoCalc server functionality: functions used by either the hub and the next.js server

25 lines 916 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.getAccountIdFromApiKey = exports.getApiKey = void 0; const misc_1 = require("@cocalc/util/misc"); const manage_1 = require("@cocalc/server/api/manage"); function getApiKey(req) { const h = req.header("Authorization"); if (h == null) { throw Error("You must provide authentication via an API key."); } const [type, user] = (0, misc_1.split)(h); switch (type) { case "Bearer": return user; case "Basic": return Buffer.from(user, "base64").toString().split(":")[0]; } throw Error(`Unknown authorization type '${type}'`); } exports.getApiKey = getApiKey; async function getAccountIdFromApiKey(req) { return await (0, manage_1.getAccountWithApiKey)(getApiKey(req)); } exports.getAccountIdFromApiKey = getAccountIdFromApiKey; //# sourceMappingURL=api.js.map