UNPKG

@azure/identity

Version:

Provides credential implementations for Azure SDK libraries that can authenticate with Microsoft Entra ID

92 lines (91 loc) 3.22 kB
var __defProp = Object.defineProperty; var __getOwnPropDesc = Object.getOwnPropertyDescriptor; var __getOwnPropNames = Object.getOwnPropertyNames; var __hasOwnProp = Object.prototype.hasOwnProperty; var __export = (target, all) => { for (var name in all) __defProp(target, name, { get: all[name], enumerable: true }); }; var __copyProps = (to, from, except, desc) => { if (from && typeof from === "object" || typeof from === "function") { for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); } return to; }; var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod); var utils_exports = {}; __export(utils_exports, { mapScopesToResource: () => mapScopesToResource, parseExpirationTimestamp: () => parseExpirationTimestamp, parseRefreshTimestamp: () => parseRefreshTimestamp, serviceFabricErrorMessage: () => serviceFabricErrorMessage }); module.exports = __toCommonJS(utils_exports); const DefaultScopeSuffix = "/.default"; const serviceFabricErrorMessage = "Specifying a `clientId` or `resourceId` is not supported by the Service Fabric managed identity environment. The managed identity configuration is determined by the Service Fabric cluster resource configuration. See https://aka.ms/servicefabricmi for more information"; function mapScopesToResource(scopes) { let scope = ""; if (Array.isArray(scopes)) { if (scopes.length !== 1) { return; } scope = scopes[0]; } else if (typeof scopes === "string") { scope = scopes; } if (!scope.endsWith(DefaultScopeSuffix)) { return scope; } return scope.substr(0, scope.lastIndexOf(DefaultScopeSuffix)); } function parseExpirationTimestamp(body) { if (typeof body.expires_on === "number") { return body.expires_on * 1e3; } if (typeof body.expires_on === "string") { const asNumber = +body.expires_on; if (!isNaN(asNumber)) { return asNumber * 1e3; } const asDate = Date.parse(body.expires_on); if (!isNaN(asDate)) { return asDate; } } if (typeof body.expires_in === "number") { return Date.now() + body.expires_in * 1e3; } throw new Error( `Failed to parse token expiration from body. expires_in="${body.expires_in}", expires_on="${body.expires_on}"` ); } function parseRefreshTimestamp(body) { if (body.refresh_on) { if (typeof body.refresh_on === "number") { return body.refresh_on * 1e3; } if (typeof body.refresh_on === "string") { const asNumber = +body.refresh_on; if (!isNaN(asNumber)) { return asNumber * 1e3; } const asDate = Date.parse(body.refresh_on); if (!isNaN(asDate)) { return asDate; } } throw new Error(`Failed to parse refresh_on from body. refresh_on="${body.refresh_on}"`); } else { return void 0; } } // Annotate the CommonJS export names for ESM import in node: 0 && (module.exports = { mapScopesToResource, parseExpirationTimestamp, parseRefreshTimestamp, serviceFabricErrorMessage }); //# sourceMappingURL=utils.js.map