Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@azure/core-rest-pipeline

Package Overview
Dependencies
Maintainers
3
Versions
316
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.0.3 to 1.1.0-beta.1

dist-esm/src/policies/bearerTokenChallengeAuthenticationPolicy.js

13

CHANGELOG.md
# Release History
## 1.1.0-beta.1 (2021-05-06)
### Features Added
- Add a new `bearerTokenChallengeAuthenticationPolicy` that provides a skeleton of handling challenge-based authorization. There are two extensible points: `authorizeRequest` and `authorizeRequestOnChallenge` callbacks.
- `authorizeRequest` allows customizing the policy to alter how it authorizes a request before sending it. By default when no callbacks are specified, this policy has the same behavior as `bearerTokenAuthenticationPolicy`. It will retrieve the token from the underlying token credential, and if it gets one, it will cache the token and set it to the outgoing request.
- `authorizeRequestOnChallenge`, which gets called only if we've found a challenge in the response. This callback has access to the original request and its response and is expected to handle the challenge. If this callback returns true, the request, usually updated after handling the challenge, will be sent again. If this call back returns false, no further actions will be taken.
### Fixed
- Rewrote `bearerTokenAuthenticationPolicy` to use a new backend that refreshes tokens only when they're about to expire and not multiple times before. This is based on a similar fix implemented on `@azure/core-http@1.2.4` ([PR with the changes](https://github.com/Azure/azure-sdk-for-js/pull/14223)). This fixes the issue: [13369](https://github.com/Azure/azure-sdk-for-js/issues/13369).
- Delay loading of NO_PROXY environment variable until when request pipeline is being created. This fixes [issue 14873](https://github.com/Azure/azure-sdk-for-js/issues/14873)
## 1.0.3 (2021-03-30)

@@ -4,0 +17,0 @@

2

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

@@ -20,3 +20,4 @@ // 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
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.
import { __awaiter } from "tslib";
import { ExpiringAccessTokenCache } from "../accessTokenCache";
import { createTokenCycler } from "../util/tokenCycler";
/**

@@ -15,13 +15,7 @@ * The programmatic identifier of the bearerTokenAuthenticationPolicy.

const { credential, scopes } = options;
const tokenCache = new ExpiringAccessTokenCache();
function getToken(tokenOptions) {
return __awaiter(this, void 0, void 0, function* () {
let accessToken = tokenCache.getCachedToken();
if (accessToken === undefined) {
accessToken = (yield credential.getToken(scopes, tokenOptions)) || undefined;
tokenCache.setCachedToken(accessToken);
}
return accessToken ? accessToken.token : undefined;
});
}
// This function encapsulates the entire process of reliably retrieving the token
// The options are left out of the public API until there's demand to configure this.
// Remember to extend `BearerTokenAuthenticationPolicyOptions` with `TokenCyclerOptions`
// in order to pass through the `options` object.
const cycler = createTokenCycler(credential /* , options */);
return {

@@ -31,3 +25,3 @@ name: bearerTokenAuthenticationPolicyName,

return __awaiter(this, void 0, void 0, function* () {
const token = yield getToken({
const { token } = yield cycler.getToken(scopes, {
abortSignal: request.abortSignal,

@@ -34,0 +28,0 @@ tracingOptions: request.tracingOptions

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

export const proxyPolicyName = "proxyPolicy";
export const noProxyList = loadNoProxy();
export const noProxyList = [];
let noProxyListLoaded = false;
const byPassedList = new Map();

@@ -73,2 +74,3 @@ let httpsProxyAgent;

const noProxy = getEnvironmentValue(NO_PROXY);
noProxyListLoaded = true;
if (noProxy) {

@@ -151,2 +153,5 @@ return noProxy

export function proxyPolicy(proxySettings = getDefaultProxySettings()) {
if (!noProxyListLoaded) {
noProxyList.push(...loadNoProxy());
}
return {

@@ -153,0 +158,0 @@ name: proxyPolicyName,

{
"name": "@azure/core-rest-pipeline",
"version": "1.0.3",
"version": "1.1.0-beta.1",
"description": "Isomorphic client library for making HTTP requests in node.js and browser.",

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

/// <reference types="node" />
import { AbortSignalLike } from '@azure/abort-controller';
import { AccessToken } from '@azure/core-auth';
import { Debugger } from '@azure/logger';
import { GetTokenOptions } from '@azure/core-auth';
import { OperationTracingOptions } from '@azure/core-tracing';

@@ -56,2 +58,40 @@ import { TokenCredential } from '@azure/core-auth';

/**
* Options sent to the authorizeRequestOnChallenge callback
*/
export declare interface AuthorizeRequestOnChallengeOptions {
/**
* The scopes for which the bearer token applies.
*/
scopes: string[];
/**
* Function that retrieves either a cached access token or a new access token.
*/
getAccessToken: (scopes: string[], options: GetTokenOptions) => Promise<AccessToken | null>;
/**
* Request that the policy is trying to fulfill.
*/
request: PipelineRequest;
/**
* Response containing the challenge.
*/
response: PipelineResponse;
}
/**
* Options sent to the authorizeRequest callback
*/
export declare interface AuthorizeRequestOptions {
/**
* The scopes for which the bearer token applies.
*/
scopes: string[];
/**
* Function that retrieves either a cached access token or a new access token.
*/
getAccessToken: (scopes: string[], options: GetTokenOptions) => Promise<AccessToken | null>;
/**
* Request that the policy is trying to fulfill.
*/
request: PipelineRequest;
}
/**
* A policy that can request a token from a TokenCredential implementation and

@@ -79,2 +119,46 @@ * then apply it to the Authorization header of a request as a Bearer token.

/**
* 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.
* If provided, it must contain at least the `authorizeRequestOnChallenge` method.
* If provided, after a request is sent, if it has a challenge, it can be processed to re-send the original request with the relevant challenge information.
*/
challengeCallbacks?: ChallengeCallbacks;
}
/**
* Options to override the processing of [Continuous Access Evaluation](https://docs.microsoft.com/azure/active-directory/conditional-access/concept-continuous-access-evaluation) challenges.
*/
export declare interface ChallengeCallbacks {
/**
* Allows for the authorization of the main request of this policy before it's sent.
*/
authorizeRequest?(options: AuthorizeRequestOptions): Promise<void>;
/**
* Allows to handle authentication challenges and to re-authorize the request.
* The response containing the challenge is `options.response`.
* If this method returns true, the underlying request will be sent once again.
* The request may be modified before being sent.
*/
authorizeRequestOnChallenge?(options: AuthorizeRequestOnChallengeOptions): Promise<boolean>;
}
/**
* Create the correct HttpClient for the current environment.

@@ -81,0 +165,0 @@ */

/// <reference types="node" />
import { AbortSignalLike } from '@azure/abort-controller';
import { AccessToken } from '@azure/core-auth';
import { Debugger } from '@azure/logger';
import { GetTokenOptions } from '@azure/core-auth';
import { OperationTracingOptions } from '@azure/core-tracing';

@@ -59,2 +61,42 @@ import { TokenCredential } from '@azure/core-auth';

/**
* Options sent to the authorizeRequestOnChallenge callback
*/
export declare interface AuthorizeRequestOnChallengeOptions {
/**
* The scopes for which the bearer token applies.
*/
scopes: string[];
/**
* Function that retrieves either a cached access token or a new access token.
*/
getAccessToken: (scopes: string[], options: GetTokenOptions) => Promise<AccessToken | null>;
/**
* Request that the policy is trying to fulfill.
*/
request: PipelineRequest;
/**
* Response containing the challenge.
*/
response: PipelineResponse;
}
/**
* Options sent to the authorizeRequest callback
*/
export declare interface AuthorizeRequestOptions {
/**
* The scopes for which the bearer token applies.
*/
scopes: string[];
/**
* Function that retrieves either a cached access token or a new access token.
*/
getAccessToken: (scopes: string[], options: GetTokenOptions) => Promise<AccessToken | null>;
/**
* Request that the policy is trying to fulfill.
*/
request: PipelineRequest;
}
/**
* A policy that can request a token from a TokenCredential implementation and

@@ -85,2 +127,50 @@ * then apply it to the Authorization header of a request as a Bearer token.

/**
* 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.
* If provided, it must contain at least the `authorizeRequestOnChallenge` method.
* If provided, after a request is sent, if it has a challenge, it can be processed to re-send the original request with the relevant challenge information.
*/
challengeCallbacks?: ChallengeCallbacks;
}
/**
* Options to override the processing of [Continuous Access Evaluation](https://docs.microsoft.com/azure/active-directory/conditional-access/concept-continuous-access-evaluation) challenges.
*/
export declare interface ChallengeCallbacks {
/**
* Allows for the authorization of the main request of this policy before it's sent.
*/
authorizeRequest?(options: AuthorizeRequestOptions): Promise<void>;
/**
* Allows to handle authentication challenges and to re-authorize the request.
* The response containing the challenge is `options.response`.
* If this method returns true, the underlying request will be sent once again.
* The request may be modified before being sent.
*/
authorizeRequestOnChallenge?(options: AuthorizeRequestOnChallengeOptions): Promise<boolean>;
}
/**
* Create the correct HttpClient for the current environment.

@@ -87,0 +177,0 @@ */

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