UNPKG

whodis-sdk

Version:

A simple sdk for easy, secure authentication with the whodis platform. Setup secure authentication for your app in seconds.

34 lines 1.45 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.getAuthedClaimsFromHeaders = void 0; const simple_jwt_auth_1 = require("simple-jwt-auth"); const reportAuthErrorForDiagnosis_1 = require("./reportAuthErrorForDiagnosis"); /** * extracts authenticated user data from the auth token found in the headers, if any exists * * additionally, monitors authentication errors to proactively help with debugging and detect potential security attacks */ const getAuthedClaimsFromHeaders = async ({ headers, config, log, }) => { try { // check if theres a token on the request const token = (0, simple_jwt_auth_1.getTokenFromHeaders)({ headers }); if (!token) return null; // if there is, grab the claims const claims = await (0, simple_jwt_auth_1.getAuthedClaims)({ token, // the token issuer: config.issuer, // who issued the token audience: config.audience, // who the token is intended for }); // return the whodis user return claims; } catch (error) { if (!(error instanceof Error)) throw error; // should never occur await (0, reportAuthErrorForDiagnosis_1.reportAuthErrorForDiagnosis)({ error, config, headers, log }); return null; } }; exports.getAuthedClaimsFromHeaders = getAuthedClaimsFromHeaders; //# sourceMappingURL=getAuthedClaimsFromHeaders.js.map