CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/npm-azure--core-auth

Provides low-level interfaces and helper methods for authentication in Azure SDK

Overall
score

97%

Overview
Eval results
Files

task.mdevals/scenario-7/

Token Fetcher with Cancellation Support

Build a token management utility that retrieves authentication tokens with support for request cancellation.

Requirements

Your utility should provide a function that retrieves authentication tokens from a credential provider while supporting:

  1. Request Cancellation: Allow callers to cancel in-flight token requests using an abort signal
  2. Scope-Based Requests: Accept authentication scopes for token requests
  3. Error Handling: Properly handle cancellation errors

Implementation Details

Create a module that exports a fetchTokenWithCancellation function with the following behavior:

  • Accepts a credential object, an array of scopes, and an options object with an optional abortSignal property
  • Calls the credential's token retrieval method with the provided options
  • Returns the retrieved token on success
  • Throws an error when the request is cancelled
  • Properly propagates cancellation to the underlying credential

Test Cases

  • When given valid credential and scopes without cancellation, it successfully retrieves a token @test
  • When the abort signal is triggered before the request starts, it throws an error immediately @test
  • When the abort signal is triggered during token retrieval, it cancels the request and throws an error @test

Implementation

@generates

API

export interface FetchTokenOptions {
  abortSignal?: AbortSignalLike;
}

export async function fetchTokenWithCancellation(
  credential: TokenCredential,
  scopes: string[],
  options?: FetchTokenOptions
): Promise<AccessToken>;

Dependencies { .dependencies }

@azure/core-auth { .dependency }

Provides authentication interfaces and token credential types.

@satisfied-by

@azure/abort-controller { .dependency }

Provides abort signal and controller types for cancellation support.

@satisfied-by

Install with Tessl CLI

npx tessl i tessl/npm-azure--core-auth

tile.json