{"version":3,"file":"SignedHttpRequest.js","sources":["../../src/crypto/SignedHttpRequest.ts"],"sourcesContent":["/*\r\n * Copyright (c) Microsoft Corporation. All rights reserved.\r\n * Licensed under the MIT License.\r\n */\r\n\r\nimport { CryptoOps } from \"./CryptoOps\";\r\nimport { Logger, LoggerOptions, PopTokenGenerator, SignedHttpRequestParameters } from \"@azure/msal-common\";\r\nimport { version, name } from \"../packageMetadata\";\r\n\r\nexport type SignedHttpRequestOptions = {\r\n loggerOptions: LoggerOptions\r\n};\r\n\r\nexport class SignedHttpRequest {\r\n private popTokenGenerator: PopTokenGenerator;\r\n private cryptoOps: CryptoOps;\r\n private shrParameters: SignedHttpRequestParameters;\r\n private logger: Logger;\r\n\r\n constructor(shrParameters: SignedHttpRequestParameters, shrOptions?: SignedHttpRequestOptions) {\r\n const loggerOptions = (shrOptions && shrOptions.loggerOptions) || {};\r\n this.logger = new Logger(loggerOptions, name, version);\r\n this.cryptoOps = new CryptoOps(this.logger);\r\n this.popTokenGenerator = new PopTokenGenerator(this.cryptoOps);\r\n this.shrParameters = shrParameters;\r\n }\r\n\r\n /**\r\n * Generates and caches a keypair for the given request options.\r\n * @returns Public key digest, which should be sent to the token issuer.\r\n */\r\n async generatePublicKeyThumbprint(): Promise {\r\n const { kid } = await this.popTokenGenerator.generateKid(this.shrParameters);\r\n\r\n return kid;\r\n }\r\n\r\n /**\r\n * Generates a signed http request for the given payload with the given key.\r\n * @param payload Payload to sign (e.g. access token)\r\n * @param publicKeyThumbprint Public key digest (from generatePublicKeyThumbprint API)\r\n * @param claims Additional claims to include/override in the signed JWT \r\n * @returns Pop token signed with the corresponding private key\r\n */\r\n async signRequest(payload: string, publicKeyThumbprint: string, claims?: object): Promise {\r\n return this.popTokenGenerator.signPayload(\r\n payload, \r\n publicKeyThumbprint,\r\n this.shrParameters, \r\n claims\r\n );\r\n }\r\n\r\n /**\r\n * Removes cached keys from browser for given public key thumbprint\r\n * @param publicKeyThumbprint Public key digest (from generatePublicKeyThumbprint API)\r\n * @returns If keys are properly deleted\r\n */\r\n async removeKeys(publicKeyThumbprint: string): Promise {\r\n return await this.cryptoOps.removeTokenBindingKey(publicKeyThumbprint);\r\n }\r\n}\r\n"],"names":[],"mappings":";;;;;;;AAAA;;;;;IAmBI,2BAAY,aAA0C,EAAE,UAAqC;QACzF,IAAM,aAAa,GAAG,CAAC,UAAU,IAAI,UAAU,CAAC,aAAa,KAAK,EAAE,CAAC;QACrE,IAAI,CAAC,MAAM,GAAG,IAAI,MAAM,CAAC,aAAa,EAAE,IAAI,EAAE,OAAO,CAAC,CAAC;QACvD,IAAI,CAAC,SAAS,GAAG,IAAI,SAAS,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;QAC5C,IAAI,CAAC,iBAAiB,GAAG,IAAI,iBAAiB,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;QAC/D,IAAI,CAAC,aAAa,GAAG,aAAa,CAAC;KACtC;;;;;IAMK,uDAA2B,GAAjC;;;;;4BACoB,qBAAM,IAAI,CAAC,iBAAiB,CAAC,WAAW,CAAC,IAAI,CAAC,aAAa,CAAC,EAAA;;wBAApE,GAAG,GAAK,CAAA,SAA4D,KAAjE;wBAEX,sBAAO,GAAG,EAAC;;;;KACd;;;;;;;;IASK,uCAAW,GAAjB,UAAkB,OAAe,EAAE,mBAA2B,EAAE,MAAe;;;gBAC3E,sBAAO,IAAI,CAAC,iBAAiB,CAAC,WAAW,CACrC,OAAO,EACP,mBAAmB,EACnB,IAAI,CAAC,aAAa,EAClB,MAAM,CACT,EAAC;;;KACL;;;;;;IAOK,sCAAU,GAAhB,UAAiB,mBAA2B;;;;4BACjC,qBAAM,IAAI,CAAC,SAAS,CAAC,qBAAqB,CAAC,mBAAmB,CAAC,EAAA;4BAAtE,sBAAO,SAA+D,EAAC;;;;KAC1E;IACL,wBAAC;AAAD,CAAC;;;;"}