Socket
Socket
Sign inDemoInstall

@azure/core-rest-pipeline

Package Overview
Dependencies
Maintainers
3
Versions
290
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@azure/core-rest-pipeline - npm Package Compare versions

Comparing version 1.1.0-beta.2 to 1.1.0-beta.3

4

CHANGELOG.md
# Release History
## 1.1.0-beta.3 (2021-06-03)
- Merged `bearerTokenChallengeAuthenticationPolicy` into `bearerTokenAuthenticationPolicy`. This will keep the functionality of `bearerTokenAuthenticationPolicy`, but also adds the `challengeCallbacks` feature.
## 1.1.0-beta.2 (2021-05-20)

@@ -4,0 +8,0 @@

2

dist-esm/src/constants.js
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.
export const SDK_VERSION = "1.1.0-beta.2";
export const SDK_VERSION = "1.1.0-beta.3";
//# sourceMappingURL=constants.js.map

@@ -20,4 +20,3 @@ // Copyright (c) Microsoft Corporation.

export { bearerTokenAuthenticationPolicy, bearerTokenAuthenticationPolicyName } from "./policies/bearerTokenAuthenticationPolicy";
export { bearerTokenChallengeAuthenticationPolicy, bearerTokenChallengeAuthenticationPolicyName } from "./policies/bearerTokenChallengeAuthenticationPolicy";
export { ndJsonPolicy, ndJsonPolicyName } from "./policies/ndJsonPolicy";
//# sourceMappingURL=index.js.map

@@ -10,2 +10,29 @@ // Copyright (c) Microsoft Corporation.

/**
* Default authorize request handler
*/
function defaultAuthorizeRequest(options) {
return __awaiter(this, void 0, void 0, function* () {
const { scopes, getAccessToken, request } = options;
const getTokenOptions = {
abortSignal: request.abortSignal,
tracingOptions: request.tracingOptions
};
const accessToken = yield getAccessToken(scopes, getTokenOptions);
if (accessToken) {
options.request.headers.set("Authorization", `Bearer ${accessToken.token}`);
}
});
}
/**
* We will retrieve the challenge only if the response status code was 401,
* and if the response contained the header "WWW-Authenticate" with a non-empty value.
*/
function getChallenge(response) {
const challenge = response.headers.get("WWW-Authenticate");
if (response.status === 401 && challenge) {
return challenge;
}
return;
}
/**
* A policy that can request a token from a TokenCredential implementation and

@@ -15,3 +42,5 @@ * then apply it to the Authorization header of a request as a Bearer token.

export function bearerTokenAuthenticationPolicy(options) {
const { credential, scopes } = options;
var _a;
const { credential, scopes, challengeCallbacks } = options;
const callbacks = Object.assign({ authorizeRequest: (_a = challengeCallbacks === null || challengeCallbacks === void 0 ? void 0 : challengeCallbacks.authorizeRequest) !== null && _a !== void 0 ? _a : defaultAuthorizeRequest, authorizeRequestOnChallenge: challengeCallbacks === null || challengeCallbacks === void 0 ? void 0 : challengeCallbacks.authorizeRequestOnChallenge }, challengeCallbacks);
// This function encapsulates the entire process of reliably retrieving the token

@@ -21,13 +50,56 @@ // The options are left out of the public API until there's demand to configure this.

// in order to pass through the `options` object.
const cycler = createTokenCycler(credential /* , options */);
const getAccessToken = credential
? createTokenCycler(credential /* , options */)
: () => Promise.resolve(null);
return {
name: bearerTokenAuthenticationPolicyName,
/**
* If there's no challenge parameter:
* - It will try to retrieve the token using the cache, or the credential's getToken.
* - Then it will try the next policy with or without the retrieved token.
*
* It uses the challenge parameters to:
* - Skip a first attempt to get the token from the credential if there's no cached token,
* since it expects the token to be retrievable only after the challenge.
* - Prepare the outgoing request if the `prepareRequest` method has been provided.
* - Send an initial request to receive the challenge if it fails.
* - Process a challenge if the response contains it.
* - Retrieve a token with the challenge information, then re-send the request.
*/
sendRequest(request, next) {
return __awaiter(this, void 0, void 0, function* () {
const { token } = yield cycler.getToken(scopes, {
abortSignal: request.abortSignal,
tracingOptions: request.tracingOptions
yield callbacks.authorizeRequest({
scopes: Array.isArray(scopes) ? scopes : [scopes],
request,
getAccessToken
});
request.headers.set("Authorization", `Bearer ${token}`);
return next(request);
let response;
let error;
try {
response = yield next(request);
}
catch (err) {
error = err;
response = err.response;
}
if (callbacks.authorizeRequestOnChallenge &&
(response === null || response === void 0 ? void 0 : response.status) === 401 &&
getChallenge(response)) {
// processes challenge
const shouldSendRequest = yield callbacks.authorizeRequestOnChallenge({
scopes: Array.isArray(scopes) ? scopes : [scopes],
request,
response,
getAccessToken
});
if (shouldSendRequest) {
return next(request);
}
}
if (error) {
throw error;
}
else {
return response;
}
});

@@ -34,0 +106,0 @@ }

@@ -6,2 +6,3 @@ // Copyright (c) Microsoft Corporation.

* A constant that indicates whether the environment the code is running is Node.JS.
* @internal
*/

@@ -11,2 +12,3 @@ export const isNode = typeof process !== "undefined" && Boolean(process.version) && Boolean((_a = process.versions) === null || _a === void 0 ? void 0 : _a.node);

* A wrapper for setTimeout that resolves a promise after t milliseconds.
* @internal
* @param t - The number of milliseconds to be delayed.

@@ -38,2 +40,13 @@ * @param value - The value to be resolved with after a timeout of t milliseconds.

}
/**
* @internal
* @returns true when input is an object type that is not null, Array, RegExp, or Date.
*/
export function isObject(input) {
return (typeof input === "object" &&
input !== null &&
!Array.isArray(input) &&
!(input instanceof RegExp) &&
!(input instanceof Date));
}
//# sourceMappingURL=helpers.js.map
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.
import { isObject } from "./helpers";
import { URL } from "./url";

@@ -57,33 +58,39 @@ const RedactedString = "REDACTED";

sanitize(obj) {
return JSON.stringify(obj, this.replacer.bind(this), 2);
const seen = new Set();
return JSON.stringify(obj, (key, value) => {
// Ensure Errors include their interesting non-enumerable members
if (value instanceof Error) {
return Object.assign(Object.assign({}, value), { name: value.name, message: value.message });
}
if (key === "headers") {
return this.sanitizeHeaders(value);
}
else if (key === "url") {
return this.sanitizeUrl(value);
}
else if (key === "query") {
return this.sanitizeQuery(value);
}
else if (key === "body") {
// Don't log the request body
return undefined;
}
else if (key === "response") {
// Don't log response again
return undefined;
}
else if (key === "operationSpec") {
// When using sendOperationRequest, the request carries a massive
// field with the autorest spec. No need to log it.
return undefined;
}
else if (Array.isArray(value) || isObject(value)) {
if (seen.has(value)) {
return "[Circular]";
}
seen.add(value);
}
return value;
}, 2);
}
replacer(key, value) {
// Ensure Errors include their interesting non-enumerable members
if (value instanceof Error) {
return Object.assign(Object.assign({}, value), { name: value.name, message: value.message });
}
if (key === "headers") {
return this.sanitizeHeaders(value);
}
else if (key === "url") {
return this.sanitizeUrl(value);
}
else if (key === "query") {
return this.sanitizeQuery(value);
}
else if (key === "body") {
// Don't log the request body
return undefined;
}
else if (key === "response") {
// Don't log response again
return undefined;
}
else if (key === "operationSpec") {
// When using sendOperationRequest, the request carries a massive
// field with the autorest spec. No need to log it.
return undefined;
}
return value;
}
sanitizeHeaders(obj) {

@@ -90,0 +97,0 @@ const sanitized = {};

@@ -129,25 +129,20 @@ // Copyright (c) Microsoft Corporation.

}
return {
get cachedToken() {
return token;
},
getToken: (scopes, tokenOptions) => __awaiter(this, void 0, void 0, function* () {
//
// Simple rules:
// - If we MUST refresh, then return the refresh task, blocking
// the pipeline until a token is available.
// - If we SHOULD refresh, then run refresh but don't return it
// (we can still use the cached token).
// - Return the token, since it's fine if we didn't return in
// step 1.
//
if (cycler.mustRefresh)
return refresh(scopes, tokenOptions);
if (cycler.shouldRefresh) {
refresh(scopes, tokenOptions);
}
return token;
})
};
return (scopes, tokenOptions) => __awaiter(this, void 0, void 0, function* () {
//
// Simple rules:
// - If we MUST refresh, then return the refresh task, blocking
// the pipeline until a token is available.
// - If we SHOULD refresh, then run refresh but don't return it
// (we can still use the cached token).
// - Return the token, since it's fine if we didn't return in
// step 1.
//
if (cycler.mustRefresh)
return refresh(scopes, tokenOptions);
if (cycler.shouldRefresh) {
refresh(scopes, tokenOptions);
}
return token;
});
}
//# sourceMappingURL=tokenCycler.js.map
{
"name": "@azure/core-rest-pipeline",
"version": "1.1.0-beta.2",
"version": "1.1.0-beta.3",
"description": "Isomorphic client library for making HTTP requests in node.js and browser.",

@@ -5,0 +5,0 @@ "sdk-type": "client",

@@ -111,3 +111,3 @@ /// <reference types="node" />

*/
credential: TokenCredential;
credential?: TokenCredential;
/**

@@ -117,25 +117,3 @@ * The scopes for which the bearer token applies.

scopes: string | string[];
}
/**
* A policy that can request a token from a TokenCredential implementation and
* then apply it to the Authorization header of a request as a Bearer token.
*/
export declare function bearerTokenChallengeAuthenticationPolicy(options: BearerTokenChallengeAuthenticationPolicyOptions): PipelinePolicy;
/**
* The programmatic identifier of the bearerTokenChallengeAuthenticationPolicy.
*/
export declare const bearerTokenChallengeAuthenticationPolicyName = "bearerTokenChallengeAuthenticationPolicy";
/**
* Options to configure the bearerTokenChallengeAuthenticationPolicy
*/
export declare interface BearerTokenChallengeAuthenticationPolicyOptions {
/**
* The TokenCredential implementation that can supply the bearer token.
*/
credential?: TokenCredential;
/**
* The scopes for which the bearer token applies.
*/
scopes: string[];
/**
* Allows for the processing of [Continuous Access Evaluation](https://docs.microsoft.com/azure/active-directory/conditional-access/concept-continuous-access-evaluation) challenges.

@@ -142,0 +120,0 @@ * If provided, it must contain at least the `authorizeRequestOnChallenge` method.

@@ -118,3 +118,3 @@ /// <reference types="node" />

*/
credential: TokenCredential;
credential?: TokenCredential;
/**

@@ -124,28 +124,3 @@ * The scopes for which the bearer token applies.

scopes: string | string[];
}
/**
* A policy that can request a token from a TokenCredential implementation and
* then apply it to the Authorization header of a request as a Bearer token.
*/
export declare function bearerTokenChallengeAuthenticationPolicy(options: BearerTokenChallengeAuthenticationPolicyOptions): PipelinePolicy;
/**
* The programmatic identifier of the bearerTokenChallengeAuthenticationPolicy.
*/
export declare const bearerTokenChallengeAuthenticationPolicyName = "bearerTokenChallengeAuthenticationPolicy";
/**
* Options to configure the bearerTokenChallengeAuthenticationPolicy
*/
export declare interface BearerTokenChallengeAuthenticationPolicyOptions {
/**
* The TokenCredential implementation that can supply the bearer token.
*/
credential?: TokenCredential;
/**
* The scopes for which the bearer token applies.
*/
scopes: string[];
/**
* Allows for the processing of [Continuous Access Evaluation](https://docs.microsoft.com/azure/active-directory/conditional-access/concept-continuous-access-evaluation) challenges.

@@ -152,0 +127,0 @@ * If provided, it must contain at least the `authorizeRequestOnChallenge` method.

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 too big to display

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc