@azure/msal-browser 2.22.1 → 2.23.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/dist/_virtual/_tslib.js +1 -1
- package/dist/app/ClientApplication.d.ts +24 -1
- package/dist/app/ClientApplication.d.ts.map +1 -1
- package/dist/app/ClientApplication.js +137 -36
- package/dist/app/ClientApplication.js.map +1 -1
- package/dist/app/IPublicClientApplication.d.ts +3 -1
- package/dist/app/IPublicClientApplication.d.ts.map +1 -1
- package/dist/app/IPublicClientApplication.js +7 -1
- package/dist/app/IPublicClientApplication.js.map +1 -1
- package/dist/app/PublicClientApplication.d.ts.map +1 -1
- package/dist/app/PublicClientApplication.js +51 -15
- package/dist/app/PublicClientApplication.js.map +1 -1
- package/dist/cache/AsyncMemoryStorage.d.ts +3 -2
- package/dist/cache/AsyncMemoryStorage.d.ts.map +1 -1
- package/dist/cache/AsyncMemoryStorage.js +17 -6
- package/dist/cache/AsyncMemoryStorage.js.map +1 -1
- package/dist/cache/BrowserCacheManager.js +7 -7
- package/dist/cache/BrowserCacheManager.js.map +1 -1
- package/dist/cache/BrowserStorage.js +1 -1
- package/dist/cache/DatabaseStorage.d.ts +5 -0
- package/dist/cache/DatabaseStorage.d.ts.map +1 -1
- package/dist/cache/DatabaseStorage.js +65 -13
- package/dist/cache/DatabaseStorage.js.map +1 -1
- package/dist/cache/MemoryStorage.js +1 -1
- package/dist/cache/TokenCache.js +1 -1
- package/dist/config/Configuration.d.ts +14 -2
- package/dist/config/Configuration.d.ts.map +1 -1
- package/dist/config/Configuration.js +16 -9
- package/dist/config/Configuration.js.map +1 -1
- package/dist/crypto/BrowserCrypto.d.ts.map +1 -1
- package/dist/crypto/BrowserCrypto.js +7 -6
- package/dist/crypto/BrowserCrypto.js.map +1 -1
- package/dist/crypto/CryptoOps.d.ts +12 -3
- package/dist/crypto/CryptoOps.d.ts.map +1 -1
- package/dist/crypto/CryptoOps.js +71 -36
- package/dist/crypto/CryptoOps.js.map +1 -1
- package/dist/crypto/GuidGenerator.d.ts +3 -2
- package/dist/crypto/GuidGenerator.d.ts.map +1 -1
- package/dist/crypto/GuidGenerator.js +4 -3
- package/dist/crypto/GuidGenerator.js.map +1 -1
- package/dist/crypto/PkceGenerator.js +1 -1
- package/dist/crypto/SignedHttpRequest.js +1 -1
- package/dist/encode/Base64Decode.d.ts.map +1 -1
- package/dist/encode/Base64Decode.js +3 -2
- package/dist/encode/Base64Decode.js.map +1 -1
- package/dist/encode/Base64Encode.d.ts.map +1 -1
- package/dist/encode/Base64Encode.js +5 -4
- package/dist/encode/Base64Encode.js.map +1 -1
- package/dist/error/BrowserAuthError.js +1 -1
- package/dist/error/BrowserConfigurationAuthError.js +1 -1
- package/dist/event/EventHandler.js +1 -1
- package/dist/event/EventMessage.js +1 -1
- package/dist/event/EventType.js +1 -1
- package/dist/index.cjs.js +1071 -258
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -2
- package/dist/index.js.map +1 -1
- package/dist/interaction_client/BaseInteractionClient.d.ts +3 -2
- package/dist/interaction_client/BaseInteractionClient.d.ts.map +1 -1
- package/dist/interaction_client/BaseInteractionClient.js +4 -3
- package/dist/interaction_client/BaseInteractionClient.js.map +1 -1
- package/dist/interaction_client/HybridSpaAuthorizationCodeClient.js +1 -1
- package/dist/interaction_client/PopupClient.d.ts.map +1 -1
- package/dist/interaction_client/PopupClient.js +3 -3
- package/dist/interaction_client/PopupClient.js.map +1 -1
- package/dist/interaction_client/RedirectClient.d.ts.map +1 -1
- package/dist/interaction_client/RedirectClient.js +4 -4
- package/dist/interaction_client/RedirectClient.js.map +1 -1
- package/dist/interaction_client/SilentAuthCodeClient.d.ts +2 -2
- package/dist/interaction_client/SilentAuthCodeClient.d.ts.map +1 -1
- package/dist/interaction_client/SilentAuthCodeClient.js +5 -5
- package/dist/interaction_client/SilentAuthCodeClient.js.map +1 -1
- package/dist/interaction_client/SilentCacheClient.d.ts.map +1 -1
- package/dist/interaction_client/SilentCacheClient.js +11 -3
- package/dist/interaction_client/SilentCacheClient.js.map +1 -1
- package/dist/interaction_client/SilentIframeClient.d.ts +2 -2
- package/dist/interaction_client/SilentIframeClient.d.ts.map +1 -1
- package/dist/interaction_client/SilentIframeClient.js +21 -7
- package/dist/interaction_client/SilentIframeClient.js.map +1 -1
- package/dist/interaction_client/SilentRefreshClient.d.ts.map +1 -1
- package/dist/interaction_client/SilentRefreshClient.js +16 -4
- package/dist/interaction_client/SilentRefreshClient.js.map +1 -1
- package/dist/interaction_client/StandardInteractionClient.d.ts +2 -2
- package/dist/interaction_client/StandardInteractionClient.d.ts.map +1 -1
- package/dist/interaction_client/StandardInteractionClient.js +30 -16
- package/dist/interaction_client/StandardInteractionClient.js.map +1 -1
- package/dist/interaction_handler/InteractionHandler.js +1 -1
- package/dist/interaction_handler/PopupHandler.js +1 -1
- package/dist/interaction_handler/RedirectHandler.js +1 -1
- package/dist/interaction_handler/SilentHandler.js +1 -1
- package/dist/navigation/NavigationClient.js +1 -1
- package/dist/network/FetchClient.d.ts.map +1 -1
- package/dist/network/FetchClient.js +3 -2
- package/dist/network/FetchClient.js.map +1 -1
- package/dist/network/XhrClient.js +1 -1
- package/dist/packageMetadata.d.ts +1 -1
- package/dist/packageMetadata.js +2 -2
- package/dist/packageMetadata.js.map +1 -1
- package/dist/telemetry/BrowserPerformanceClient.d.ts +19 -0
- package/dist/telemetry/BrowserPerformanceClient.d.ts.map +1 -0
- package/dist/telemetry/BrowserPerformanceClient.js +52 -0
- package/dist/telemetry/BrowserPerformanceClient.js.map +1 -0
- package/dist/telemetry/BrowserPerformanceMeasurement.d.ts +13 -0
- package/dist/telemetry/BrowserPerformanceMeasurement.d.ts.map +1 -0
- package/dist/telemetry/BrowserPerformanceMeasurement.js +66 -0
- package/dist/telemetry/BrowserPerformanceMeasurement.js.map +1 -0
- package/dist/utils/BrowserConstants.js +1 -1
- package/dist/utils/BrowserProtocolUtils.js +1 -1
- package/dist/utils/BrowserStringUtils.d.ts.map +1 -1
- package/dist/utils/BrowserStringUtils.js +4 -2
- package/dist/utils/BrowserStringUtils.js.map +1 -1
- package/dist/utils/BrowserUtils.js +2 -2
- package/dist/utils/BrowserUtils.js.map +1 -1
- package/dist/utils/MathUtils.js +1 -1
- package/dist/utils/PopupUtils.js +1 -1
- package/lib/msal-browser.js +1071 -258
- package/lib/msal-browser.js.map +1 -1
- package/lib/msal-browser.min.js +41 -36
- package/package.json +2 -2
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CryptoOps.js","sources":["../../src/crypto/CryptoOps.ts"],"sourcesContent":["/*\n * Copyright (c) Microsoft Corporation. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { ICrypto, Logger, PkceCodes, SignedHttpRequest, SignedHttpRequestParameters } from \"@azure/msal-common\";\nimport { GuidGenerator } from \"./GuidGenerator\";\nimport { Base64Encode } from \"../encode/Base64Encode\";\nimport { Base64Decode } from \"../encode/Base64Decode\";\nimport { PkceGenerator } from \"./PkceGenerator\";\nimport { BrowserCrypto } from \"./BrowserCrypto\";\nimport { BrowserStringUtils } from \"../utils/BrowserStringUtils\";\nimport { KEY_FORMAT_JWK } from \"../utils/BrowserConstants\";\nimport { BrowserAuthError } from \"../error/BrowserAuthError\";\nimport { AsyncMemoryStorage } from \"../cache/AsyncMemoryStorage\";\n\nexport type CachedKeyPair = {\n publicKey: CryptoKey,\n privateKey: CryptoKey,\n requestMethod?: string,\n requestUri?: string\n};\n\n/**\n * MSAL CryptoKeyStore DB Version 2\n */\nexport type CryptoKeyStore = {\n asymmetricKeys: AsyncMemoryStorage<CachedKeyPair>;\n symmetricKeys: AsyncMemoryStorage<CryptoKey>;\n};\n\n/**\n * This class implements MSAL's crypto interface, which allows it to perform base64 encoding and decoding, generating cryptographically random GUIDs and \n * implementing Proof Key for Code Exchange specs for the OAuth Authorization Code Flow using PKCE (rfc here: https://tools.ietf.org/html/rfc7636).\n */\nexport class CryptoOps implements ICrypto {\n\n private browserCrypto: BrowserCrypto;\n private guidGenerator: GuidGenerator;\n private b64Encode: Base64Encode;\n private b64Decode: Base64Decode;\n private pkceGenerator: PkceGenerator;\n private logger: Logger;\n\n private static POP_KEY_USAGES: Array<KeyUsage> = [\"sign\", \"verify\"];\n private static EXTRACTABLE: boolean = true;\n private cache: CryptoKeyStore;\n\n constructor(logger: Logger) {\n this.logger = logger;\n // Browser crypto needs to be validated first before any other classes can be set.\n this.browserCrypto = new BrowserCrypto(this.logger);\n this.b64Encode = new Base64Encode();\n this.b64Decode = new Base64Decode();\n this.guidGenerator = new GuidGenerator(this.browserCrypto);\n this.pkceGenerator = new PkceGenerator(this.browserCrypto);\n this.cache = {\n asymmetricKeys: new AsyncMemoryStorage<CachedKeyPair>(this.logger),\n symmetricKeys: new AsyncMemoryStorage<CryptoKey>(this.logger)\n };\n }\n\n /**\n * Creates a new random GUID - used to populate state and nonce.\n * @returns string (GUID)\n */\n createNewGuid(): string {\n return this.guidGenerator.generateGuid();\n }\n\n /**\n * Encodes input string to base64.\n * @param input \n */\n base64Encode(input: string): string {\n return this.b64Encode.encode(input);\n } \n \n /**\n * Decodes input string from base64.\n * @param input \n */\n base64Decode(input: string): string {\n return this.b64Decode.decode(input);\n }\n\n /**\n * Generates PKCE codes used in Authorization Code Flow.\n */\n async generatePkceCodes(): Promise<PkceCodes> {\n return this.pkceGenerator.generateCodes();\n }\n\n /**\n * Generates a keypair, stores it and returns a thumbprint\n * @param request\n */\n async getPublicKeyThumbprint(request: SignedHttpRequestParameters): Promise<string> {\n // Generate Keypair\n const keyPair: CryptoKeyPair = await this.browserCrypto.generateKeyPair(CryptoOps.EXTRACTABLE, CryptoOps.POP_KEY_USAGES);\n\n // Generate Thumbprint for Public Key\n const publicKeyJwk: JsonWebKey = await this.browserCrypto.exportJwk(keyPair.publicKey);\n \n const pubKeyThumprintObj: JsonWebKey = {\n e: publicKeyJwk.e,\n kty: publicKeyJwk.kty,\n n: publicKeyJwk.n\n };\n\n const publicJwkString: string = BrowserCrypto.getJwkString(pubKeyThumprintObj);\n const publicJwkHash = await this.hashString(publicJwkString);\n\n // Generate Thumbprint for Private Key\n const privateKeyJwk: JsonWebKey = await this.browserCrypto.exportJwk(keyPair.privateKey);\n // Re-import private key to make it unextractable\n const unextractablePrivateKey: CryptoKey = await this.browserCrypto.importJwk(privateKeyJwk, false, [\"sign\"]);\n\n // Store Keypair data in keystore\n await this.cache.asymmetricKeys.setItem(\n publicJwkHash, \n {\n privateKey: unextractablePrivateKey,\n publicKey: keyPair.publicKey,\n requestMethod: request.resourceRequestMethod,\n requestUri: request.resourceRequestUri\n }\n );\n\n return publicJwkHash;\n }\n\n /**\n * Removes cryptographic keypair from key store matching the keyId passed in\n * @param kid \n */\n async removeTokenBindingKey(kid: string): Promise<boolean> {\n await this.cache.asymmetricKeys.removeItem(kid);\n const keyFound = await this.cache.asymmetricKeys.containsKey(kid);\n return !keyFound;\n }\n\n /**\n * Removes all cryptographic keys from IndexedDB storage\n */\n async clearKeystore(): Promise<boolean> {\n const dataStoreNames = Object.keys(this.cache);\n const databaseStorage = this.cache[dataStoreNames[0]];\n return databaseStorage ? await databaseStorage.deleteDatabase() : false;\n }\n\n /**\n * Signs the given object as a jwt payload with private key retrieved by given kid.\n * @param payload \n * @param kid \n */\n async signJwt(payload: SignedHttpRequest, kid: string): Promise<string> {\n const cachedKeyPair = await this.cache.asymmetricKeys.getItem(kid);\n \n if (!cachedKeyPair) {\n throw BrowserAuthError.createSigningKeyNotFoundInStorageError(kid);\n }\n\n // Get public key as JWK\n const publicKeyJwk = await this.browserCrypto.exportJwk(cachedKeyPair.publicKey);\n const publicKeyJwkString = BrowserCrypto.getJwkString(publicKeyJwk);\n\n // Generate header\n const header = {\n alg: publicKeyJwk.alg,\n type: KEY_FORMAT_JWK\n };\n const encodedHeader = this.b64Encode.urlEncode(JSON.stringify(header));\n\n // Generate payload\n payload.cnf = {\n jwk: JSON.parse(publicKeyJwkString)\n };\n const encodedPayload = this.b64Encode.urlEncode(JSON.stringify(payload));\n\n // Form token string\n const tokenString = `${encodedHeader}.${encodedPayload}`;\n\n // Sign token\n const tokenBuffer = BrowserStringUtils.stringToArrayBuffer(tokenString);\n const signatureBuffer = await this.browserCrypto.sign(cachedKeyPair.privateKey, tokenBuffer);\n const encodedSignature = this.b64Encode.urlEncodeArr(new Uint8Array(signatureBuffer));\n\n return `${tokenString}.${encodedSignature}`;\n }\n\n /**\n * Returns the SHA-256 hash of an input string\n * @param plainText\n */\n async hashString(plainText: string): Promise<string> {\n const hashBuffer: ArrayBuffer = await this.browserCrypto.sha256Digest(plainText);\n const hashBytes = new Uint8Array(hashBuffer);\n return this.b64Encode.urlEncodeArr(hashBytes);\n }\n}\n"],"names":[],"mappings":";;;;;;;;;;;;;AAAA;;;;AA+BA;;;;;IAiBI,mBAAY,MAAc;QACtB,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;;QAErB,IAAI,CAAC,aAAa,GAAG,IAAI,aAAa,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;QACpD,IAAI,CAAC,SAAS,GAAG,IAAI,YAAY,EAAE,CAAC;QACpC,IAAI,CAAC,SAAS,GAAG,IAAI,YAAY,EAAE,CAAC;QACpC,IAAI,CAAC,aAAa,GAAG,IAAI,aAAa,CAAC,IAAI,CAAC,aAAa,CAAC,CAAC;QAC3D,IAAI,CAAC,aAAa,GAAG,IAAI,aAAa,CAAC,IAAI,CAAC,aAAa,CAAC,CAAC;QAC3D,IAAI,CAAC,KAAK,GAAG;YACT,cAAc,EAAE,IAAI,kBAAkB,CAAgB,IAAI,CAAC,MAAM,CAAC;YAClE,aAAa,EAAE,IAAI,kBAAkB,CAAY,IAAI,CAAC,MAAM,CAAC;SAChE,CAAC;KACL;;;;;IAMD,iCAAa,GAAb;QACI,OAAO,IAAI,CAAC,aAAa,CAAC,YAAY,EAAE,CAAC;KAC5C;;;;;IAMD,gCAAY,GAAZ,U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1
|
+
{"version":3,"file":"CryptoOps.js","sources":["../../src/crypto/CryptoOps.ts"],"sourcesContent":["/*\n * Copyright (c) Microsoft Corporation. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { ICrypto, IPerformanceClient, Logger, PerformanceEvents, PkceCodes, SignedHttpRequest, SignedHttpRequestParameters } from \"@azure/msal-common\";\nimport { GuidGenerator } from \"./GuidGenerator\";\nimport { Base64Encode } from \"../encode/Base64Encode\";\nimport { Base64Decode } from \"../encode/Base64Decode\";\nimport { PkceGenerator } from \"./PkceGenerator\";\nimport { BrowserCrypto } from \"./BrowserCrypto\";\nimport { BrowserStringUtils } from \"../utils/BrowserStringUtils\";\nimport { KEY_FORMAT_JWK } from \"../utils/BrowserConstants\";\nimport { BrowserAuthError } from \"../error/BrowserAuthError\";\nimport { AsyncMemoryStorage } from \"../cache/AsyncMemoryStorage\";\n\nexport type CachedKeyPair = {\n publicKey: CryptoKey,\n privateKey: CryptoKey,\n requestMethod?: string,\n requestUri?: string\n};\n\n/**\n * MSAL CryptoKeyStore DB Version 2\n */\nexport type CryptoKeyStore = {\n asymmetricKeys: AsyncMemoryStorage<CachedKeyPair>;\n symmetricKeys: AsyncMemoryStorage<CryptoKey>;\n};\n\nexport enum CryptoKeyStoreNames {\n asymmetricKeys = \"asymmetricKeys\",\n symmetricKeys = \"symmetricKeys\"\n}\n\n/**\n * This class implements MSAL's crypto interface, which allows it to perform base64 encoding and decoding, generating cryptographically random GUIDs and \n * implementing Proof Key for Code Exchange specs for the OAuth Authorization Code Flow using PKCE (rfc here: https://tools.ietf.org/html/rfc7636).\n */\nexport class CryptoOps implements ICrypto {\n\n private browserCrypto: BrowserCrypto;\n private guidGenerator: GuidGenerator;\n private b64Encode: Base64Encode;\n private b64Decode: Base64Decode;\n private pkceGenerator: PkceGenerator;\n private logger: Logger;\n\n /**\n * CryptoOps can be used in contexts outside a PCA instance,\n * meaning there won't be a performance manager available.\n */\n private performanceClient: IPerformanceClient | undefined;\n\n private static POP_KEY_USAGES: Array<KeyUsage> = [\"sign\", \"verify\"];\n private static EXTRACTABLE: boolean = true;\n private cache: CryptoKeyStore;\n\n constructor(logger: Logger, performanceClient?: IPerformanceClient) {\n this.logger = logger;\n // Browser crypto needs to be validated first before any other classes can be set.\n this.browserCrypto = new BrowserCrypto(this.logger);\n this.b64Encode = new Base64Encode();\n this.b64Decode = new Base64Decode();\n this.guidGenerator = new GuidGenerator(this.browserCrypto);\n this.pkceGenerator = new PkceGenerator(this.browserCrypto);\n this.cache = {\n asymmetricKeys: new AsyncMemoryStorage<CachedKeyPair>(this.logger, CryptoKeyStoreNames.asymmetricKeys),\n symmetricKeys: new AsyncMemoryStorage<CryptoKey>(this.logger, CryptoKeyStoreNames.symmetricKeys)\n };\n this.performanceClient = performanceClient;\n }\n\n /**\n * Creates a new random GUID - used to populate state and nonce.\n * @returns string (GUID)\n */\n createNewGuid(): string {\n return this.guidGenerator.generateGuid();\n }\n\n /**\n * Encodes input string to base64.\n * @param input \n */\n base64Encode(input: string): string {\n return this.b64Encode.encode(input);\n } \n \n /**\n * Decodes input string from base64.\n * @param input \n */\n base64Decode(input: string): string {\n return this.b64Decode.decode(input);\n }\n\n /**\n * Generates PKCE codes used in Authorization Code Flow.\n */\n async generatePkceCodes(): Promise<PkceCodes> {\n return this.pkceGenerator.generateCodes();\n }\n\n /**\n * Generates a keypair, stores it and returns a thumbprint\n * @param request\n */\n async getPublicKeyThumbprint(request: SignedHttpRequestParameters): Promise<string> {\n const publicKeyThumbMeasurement = this.performanceClient?.startMeasurement(PerformanceEvents.CryptoOptsGetPublicKeyThumbprint, request.correlationId);\n\n // Generate Keypair\n const keyPair: CryptoKeyPair = await this.browserCrypto.generateKeyPair(CryptoOps.EXTRACTABLE, CryptoOps.POP_KEY_USAGES);\n\n // Generate Thumbprint for Public Key\n const publicKeyJwk: JsonWebKey = await this.browserCrypto.exportJwk(keyPair.publicKey);\n \n const pubKeyThumprintObj: JsonWebKey = {\n e: publicKeyJwk.e,\n kty: publicKeyJwk.kty,\n n: publicKeyJwk.n\n };\n\n const publicJwkString: string = BrowserCrypto.getJwkString(pubKeyThumprintObj);\n const publicJwkHash = await this.hashString(publicJwkString);\n\n // Generate Thumbprint for Private Key\n const privateKeyJwk: JsonWebKey = await this.browserCrypto.exportJwk(keyPair.privateKey);\n // Re-import private key to make it unextractable\n const unextractablePrivateKey: CryptoKey = await this.browserCrypto.importJwk(privateKeyJwk, false, [\"sign\"]);\n\n // Store Keypair data in keystore\n await this.cache.asymmetricKeys.setItem(\n publicJwkHash, \n {\n privateKey: unextractablePrivateKey,\n publicKey: keyPair.publicKey,\n requestMethod: request.resourceRequestMethod,\n requestUri: request.resourceRequestUri\n }\n );\n\n if (publicKeyThumbMeasurement) {\n publicKeyThumbMeasurement.endMeasurement({\n success: true\n });\n }\n\n return publicJwkHash;\n }\n\n /**\n * Removes cryptographic keypair from key store matching the keyId passed in\n * @param kid \n */\n async removeTokenBindingKey(kid: string): Promise<boolean> {\n await this.cache.asymmetricKeys.removeItem(kid);\n const keyFound = await this.cache.asymmetricKeys.containsKey(kid);\n return !keyFound;\n }\n\n /**\n * Removes all cryptographic keys from IndexedDB storage\n */\n async clearKeystore(): Promise<boolean> {\n try {\n this.logger.verbose(\"Deleting in-memory and persistent asymmetric key stores\");\n await this.cache.asymmetricKeys.clear();\n this.logger.verbose(\"Successfully deleted asymmetric key stores\");\n this.logger.verbose(\"Deleting in-memory and persistent symmetric key stores\");\n await this.cache.symmetricKeys.clear();\n this.logger.verbose(\"Successfully deleted symmetric key stores\");\n return true;\n } catch (e) {\n if (e instanceof Error) {\n this.logger.error(`Clearing keystore failed with error: ${e.message}`);\n } else {\n this.logger.error(\"Clearing keystore failed with unknown error\");\n }\n \n return false;\n }\n }\n\n /**\n * Signs the given object as a jwt payload with private key retrieved by given kid.\n * @param payload \n * @param kid \n */\n async signJwt(payload: SignedHttpRequest, kid: string, correlationId?: string): Promise<string> {\n const signJwtMeasurement = this.performanceClient?.startMeasurement(PerformanceEvents.CryptoOptsSignJwt, correlationId);\n const cachedKeyPair = await this.cache.asymmetricKeys.getItem(kid);\n \n if (!cachedKeyPair) {\n throw BrowserAuthError.createSigningKeyNotFoundInStorageError(kid);\n }\n\n // Get public key as JWK\n const publicKeyJwk = await this.browserCrypto.exportJwk(cachedKeyPair.publicKey);\n const publicKeyJwkString = BrowserCrypto.getJwkString(publicKeyJwk);\n\n // Generate header\n const header = {\n alg: publicKeyJwk.alg,\n type: KEY_FORMAT_JWK\n };\n const encodedHeader = this.b64Encode.urlEncode(JSON.stringify(header));\n\n // Generate payload\n payload.cnf = {\n jwk: JSON.parse(publicKeyJwkString)\n };\n const encodedPayload = this.b64Encode.urlEncode(JSON.stringify(payload));\n\n // Form token string\n const tokenString = `${encodedHeader}.${encodedPayload}`;\n\n // Sign token\n const tokenBuffer = BrowserStringUtils.stringToArrayBuffer(tokenString);\n const signatureBuffer = await this.browserCrypto.sign(cachedKeyPair.privateKey, tokenBuffer);\n const encodedSignature = this.b64Encode.urlEncodeArr(new Uint8Array(signatureBuffer));\n\n const signedJwt = `${tokenString}.${encodedSignature}`;\n\n if (signJwtMeasurement) {\n signJwtMeasurement.endMeasurement({\n success: true\n });\n }\n\n return signedJwt;\n }\n\n /**\n * Returns the SHA-256 hash of an input string\n * @param plainText\n */\n async hashString(plainText: string): Promise<string> {\n const hashBuffer: ArrayBuffer = await this.browserCrypto.sha256Digest(plainText);\n const hashBytes = new Uint8Array(hashBuffer);\n return this.b64Encode.urlEncodeArr(hashBytes);\n }\n}\n"],"names":[],"mappings":";;;;;;;;;;;;;;AAAA;;;;IA+BY;AAAZ,WAAY,mBAAmB;IAC3B,wDAAiC,CAAA;IACjC,sDAA+B,CAAA;AACnC,CAAC,EAHW,mBAAmB,KAAnB,mBAAmB,QAG9B;AAED;;;;;IAuBI,mBAAY,MAAc,EAAE,iBAAsC;QAC9D,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;;QAErB,IAAI,CAAC,aAAa,GAAG,IAAI,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,SAAiB;;;;;4BACE,qBAAM,IAAI,CAAC,aAAa,CAAC,YAAY,CAAC,SAAS,CAAC,EAAA;;wBAA1E,UAAU,GAAgB,SAAgD;wBAC1E,SAAS,GAAG,IAAI,UAAU,CAAC,UAAU,CAAC,CAAC;wBAC7C,sBAAO,IAAI,CAAC,SAAS,CAAC,YAAY,CAAC,SAAS,CAAC,EAAC;;;;KACjD;IA3Lc,wBAAc,GAAoB,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAC;IACrD,qBAAW,GAAY,IAAI,CAAC;IA2L/C,gBAAC;CA3MD;;;;"}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
+
import { IGuidGenerator } from "@azure/msal-common";
|
|
1
2
|
import { BrowserCrypto } from "./BrowserCrypto";
|
|
2
|
-
export declare class GuidGenerator {
|
|
3
|
+
export declare class GuidGenerator implements IGuidGenerator {
|
|
3
4
|
private cryptoObj;
|
|
4
5
|
constructor(cryptoObj: BrowserCrypto);
|
|
5
6
|
generateGuid(): string;
|
|
@@ -7,6 +8,6 @@ export declare class GuidGenerator {
|
|
|
7
8
|
* verifies if a string is GUID
|
|
8
9
|
* @param guid
|
|
9
10
|
*/
|
|
10
|
-
|
|
11
|
+
isGuid(guid: string): boolean;
|
|
11
12
|
}
|
|
12
13
|
//# sourceMappingURL=GuidGenerator.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"GuidGenerator.d.ts","sourceRoot":"","sources":["../../src/crypto/GuidGenerator.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"GuidGenerator.d.ts","sourceRoot":"","sources":["../../src/crypto/GuidGenerator.ts"],"names":[],"mappings":"AAKA,OAAO,EAAc,cAAc,EAAE,MAAM,oBAAoB,CAAC;AAEhE,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAChD,qBAAa,aAAc,YAAW,cAAc;IAGhD,OAAO,CAAC,SAAS,CAAgB;gBAErB,SAAS,EAAE,aAAa;IA0BpC,YAAY,IAAI,MAAM;IA+CtB;;;OAGG;IACH,MAAM,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO;CAIhC"}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
/*! @azure/msal-browser v2.
|
|
1
|
+
/*! @azure/msal-browser v2.23.0 2022-04-04 */
|
|
2
2
|
'use strict';
|
|
3
|
+
import { Constants } from '@azure/msal-common';
|
|
3
4
|
import { MathUtils } from '../utils/MathUtils.js';
|
|
4
5
|
|
|
5
6
|
/*
|
|
@@ -55,7 +56,7 @@ var GuidGenerator = /** @class */ (function () {
|
|
|
55
56
|
var guidHolder = "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx";
|
|
56
57
|
var hex = "0123456789abcdef";
|
|
57
58
|
var r = 0;
|
|
58
|
-
var guidResponse =
|
|
59
|
+
var guidResponse = Constants.EMPTY_STRING;
|
|
59
60
|
for (var i = 0; i < 36; i++) {
|
|
60
61
|
if (guidHolder[i] !== "-" && guidHolder[i] !== "4") {
|
|
61
62
|
// each x and y needs to be random
|
|
@@ -81,7 +82,7 @@ var GuidGenerator = /** @class */ (function () {
|
|
|
81
82
|
* verifies if a string is GUID
|
|
82
83
|
* @param guid
|
|
83
84
|
*/
|
|
84
|
-
GuidGenerator.isGuid = function (guid) {
|
|
85
|
+
GuidGenerator.prototype.isGuid = function (guid) {
|
|
85
86
|
var regexGuid = /^[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i;
|
|
86
87
|
return regexGuid.test(guid);
|
|
87
88
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"GuidGenerator.js","sources":["../../src/crypto/GuidGenerator.ts"],"sourcesContent":["/*\n * Copyright (c) Microsoft Corporation. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { MathUtils } from \"../utils/MathUtils\";\nimport { BrowserCrypto } from \"./BrowserCrypto\";\
|
|
1
|
+
{"version":3,"file":"GuidGenerator.js","sources":["../../src/crypto/GuidGenerator.ts"],"sourcesContent":["/*\n * Copyright (c) Microsoft Corporation. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { Constants , IGuidGenerator } from \"@azure/msal-common\";\nimport { MathUtils } from \"../utils/MathUtils\";\nimport { BrowserCrypto } from \"./BrowserCrypto\";\nexport class GuidGenerator implements IGuidGenerator {\n\n // browser crypto object used to generate random values\n private cryptoObj: BrowserCrypto;\n\n constructor(cryptoObj: BrowserCrypto) {\n this.cryptoObj = cryptoObj;\n }\n\n /*\n * RFC4122: The version 4 UUID is meant for generating UUIDs from truly-random or\n * pseudo-random numbers.\n * The algorithm is as follows:\n * Set the two most significant bits (bits 6 and 7) of the\n * clock_seq_hi_and_reserved to zero and one, respectively.\n * Set the four most significant bits (bits 12 through 15) of the\n * time_hi_and_version field to the 4-bit version number from\n * Section 4.1.3. Version4\n * Set all the other bits to randomly (or pseudo-randomly) chosen\n * values.\n * UUID = time-low \"-\" time-mid \"-\"time-high-and-version \"-\"clock-seq-reserved and low(2hexOctet)\"-\" node\n * time-low = 4hexOctet\n * time-mid = 2hexOctet\n * time-high-and-version = 2hexOctet\n * clock-seq-and-reserved = hexOctet:\n * clock-seq-low = hexOctet\n * node = 6hexOctet\n * Format: xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx\n * y could be 1000, 1001, 1010, 1011 since most significant two bits needs to be 10\n * y values are 8, 9, A, B\n */\n generateGuid(): string {\n try {\n const buffer: Uint8Array = new Uint8Array(16);\n this.cryptoObj.getRandomValues(buffer);\n\n // buffer[6] and buffer[7] represents the time_hi_and_version field. We will set the four most significant bits (4 through 7) of buffer[6] to represent decimal number 4 (UUID version number).\n buffer[6] |= 0x40; // buffer[6] | 01000000 will set the 6 bit to 1.\n buffer[6] &= 0x4f; // buffer[6] & 01001111 will set the 4, 5, and 7 bit to 0 such that bits 4-7 == 0100 = \"4\".\n\n // buffer[8] represents the clock_seq_hi_and_reserved field. We will set the two most significant bits (6 and 7) of the clock_seq_hi_and_reserved to zero and one, respectively.\n buffer[8] |= 0x80; // buffer[8] | 10000000 will set the 7 bit to 1.\n buffer[8] &= 0xbf; // buffer[8] & 10111111 will set the 6 bit to 0.\n\n return MathUtils.decimalToHex(buffer[0]) + MathUtils.decimalToHex(buffer[1])\n + MathUtils.decimalToHex(buffer[2]) + MathUtils.decimalToHex(buffer[3])\n + \"-\" + MathUtils.decimalToHex(buffer[4]) + MathUtils.decimalToHex(buffer[5])\n + \"-\" + MathUtils.decimalToHex(buffer[6]) + MathUtils.decimalToHex(buffer[7])\n + \"-\" + MathUtils.decimalToHex(buffer[8]) + MathUtils.decimalToHex(buffer[9])\n + \"-\" + MathUtils.decimalToHex(buffer[10]) + MathUtils.decimalToHex(buffer[11])\n + MathUtils.decimalToHex(buffer[12]) + MathUtils.decimalToHex(buffer[13])\n + MathUtils.decimalToHex(buffer[14]) + MathUtils.decimalToHex(buffer[15]);\n }\n catch (err) {\n const guidHolder: string = \"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx\";\n const hex: string = \"0123456789abcdef\";\n let r: number = 0;\n let guidResponse: string = Constants.EMPTY_STRING;\n for (let i: number = 0; i < 36; i++) {\n if (guidHolder[i] !== \"-\" && guidHolder[i] !== \"4\") {\n // each x and y needs to be random\n r = Math.random() * 16 | 0;\n }\n if (guidHolder[i] === \"x\") {\n guidResponse += hex[r];\n } else if (guidHolder[i] === \"y\") {\n // clock-seq-and-reserved first hex is filtered and remaining hex values are random\n r &= 0x3; // bit and with 0011 to set pos 2 to zero ?0??\n r |= 0x8; // set pos 3 to 1 as 1???\n guidResponse += hex[r];\n } else {\n guidResponse += guidHolder[i];\n }\n }\n return guidResponse;\n }\n }\n\n /**\n * verifies if a string is GUID\n * @param guid\n */\n isGuid(guid: string): boolean {\n const regexGuid = /^[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i;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F,OAAO,SAAS,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;KAC/B;IACL,oBAAC;AAAD,CAAC;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Base64Decode.d.ts","sourceRoot":"","sources":["../../src/encode/Base64Decode.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"Base64Decode.d.ts","sourceRoot":"","sources":["../../src/encode/Base64Decode.ts"],"names":[],"mappings":"AAQA;;;GAGG;AACH,qBAAa,YAAY;IAErB;;;OAGG;IACH,MAAM,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM;IAmB7B;;;;OAIG;IACH,OAAO,CAAC,cAAc;IAoBtB;;;OAGG;IACH,OAAO,CAAC,UAAU;CAcrB"}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
/*! @azure/msal-browser v2.
|
|
1
|
+
/*! @azure/msal-browser v2.23.0 2022-04-04 */
|
|
2
2
|
'use strict';
|
|
3
|
+
import { Constants } from '@azure/msal-common';
|
|
3
4
|
import { BrowserStringUtils } from '../utils/BrowserStringUtils.js';
|
|
4
5
|
|
|
5
6
|
/*
|
|
@@ -40,7 +41,7 @@ var Base64Decode = /** @class */ (function () {
|
|
|
40
41
|
* @param nBlockSize
|
|
41
42
|
*/
|
|
42
43
|
Base64Decode.prototype.base64DecToArr = function (base64String, nBlockSize) {
|
|
43
|
-
var sB64Enc = base64String.replace(/[^A-Za-z0-9\+\/]/g,
|
|
44
|
+
var sB64Enc = base64String.replace(/[^A-Za-z0-9\+\/]/g, Constants.EMPTY_STRING);
|
|
44
45
|
var nInLen = sB64Enc.length;
|
|
45
46
|
var nOutLen = nBlockSize ? Math.ceil((nInLen * 3 + 1 >>> 2) / nBlockSize) * nBlockSize : nInLen * 3 + 1 >>> 2;
|
|
46
47
|
var aBytes = new Uint8Array(nOutLen);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Base64Decode.js","sources":["../../src/encode/Base64Decode.ts"],"sourcesContent":["/*\n * Copyright (c) Microsoft Corporation. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { BrowserStringUtils } from \"../utils/BrowserStringUtils\";\n\n/**\n * Class which exposes APIs to decode base64 strings to plaintext. See here for implementation details:\n * https://developer.mozilla.org/en-US/docs/Web/API/WindowBase64/Base64_encoding_and_decoding#Solution_2_%E2%80%93_JavaScript's_UTF-16_%3E_UTF-8_%3E_base64\n */\nexport class Base64Decode {\n\n /**\n * Returns a URL-safe plaintext decoded string from b64 encoded input.\n * @param input \n */\n decode(input: string): string {\n let encodedString = input.replace(/-/g, \"+\").replace(/_/g, \"/\");\n switch (encodedString.length % 4) {\n case 0:\n break;\n case 2:\n encodedString += \"==\";\n break;\n case 3:\n encodedString += \"=\";\n break;\n default:\n throw new Error(\"Invalid base64 string\");\n }\n\n const inputUtf8Arr = this.base64DecToArr(encodedString);\n return BrowserStringUtils.utf8ArrToString(inputUtf8Arr);\n }\n\n /**\n * Decodes base64 into Uint8Array\n * @param base64String \n * @param nBlockSize \n */\n private base64DecToArr(base64String: string, nBlockSize?: number): Uint8Array {\n const sB64Enc = base64String.replace(/[^A-Za-z0-9\\+\\/]/g,
|
|
1
|
+
{"version":3,"file":"Base64Decode.js","sources":["../../src/encode/Base64Decode.ts"],"sourcesContent":["/*\n * Copyright (c) Microsoft Corporation. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { Constants } from \"@azure/msal-common\";\nimport { BrowserStringUtils } from \"../utils/BrowserStringUtils\";\n\n/**\n * Class which exposes APIs to decode base64 strings to plaintext. See here for implementation details:\n * https://developer.mozilla.org/en-US/docs/Web/API/WindowBase64/Base64_encoding_and_decoding#Solution_2_%E2%80%93_JavaScript's_UTF-16_%3E_UTF-8_%3E_base64\n */\nexport class Base64Decode {\n\n /**\n * Returns a URL-safe plaintext decoded string from b64 encoded input.\n * @param input \n */\n decode(input: string): string {\n let encodedString = input.replace(/-/g, \"+\").replace(/_/g, \"/\");\n switch (encodedString.length % 4) {\n case 0:\n break;\n case 2:\n encodedString += \"==\";\n break;\n case 3:\n encodedString += \"=\";\n break;\n default:\n throw new Error(\"Invalid base64 string\");\n }\n\n const inputUtf8Arr = this.base64DecToArr(encodedString);\n return BrowserStringUtils.utf8ArrToString(inputUtf8Arr);\n }\n\n /**\n * Decodes base64 into Uint8Array\n * @param base64String \n * @param nBlockSize \n */\n private base64DecToArr(base64String: string, nBlockSize?: number): Uint8Array {\n const sB64Enc = base64String.replace(/[^A-Za-z0-9\\+\\/]/g, Constants.EMPTY_STRING);\n const nInLen = sB64Enc.length;\n const nOutLen = nBlockSize ? Math.ceil((nInLen * 3 + 1 >>> 2) / nBlockSize) * nBlockSize : nInLen * 3 + 1 >>> 2;\n const aBytes = new Uint8Array(nOutLen);\n\n for (let nMod3, nMod4, nUint24 = 0, nOutIdx = 0, nInIdx = 0; nInIdx < nInLen; nInIdx++) {\n nMod4 = nInIdx & 3;\n nUint24 |= this.b64ToUint6(sB64Enc.charCodeAt(nInIdx)) << 18 - 6 * nMod4;\n if (nMod4 === 3 || nInLen - nInIdx === 1) {\n for (nMod3 = 0; nMod3 < 3 && nOutIdx < nOutLen; nMod3++, nOutIdx++) {\n aBytes[nOutIdx] = nUint24 >>> (16 >>> nMod3 & 24) & 255;\n }\n nUint24 = 0;\n }\n }\n\n return aBytes;\n }\n\n /**\n * Base64 string to array decoding helper\n * @param charNum \n */\n private b64ToUint6(charNum: number): number {\n return charNum > 64 && charNum < 91 ?\n charNum - 65\n : charNum > 96 && charNum < 123 ? \n charNum - 71\n : charNum > 47 && charNum < 58 ?\n charNum + 4\n : charNum === 43 ?\n 62\n : charNum === 47 ?\n 63\n :\n 0;\n }\n}\n"],"names":[],"mappings":";;;;;AAAA;;;;AAQA;;;;;IAIA;KAoEC;;;;;IA9DG,6BAAM,GAAN,UAAO,KAAa;QAChB,IAAI,aAAa,GAAG,KAAK,CAAC,OAAO,CAAC,IAAI,EAAE,GAAG,CAAC,CAAC,OAAO,CAAC,IAAI,EAA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AM,GAAG,MAAM,KAAK,CAAC,EAAE;gBACtC,KAAK,KAAK,GAAG,CAAC,EAAE,KAAK,GAAG,CAAC,IAAI,OAAO,GAAG,OAAO,EAAE,KAAK,EAAE,EAAE,OAAO,EAAE,EAAE;oBAChE,MAAM,CAAC,OAAO,CAAC,GAAG,OAAO,MAAM,EAAE,KAAK,KAAK,GAAG,EAAE,CAAC,GAAG,GAAG,CAAC;iBAC3D;gBACD,OAAO,GAAG,CAAC,CAAC;aACf;SACJ;QAED,OAAO,MAAM,CAAC;KACjB;;;;;IAMO,iCAAU,GAAlB,UAAmB,OAAe;QAC9B,OAAO,OAAO,GAAG,EAAE,IAAI,OAAO,GAAG,EAAE;YAC/B,OAAO,GAAG,EAAE;cACV,OAAO,GAAG,EAAE,IAAI,OAAO,GAAG,GAAG;gBAC3B,OAAO,GAAG,EAAE;kBACV,OAAO,GAAG,EAAE,IAAI,OAAO,GAAG,EAAE;oBAC1B,OAAO,GAAG,CAAC;sBACT,OAAO,KAAK,EAAE;wBACZ,EAAE;0BACA,OAAO,KAAK,EAAE;4BACZ,EAAE;;gCAEF,CAAC,CAAC;KACzB;IACL,mBAAC;AAAD,CAAC;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Base64Encode.d.ts","sourceRoot":"","sources":["../../src/encode/Base64Encode.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"Base64Encode.d.ts","sourceRoot":"","sources":["../../src/encode/Base64Encode.ts"],"names":[],"mappings":"AAQA;;;GAGG;AACH,qBAAa,YAAY;IAErB;;;OAGG;IACH,SAAS,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM;IAOhC;;;OAGG;IACH,YAAY,CAAC,QAAQ,EAAE,UAAU,GAAG,MAAM;IAO1C;;;OAGG;IACH,MAAM,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM;IAK7B;;;OAGG;IACH,OAAO,CAAC,YAAY;IAyBpB;;;OAGG;IACH,OAAO,CAAC,UAAU;CAcrB"}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
/*! @azure/msal-browser v2.
|
|
1
|
+
/*! @azure/msal-browser v2.23.0 2022-04-04 */
|
|
2
2
|
'use strict';
|
|
3
|
+
import { Constants } from '@azure/msal-common';
|
|
3
4
|
import { BrowserStringUtils } from '../utils/BrowserStringUtils.js';
|
|
4
5
|
|
|
5
6
|
/*
|
|
@@ -19,7 +20,7 @@ var Base64Encode = /** @class */ (function () {
|
|
|
19
20
|
*/
|
|
20
21
|
Base64Encode.prototype.urlEncode = function (input) {
|
|
21
22
|
return encodeURIComponent(this.encode(input)
|
|
22
|
-
.replace(/=/g,
|
|
23
|
+
.replace(/=/g, Constants.EMPTY_STRING)
|
|
23
24
|
.replace(/\+/g, "-")
|
|
24
25
|
.replace(/\//g, "_"));
|
|
25
26
|
};
|
|
@@ -29,7 +30,7 @@ var Base64Encode = /** @class */ (function () {
|
|
|
29
30
|
*/
|
|
30
31
|
Base64Encode.prototype.urlEncodeArr = function (inputArr) {
|
|
31
32
|
return this.base64EncArr(inputArr)
|
|
32
|
-
.replace(/=/g,
|
|
33
|
+
.replace(/=/g, Constants.EMPTY_STRING)
|
|
33
34
|
.replace(/\+/g, "-")
|
|
34
35
|
.replace(/\//g, "_");
|
|
35
36
|
};
|
|
@@ -47,7 +48,7 @@ var Base64Encode = /** @class */ (function () {
|
|
|
47
48
|
*/
|
|
48
49
|
Base64Encode.prototype.base64EncArr = function (aBytes) {
|
|
49
50
|
var eqLen = (3 - (aBytes.length % 3)) % 3;
|
|
50
|
-
var sB64Enc =
|
|
51
|
+
var sB64Enc = Constants.EMPTY_STRING;
|
|
51
52
|
for (var nMod3 = void 0, nLen = aBytes.length, nUint24 = 0, nIdx = 0; nIdx < nLen; nIdx++) {
|
|
52
53
|
nMod3 = nIdx % 3;
|
|
53
54
|
/* Uncomment the following line in order to split the output in lines 76-character long: */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Base64Encode.js","sources":["../../src/encode/Base64Encode.ts"],"sourcesContent":["/*\n * Copyright (c) Microsoft Corporation. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { BrowserStringUtils } from \"../utils/BrowserStringUtils\";\n\n/**\n * Class which exposes APIs to encode plaintext to base64 encoded string. See here for implementation details:\n * https://developer.mozilla.org/en-US/docs/Web/API/WindowBase64/Base64_encoding_and_decoding#Solution_2_%E2%80%93_JavaScript's_UTF-16_%3E_UTF-8_%3E_base64\n */\nexport class Base64Encode {\n \n /**\n * Returns URL Safe b64 encoded string from a plaintext string.\n * @param input \n */\n urlEncode(input: string): string {\n return encodeURIComponent(this.encode(input)\n .replace(/=/g,
|
|
1
|
+
{"version":3,"file":"Base64Encode.js","sources":["../../src/encode/Base64Encode.ts"],"sourcesContent":["/*\n * Copyright (c) Microsoft Corporation. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { Constants } from \"@azure/msal-common\";\nimport { BrowserStringUtils } from \"../utils/BrowserStringUtils\";\n\n/**\n * Class which exposes APIs to encode plaintext to base64 encoded string. See here for implementation details:\n * https://developer.mozilla.org/en-US/docs/Web/API/WindowBase64/Base64_encoding_and_decoding#Solution_2_%E2%80%93_JavaScript's_UTF-16_%3E_UTF-8_%3E_base64\n */\nexport class Base64Encode {\n \n /**\n * Returns URL Safe b64 encoded string from a plaintext string.\n * @param input \n */\n urlEncode(input: string): string {\n return encodeURIComponent(this.encode(input)\n .replace(/=/g, Constants.EMPTY_STRING)\n .replace(/\\+/g, \"-\")\n .replace(/\\//g, \"_\"));\n }\n\n /**\n * Returns URL Safe b64 encoded string from an int8Array.\n * @param inputArr \n */\n urlEncodeArr(inputArr: Uint8Array): string {\n return this.base64EncArr(inputArr)\n .replace(/=/g, Constants.EMPTY_STRING)\n .replace(/\\+/g, \"-\")\n .replace(/\\//g, \"_\");\n }\n\n /**\n * Returns b64 encoded string from plaintext string.\n * @param input \n */\n encode(input: string): string {\n const inputUtf8Arr = BrowserStringUtils.stringToUtf8Arr(input);\n return this.base64EncArr(inputUtf8Arr);\n }\n\n /**\n * Base64 encode byte array\n * @param aBytes \n */\n private base64EncArr(aBytes: Uint8Array): string { \n const eqLen = (3 - (aBytes.length % 3)) % 3;\n let sB64Enc = Constants.EMPTY_STRING;\n \n for (let nMod3, nLen = aBytes.length, nUint24 = 0, nIdx = 0; nIdx < nLen; nIdx++) {\n nMod3 = nIdx % 3;\n /* Uncomment the following line in order to split the output in lines 76-character long: */\n /*\n *if (nIdx > 0 && (nIdx * 4 / 3) % 76 === 0) { sB64Enc += \"\\r\\n\"; }\n */\n nUint24 |= aBytes[nIdx] << (16 >>> nMod3 & 24);\n if (nMod3 === 2 || aBytes.length - nIdx === 1) {\n sB64Enc += String.fromCharCode(\n this.uint6ToB64(nUint24 >>> 18 & 63), \n this.uint6ToB64(nUint24 >>> 12 & 63), \n this.uint6ToB64(nUint24 >>> 6 & 63), \n this.uint6ToB64(nUint24 & 63)\n );\n nUint24 = 0;\n }\n }\n\n return eqLen === 0 ? sB64Enc : sB64Enc.substring(0, sB64Enc.length - eqLen) + (eqLen === 1 ? \"=\" : \"==\");\n }\n\n /**\n * Base64 string to array encoding helper\n * @param nUint6 \n */\n private uint6ToB64 (nUint6: number): number {\n return nUint6 < 26 ?\n nUint6 + 65\n : nUint6 < 52 ?\n nUint6 + 71\n : nUint6 < 62 ?\n nUint6 - 4\n : nUint6 === 62 ?\n 43\n : nUint6 === 63 ?\n 47\n :\n 65;\n }\n}\n"],"names":[],"mappings":";;;;;AAAA;;;;AAQA;;;;;IAIA;KAgFC;;;;;IA1EG,gCAAS,GAAT,UAAU,KAAa;QACnB,OAAO,kBAAkB,CAAC,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC;aACvC,OAAO,CAAC,IAAI,EAAE,SAAS,CAAC,YAAY,CAAC;aACrC,OAAO,CAAC,KAAK,EAAE,GAAG,CAAC;aACnB,OAAO,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC,CAAC;KAC7B;;;;;IAMD,mCAAY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