Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[core-rest-pipeline] expose tokenCycler #15294

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions common/config/rush/common-versions.json
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,8 @@
// @azure/test-utils-perfstress should depend on lowest version of @azure/core-http for maximum compatibility, allowing test
// projects to choose a higher version if desired.
"@azure/core-http": ["^1.0.0"],
// @azure/container-registry is using the beta.1 version for CAE support
"@azure/core-rest-pipeline": ["1.1.0-beta.1"],
// @azure/container-registry is using the beta.2 version for CAE support
"@azure/core-rest-pipeline": ["1.1.0-beta.2"],
// @azure/event-processor-host is on a much lower major version
"@azure/ms-rest-nodeauth": ["^0.9.2"],
// Idenity is moving from v1 to v2. Moving all packages to v2 is going to take a bit of time, in the mean time we could use v2 on the perf-identity tests.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@
"dependencies": {
"@azure/core-auth": "^1.3.0",
"@azure-rest/core-client": "1.0.0-beta.2",
"@azure/core-rest-pipeline": "1.1.0-beta.1",
"@azure/core-rest-pipeline": "1.1.0-beta.2",
"@azure/logger": "^1.0.0",
"tslib": "^2.0.0"
},
Expand Down
2 changes: 1 addition & 1 deletion sdk/containerregistry/container-registry/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@
"dependencies": {
"@azure/core-auth": "^1.3.0",
"@azure/core-client": "^1.0.0",
"@azure/core-rest-pipeline": "1.1.0-beta.1",
"@azure/core-rest-pipeline": "1.1.0-beta.2",
"@azure/core-paging": "^1.1.1",
"@azure/core-tracing": "1.0.0-preview.11",
"@azure/core-util": "^1.0.0-beta.1",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,15 @@ import { GetTokenOptions } from "@azure/core-auth";
import {
AuthorizeRequestOnChallengeOptions,
ChallengeCallbacks,
AccessTokenRefresher,
createTokenCycler,
AuthorizeRequestOptions
} from "@azure/core-rest-pipeline";
import { parseWWWAuthenticate } from "./wwwAuthenticateParser";
import {
ContainerRegistryGetTokenOptions,
ContainerRegistryRefreshTokenCredential
} from "./containerRegistryTokenCredential";
import { AccessTokenRefresher, createTokenCycler } from "./tokenCycler";

const fiveMinutesInMs = 5 * 60 * 1000;

Expand Down
220 changes: 0 additions & 220 deletions sdk/containerregistry/container-registry/src/tokenCycler.ts

This file was deleted.

2 changes: 1 addition & 1 deletion sdk/core-rest/core-client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@
"prettier": "@azure/eslint-plugin-azure-sdk/prettier.json",
"dependencies": {
"@azure/core-auth": "^1.3.0",
"@azure/core-rest-pipeline": "1.1.0-beta.1",
"@azure/core-rest-pipeline": "1.1.0-beta.2",
"tslib": "^2.0.0"
},
"devDependencies": {
Expand Down
15 changes: 15 additions & 0 deletions sdk/core/core-rest-pipeline/review/core-rest-pipeline.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,16 @@ import { GetTokenOptions } from '@azure/core-auth';
import { OperationTracingOptions } from '@azure/core-tracing';
import { TokenCredential } from '@azure/core-auth';

// @public
export interface AccessTokenRefresher<T extends GetTokenOptions> {
// (undocumented)
cachedToken: AccessToken | null;
// Warning: (ae-forgotten-export) The symbol "AccessTokenGetter" needs to be exported by the entry point index.d.ts
//
// (undocumented)
getToken: AccessTokenGetter<T>;
}

// @public
export interface AddPipelineOptions {
afterPhase?: PipelinePhase;
Expand Down Expand Up @@ -89,6 +99,11 @@ export function createPipelineFromOptions(options: InternalPipelineOptions): Pip
// @public
export function createPipelineRequest(options: PipelineRequestOptions): PipelineRequest;

// Warning: (ae-forgotten-export) The symbol "TokenCyclerOptions" needs to be exported by the entry point index.d.ts
//
// @public
export function createTokenCycler<T extends GetTokenOptions>(credential: TokenCredential, tokenCyclerOptions?: Partial<TokenCyclerOptions>): AccessTokenRefresher<T>;

// @public
export function decompressResponsePolicy(): PipelinePolicy;

Expand Down
1 change: 1 addition & 0 deletions sdk/core/core-rest-pipeline/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,3 +77,4 @@ export {
AuthorizeRequestOnChallengeOptions
} from "./policies/bearerTokenChallengeAuthenticationPolicy";
export { ndJsonPolicy, ndJsonPolicyName } from "./policies/ndJsonPolicy";
export { AccessTokenRefresher, createTokenCycler } from "./util/tokenCycler";
22 changes: 8 additions & 14 deletions sdk/core/core-rest-pipeline/src/util/tokenCycler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,17 @@ import { delay } from "./helpers";
*
* @param options - the options to pass to the underlying token provider
*/
export type AccessTokenGetter = (
export type AccessTokenGetter<T extends GetTokenOptions> = (
scopes: string | string[],
options: GetTokenOptions
options: T
) => Promise<AccessToken>;

/**
* The response of the
*/
export interface AccessTokenRefresher {
export interface AccessTokenRefresher<T extends GetTokenOptions> {
cachedToken: AccessToken | null;
getToken: AccessTokenGetter;
getToken: AccessTokenGetter<T>;
}

export interface TokenCyclerOptions {
Expand Down Expand Up @@ -112,10 +112,10 @@ async function beginRefresh(
*
* @returns - a function that reliably produces a valid access token
*/
export function createTokenCycler(
export function createTokenCycler<T extends GetTokenOptions>(
credential: TokenCredential,
tokenCyclerOptions?: Partial<TokenCyclerOptions>
): AccessTokenRefresher {
): AccessTokenRefresher<T> {
let refreshWorker: Promise<AccessToken> | null = null;
let token: AccessToken | null = null;

Expand Down Expand Up @@ -160,10 +160,7 @@ export function createTokenCycler(
* Starts a refresh job or returns the existing job if one is already
* running.
*/
function refresh(
scopes: string | string[],
getTokenOptions: GetTokenOptions
): Promise<AccessToken> {
function refresh(scopes: string | string[], getTokenOptions: T): Promise<AccessToken> {
if (!cycler.isRefreshing) {
// We bind `scopes` here to avoid passing it around a lot
const tryGetAccessToken = (): Promise<AccessToken | null> =>
Expand Down Expand Up @@ -199,10 +196,7 @@ export function createTokenCycler(
get cachedToken(): AccessToken | null {
return token;
},
getToken: async (
scopes: string | string[],
tokenOptions: GetTokenOptions
): Promise<AccessToken> => {
getToken: async (scopes: string | string[], tokenOptions: T): Promise<AccessToken> => {
//
// Simple rules:
// - If we MUST refresh, then return the refresh task, blocking
Expand Down
2 changes: 1 addition & 1 deletion sdk/core/perf-tests/core-rest-pipeline/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"author": "",
"license": "ISC",
"dependencies": {
"@azure/core-rest-pipeline": "1.1.0-beta.1",
"@azure/core-rest-pipeline": "1.1.0-beta.2",
"@azure/core-auth": "^1.3.0",
"@azure/test-utils-perfstress": "^1.0.0",
"dotenv": "^8.2.0"
Expand Down