@okta/auth-foundation 0.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +189 -0
- package/THIRD-PARTY-NOTICES.md +5 -0
- package/dist/esm/Credential/Credential.js +219 -0
- package/dist/esm/Credential/Credential.js.map +1 -0
- package/dist/esm/Credential/CredentialCoordinator.js +160 -0
- package/dist/esm/Credential/CredentialCoordinator.js.map +1 -0
- package/dist/esm/Credential/CredentialDataSource.js +61 -0
- package/dist/esm/Credential/CredentialDataSource.js.map +1 -0
- package/dist/esm/Credential/TokenStorage.js +99 -0
- package/dist/esm/Credential/TokenStorage.js.map +1 -0
- package/dist/esm/FetchClient.js +91 -0
- package/dist/esm/FetchClient.js.map +1 -0
- package/dist/esm/Token.js +274 -0
- package/dist/esm/Token.js.map +1 -0
- package/dist/esm/TokenOrchestrator.js +56 -0
- package/dist/esm/TokenOrchestrator.js.map +1 -0
- package/dist/esm/core.js +59 -0
- package/dist/esm/core.js.map +1 -0
- package/dist/esm/crypto/index.js +60 -0
- package/dist/esm/crypto/index.js.map +1 -0
- package/dist/esm/errors/APIClientError.js +19 -0
- package/dist/esm/errors/APIClientError.js.map +1 -0
- package/dist/esm/errors/AuthSdkError.js +22 -0
- package/dist/esm/errors/AuthSdkError.js.map +1 -0
- package/dist/esm/errors/CredentialError.js +19 -0
- package/dist/esm/errors/CredentialError.js.map +1 -0
- package/dist/esm/errors/DPoPError.js +19 -0
- package/dist/esm/errors/DPoPError.js.map +1 -0
- package/dist/esm/errors/JWTError.js +19 -0
- package/dist/esm/errors/JWTError.js.map +1 -0
- package/dist/esm/errors/NetworkError.js +19 -0
- package/dist/esm/errors/NetworkError.js.map +1 -0
- package/dist/esm/errors/OAuth2Error.js +34 -0
- package/dist/esm/errors/OAuth2Error.js.map +1 -0
- package/dist/esm/errors/TokenError.js +19 -0
- package/dist/esm/errors/TokenError.js.map +1 -0
- package/dist/esm/errors/TokenOrchestratorError.js +19 -0
- package/dist/esm/errors/TokenOrchestratorError.js.map +1 -0
- package/dist/esm/http/APIClient.js +172 -0
- package/dist/esm/http/APIClient.js.map +1 -0
- package/dist/esm/http/oktaUserAgent.js +23 -0
- package/dist/esm/http/oktaUserAgent.js.map +1 -0
- package/dist/esm/http/requests/APIRequest.js +41 -0
- package/dist/esm/http/requests/APIRequest.js.map +1 -0
- package/dist/esm/http/requests/OAuth2Request.js +38 -0
- package/dist/esm/http/requests/OAuth2Request.js.map +1 -0
- package/dist/esm/http/wwwAuthenticate.js +48 -0
- package/dist/esm/http/wwwAuthenticate.js.map +1 -0
- package/dist/esm/index.js +64 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/internal.js +17 -0
- package/dist/esm/internal.js.map +1 -0
- package/dist/esm/jwt/IDTokenValidator.js +115 -0
- package/dist/esm/jwt/IDTokenValidator.js.map +1 -0
- package/dist/esm/jwt/JWK.js +48 -0
- package/dist/esm/jwt/JWK.js.map +1 -0
- package/dist/esm/jwt/JWT.js +159 -0
- package/dist/esm/jwt/JWT.js.map +1 -0
- package/dist/esm/jwt/TokenHashValidator.js +44 -0
- package/dist/esm/jwt/TokenHashValidator.js.map +1 -0
- package/dist/esm/oauth2/client.js +386 -0
- package/dist/esm/oauth2/client.js.map +1 -0
- package/dist/esm/oauth2/configuration.js +86 -0
- package/dist/esm/oauth2/configuration.js.map +1 -0
- package/dist/esm/oauth2/dpop/index.js +84 -0
- package/dist/esm/oauth2/dpop/index.js.map +1 -0
- package/dist/esm/oauth2/dpop/nonceCache.js +31 -0
- package/dist/esm/oauth2/dpop/nonceCache.js.map +1 -0
- package/dist/esm/oauth2/dpop/storage.js +39 -0
- package/dist/esm/oauth2/dpop/storage.js.map +1 -0
- package/dist/esm/oauth2/pkce.js +33 -0
- package/dist/esm/oauth2/pkce.js.map +1 -0
- package/dist/esm/oauth2/requests/UserInfo.js +40 -0
- package/dist/esm/oauth2/requests/UserInfo.js.map +1 -0
- package/dist/esm/platform/Platform.js +54 -0
- package/dist/esm/platform/Platform.js.map +1 -0
- package/dist/esm/platform/defaults.js +28 -0
- package/dist/esm/platform/defaults.js.map +1 -0
- package/dist/esm/types/oauth.js +41 -0
- package/dist/esm/types/oauth.js.map +1 -0
- package/dist/esm/utils/EventEmitter.js +63 -0
- package/dist/esm/utils/EventEmitter.js.map +1 -0
- package/dist/esm/utils/PromiseQueue.js +50 -0
- package/dist/esm/utils/PromiseQueue.js.map +1 -0
- package/dist/esm/utils/TaskBridge.js +242 -0
- package/dist/esm/utils/TaskBridge.js.map +1 -0
- package/dist/esm/utils/TimeCoordinator.js +77 -0
- package/dist/esm/utils/TimeCoordinator.js.map +1 -0
- package/dist/esm/utils/buildUrl.js +23 -0
- package/dist/esm/utils/buildUrl.js.map +1 -0
- package/dist/esm/utils/equality.js +38 -0
- package/dist/esm/utils/equality.js.map +1 -0
- package/dist/esm/utils/getSearchParam.js +24 -0
- package/dist/esm/utils/getSearchParam.js.map +1 -0
- package/dist/esm/utils/hashObject.js +30 -0
- package/dist/esm/utils/hashObject.js.map +1 -0
- package/dist/esm/utils/ignoreUndefineds.js +24 -0
- package/dist/esm/utils/ignoreUndefineds.js.map +1 -0
- package/dist/esm/utils/merge.js +47 -0
- package/dist/esm/utils/merge.js.map +1 -0
- package/dist/esm/utils/pause.js +20 -0
- package/dist/esm/utils/pause.js.map +1 -0
- package/dist/esm/utils/toRelativeUrl.js +19 -0
- package/dist/esm/utils/toRelativeUrl.js.map +1 -0
- package/dist/esm/utils/validators.js +32 -0
- package/dist/esm/utils/validators.js.map +1 -0
- package/dist/types/Credential/Credential.d.ts +292 -0
- package/dist/types/Credential/CredentialCoordinator.d.ts +103 -0
- package/dist/types/Credential/CredentialDataSource.d.ts +75 -0
- package/dist/types/Credential/TokenStorage.d.ts +116 -0
- package/dist/types/Credential/index.d.ts +8 -0
- package/dist/types/FetchClient.d.ts +28 -0
- package/dist/types/Token.d.ts +246 -0
- package/dist/types/TokenOrchestrator.d.ts +64 -0
- package/dist/types/core.d.ts +21 -0
- package/dist/types/crypto/index.d.ts +32 -0
- package/dist/types/errors/APIClientError.d.ts +12 -0
- package/dist/types/errors/AuthSdkError.d.ts +20 -0
- package/dist/types/errors/CredentialError.d.ts +12 -0
- package/dist/types/errors/DPoPError.d.ts +12 -0
- package/dist/types/errors/JWTError.d.ts +12 -0
- package/dist/types/errors/NetworkError.d.ts +12 -0
- package/dist/types/errors/OAuth2Error.d.ts +17 -0
- package/dist/types/errors/TokenError.d.ts +12 -0
- package/dist/types/errors/TokenOrchestratorError.d.ts +12 -0
- package/dist/types/errors/index.d.ts +13 -0
- package/dist/types/http/APIClient.d.ts +113 -0
- package/dist/types/http/index.d.ts +6 -0
- package/dist/types/http/oktaUserAgent.d.ts +8 -0
- package/dist/types/http/requests/APIRequest.d.ts +19 -0
- package/dist/types/http/requests/OAuth2Request.d.ts +30 -0
- package/dist/types/http/wwwAuthenticate.d.ts +32 -0
- package/dist/types/index.d.ts +4 -0
- package/dist/types/internal.d.ts +8 -0
- package/dist/types/jwt/IDTokenValidator.d.ts +38 -0
- package/dist/types/jwt/JWK.d.ts +31 -0
- package/dist/types/jwt/JWT.d.ts +107 -0
- package/dist/types/jwt/TokenHashValidator.d.ts +13 -0
- package/dist/types/jwt/index.d.ts +8 -0
- package/dist/types/oauth2/client.d.ts +120 -0
- package/dist/types/oauth2/configuration.d.ts +56 -0
- package/dist/types/oauth2/dpop/index.d.ts +70 -0
- package/dist/types/oauth2/dpop/nonceCache.d.ts +27 -0
- package/dist/types/oauth2/dpop/storage.d.ts +27 -0
- package/dist/types/oauth2/dpop/types.d.ts +52 -0
- package/dist/types/oauth2/pkce.d.ts +23 -0
- package/dist/types/oauth2/requests/UserInfo.d.ts +32 -0
- package/dist/types/platform/Platform.d.ts +121 -0
- package/dist/types/platform/defaults.d.ts +10 -0
- package/dist/types/types/index.d.ts +6 -0
- package/dist/types/types/lib.d.ts +106 -0
- package/dist/types/types/oauth.d.ts +117 -0
- package/dist/types/types/openid.d.ts +320 -0
- package/dist/types/utils/EventEmitter.d.ts +29 -0
- package/dist/types/utils/PromiseQueue.d.ts +18 -0
- package/dist/types/utils/TaskBridge.d.ts +153 -0
- package/dist/types/utils/TimeCoordinator.d.ts +49 -0
- package/dist/types/utils/buildUrl.d.ts +10 -0
- package/dist/types/utils/equality.d.ts +19 -0
- package/dist/types/utils/getSearchParam.d.ts +13 -0
- package/dist/types/utils/hashObject.d.ts +6 -0
- package/dist/types/utils/ignoreUndefineds.d.ts +14 -0
- package/dist/types/utils/index.d.ts +13 -0
- package/dist/types/utils/merge.d.ts +16 -0
- package/dist/types/utils/pause.d.ts +15 -0
- package/dist/types/utils/toRelativeUrl.d.ts +10 -0
- package/dist/types/utils/validators.d.ts +6 -0
- package/package.json +1 -0
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { APIClient, APIRequest, WWWAuth } from './http/index.ts';
|
|
2
|
+
import { TokenOrchestrator } from './TokenOrchestrator.ts';
|
|
3
|
+
/**
|
|
4
|
+
* @module FetchClient
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* Wrapper around [fetch](https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API) to perform authenticated requests
|
|
8
|
+
* to a resource server
|
|
9
|
+
*
|
|
10
|
+
* The provided {@link TokenOrchestrator} is used to retrieve {@link Token}s which match the criteria passed in via
|
|
11
|
+
* {@link TokenOrchestrator.AuthorizeParams}, like `issuer`, `client` and `scopes`. Once a valid {@link Token} is found, the request is made
|
|
12
|
+
*/
|
|
13
|
+
export declare class FetchClient<E extends APIClient.Events = APIClient.Events> extends APIClient<E> {
|
|
14
|
+
private readonly orchestrator;
|
|
15
|
+
constructor(orchestrator: TokenOrchestrator, ...[params]: ConstructorParameters<typeof APIClient>);
|
|
16
|
+
/**
|
|
17
|
+
* default options
|
|
18
|
+
*/
|
|
19
|
+
defaultRequestOptions: APIClient.RequestOptions;
|
|
20
|
+
protected checkForDPoPNonceErrorResponse(response: Response): Promise<string | undefined>;
|
|
21
|
+
protected prepareDPoPNonceRetry(request: APIRequest, nonce: string): Promise<void>;
|
|
22
|
+
protected prepareAcrStepUpRetry(response: Response, request: APIRequest, error: WWWAuth.WWWAuthenticateError): Promise<void>;
|
|
23
|
+
protected processErrorResponse(response: Response, request: APIRequest): Promise<Response>;
|
|
24
|
+
protected prepare401Retry(response: Response, request: APIRequest): Promise<void>;
|
|
25
|
+
protected prepare429Retry(response: Response, request: APIRequest): Promise<void>;
|
|
26
|
+
protected authorize(request: APIRequest): Promise<void>;
|
|
27
|
+
fetch(input: string | URL | Request, init?: TokenOrchestrator.AuthorizeParams & RequestInit & Partial<APIClient.RequestOptions>): Promise<Response>;
|
|
28
|
+
}
|
|
@@ -0,0 +1,246 @@
|
|
|
1
|
+
import { type GrantType, type Expires, type TokenType, type RequestAuthorizer, type RequestAuthorizerInit, type Seconds, type JSONSerializable, type AcrValues, type TimeInterval, type JsonPrimitive, type JsonRecord } from './types/index.ts';
|
|
2
|
+
import type { OAuth2Client } from './oauth2/client.ts';
|
|
3
|
+
import { JWT } from './jwt/index.ts';
|
|
4
|
+
import { OAuth2Request } from './http/index.ts';
|
|
5
|
+
/**
|
|
6
|
+
* @module Token
|
|
7
|
+
*/
|
|
8
|
+
/**
|
|
9
|
+
* Object representation of a token response
|
|
10
|
+
* @group Types
|
|
11
|
+
*/
|
|
12
|
+
export type TokenResponse = {
|
|
13
|
+
id?: string;
|
|
14
|
+
tokenType: TokenType;
|
|
15
|
+
expiresIn: number;
|
|
16
|
+
issuedAt?: number;
|
|
17
|
+
scopes?: string | string[];
|
|
18
|
+
accessToken: string;
|
|
19
|
+
idToken?: string;
|
|
20
|
+
refreshToken?: string;
|
|
21
|
+
context: Token.Context;
|
|
22
|
+
};
|
|
23
|
+
/**
|
|
24
|
+
* Required and optional values to construct a {@link Token} instance
|
|
25
|
+
* @group Types
|
|
26
|
+
*/
|
|
27
|
+
export type TokenInit = Omit<TokenResponse, 'idToken'> & {
|
|
28
|
+
idToken?: string | JWT;
|
|
29
|
+
};
|
|
30
|
+
/**
|
|
31
|
+
* JSON representation of token (only contains primitive types)
|
|
32
|
+
* @group Types
|
|
33
|
+
*/
|
|
34
|
+
export type TokenPrimitiveInit = TokenResponse;
|
|
35
|
+
/**
|
|
36
|
+
* Internal representation of a OAuth2/OIDC Token.
|
|
37
|
+
* Contains `accessToken`, conditionally contains `idToken` and `refreshToken`
|
|
38
|
+
*
|
|
39
|
+
* @group Token
|
|
40
|
+
*
|
|
41
|
+
* @remarks
|
|
42
|
+
* Most operations can be done by {@link Credential} methods. It's recommended
|
|
43
|
+
* to use those instead before reaching for a {@link Token.Token | Token} method
|
|
44
|
+
*
|
|
45
|
+
* @see
|
|
46
|
+
* - Okta Documentation: {@link https://developer.okta.com/docs/reference/api/oidc/#response-properties-4 | OIDC }
|
|
47
|
+
*/
|
|
48
|
+
export declare class Token implements JSONSerializable, Expires, RequestAuthorizer {
|
|
49
|
+
/** @internal */
|
|
50
|
+
static expiryTimeouts: {
|
|
51
|
+
[key: string]: ReturnType<typeof setTimeout>;
|
|
52
|
+
};
|
|
53
|
+
readonly id: string;
|
|
54
|
+
readonly issuedAt: Date;
|
|
55
|
+
/**
|
|
56
|
+
* The audience of the token. ex `Bearer` or `DPoP`
|
|
57
|
+
*/
|
|
58
|
+
readonly tokenType: TokenType;
|
|
59
|
+
/**
|
|
60
|
+
* Seconds until token expires
|
|
61
|
+
*/
|
|
62
|
+
readonly expiresIn: number;
|
|
63
|
+
/**
|
|
64
|
+
* OAuth2 / OIDC scopes associated with token
|
|
65
|
+
*/
|
|
66
|
+
readonly scope: string;
|
|
67
|
+
/**
|
|
68
|
+
* String value of `accessToken`
|
|
69
|
+
*/
|
|
70
|
+
readonly accessToken: string;
|
|
71
|
+
/**
|
|
72
|
+
* If the OAuth2 configuration includes OIDC, an `idToken` will be available
|
|
73
|
+
*/
|
|
74
|
+
readonly idToken?: JWT;
|
|
75
|
+
/**
|
|
76
|
+
* If the OAuth2 configuration includes the scope `offline_access`, a `refreshToken` will be available
|
|
77
|
+
*/
|
|
78
|
+
readonly refreshToken?: string;
|
|
79
|
+
/**
|
|
80
|
+
* Defines the context this token was issued from
|
|
81
|
+
*/
|
|
82
|
+
readonly context: Token.Context;
|
|
83
|
+
/**
|
|
84
|
+
* The constructor of Token
|
|
85
|
+
*/
|
|
86
|
+
constructor(obj: TokenInit);
|
|
87
|
+
/**
|
|
88
|
+
* @internal
|
|
89
|
+
*
|
|
90
|
+
* A static method (within this Base class) used to return instances of Derived classes
|
|
91
|
+
* References:
|
|
92
|
+
* - https://stackoverflow.com/questions/68672717/create-instance-of-derived-class-from-base-class-with-generic-types
|
|
93
|
+
* - https://stackoverflow.com/questions/60199917/in-typescript-how-to-return-sub-class-instance-in-a-static-function-in-base-cla
|
|
94
|
+
*/
|
|
95
|
+
protected static create<T extends Token>(this: new (init: TokenInit) => T, init: TokenInit): T;
|
|
96
|
+
static serializer(t: object): string;
|
|
97
|
+
static isEqual(lhs: Token, rhs: Token): boolean;
|
|
98
|
+
static from(refreshToken: string, client: OAuth2Client): Promise<Token>;
|
|
99
|
+
/**
|
|
100
|
+
* When the Token will expire, represented as a `Date`
|
|
101
|
+
* @public
|
|
102
|
+
*/
|
|
103
|
+
get expiresAt(): Date;
|
|
104
|
+
/**
|
|
105
|
+
* Compares `this.expiresAt` against `TimeCoordinator` to determine if Token is expired
|
|
106
|
+
* @public
|
|
107
|
+
*/
|
|
108
|
+
get isExpired(): boolean;
|
|
109
|
+
/**
|
|
110
|
+
* Returns `true` if the {@link Token.Token | Token} is _not_ expired
|
|
111
|
+
*
|
|
112
|
+
* @see {@link Token.isExpired}
|
|
113
|
+
*/
|
|
114
|
+
get isValid(): boolean;
|
|
115
|
+
/**
|
|
116
|
+
* Returns `true` if the {@link Token.Token | Token} will expire after a duration (seconds)
|
|
117
|
+
*
|
|
118
|
+
* @see {@link Token.willBeValidIn}
|
|
119
|
+
*/
|
|
120
|
+
willBeExpiredIn(duration: Seconds): boolean;
|
|
121
|
+
/**
|
|
122
|
+
* Returns `true` if the {@link Token.Token | Token} will _not_ expire after a duration (seconds)
|
|
123
|
+
*
|
|
124
|
+
* @see {@link Token.willBeExpiredIn}
|
|
125
|
+
*/
|
|
126
|
+
willBeValidIn(duration: Seconds): boolean;
|
|
127
|
+
/**
|
|
128
|
+
* Returns the OAuth2 `scope`(s) used to issue the token
|
|
129
|
+
*/
|
|
130
|
+
get scopes(): string[];
|
|
131
|
+
/**
|
|
132
|
+
* Converts a {@link Token.Token | Token} instance to an serializable object literal representation
|
|
133
|
+
*/
|
|
134
|
+
toJSON(): JsonRecord;
|
|
135
|
+
/**
|
|
136
|
+
* Used to merge separate {@link Token.Token | Token} instances together. Useful when handling token refresh as
|
|
137
|
+
* not every value is returned in a refresh request compared to the initial token request
|
|
138
|
+
*
|
|
139
|
+
* @param token the "old" token instance to be merged into the "new" token
|
|
140
|
+
* @returns new {@link Token.Token | Token} instance
|
|
141
|
+
*/
|
|
142
|
+
merge(token: Token): Token;
|
|
143
|
+
serialize(): string;
|
|
144
|
+
/**
|
|
145
|
+
* Signs a outgoing {@link https://developer.mozilla.org/en-US/docs/Web/API/Request | Request} with an `Authorization` header.
|
|
146
|
+
* Accepts the same method signature as {@link https://developer.mozilla.org/en-US/docs/Web/API/Window/fetch | fetch}
|
|
147
|
+
* @returns {@link https://developer.mozilla.org/en-US/docs/Web/API/Request | Request} wrapped in a `Promise`
|
|
148
|
+
*
|
|
149
|
+
*/
|
|
150
|
+
authorize(input: string | URL | Request, init?: RequestAuthorizerInit): Promise<Request>;
|
|
151
|
+
}
|
|
152
|
+
/**
|
|
153
|
+
* @group Token
|
|
154
|
+
*/
|
|
155
|
+
export declare namespace Token {
|
|
156
|
+
/**
|
|
157
|
+
* Context used to request the token
|
|
158
|
+
*/
|
|
159
|
+
type Context = {
|
|
160
|
+
issuer: string;
|
|
161
|
+
clientId: string;
|
|
162
|
+
scopes: string[];
|
|
163
|
+
dpopPairId?: string;
|
|
164
|
+
acrValues?: AcrValues;
|
|
165
|
+
maxAge?: TimeInterval;
|
|
166
|
+
};
|
|
167
|
+
/**
|
|
168
|
+
* Utility function for extracting {@link Token.Context} from an union-type object like {@link Token.Metadata:TYPE | Token.Metadata}
|
|
169
|
+
*/
|
|
170
|
+
function extractContext(input: {
|
|
171
|
+
[key: string]: unknown;
|
|
172
|
+
}): Token.Context;
|
|
173
|
+
/**
|
|
174
|
+
* Non-sensitive metadata values associated with a {@link Token.Token | Token}. Used to store {@link Token.Context} and additional
|
|
175
|
+
* metadata for a given {@link Token.Token | Token}
|
|
176
|
+
* {@label TYPE}
|
|
177
|
+
*/
|
|
178
|
+
type Metadata = Context & {
|
|
179
|
+
id: string;
|
|
180
|
+
tags: string[];
|
|
181
|
+
claims?: JsonRecord;
|
|
182
|
+
};
|
|
183
|
+
function Metadata(token: Token, tags?: string[]): Metadata;
|
|
184
|
+
/** @internal */
|
|
185
|
+
interface TokenRequestParams extends OAuth2Request.RequestParams {
|
|
186
|
+
grantType: GrantType;
|
|
187
|
+
acrValues?: AcrValues;
|
|
188
|
+
maxAge?: TimeInterval;
|
|
189
|
+
}
|
|
190
|
+
/** @internal */
|
|
191
|
+
class TokenRequest extends OAuth2Request {
|
|
192
|
+
grantType: GrantType;
|
|
193
|
+
acrValues?: AcrValues;
|
|
194
|
+
maxAge?: TimeInterval;
|
|
195
|
+
constructor(params: TokenRequestParams);
|
|
196
|
+
get url(): string;
|
|
197
|
+
}
|
|
198
|
+
/** @internal */
|
|
199
|
+
interface RefreshRequestParams extends Omit<Token.TokenRequestParams, 'grantType'> {
|
|
200
|
+
id?: string;
|
|
201
|
+
scope?: string;
|
|
202
|
+
refreshToken: string;
|
|
203
|
+
}
|
|
204
|
+
/** @internal */
|
|
205
|
+
class RefreshRequest extends Token.TokenRequest {
|
|
206
|
+
id?: string;
|
|
207
|
+
scope?: string;
|
|
208
|
+
refreshToken: string;
|
|
209
|
+
constructor(params: RefreshRequestParams);
|
|
210
|
+
}
|
|
211
|
+
/**
|
|
212
|
+
* Possible values provided to {@link OAuth2.OAuth2Client.revoke | OAuth2Client.revoke} to determine which tokens to revoke
|
|
213
|
+
*/
|
|
214
|
+
type RevokeType = 'ALL' | 'ACCESS' | 'REFRESH';
|
|
215
|
+
/** @internal */
|
|
216
|
+
interface RevokeRequestParams extends OAuth2Request.RequestParams {
|
|
217
|
+
token: string;
|
|
218
|
+
hint: 'access_token' | 'refresh_token';
|
|
219
|
+
}
|
|
220
|
+
/** @internal */
|
|
221
|
+
class RevokeRequest extends OAuth2Request {
|
|
222
|
+
constructor(params: RevokeRequestParams);
|
|
223
|
+
get url(): string;
|
|
224
|
+
}
|
|
225
|
+
/**
|
|
226
|
+
* Possible values provided to {@link OAuth2.OAuth2Client.introspect | OAuth2Client.introspect} to determine which token to introspect
|
|
227
|
+
*/
|
|
228
|
+
type Kind = 'access_token' | 'refresh_token' | 'id_token';
|
|
229
|
+
/** @internal */
|
|
230
|
+
interface IntrospectRequestParams extends OAuth2Request.RequestParams {
|
|
231
|
+
token: Token;
|
|
232
|
+
type: Token.Kind;
|
|
233
|
+
}
|
|
234
|
+
/** @internal */
|
|
235
|
+
class IntrospectRequest extends OAuth2Request {
|
|
236
|
+
constructor(params: IntrospectRequestParams);
|
|
237
|
+
get url(): string;
|
|
238
|
+
}
|
|
239
|
+
/**
|
|
240
|
+
* Payload structure of a `/introspect` response
|
|
241
|
+
*/
|
|
242
|
+
type IntrospectResponse = {
|
|
243
|
+
active: boolean;
|
|
244
|
+
[key: string]: JsonPrimitive;
|
|
245
|
+
};
|
|
246
|
+
}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import type { RequestAuthorizer, RequestAuthorizerInit, JsonRecord, AcrValues } from './types/index.ts';
|
|
2
|
+
import { Token } from './Token.ts';
|
|
3
|
+
import { EventEmitter } from './utils/EventEmitter.ts';
|
|
4
|
+
/**
|
|
5
|
+
* @module TokenOrchestrator
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* @abstract
|
|
9
|
+
*
|
|
10
|
+
* Defines how {@link Token | Tokens} are retrieved to be consumed within an application
|
|
11
|
+
*
|
|
12
|
+
* @see {@link FetchClient}
|
|
13
|
+
*/
|
|
14
|
+
export declare abstract class TokenOrchestrator<E extends TokenOrchestrator.Events = TokenOrchestrator.Events> implements RequestAuthorizer {
|
|
15
|
+
protected readonly emitter: EventEmitter<E>;
|
|
16
|
+
on(...args: Parameters<EventEmitter<E>['on']>): EventEmitter<E>;
|
|
17
|
+
off(...args: Parameters<EventEmitter<E>['off']>): EventEmitter<E>;
|
|
18
|
+
/**
|
|
19
|
+
* @abstract
|
|
20
|
+
* Retrieves a valid {@link Token.Token | Token} to be used within an application
|
|
21
|
+
*
|
|
22
|
+
*/
|
|
23
|
+
abstract getToken(params: TokenOrchestrator.AuthorizeParams): Promise<Token | null>;
|
|
24
|
+
/**
|
|
25
|
+
* Signs an outgoing {@link !Request} with an `Authorization` header via {@link Token.Token | Token} retrieved from {@link getToken}
|
|
26
|
+
*
|
|
27
|
+
* Optionally {@link TokenOrchestrator.AuthorizeParams | AuthorizeParams} can be provided to be passed along to {@link getToken}
|
|
28
|
+
*
|
|
29
|
+
* @see {@link FetchClient}
|
|
30
|
+
*/
|
|
31
|
+
authorize(input: string | URL | Request, init?: RequestAuthorizerInit & TokenOrchestrator.AuthorizeParams): Promise<Request>;
|
|
32
|
+
}
|
|
33
|
+
export declare namespace TokenOrchestrator {
|
|
34
|
+
type Events = {
|
|
35
|
+
error: {
|
|
36
|
+
error: Error | JsonRecord;
|
|
37
|
+
type?: string;
|
|
38
|
+
};
|
|
39
|
+
};
|
|
40
|
+
/**
|
|
41
|
+
* Parameters used to make OAuth2 token requests
|
|
42
|
+
*/
|
|
43
|
+
type AuthorizeParams = {
|
|
44
|
+
issuer?: string | URL;
|
|
45
|
+
clientId?: string;
|
|
46
|
+
scopes?: string[];
|
|
47
|
+
maxAge?: number;
|
|
48
|
+
acrValues?: AcrValues;
|
|
49
|
+
};
|
|
50
|
+
/**
|
|
51
|
+
* Utility function to separate {@link AuthorizeParams} from other options.
|
|
52
|
+
* Intended to help separate params from intersected types in method signatures
|
|
53
|
+
*
|
|
54
|
+
* Convenient for custom {@link TokenOrchestrator} implementations
|
|
55
|
+
*/
|
|
56
|
+
function extractAuthParams(input: {
|
|
57
|
+
[key: string]: any;
|
|
58
|
+
}): {
|
|
59
|
+
authParams: TokenOrchestrator.AuthorizeParams;
|
|
60
|
+
rest: {
|
|
61
|
+
[key: string]: any;
|
|
62
|
+
};
|
|
63
|
+
};
|
|
64
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module Core
|
|
3
|
+
*/
|
|
4
|
+
export * from './types/index.ts';
|
|
5
|
+
export * from './http/index.ts';
|
|
6
|
+
export * from './errors/index.ts';
|
|
7
|
+
export * from './utils/index.ts';
|
|
8
|
+
export * from './utils/EventEmitter.ts';
|
|
9
|
+
export * from './utils/TimeCoordinator.ts';
|
|
10
|
+
export * from './utils/TaskBridge.ts';
|
|
11
|
+
export { randomBytes, shortID } from './crypto/index.ts';
|
|
12
|
+
export * from './jwt/index.ts';
|
|
13
|
+
export * from './oauth2/pkce.ts';
|
|
14
|
+
export * from './oauth2/dpop/index.ts';
|
|
15
|
+
export * from './oauth2/client.ts';
|
|
16
|
+
export * from './Token.ts';
|
|
17
|
+
export * from './Credential/index.ts';
|
|
18
|
+
export * from './TokenOrchestrator.ts';
|
|
19
|
+
export * from './FetchClient.ts';
|
|
20
|
+
export { addEnv } from './http/oktaUserAgent.ts';
|
|
21
|
+
export { Platform, type PlatformDependencies } from './platform/Platform.ts';
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module
|
|
3
|
+
* @mergeModuleWith Core
|
|
4
|
+
*/
|
|
5
|
+
/** @internal */
|
|
6
|
+
export declare function buf(input: string): ArrayBuffer;
|
|
7
|
+
export declare function buf(input: Uint8Array | ArrayBuffer): string;
|
|
8
|
+
/** @internal */
|
|
9
|
+
export declare function encodeBase64Url(input: Uint8Array | ArrayBuffer): string;
|
|
10
|
+
/** @internal */
|
|
11
|
+
export declare function decodeBase64Url(input: string): Uint8Array<ArrayBuffer>;
|
|
12
|
+
/** @internal */
|
|
13
|
+
export declare function b64u(input: string): ArrayBuffer;
|
|
14
|
+
export declare function b64u(input: Uint8Array | ArrayBuffer): string;
|
|
15
|
+
/**
|
|
16
|
+
* @internal
|
|
17
|
+
* @group Crypto
|
|
18
|
+
* @returns SHA-256 hash of input `string`
|
|
19
|
+
*/
|
|
20
|
+
export declare function hash(str: string): Promise<string>;
|
|
21
|
+
/**
|
|
22
|
+
* Generates a cryptographically random string
|
|
23
|
+
*
|
|
24
|
+
* @group Crypto
|
|
25
|
+
*/
|
|
26
|
+
export declare function randomBytes(): string;
|
|
27
|
+
/**
|
|
28
|
+
* Generates a cryptographically random short ID
|
|
29
|
+
*
|
|
30
|
+
* @group Crypto
|
|
31
|
+
*/
|
|
32
|
+
export declare function shortID(): string;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module
|
|
3
|
+
* @mergeModuleWith Core
|
|
4
|
+
*/
|
|
5
|
+
import { AuthSdkError } from './AuthSdkError.ts';
|
|
6
|
+
/**
|
|
7
|
+
* Thrown when an {@link Networking.APIClient} encounters an unexpected condition
|
|
8
|
+
*
|
|
9
|
+
* @group Errors
|
|
10
|
+
*/
|
|
11
|
+
export declare class APIClientError extends AuthSdkError {
|
|
12
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module
|
|
3
|
+
* @mergeModuleWith Core
|
|
4
|
+
*/
|
|
5
|
+
import { JsonRecord } from '../types/lib.ts';
|
|
6
|
+
/**
|
|
7
|
+
* Base Error class for all errors defined within Okta Client JavaScript
|
|
8
|
+
*
|
|
9
|
+
* @group Errors
|
|
10
|
+
*/
|
|
11
|
+
export declare class AuthSdkError extends Error {
|
|
12
|
+
/**
|
|
13
|
+
* A dictionary to store the context in which the error was thrown
|
|
14
|
+
* For example: The authentication context when an error is thrown during an authentication flow
|
|
15
|
+
*/
|
|
16
|
+
context: JsonRecord;
|
|
17
|
+
constructor(message?: string, options?: ErrorOptions & {
|
|
18
|
+
context?: JsonRecord;
|
|
19
|
+
});
|
|
20
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module
|
|
3
|
+
* @mergeModuleWith Core
|
|
4
|
+
*/
|
|
5
|
+
import { AuthSdkError } from './AuthSdkError.ts';
|
|
6
|
+
/**
|
|
7
|
+
* Thrown when a {@link Credential} instance encounters an unexpected condition
|
|
8
|
+
*
|
|
9
|
+
* @group Errors
|
|
10
|
+
*/
|
|
11
|
+
export declare class CredentialError extends AuthSdkError {
|
|
12
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module
|
|
3
|
+
* @mergeModuleWith Core
|
|
4
|
+
*/
|
|
5
|
+
import { AuthSdkError } from './AuthSdkError.ts';
|
|
6
|
+
/**
|
|
7
|
+
* Thrown when a problem occurs during a token DPoP operation
|
|
8
|
+
*
|
|
9
|
+
* @group Errors
|
|
10
|
+
*/
|
|
11
|
+
export declare class DPoPError extends AuthSdkError {
|
|
12
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module
|
|
3
|
+
* @mergeModuleWith Core
|
|
4
|
+
*/
|
|
5
|
+
import { AuthSdkError } from './AuthSdkError.ts';
|
|
6
|
+
/**
|
|
7
|
+
* Thrown when a problem occurs during {@link JWT} parsing or processing
|
|
8
|
+
*
|
|
9
|
+
* @group Errors
|
|
10
|
+
*/
|
|
11
|
+
export declare class JWTError extends AuthSdkError {
|
|
12
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module
|
|
3
|
+
* @mergeModuleWith Core
|
|
4
|
+
*/
|
|
5
|
+
import { AuthSdkError } from './AuthSdkError.ts';
|
|
6
|
+
/**
|
|
7
|
+
* Thrown when a problem occurs when sending or processing a network request
|
|
8
|
+
*
|
|
9
|
+
* @group Errors
|
|
10
|
+
*/
|
|
11
|
+
export declare class NetworkError extends AuthSdkError {
|
|
12
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module
|
|
3
|
+
* @mergeModuleWith Core
|
|
4
|
+
*/
|
|
5
|
+
import { OAuth2ErrorResponse } from '../types/index.ts';
|
|
6
|
+
import { AuthSdkError } from './AuthSdkError.ts';
|
|
7
|
+
/**
|
|
8
|
+
* Thrown when an OAuth2 request (like /token) returns an error status
|
|
9
|
+
*
|
|
10
|
+
* @group Errors
|
|
11
|
+
*/
|
|
12
|
+
export declare class OAuth2Error extends AuthSdkError {
|
|
13
|
+
description?: string;
|
|
14
|
+
uri?: string;
|
|
15
|
+
constructor(error: string | OAuth2ErrorResponse, description?: string, uri?: string);
|
|
16
|
+
get error(): string;
|
|
17
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module
|
|
3
|
+
* @mergeModuleWith Core
|
|
4
|
+
*/
|
|
5
|
+
import { AuthSdkError } from './AuthSdkError.ts';
|
|
6
|
+
/**
|
|
7
|
+
* Thrown when a {@link Token | Token} instance encounters an unexpected condition
|
|
8
|
+
*
|
|
9
|
+
* @group Errors
|
|
10
|
+
*/
|
|
11
|
+
export declare class TokenError extends AuthSdkError {
|
|
12
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module
|
|
3
|
+
* @mergeModuleWith Core
|
|
4
|
+
*/
|
|
5
|
+
import { AuthSdkError } from './AuthSdkError.ts';
|
|
6
|
+
/**
|
|
7
|
+
* Thrown when a {@link TokenOrchestrator} encounters an unexpected condition
|
|
8
|
+
*
|
|
9
|
+
* @group Errors
|
|
10
|
+
*/
|
|
11
|
+
export declare class TokenOrchestratorError extends AuthSdkError {
|
|
12
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @packageDocumentation
|
|
3
|
+
* @internal
|
|
4
|
+
*/
|
|
5
|
+
export * from './AuthSdkError.ts';
|
|
6
|
+
export * from './OAuth2Error.ts';
|
|
7
|
+
export * from './JWTError.ts';
|
|
8
|
+
export * from './TokenError.ts';
|
|
9
|
+
export * from './APIClientError.ts';
|
|
10
|
+
export * from './DPoPError.ts';
|
|
11
|
+
export * from './CredentialError.ts';
|
|
12
|
+
export * from './TokenOrchestratorError.ts';
|
|
13
|
+
export * from './NetworkError.ts';
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module
|
|
3
|
+
* @mergeModuleWith Networking
|
|
4
|
+
*/
|
|
5
|
+
import type { JsonRecord, JSONSerializable } from '../types/index.ts';
|
|
6
|
+
import { DPoPNonceCache } from '../oauth2/dpop/nonceCache.ts';
|
|
7
|
+
import { APIRequest } from './requests/APIRequest.ts';
|
|
8
|
+
import { EventEmitter } from '../utils/EventEmitter.ts';
|
|
9
|
+
import { APIClientError } from '../errors/index.ts';
|
|
10
|
+
export * from './requests/APIRequest.ts';
|
|
11
|
+
export * from './requests/OAuth2Request.ts';
|
|
12
|
+
/**
|
|
13
|
+
* @group APIClient
|
|
14
|
+
*/
|
|
15
|
+
export declare abstract class APIClient<E extends APIClient.Events = APIClient.Events> {
|
|
16
|
+
#private;
|
|
17
|
+
readonly configuration: APIClient.Configuration;
|
|
18
|
+
readonly emitter: EventEmitter<E>;
|
|
19
|
+
protected readonly dpopNonceCache: DPoPNonceCache;
|
|
20
|
+
protected readonly interceptors: APIClient.RequestInterceptor[];
|
|
21
|
+
defaultHeaders: Record<string, string>;
|
|
22
|
+
defaultRequestOptions: APIClient.RequestOptions;
|
|
23
|
+
constructor(params?: APIClient.ConfigurationParams | APIClient.Configuration);
|
|
24
|
+
protected getDPoPNonceCacheKey(request: Request): string;
|
|
25
|
+
protected getDPoPNonceFromCache(request: Request): Promise<string | undefined>;
|
|
26
|
+
protected cacheDPoPNonce(request: Request, nonce: string): Promise<void>;
|
|
27
|
+
/**
|
|
28
|
+
* Registers an {@link APIClient.RequestInterceptor} on the {@link APIClient}
|
|
29
|
+
*
|
|
30
|
+
* @example
|
|
31
|
+
* const interceptor = (request: Request) => {
|
|
32
|
+
* req.headers.append('foo', '1');
|
|
33
|
+
* return req;
|
|
34
|
+
* };
|
|
35
|
+
* client.addInterceptor(interceptor);
|
|
36
|
+
*/
|
|
37
|
+
addInterceptor(interceptor: APIClient.RequestInterceptor): void;
|
|
38
|
+
/**
|
|
39
|
+
* Unregisters an {@link APIClient.RequestInterceptor} on the {@link APIClient}
|
|
40
|
+
*
|
|
41
|
+
* @example
|
|
42
|
+
* const interceptor = (request: Request) => { ... };
|
|
43
|
+
* client.addInterceptor(interceptor);
|
|
44
|
+
* ...
|
|
45
|
+
* client.removeInterceptor(interceptor);
|
|
46
|
+
*/
|
|
47
|
+
removeInterceptor(interceptor: APIClient.RequestInterceptor): void;
|
|
48
|
+
protected applyInterceptors(request: APIRequest): Promise<Request>;
|
|
49
|
+
protected abstract checkForDPoPNonceErrorResponse(response: Response): Promise<string | undefined>;
|
|
50
|
+
protected abstract prepareDPoPNonceRetry(request: APIRequest, nonce: string): Promise<void>;
|
|
51
|
+
protected processResponse(response: Response, request: APIRequest): Promise<void>;
|
|
52
|
+
protected processErrorResponse(response: Response, request: APIRequest): Promise<Response>;
|
|
53
|
+
protected authorize(request: APIRequest): Promise<void>;
|
|
54
|
+
protected sendRequest(request: Request): Promise<Response>;
|
|
55
|
+
protected send(request: APIRequest): Promise<Response>;
|
|
56
|
+
protected retry(request: APIRequest): Promise<Response>;
|
|
57
|
+
protected getRetryDelay(response: Response, request: APIRequest): number;
|
|
58
|
+
fetch(...args: ConstructorParameters<typeof APIRequest>): Promise<Response>;
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* @group APIClient
|
|
62
|
+
*/
|
|
63
|
+
export declare namespace APIClient {
|
|
64
|
+
type ConfigurationParams = {
|
|
65
|
+
dpop?: boolean;
|
|
66
|
+
fetchImpl?: typeof fetch;
|
|
67
|
+
};
|
|
68
|
+
class Configuration implements JSONSerializable {
|
|
69
|
+
dpop: boolean;
|
|
70
|
+
fetchImpl?: typeof fetch;
|
|
71
|
+
static DefaultOptions: {
|
|
72
|
+
dpop: boolean;
|
|
73
|
+
fetchImpl?: typeof fetch;
|
|
74
|
+
};
|
|
75
|
+
constructor(params: APIClient.ConfigurationParams);
|
|
76
|
+
toJSON(): JsonRecord;
|
|
77
|
+
}
|
|
78
|
+
type RequestOptions = {
|
|
79
|
+
/**
|
|
80
|
+
* When `true`, utilizes the provided {@link TokenOrchestrator} to acquire an access token to sign the outgoing request with the proper
|
|
81
|
+
* `Authorization` and `Dpop` headers, depending on the {@link TokenType} of the acquired {@link Token}. Defaults to `true`
|
|
82
|
+
*/
|
|
83
|
+
authorizeRequest: boolean | ((request: APIRequest) => boolean);
|
|
84
|
+
};
|
|
85
|
+
type RequestInterceptor = (request: APIRequest) => (Promise<APIRequest> | APIRequest);
|
|
86
|
+
type Events = {
|
|
87
|
+
/**
|
|
88
|
+
* Fired before a request is sent
|
|
89
|
+
*
|
|
90
|
+
* @remarks
|
|
91
|
+
* The `request` instance is `readonly`. For outgoing request customization see {@link APIClient.addInterceptor}
|
|
92
|
+
*/
|
|
93
|
+
'will_send': {
|
|
94
|
+
request: Request;
|
|
95
|
+
};
|
|
96
|
+
/**
|
|
97
|
+
* Fired after a response is received
|
|
98
|
+
*/
|
|
99
|
+
'did_send': {
|
|
100
|
+
request: Request;
|
|
101
|
+
response: Response;
|
|
102
|
+
};
|
|
103
|
+
/**
|
|
104
|
+
* Fired after a {@link fetch} call fails to complete (`TypeError: Failed to fetch`)
|
|
105
|
+
*/
|
|
106
|
+
'network_failure': {
|
|
107
|
+
request: Request;
|
|
108
|
+
error: APIClientError;
|
|
109
|
+
cause: Error;
|
|
110
|
+
};
|
|
111
|
+
};
|
|
112
|
+
function isNetworkError(err: unknown): boolean;
|
|
113
|
+
}
|