UNPKG

@azure/identity

Version:

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

103 lines (102 loc) 4.08 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 authorizationCodeCredential_exports = {}; __export(authorizationCodeCredential_exports, { AuthorizationCodeCredential: () => AuthorizationCodeCredential }); module.exports = __toCommonJS(authorizationCodeCredential_exports); var import_tenantIdUtils = require("../util/tenantIdUtils.js"); var import_tenantIdUtils2 = require("../util/tenantIdUtils.js"); var import_logging = require("../util/logging.js"); var import_scopeUtils = require("../util/scopeUtils.js"); var import_tracing = require("../util/tracing.js"); var import_msalClient = require("../msal/nodeFlows/msalClient.js"); const logger = (0, import_logging.credentialLogger)("AuthorizationCodeCredential"); class AuthorizationCodeCredential { msalClient; disableAutomaticAuthentication; authorizationCode; redirectUri; tenantId; additionallyAllowedTenantIds; clientSecret; /** * @hidden * @internal */ constructor(tenantId, clientId, clientSecretOrAuthorizationCode, authorizationCodeOrRedirectUri, redirectUriOrOptions, options) { (0, import_tenantIdUtils2.checkTenantId)(logger, tenantId); this.clientSecret = clientSecretOrAuthorizationCode; if (typeof redirectUriOrOptions === "string") { this.authorizationCode = authorizationCodeOrRedirectUri; this.redirectUri = redirectUriOrOptions; } else { this.authorizationCode = clientSecretOrAuthorizationCode; this.redirectUri = authorizationCodeOrRedirectUri; this.clientSecret = void 0; options = redirectUriOrOptions; } this.tenantId = tenantId; this.additionallyAllowedTenantIds = (0, import_tenantIdUtils.resolveAdditionallyAllowedTenantIds)( options?.additionallyAllowedTenants ); this.msalClient = (0, import_msalClient.createMsalClient)(clientId, tenantId, { ...options, logger, tokenCredentialOptions: options ?? {} }); } /** * Authenticates with Microsoft Entra ID and returns an access token if successful. * If authentication fails, a {@link CredentialUnavailableError} will be thrown with the details of the failure. * * @param scopes - The list of scopes for which the token will have access. * @param options - The options used to configure any requests this * TokenCredential implementation might make. */ async getToken(scopes, options = {}) { return import_tracing.tracingClient.withSpan( `${this.constructor.name}.getToken`, options, async (newOptions) => { const tenantId = (0, import_tenantIdUtils.processMultiTenantRequest)( this.tenantId, newOptions, this.additionallyAllowedTenantIds ); newOptions.tenantId = tenantId; const arrayScopes = (0, import_scopeUtils.ensureScopes)(scopes); return this.msalClient.getTokenByAuthorizationCode( arrayScopes, this.redirectUri, this.authorizationCode, this.clientSecret, { ...newOptions, disableAutomaticAuthentication: this.disableAutomaticAuthentication } ); } ); } } // Annotate the CommonJS export names for ESM import in node: 0 && (module.exports = { AuthorizationCodeCredential }); //# sourceMappingURL=authorizationCodeCredential.js.map