1 line
2.7 KiB
Plaintext
1 line
2.7 KiB
Plaintext
{"version":3,"sources":["../src/ServiceBase.ts"],"sourcesContent":["// SPDX-FileCopyrightText: 2024 LiveKit, Inc.\n//\n// SPDX-License-Identifier: Apache-2.0\nimport { AccessToken } from './AccessToken.js';\nimport type { SIPGrant, VideoGrant } from './grants.js';\n\n/**\n * Authentication options for a service client.\n */\nexport interface ServiceBaseOptions {\n /** API Key. */\n apiKey?: string;\n /** API Secret. */\n secret?: string;\n /** Token TTL. Defaults to `10m`. */\n ttl?: string;\n /** Pre-signed token; sent verbatim, skipping per-call signing. */\n token?: string;\n}\n\n/**\n * Utilities to handle authentication\n */\nexport class ServiceBase {\n private readonly apiKey?: string;\n\n private readonly secret?: string;\n\n private readonly token?: string;\n\n private readonly ttl: string;\n\n /**\n * @param options - authentication options\n */\n constructor(options?: ServiceBaseOptions);\n /**\n * @deprecated pass a {@link ServiceBaseOptions} object instead.\n * @param apiKey - API Key.\n * @param secret - API Secret.\n * @param ttl - token TTL\n */\n constructor(apiKey?: string, secret?: string, ttl?: string);\n constructor(apiKeyOrOptions?: string | ServiceBaseOptions, secret?: string, ttl?: string) {\n const options: ServiceBaseOptions =\n typeof apiKeyOrOptions === 'object'\n ? apiKeyOrOptions\n : { apiKey: apiKeyOrOptions, secret, ttl };\n this.apiKey = options.apiKey;\n this.secret = options.secret;\n this.ttl = options.ttl || '10m';\n this.token = options.token;\n }\n\n async authHeader(grant: VideoGrant, sip?: SIPGrant): Promise<Record<string, string>> {\n // A pre-signed token is sent verbatim; the caller is responsible for its grants.\n if (this.token) {\n return { Authorization: `Bearer ${this.token}` };\n }\n const at = new AccessToken(this.apiKey, this.secret, { ttl: this.ttl });\n if (grant) {\n at.addGrant(grant);\n }\n if (sip) {\n at.addSIPGrant(sip);\n }\n return {\n Authorization: `Bearer ${await at.toJwt()}`,\n };\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,yBAA4B;AAoBrB,MAAM,YAAY;AAAA,EAoBvB,YAAY,iBAA+C,QAAiB,KAAc;AACxF,UAAM,UACJ,OAAO,oBAAoB,WACvB,kBACA,EAAE,QAAQ,iBAAiB,QAAQ,IAAI;AAC7C,SAAK,SAAS,QAAQ;AACtB,SAAK,SAAS,QAAQ;AACtB,SAAK,MAAM,QAAQ,OAAO;AAC1B,SAAK,QAAQ,QAAQ;AAAA,EACvB;AAAA,EAEA,MAAM,WAAW,OAAmB,KAAiD;AAEnF,QAAI,KAAK,OAAO;AACd,aAAO,EAAE,eAAe,UAAU,KAAK,KAAK,GAAG;AAAA,IACjD;AACA,UAAM,KAAK,IAAI,+BAAY,KAAK,QAAQ,KAAK,QAAQ,EAAE,KAAK,KAAK,IAAI,CAAC;AACtE,QAAI,OAAO;AACT,SAAG,SAAS,KAAK;AAAA,IACnB;AACA,QAAI,KAAK;AACP,SAAG,YAAY,GAAG;AAAA,IACpB;AACA,WAAO;AAAA,MACL,eAAe,UAAU,MAAM,GAAG,MAAM,CAAC;AAAA,IAC3C;AAAA,EACF;AACF;","names":[]} |