{"version":3,"file":"ClientConfiguration.js","sources":["../../src/config/ClientConfiguration.ts"],"sourcesContent":["/*\r\n * Copyright (c) Microsoft Corporation. All rights reserved.\r\n * Licensed under the MIT License.\r\n */\r\n\r\nimport { INetworkModule } from \"../network/INetworkModule\";\r\nimport { DEFAULT_CRYPTO_IMPLEMENTATION, ICrypto } from \"../crypto/ICrypto\";\r\nimport { AuthError } from \"../error/AuthError\";\r\nimport { ILoggerCallback, LogLevel } from \"../logger/Logger\";\r\nimport { Constants } from \"../utils/Constants\";\r\nimport { version } from \"../packageMetadata\";\r\nimport { Authority } from \"../authority/Authority\";\r\nimport { AzureCloudInstance } from \"../authority/AuthorityOptions\";\r\nimport { CacheManager, DefaultStorageClass } from \"../cache/CacheManager\";\r\nimport { ServerTelemetryManager } from \"../telemetry/server/ServerTelemetryManager\";\r\nimport { ICachePlugin } from \"../cache/interface/ICachePlugin\";\r\nimport { ISerializableTokenCache } from \"../cache/interface/ISerializableTokenCache\";\r\nimport { ClientCredentials } from \"../account/ClientCredentials\";\r\n\r\n// Token renewal offset default in seconds\r\nconst DEFAULT_TOKEN_RENEWAL_OFFSET_SEC = 300;\r\n\r\n/**\r\n * Use the configuration object to configure MSAL Modules and initialize the base interfaces for MSAL.\r\n *\r\n * This object allows you to configure important elements of MSAL functionality:\r\n * - authOptions - Authentication for application\r\n * - cryptoInterface - Implementation of crypto functions\r\n * - libraryInfo - Library metadata\r\n * - telemetry - Telemetry options and data\r\n * - loggerOptions - Logging for application\r\n * - networkInterface - Network implementation\r\n * - storageInterface - Storage implementation\r\n * - systemOptions - Additional library options\r\n * - clientCredentials - Credentials options for confidential clients\r\n */\r\nexport type ClientConfiguration = {\r\n authOptions: AuthOptions,\r\n systemOptions?: SystemOptions,\r\n loggerOptions?: LoggerOptions,\r\n storageInterface?: CacheManager,\r\n networkInterface?: INetworkModule,\r\n cryptoInterface?: ICrypto,\r\n clientCredentials?: ClientCredentials,\r\n libraryInfo?: LibraryInfo\r\n telemetry?: TelemetryOptions,\r\n serverTelemetryManager?: ServerTelemetryManager | null,\r\n persistencePlugin?: ICachePlugin | null,\r\n serializableCache?: ISerializableTokenCache | null, \r\n};\r\n\r\nexport type CommonClientConfiguration = {\r\n authOptions: Required,\r\n systemOptions: Required,\r\n loggerOptions : Required,\r\n storageInterface: CacheManager,\r\n networkInterface : INetworkModule,\r\n cryptoInterface : Required,\r\n libraryInfo : LibraryInfo,\r\n telemetry: Required,\r\n serverTelemetryManager: ServerTelemetryManager | null,\r\n clientCredentials: ClientCredentials,\r\n persistencePlugin: ICachePlugin | null,\r\n serializableCache: ISerializableTokenCache | null, \r\n};\r\n\r\n/**\r\n * Use this to configure the auth options in the ClientConfiguration object\r\n *\r\n * - clientId - Client ID of your app registered with our Application registration portal : https://portal.azure.com/#blade/Microsoft_AAD_IAM/ActiveDirectoryMenuBlade/RegisteredAppsPreview in Microsoft Identity Platform\r\n * - authority - You can configure a specific authority, defaults to \" \" or \"https://login.microsoftonline.com/common\"\r\n * - knownAuthorities - An array of URIs that are known to be valid. Used in B2C scenarios.\r\n * - cloudDiscoveryMetadata - A string containing the cloud discovery response. Used in AAD scenarios.\r\n * - clientCapabilities - Array of capabilities which will be added to the claims.access_token.xms_cc request property on every network request.\r\n * - protocolMode - Enum that represents the protocol that msal follows. Used for configuring proper endpoints.\r\n * - skipAuthorityMetadataCache - A flag to choose whether to use or not use the local metadata cache during authority initialization. Defaults to false.\r\n */\r\nexport type AuthOptions = {\r\n clientId: string;\r\n authority: Authority;\r\n clientCapabilities?: Array;\r\n azureCloudOptions?: AzureCloudOptions;\r\n skipAuthorityMetadataCache?: boolean;\r\n};\r\n\r\n/**\r\n * Use this to configure token renewal info in the Configuration object\r\n *\r\n * - tokenRenewalOffsetSeconds - Sets the window of offset needed to renew the token before expiry\r\n */\r\nexport type SystemOptions = {\r\n tokenRenewalOffsetSeconds?: number;\r\n preventCorsPreflight?: boolean;\r\n proxyUrl?: string;\r\n};\r\n\r\n/**\r\n * Use this to configure the logging that MSAL does, by configuring logger options in the Configuration object\r\n *\r\n * - loggerCallback - Callback for logger\r\n * - piiLoggingEnabled - Sets whether pii logging is enabled\r\n * - logLevel - Sets the level at which logging happens\r\n * - correlationId - Sets the correlationId printed by the logger\r\n */\r\nexport type LoggerOptions = {\r\n loggerCallback?: ILoggerCallback,\r\n piiLoggingEnabled?: boolean,\r\n logLevel?: LogLevel,\r\n correlationId?: string\r\n};\r\n\r\n/**\r\n * Library-specific options\r\n */\r\nexport type LibraryInfo = {\r\n sku: string,\r\n version: string,\r\n cpu: string,\r\n os: string\r\n};\r\n\r\n/**\r\n * AzureCloudInstance specific options\r\n *\r\n * - azureCloudInstance - string enum providing short notation for soverign and public cloud authorities\r\n * - tenant - provision to provide the tenant info\r\n */\r\nexport type AzureCloudOptions = {\r\n azureCloudInstance: AzureCloudInstance;\r\n tenant?: string,\r\n};\r\n\r\nexport type TelemetryOptions = {\r\n application: ApplicationTelemetry;\r\n};\r\n\r\n/**\r\n * Telemetry information sent on request\r\n * - appName: Unique string name of an application\r\n * - appVersion: Version of the application using MSAL\r\n */\r\nexport type ApplicationTelemetry = {\r\n appName: string;\r\n appVersion: string;\r\n};\r\n\r\nexport const DEFAULT_SYSTEM_OPTIONS: Required = {\r\n tokenRenewalOffsetSeconds: DEFAULT_TOKEN_RENEWAL_OFFSET_SEC,\r\n preventCorsPreflight: false,\r\n proxyUrl: Constants.EMPTY_STRING\r\n};\r\n\r\nconst DEFAULT_LOGGER_IMPLEMENTATION: Required = {\r\n loggerCallback: () => {\r\n // allow users to not set loggerCallback\r\n },\r\n piiLoggingEnabled: false,\r\n logLevel: LogLevel.Info,\r\n correlationId: Constants.EMPTY_STRING\r\n};\r\n\r\nconst DEFAULT_NETWORK_IMPLEMENTATION: INetworkModule = {\r\n async sendGetRequestAsync(): Promise {\r\n const notImplErr = \"Network interface - sendGetRequestAsync() has not been implemented\";\r\n throw AuthError.createUnexpectedError(notImplErr);\r\n },\r\n async sendPostRequestAsync(): Promise {\r\n const notImplErr = \"Network interface - sendPostRequestAsync() has not been implemented\";\r\n throw AuthError.createUnexpectedError(notImplErr);\r\n }\r\n};\r\n\r\nconst DEFAULT_LIBRARY_INFO: LibraryInfo = {\r\n sku: Constants.SKU,\r\n version: version,\r\n cpu: Constants.EMPTY_STRING,\r\n os: Constants.EMPTY_STRING\r\n};\r\n\r\nconst DEFAULT_CLIENT_CREDENTIALS: ClientCredentials = {\r\n clientSecret: Constants.EMPTY_STRING,\r\n clientAssertion: undefined\r\n};\r\n\r\nconst DEFAULT_AZURE_CLOUD_OPTIONS: AzureCloudOptions = {\r\n azureCloudInstance: AzureCloudInstance.None,\r\n tenant: `${Constants.DEFAULT_COMMON_TENANT}`\r\n};\r\n\r\nconst DEFAULT_TELEMETRY_OPTIONS: Required = {\r\n application: {\r\n appName: \"\",\r\n appVersion: \"\"\r\n }\r\n};\r\n\r\n/**\r\n * Function that sets the default options when not explicitly configured from app developer\r\n *\r\n * @param Configuration\r\n *\r\n * @returns Configuration\r\n */\r\nexport function buildClientConfiguration(\r\n {\r\n authOptions: userAuthOptions,\r\n systemOptions: userSystemOptions,\r\n loggerOptions: userLoggerOption,\r\n storageInterface: storageImplementation,\r\n networkInterface: networkImplementation,\r\n cryptoInterface: cryptoImplementation,\r\n clientCredentials: clientCredentials,\r\n libraryInfo: libraryInfo,\r\n telemetry: telemetry,\r\n serverTelemetryManager: serverTelemetryManager,\r\n persistencePlugin: persistencePlugin,\r\n serializableCache: serializableCache, \r\n }: ClientConfiguration): CommonClientConfiguration {\r\n\r\n const loggerOptions = { ...DEFAULT_LOGGER_IMPLEMENTATION, ...userLoggerOption };\r\n\r\n return {\r\n authOptions: buildAuthOptions(userAuthOptions),\r\n systemOptions: { ...DEFAULT_SYSTEM_OPTIONS, ...userSystemOptions },\r\n loggerOptions: loggerOptions,\r\n storageInterface: storageImplementation || new DefaultStorageClass(userAuthOptions.clientId, DEFAULT_CRYPTO_IMPLEMENTATION),\r\n networkInterface: networkImplementation || DEFAULT_NETWORK_IMPLEMENTATION,\r\n cryptoInterface: cryptoImplementation || DEFAULT_CRYPTO_IMPLEMENTATION,\r\n clientCredentials: clientCredentials || DEFAULT_CLIENT_CREDENTIALS,\r\n libraryInfo: { ...DEFAULT_LIBRARY_INFO, ...libraryInfo },\r\n telemetry: { ...DEFAULT_TELEMETRY_OPTIONS, ...telemetry },\r\n serverTelemetryManager: serverTelemetryManager || null,\r\n persistencePlugin: persistencePlugin || null,\r\n serializableCache: serializableCache || null, \r\n };\r\n}\r\n\r\n/**\r\n * Construct authoptions from the client and platform passed values\r\n * @param authOptions\r\n */\r\nfunction buildAuthOptions(authOptions: AuthOptions): Required {\r\n return {\r\n clientCapabilities: [],\r\n azureCloudOptions: DEFAULT_AZURE_CLOUD_OPTIONS,\r\n skipAuthorityMetadataCache: false,\r\n ...authOptions\r\n };\r\n}\r\n"],"names":[],"mappings":";;;;;;;;;;;AAAA;;;AAGG;AAgBH;AACA,IAAM,gCAAgC,GAAG,GAAG,CAAC;AA8HhC,IAAA,sBAAsB,GAA4B;AAC3D,IAAA,yBAAyB,EAAE,gCAAgC;AAC3D,IAAA,oBAAoB,EAAE,KAAK;IAC3B,QAAQ,EAAE,SAAS,CAAC,YAAY;EAClC;AAEF,IAAM,6BAA6B,GAA4B;AAC3D,IAAA,cAAc,EAAE,YAAA;;KAEf;AACD,IAAA,iBAAiB,EAAE,KAAK;IACxB,QAAQ,EAAE,QAAQ,CAAC,IAAI;IACvB,aAAa,EAAE,SAAS,CAAC,YAAY;CACxC,CAAC;AAEF,IAAM,8BAA8B,GAAmB;AAC7C,IAAA,mBAAmB,EAAzB,YAAA;;;;gBACU,UAAU,GAAG,oEAAoE,CAAC;AACxF,gBAAA,MAAM,SAAS,CAAC,qBAAqB,CAAC,UAAU,CAAC,CAAC;;;AACrD,KAAA;AACK,IAAA,oBAAoB,EAA1B,YAAA;;;;gBACU,UAAU,GAAG,qEAAqE,CAAC;AACzF,gBAAA,MAAM,SAAS,CAAC,qBAAqB,CAAC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