Skip to content

Commit 09b18b6

Browse files
committed
feat(auth): auth extensions
Introduces TokenManager and supporting classes to handle token acquisition, automatic refresh, and updates via identity providers. This foundation enables consistent authentication token management across different identity provider implementations. Key additions: - Add TokenManager to obtain and maintain auth tokens from identity providers with automated refresh scheduling based on TTL and configurable thresholds - Add IdentityProvider interface for token acquisition from auth providers - Implement Token class for managing token state and TTL tracking - Include configurable retry mechanism with exponential backoff and jitter - Add comprehensive test suite covering refresh cycles and error handling This change establishes the core infrastructure needed for reliable token lifecycle management across different authentication providers.
1 parent a0c324b commit 09b18b6

13 files changed

+1156
-35
lines changed

package-lock.json

+145-5
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/authx/index.ts

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
export { TokenManager, TokenManagerConfig, TokenStreamListener, RetryPolicy, IDPError } from './lib/token-manager';
2+
export {
3+
CredentialsProvider,
4+
StreamingCredentialsProvider,
5+
UnableToObtainNewCredentialsError,
6+
CredentialsError,
7+
StreamingCredentialsListener,
8+
AsyncCredentialsProvider,
9+
ReAuthenticationError,
10+
BasicAuth
11+
} from './lib/credentials-provider';
12+
export { Token } from './lib/token';
13+
export { IdentityProvider, TokenResponse } from './lib/identity-provider';

packages/client/lib/client/authx/credentials-provider.ts packages/authx/lib/credentials-provider.ts

+1-6
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
12
/**
23
* Provides credentials asynchronously.
34
*/
@@ -66,12 +67,6 @@ export type StreamingCredentialsListener<T> = {
6667
onError: (e: Error) => void;
6768
}
6869

69-
/**
70-
* Disposable is an interface for objects that hold resources that should be released when they are no longer needed.
71-
*/
72-
export type Disposable = {
73-
dispose: () => void;
74-
}
7570

7671
/**
7772
* Providers that can supply authentication credentials
+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/**
2+
* An identity provider is responsible for providing a token that can be used to authenticate with a service.
3+
*/
4+
5+
/**
6+
* The response from an identity provider when requesting a token.
7+
*
8+
* note: "native" refers to the type of the token that the actual identity provider library is using.
9+
*
10+
* @type T The type of the native idp token.
11+
* @property token The token.
12+
* @property ttlMs The time-to-live of the token in epoch milliseconds extracted from the native token in local time.
13+
*/
14+
export type TokenResponse<T> = { token: T, ttlMs: number };
15+
16+
export interface IdentityProvider<T> {
17+
/**
18+
* Request a token from the identity provider.
19+
* @returns A promise that resolves to an object containing the token and the time-to-live in epoch milliseconds.
20+
*/
21+
requestToken(): Promise<TokenResponse<T>>;
22+
}

0 commit comments

Comments
 (0)