@azure/communication-common
Advanced tools
Comparing version 1.0.1-alpha.20210517.1 to 1.0.1-alpha.20210610.1
// Copyright (c) Microsoft Corporation. | ||
// Licensed under the MIT license. | ||
import { __awaiter } from "tslib"; | ||
import { parseToken } from "./tokenParser"; | ||
@@ -22,13 +21,11 @@ const expiredToken = { token: "", expiresOnTimestamp: -10 }; | ||
} | ||
getToken(options) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
if (!this.isCurrentTokenExpiringSoon) { | ||
return this.currentToken; | ||
} | ||
const updatePromise = this.updateTokenAndReschedule(options === null || options === void 0 ? void 0 : options.abortSignal); | ||
if (!this.isCurrentTokenValid) { | ||
yield updatePromise; | ||
} | ||
async getToken(options) { | ||
if (!this.isCurrentTokenExpiringSoon) { | ||
return this.currentToken; | ||
}); | ||
} | ||
const updatePromise = this.updateTokenAndReschedule(options === null || options === void 0 ? void 0 : options.abortSignal); | ||
if (!this.isCurrentTokenValid) { | ||
await updatePromise; | ||
} | ||
return this.currentToken; | ||
} | ||
@@ -44,36 +41,30 @@ dispose() { | ||
} | ||
updateTokenAndReschedule(abortSignal) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
if (this.activeTokenUpdating) { | ||
return this.activeTokenUpdating; | ||
} | ||
this.activeTokenUpdating = this.refreshTokenAndReschedule(abortSignal); | ||
try { | ||
yield this.activeTokenUpdating; | ||
} | ||
finally { | ||
this.activeTokenUpdating = null; | ||
} | ||
}); | ||
async updateTokenAndReschedule(abortSignal) { | ||
if (this.activeTokenUpdating) { | ||
return this.activeTokenUpdating; | ||
} | ||
this.activeTokenUpdating = this.refreshTokenAndReschedule(abortSignal); | ||
try { | ||
await this.activeTokenUpdating; | ||
} | ||
finally { | ||
this.activeTokenUpdating = null; | ||
} | ||
} | ||
refreshTokenAndReschedule(abortSignal) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
this.currentToken = yield this.refreshToken(abortSignal); | ||
if (this.refreshProactively) { | ||
this.scheduleRefresh(); | ||
} | ||
}); | ||
async refreshTokenAndReschedule(abortSignal) { | ||
this.currentToken = await this.refreshToken(abortSignal); | ||
if (this.refreshProactively) { | ||
this.scheduleRefresh(); | ||
} | ||
} | ||
refreshToken(abortSignal) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
try { | ||
if (!this.activeTokenFetching) { | ||
this.activeTokenFetching = this.refresh(abortSignal); | ||
} | ||
return parseToken(yield this.activeTokenFetching); | ||
async refreshToken(abortSignal) { | ||
try { | ||
if (!this.activeTokenFetching) { | ||
this.activeTokenFetching = this.refresh(abortSignal); | ||
} | ||
finally { | ||
this.activeTokenFetching = null; | ||
} | ||
}); | ||
return parseToken(await this.activeTokenFetching); | ||
} | ||
finally { | ||
this.activeTokenFetching = null; | ||
} | ||
} | ||
@@ -80,0 +71,0 @@ scheduleRefresh() { |
// Copyright (c) Microsoft Corporation. | ||
// Licensed under the MIT license. | ||
import { __awaiter } from "tslib"; | ||
import { parseToken } from "./tokenParser"; | ||
@@ -24,9 +23,7 @@ import { StaticTokenCredential } from "./staticTokenCredential"; | ||
*/ | ||
getToken(options) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
this.throwIfDisposed(); | ||
const token = yield this.tokenCredential.getToken(options); | ||
this.throwIfDisposed(); | ||
return token; | ||
}); | ||
async getToken(options) { | ||
this.throwIfDisposed(); | ||
const token = await this.tokenCredential.getToken(options); | ||
this.throwIfDisposed(); | ||
return token; | ||
} | ||
@@ -33,0 +30,0 @@ /** |
// Copyright (c) Microsoft Corporation. | ||
// Licensed under the MIT license. | ||
import { __awaiter } from "tslib"; | ||
import { URLBuilder, isNode, BaseRequestPolicy } from "@azure/core-http"; | ||
@@ -38,24 +37,22 @@ import { shaHash, shaHMAC } from "./cryptoUtils"; | ||
*/ | ||
signRequest(webResource) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const verb = webResource.method.toUpperCase(); | ||
const utcNow = new Date().toUTCString(); | ||
const contentHash = yield shaHash(webResource.body || ""); | ||
const dateHeader = isNode ? "date" : "x-ms-date"; | ||
const signedHeaders = `${dateHeader};host;x-ms-content-sha256`; | ||
const url = URLBuilder.parse(webResource.url); | ||
const query = url.getQuery(); | ||
const urlPathAndQuery = query ? `${url.getPath()}?${query}` : url.getPath(); | ||
const port = url.getPort(); | ||
const hostAndPort = port ? `${url.getHost()}:${port}` : url.getHost(); | ||
const stringToSign = `${verb}\n${urlPathAndQuery}\n${utcNow};${hostAndPort};${contentHash}`; | ||
const signature = yield shaHMAC(this.accessKey.key, stringToSign); | ||
if (isNode) { | ||
webResource.headers.set("Host", hostAndPort || ""); | ||
} | ||
webResource.headers.set(dateHeader, utcNow); | ||
webResource.headers.set("x-ms-content-sha256", contentHash); | ||
webResource.headers.set("Authorization", `HMAC-SHA256 SignedHeaders=${signedHeaders}&Signature=${signature}`); | ||
return webResource; | ||
}); | ||
async signRequest(webResource) { | ||
const verb = webResource.method.toUpperCase(); | ||
const utcNow = new Date().toUTCString(); | ||
const contentHash = await shaHash(webResource.body || ""); | ||
const dateHeader = isNode ? "date" : "x-ms-date"; | ||
const signedHeaders = `${dateHeader};host;x-ms-content-sha256`; | ||
const url = URLBuilder.parse(webResource.url); | ||
const query = url.getQuery(); | ||
const urlPathAndQuery = query ? `${url.getPath()}?${query}` : url.getPath(); | ||
const port = url.getPort(); | ||
const hostAndPort = port ? `${url.getHost()}:${port}` : url.getHost(); | ||
const stringToSign = `${verb}\n${urlPathAndQuery}\n${utcNow};${hostAndPort};${contentHash}`; | ||
const signature = await shaHMAC(this.accessKey.key, stringToSign); | ||
if (isNode) { | ||
webResource.headers.set("Host", hostAndPort || ""); | ||
} | ||
webResource.headers.set(dateHeader, utcNow); | ||
webResource.headers.set("x-ms-content-sha256", contentHash); | ||
webResource.headers.set("Authorization", `HMAC-SHA256 SignedHeaders=${signedHeaders}&Signature=${signature}`); | ||
return webResource; | ||
} | ||
@@ -65,11 +62,9 @@ /** | ||
*/ | ||
sendRequest(webResource) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
if (!webResource) { | ||
throw new Error("webResource cannot be null or undefined"); | ||
} | ||
return this._nextPolicy.sendRequest(yield this.signRequest(webResource)); | ||
}); | ||
async sendRequest(webResource) { | ||
if (!webResource) { | ||
throw new Error("webResource cannot be null or undefined"); | ||
} | ||
return this._nextPolicy.sendRequest(await this.signRequest(webResource)); | ||
} | ||
} | ||
//# sourceMappingURL=communicationAccessKeyCredentialPolicy.js.map |
// Copyright (c) Microsoft Corporation. | ||
// Licensed under the MIT license. | ||
import { __awaiter } from "tslib"; | ||
import { encodeUTF8, encodeBase64, encodeUTF8fromBase64 } from "./encodeUtils.browser"; | ||
@@ -15,8 +14,8 @@ const globalRef = globalThis; | ||
}; | ||
export const shaHash = (content) => __awaiter(void 0, void 0, void 0, function* () { | ||
export const shaHash = async (content) => { | ||
const data = encodeUTF8(content); | ||
const hash = yield getCrypto().digest("SHA-256", data); | ||
const hash = await getCrypto().digest("SHA-256", data); | ||
return encodeBase64(hash); | ||
}); | ||
export const shaHMAC = (secret, content) => __awaiter(void 0, void 0, void 0, function* () { | ||
}; | ||
export const shaHMAC = async (secret, content) => { | ||
const importParams = { name: "HMAC", hash: { name: "SHA-256" } }; | ||
@@ -26,6 +25,6 @@ const encodedMessage = encodeUTF8(content); | ||
const crypto = getCrypto(); | ||
const cryptoKey = yield crypto.importKey("raw", encodedKey, importParams, false, ["sign"]); | ||
const signature = yield crypto.sign(importParams, cryptoKey, encodedMessage); | ||
const cryptoKey = await crypto.importKey("raw", encodedKey, importParams, false, ["sign"]); | ||
const signature = await crypto.sign(importParams, cryptoKey, encodedMessage); | ||
return encodeBase64(signature); | ||
}); | ||
}; | ||
//# sourceMappingURL=cryptoUtils.browser.js.map |
// Copyright (c) Microsoft Corporation. | ||
// Licensed under the MIT license. | ||
import { __awaiter } from "tslib"; | ||
import { createHash, createHmac } from "crypto"; | ||
export const shaHash = (content) => __awaiter(void 0, void 0, void 0, function* () { | ||
return createHash("sha256") | ||
.update(content) | ||
.digest("base64"); | ||
}); | ||
export const shaHMAC = (secret, content) => __awaiter(void 0, void 0, void 0, function* () { | ||
export const shaHash = async (content) => createHash("sha256") | ||
.update(content) | ||
.digest("base64"); | ||
export const shaHMAC = async (secret, content) => { | ||
const decodedSecret = Buffer.from(secret, "base64"); | ||
@@ -15,3 +12,3 @@ return createHmac("sha256", decodedSecret) | ||
.digest("base64"); | ||
}); | ||
}; | ||
//# sourceMappingURL=cryptoUtils.js.map |
// Copyright (c) Microsoft Corporation. | ||
// Licensed under the MIT license. | ||
import { __awaiter } from "tslib"; | ||
/** | ||
@@ -11,6 +10,4 @@ * StaticTokenCredential | ||
} | ||
getToken() { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
return this.token; | ||
}); | ||
async getToken() { | ||
return this.token; | ||
} | ||
@@ -17,0 +14,0 @@ dispose() { |
@@ -7,3 +7,2 @@ 'use strict'; | ||
var tslib = require('tslib'); | ||
var jwtDecode = _interopDefault(require('jwt-decode')); | ||
@@ -13,2 +12,3 @@ var coreHttp = require('@azure/core-http'); | ||
var coreAuth = require('@azure/core-auth'); | ||
var tslib = require('tslib'); | ||
@@ -25,2 +25,3 @@ // Copyright (c) Microsoft Corporation. | ||
// Copyright (c) Microsoft Corporation. | ||
// Licensed under the MIT license. | ||
/** | ||
@@ -33,6 +34,4 @@ * StaticTokenCredential | ||
} | ||
getToken() { | ||
return tslib.__awaiter(this, void 0, void 0, function* () { | ||
return this.token; | ||
}); | ||
async getToken() { | ||
return this.token; | ||
} | ||
@@ -62,13 +61,11 @@ dispose() { | ||
} | ||
getToken(options) { | ||
return tslib.__awaiter(this, void 0, void 0, function* () { | ||
if (!this.isCurrentTokenExpiringSoon) { | ||
return this.currentToken; | ||
} | ||
const updatePromise = this.updateTokenAndReschedule(options === null || options === void 0 ? void 0 : options.abortSignal); | ||
if (!this.isCurrentTokenValid) { | ||
yield updatePromise; | ||
} | ||
async getToken(options) { | ||
if (!this.isCurrentTokenExpiringSoon) { | ||
return this.currentToken; | ||
}); | ||
} | ||
const updatePromise = this.updateTokenAndReschedule(options === null || options === void 0 ? void 0 : options.abortSignal); | ||
if (!this.isCurrentTokenValid) { | ||
await updatePromise; | ||
} | ||
return this.currentToken; | ||
} | ||
@@ -84,36 +81,30 @@ dispose() { | ||
} | ||
updateTokenAndReschedule(abortSignal) { | ||
return tslib.__awaiter(this, void 0, void 0, function* () { | ||
if (this.activeTokenUpdating) { | ||
return this.activeTokenUpdating; | ||
} | ||
this.activeTokenUpdating = this.refreshTokenAndReschedule(abortSignal); | ||
try { | ||
yield this.activeTokenUpdating; | ||
} | ||
finally { | ||
this.activeTokenUpdating = null; | ||
} | ||
}); | ||
async updateTokenAndReschedule(abortSignal) { | ||
if (this.activeTokenUpdating) { | ||
return this.activeTokenUpdating; | ||
} | ||
this.activeTokenUpdating = this.refreshTokenAndReschedule(abortSignal); | ||
try { | ||
await this.activeTokenUpdating; | ||
} | ||
finally { | ||
this.activeTokenUpdating = null; | ||
} | ||
} | ||
refreshTokenAndReschedule(abortSignal) { | ||
return tslib.__awaiter(this, void 0, void 0, function* () { | ||
this.currentToken = yield this.refreshToken(abortSignal); | ||
if (this.refreshProactively) { | ||
this.scheduleRefresh(); | ||
} | ||
}); | ||
async refreshTokenAndReschedule(abortSignal) { | ||
this.currentToken = await this.refreshToken(abortSignal); | ||
if (this.refreshProactively) { | ||
this.scheduleRefresh(); | ||
} | ||
} | ||
refreshToken(abortSignal) { | ||
return tslib.__awaiter(this, void 0, void 0, function* () { | ||
try { | ||
if (!this.activeTokenFetching) { | ||
this.activeTokenFetching = this.refresh(abortSignal); | ||
} | ||
return parseToken(yield this.activeTokenFetching); | ||
async refreshToken(abortSignal) { | ||
try { | ||
if (!this.activeTokenFetching) { | ||
this.activeTokenFetching = this.refresh(abortSignal); | ||
} | ||
finally { | ||
this.activeTokenFetching = null; | ||
} | ||
}); | ||
return parseToken(await this.activeTokenFetching); | ||
} | ||
finally { | ||
this.activeTokenFetching = null; | ||
} | ||
} | ||
@@ -157,9 +148,7 @@ scheduleRefresh() { | ||
*/ | ||
getToken(options) { | ||
return tslib.__awaiter(this, void 0, void 0, function* () { | ||
this.throwIfDisposed(); | ||
const token = yield this.tokenCredential.getToken(options); | ||
this.throwIfDisposed(); | ||
return token; | ||
}); | ||
async getToken(options) { | ||
this.throwIfDisposed(); | ||
const token = await this.tokenCredential.getToken(options); | ||
this.throwIfDisposed(); | ||
return token; | ||
} | ||
@@ -181,8 +170,6 @@ /** | ||
// Copyright (c) Microsoft Corporation. | ||
const shaHash = (content) => tslib.__awaiter(void 0, void 0, void 0, function* () { | ||
return crypto.createHash("sha256") | ||
.update(content) | ||
.digest("base64"); | ||
}); | ||
const shaHMAC = (secret, content) => tslib.__awaiter(void 0, void 0, void 0, function* () { | ||
const shaHash = async (content) => crypto.createHash("sha256") | ||
.update(content) | ||
.digest("base64"); | ||
const shaHMAC = async (secret, content) => { | ||
const decodedSecret = Buffer.from(secret, "base64"); | ||
@@ -192,3 +179,3 @@ return crypto.createHmac("sha256", decodedSecret) | ||
.digest("base64"); | ||
}); | ||
}; | ||
@@ -228,24 +215,22 @@ // Copyright (c) Microsoft Corporation. | ||
*/ | ||
signRequest(webResource) { | ||
return tslib.__awaiter(this, void 0, void 0, function* () { | ||
const verb = webResource.method.toUpperCase(); | ||
const utcNow = new Date().toUTCString(); | ||
const contentHash = yield shaHash(webResource.body || ""); | ||
const dateHeader = coreHttp.isNode ? "date" : "x-ms-date"; | ||
const signedHeaders = `${dateHeader};host;x-ms-content-sha256`; | ||
const url = coreHttp.URLBuilder.parse(webResource.url); | ||
const query = url.getQuery(); | ||
const urlPathAndQuery = query ? `${url.getPath()}?${query}` : url.getPath(); | ||
const port = url.getPort(); | ||
const hostAndPort = port ? `${url.getHost()}:${port}` : url.getHost(); | ||
const stringToSign = `${verb}\n${urlPathAndQuery}\n${utcNow};${hostAndPort};${contentHash}`; | ||
const signature = yield shaHMAC(this.accessKey.key, stringToSign); | ||
{ | ||
webResource.headers.set("Host", hostAndPort || ""); | ||
} | ||
webResource.headers.set(dateHeader, utcNow); | ||
webResource.headers.set("x-ms-content-sha256", contentHash); | ||
webResource.headers.set("Authorization", `HMAC-SHA256 SignedHeaders=${signedHeaders}&Signature=${signature}`); | ||
return webResource; | ||
}); | ||
async signRequest(webResource) { | ||
const verb = webResource.method.toUpperCase(); | ||
const utcNow = new Date().toUTCString(); | ||
const contentHash = await shaHash(webResource.body || ""); | ||
const dateHeader = coreHttp.isNode ? "date" : "x-ms-date"; | ||
const signedHeaders = `${dateHeader};host;x-ms-content-sha256`; | ||
const url = coreHttp.URLBuilder.parse(webResource.url); | ||
const query = url.getQuery(); | ||
const urlPathAndQuery = query ? `${url.getPath()}?${query}` : url.getPath(); | ||
const port = url.getPort(); | ||
const hostAndPort = port ? `${url.getHost()}:${port}` : url.getHost(); | ||
const stringToSign = `${verb}\n${urlPathAndQuery}\n${utcNow};${hostAndPort};${contentHash}`; | ||
const signature = await shaHMAC(this.accessKey.key, stringToSign); | ||
{ | ||
webResource.headers.set("Host", hostAndPort || ""); | ||
} | ||
webResource.headers.set(dateHeader, utcNow); | ||
webResource.headers.set("x-ms-content-sha256", contentHash); | ||
webResource.headers.set("Authorization", `HMAC-SHA256 SignedHeaders=${signedHeaders}&Signature=${signature}`); | ||
return webResource; | ||
} | ||
@@ -255,9 +240,7 @@ /** | ||
*/ | ||
sendRequest(webResource) { | ||
return tslib.__awaiter(this, void 0, void 0, function* () { | ||
if (!webResource) { | ||
throw new Error("webResource cannot be null or undefined"); | ||
} | ||
return this._nextPolicy.sendRequest(yield this.signRequest(webResource)); | ||
}); | ||
async sendRequest(webResource) { | ||
if (!webResource) { | ||
throw new Error("webResource cannot be null or undefined"); | ||
} | ||
return this._nextPolicy.sendRequest(await this.signRequest(webResource)); | ||
} | ||
@@ -264,0 +247,0 @@ } |
{ | ||
"name": "@azure/communication-common", | ||
"version": "1.0.1-alpha.20210517.1", | ||
"version": "1.0.1-alpha.20210610.1", | ||
"description": "Common package for Azure Communication services.", | ||
@@ -5,0 +5,0 @@ "sdk-type": "client", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
147233
1314