UNPKG

@microsoft/teams.api

Version:

<p> <a href="https://www.npmjs.com/package/@microsoft/teams.api" target="_blank"> <img src="https://img.shields.io/npm/v/@microsoft/teams.api/latest" /> </a> <a href="https://www.npmjs.com/package/@microsoft/teams.api?activeTab=code" t

84 lines (81 loc) • 2.15 kB
'use strict'; var jwtDecode = require('jwt-decode'); var caller = require('./caller'); class JsonWebToken { get audience() { return this._payload.aud; } get issuer() { return this._payload.iss; } get keyId() { return this._payload["kid"]; } get appId() { return this._payload["appid"]; } get appDisplayName() { return this._payload["app_displayname"]; } get tenantId() { return this._payload["tid"]; } get version() { return this._payload["version"]; } get serviceUrl() { let v = this._payload["serviceurl"] || "https://smba.trafficmanager.net/teams"; if (v.endsWith("/")) { v = v.slice(0, v.length - 1); } return v; } get from() { if (this.appId) { return "bot"; } return "azure"; } get fromId() { if (this.from === "bot") { return `${caller.CallerIds.bot}:${this.appId}`; } return caller.CallerIds.azure; } get expiration() { if (this._payload.exp) { return this._payload.exp * 1e3; } return void 0; } _value; _payload; /** * Typed accessor for an already-validated JWT payload. This constructor * performs no signature verification, no issuer/audience checks, and no * expiry enforcement. Constructing it from an untrusted token does NOT * establish trust in the contained claims. * * Signature verification happens at the HTTP trust boundary via * `JwtValidator.validateAccessToken` (packages/apps/src/middleware/auth/ * jwt-validator.ts). Internal callers may also construct from tokens * sourced from trusted identity infrastructure (MSAL, Bot Framework API * responses). * * Callers must not construct this class from raw network input. */ constructor(value) { this._value = value; this._payload = jwtDecode.jwtDecode(value); } isExpired(bufferMs = 1e3 * 60 * 5) { if (!this.expiration) return false; return this.expiration < Date.now() + bufferMs; } toString() { return this._value; } } exports.JsonWebToken = JsonWebToken; //# sourceMappingURL=json-web-token.js.map //# sourceMappingURL=json-web-token.js.map