@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
82 lines (80 loc) • 2.1 kB
JavaScript
import { jwtDecode } from 'jwt-decode';
import { CallerIds } from './caller.mjs';
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 `${CallerIds.bot}:${this.appId}`;
}
return 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(value);
}
isExpired(bufferMs = 1e3 * 60 * 5) {
if (!this.expiration) return false;
return this.expiration < Date.now() + bufferMs;
}
toString() {
return this._value;
}
}
export { JsonWebToken };
//# sourceMappingURL=json-web-token.mjs.map
//# sourceMappingURL=json-web-token.mjs.map