@okta/auth-foundation 0.6.0 → 0.9.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/README.MD +136 -0
- package/claude.md +256 -0
- package/dist/esm/Credential/Credential.js +17 -14
- package/dist/esm/Credential/Credential.js.map +1 -1
- package/dist/esm/Credential/CredentialCoordinator.js +6 -2
- package/dist/esm/Credential/CredentialCoordinator.js.map +1 -1
- package/dist/esm/Credential/CredentialDataSource.js +6 -4
- package/dist/esm/Credential/CredentialDataSource.js.map +1 -1
- package/dist/esm/Credential/TokenStorage.js +3 -0
- package/dist/esm/Credential/TokenStorage.js.map +1 -1
- package/dist/esm/FetchClient.js +5 -1
- package/dist/esm/FetchClient.js.map +1 -1
- package/dist/esm/Token.js +1 -0
- package/dist/esm/Token.js.map +1 -1
- package/dist/esm/TokenOrchestrator.js +4 -1
- package/dist/esm/TokenOrchestrator.js.map +1 -1
- package/dist/esm/http/APIClient.js +4 -0
- package/dist/esm/http/APIClient.js.map +1 -1
- package/dist/esm/http/oktaUserAgent.js +1 -1
- package/dist/esm/http/requests/APIRequest.js.map +1 -1
- package/dist/esm/http/requests/OAuth2Request.js.map +1 -1
- package/dist/esm/http/wwwAuthenticate.js.map +1 -1
- package/dist/esm/jwt/IDTokenValidator.js +3 -0
- package/dist/esm/jwt/IDTokenValidator.js.map +1 -1
- package/dist/esm/jwt/JWK.js.map +1 -1
- package/dist/esm/jwt/JWT.js.map +1 -1
- package/dist/esm/jwt/TokenHashValidator.js.map +1 -1
- package/dist/esm/oauth2/client.js +14 -9
- package/dist/esm/oauth2/client.js.map +1 -1
- package/dist/esm/oauth2/configuration.js +7 -3
- package/dist/esm/oauth2/configuration.js.map +1 -1
- package/dist/esm/oauth2/dpop/index.js.map +1 -1
- package/dist/esm/oauth2/dpop/nonceCache.js.map +1 -1
- package/dist/esm/oauth2/dpop/storage.js.map +1 -1
- package/dist/esm/oauth2/pkce.js.map +1 -1
- package/dist/esm/oauth2/requests/UserInfo.js.map +1 -1
- package/dist/esm/platform/Platform.js.map +1 -1
- package/dist/esm/platform/defaults.js.map +1 -1
- package/dist/esm/types/oauth.js.map +1 -1
- package/dist/esm/utils/EventEmitter.js +29 -1
- package/dist/esm/utils/EventEmitter.js.map +1 -1
- package/dist/esm/utils/TaskBridge.js +13 -0
- package/dist/esm/utils/TaskBridge.js.map +1 -1
- package/dist/esm/utils/TimeCoordinator.js.map +1 -1
- package/dist/esm/utils/merge.js.map +1 -1
- package/dist/esm/utils/pause.js.map +1 -1
- package/dist/types/Credential/Credential.d.ts +38 -21
- package/dist/types/Credential/CredentialCoordinator.d.ts +10 -3
- package/dist/types/Credential/CredentialDataSource.d.ts +2 -1
- package/dist/types/Credential/TokenStorage.d.ts +13 -2
- package/dist/types/FetchClient.d.ts +26 -5
- package/dist/types/Token.d.ts +23 -11
- package/dist/types/TokenOrchestrator.d.ts +61 -11
- package/dist/types/http/APIClient.d.ts +220 -8
- package/dist/types/http/index.d.ts +5 -0
- package/dist/types/http/requests/APIRequest.d.ts +28 -2
- package/dist/types/http/requests/OAuth2Request.d.ts +12 -2
- package/dist/types/http/wwwAuthenticate.d.ts +10 -2
- package/dist/types/jwt/IDTokenValidator.d.ts +46 -3
- package/dist/types/jwt/JWK.d.ts +35 -0
- package/dist/types/jwt/JWT.d.ts +126 -4
- package/dist/types/jwt/TokenHashValidator.d.ts +6 -0
- package/dist/types/oauth2/client.d.ts +95 -11
- package/dist/types/oauth2/configuration.d.ts +81 -7
- package/dist/types/oauth2/dpop/index.d.ts +10 -5
- package/dist/types/oauth2/dpop/nonceCache.d.ts +18 -0
- package/dist/types/oauth2/dpop/storage.d.ts +1 -0
- package/dist/types/oauth2/dpop/types.d.ts +7 -0
- package/dist/types/oauth2/pkce.d.ts +19 -0
- package/dist/types/oauth2/requests/UserInfo.d.ts +2 -1
- package/dist/types/platform/Platform.d.ts +51 -3
- package/dist/types/platform/defaults.d.ts +1 -0
- package/dist/types/types/lib.d.ts +16 -2
- package/dist/types/types/oauth.d.ts +5 -5
- package/dist/types/types/openid.d.ts +50 -234
- package/dist/types/utils/EventEmitter.d.ts +84 -2
- package/dist/types/utils/TaskBridge.d.ts +9 -1
- package/dist/types/utils/TimeCoordinator.d.ts +2 -0
- package/dist/types/utils/merge.d.ts +2 -0
- package/dist/types/utils/pause.d.ts +1 -0
- package/package.json +1 -1
|
@@ -5,27 +5,70 @@
|
|
|
5
5
|
import type { AcrValues } from '../types/index.ts';
|
|
6
6
|
import type { JWT } from './JWT.ts';
|
|
7
7
|
/**
|
|
8
|
+
* Contextual data, usually from the `/authorize` request, which resulted in an ID token
|
|
9
|
+
* needed to validate said `ID Token`
|
|
8
10
|
* @group JWT
|
|
9
11
|
*/
|
|
10
12
|
export interface IDTokenValidatorContext {
|
|
13
|
+
allowHTTP?: boolean;
|
|
11
14
|
nonce?: string;
|
|
12
15
|
maxAge?: number;
|
|
13
16
|
acrValues?: AcrValues;
|
|
14
17
|
supportedAlgs?: string[];
|
|
15
18
|
}
|
|
16
19
|
/**
|
|
20
|
+
* Performs ID token validation, conforming to {@link https://openid.net/specs/openid-connect-core-1_0.html | OIDC Spec}
|
|
21
|
+
*
|
|
22
|
+
* A default implementation is provided by this library. To override, set `OAuth2Client.idTokenValidator`
|
|
23
|
+
* ```ts
|
|
24
|
+
* const customValidator: IDTokenValidator = { ... };
|
|
25
|
+
* OAuth2Client.idTokenValidator = customValidator;
|
|
26
|
+
* ```
|
|
27
|
+
*
|
|
28
|
+
* @see
|
|
29
|
+
* * {@link https://openid.net/specs/openid-connect-core-1_0.html#IDTokenValidation | OIDC Spec: ID Token Validation}
|
|
30
|
+
*
|
|
17
31
|
* @group JWT
|
|
18
32
|
*/
|
|
19
33
|
export interface IDTokenValidator {
|
|
34
|
+
/** Defines a grace period for when performing time-based validations */
|
|
20
35
|
issuedAtGraceInterval: number;
|
|
36
|
+
/**
|
|
37
|
+
* By convention, a list of all validation checks performed within {@link IDTokenValidator.validate}.
|
|
38
|
+
*
|
|
39
|
+
* See {@link IDTokenValidator.validate} for more details.
|
|
40
|
+
*/
|
|
21
41
|
checks: IDTokenValidator.ValidationCheck[];
|
|
42
|
+
/**
|
|
43
|
+
* Validates ID tokens by performing a series of checks, listed by name in {@link IDTokenValidator.checks}
|
|
44
|
+
*
|
|
45
|
+
* @param token - The ID token to be validated
|
|
46
|
+
* @param issuer - The issuer (URL) from which the ID token was issued from
|
|
47
|
+
* @param clientId - The `client_id` from which the ID token was issued from
|
|
48
|
+
* @param context - Additional context needed to validate the ID token
|
|
49
|
+
* @throws {@link Core.JWTError | JWTError} if a validation check fails
|
|
50
|
+
*
|
|
51
|
+
* @remarks
|
|
52
|
+
* By design, {@link IDTokenValidator.checks} is a list of all validation checks performed within {@link IDTokenValidator.validate}.
|
|
53
|
+
* This is done to simplify disabling a specific check (as seen the example below). This is not a requirement however.
|
|
54
|
+
* If a custom {@link IDTokenValidator} is provided, the `validate` does not need to utilize this pattern.
|
|
55
|
+
*
|
|
56
|
+
* @example
|
|
57
|
+
* How to disable a specific validation check
|
|
58
|
+
* ```ts
|
|
59
|
+
* const currentChecks = OAuth2Client.idTokenValidator.checks;
|
|
60
|
+
* OAuth2Client.idTokenValidator.checks = currentChecks.filter(check !== 'expirationTime');
|
|
61
|
+
* // the 'expirationTime' validation check will now be skipped
|
|
62
|
+
* ```
|
|
63
|
+
*
|
|
64
|
+
* @see
|
|
65
|
+
* * {@link https://openid.net/specs/openid-connect-core-1_0.html#IDTokenValidation | OIDC Spec: ID Token Validation}
|
|
66
|
+
*/
|
|
22
67
|
validate: (token: JWT, issuer: URL, clientId: string, context?: IDTokenValidatorContext) => void;
|
|
23
68
|
}
|
|
24
69
|
/**
|
|
70
|
+
* {@inheritDoc IDTokenValidator}
|
|
25
71
|
* @group JWT
|
|
26
|
-
*
|
|
27
|
-
* @remarks
|
|
28
|
-
* https://openid.net/specs/openid-connect-core-1_0-final.html#IDToken
|
|
29
72
|
*/
|
|
30
73
|
export declare namespace IDTokenValidator {
|
|
31
74
|
/**
|
package/dist/types/jwt/JWK.d.ts
CHANGED
|
@@ -4,18 +4,52 @@
|
|
|
4
4
|
*/
|
|
5
5
|
import type { JWT } from './JWT.ts';
|
|
6
6
|
/**
|
|
7
|
+
* Defines properties of a JSON Web Key
|
|
7
8
|
* @group JWT
|
|
9
|
+
*
|
|
10
|
+
* @remarks
|
|
11
|
+
* Currently only `RSA`/`RS256` are supported.
|
|
12
|
+
*
|
|
13
|
+
* @see
|
|
14
|
+
* * {@link https://datatracker.ietf.org/doc/html/rfc7517#section-4 | RFC 7517 - JSON Web Key (JWK) Format}
|
|
8
15
|
*/
|
|
9
16
|
export interface JWK extends JsonWebKey {
|
|
17
|
+
/**
|
|
18
|
+
* Key Type
|
|
19
|
+
* @see {@link https://datatracker.ietf.org/doc/html/rfc7517#section-4.1 | RFC 7517 - "kty" (Key Type) Parameter}
|
|
20
|
+
*/
|
|
21
|
+
kty: 'RSA';
|
|
22
|
+
/**
|
|
23
|
+
* Algorithm
|
|
24
|
+
* @see {@link https://datatracker.ietf.org/doc/html/rfc7517#section-4.4 | RFC 7517 - "alg" (Algorithm) Parameter}
|
|
25
|
+
*/
|
|
10
26
|
alg: JWK.Algorithm;
|
|
27
|
+
/**
|
|
28
|
+
* Key ID
|
|
29
|
+
* @see {@link https://datatracker.ietf.org/doc/html/rfc7517#section-4.5 | RFC 7517 - "kid" (Key ID) Parameter}
|
|
30
|
+
*/
|
|
11
31
|
kid: string;
|
|
32
|
+
/**
|
|
33
|
+
* "Use" (public key use)
|
|
34
|
+
* @remarks
|
|
35
|
+
* According to RFC 7517, `sig` and `enc` are defined, but any value may be used.
|
|
36
|
+
* @see {@link https://datatracker.ietf.org/doc/html/rfc7517#section-4.2 | RFC 7517 - "use" (Public Key Use) Parameter}
|
|
37
|
+
*/
|
|
38
|
+
use?: 'sig' | 'enc' | string;
|
|
12
39
|
}
|
|
13
40
|
/**
|
|
41
|
+
* Alias for `JWK[]`.
|
|
14
42
|
* @group JWT
|
|
15
43
|
*/
|
|
16
44
|
export type JWKS = JWK[];
|
|
17
45
|
/**
|
|
46
|
+
* Verifies the signature of a {@link JWT} signed by a {@link JWK}.
|
|
47
|
+
* @remarks
|
|
48
|
+
* Accepts a {@link JWKS} (aka `JWK[]`) to ease use with the results of a `jwks_uri` request.
|
|
18
49
|
* @group JWT
|
|
50
|
+
* @see
|
|
51
|
+
* * {@link https://datatracker.ietf.org/doc/html/rfc7519| RFC 7519 - JSON Web Token (JWT)}
|
|
52
|
+
* * {@link https://datatracker.ietf.org/doc/html/rfc7517| RFC 7517 - JSON Web Key (JWK)}
|
|
19
53
|
*/
|
|
20
54
|
export type JWKValidator = {
|
|
21
55
|
validate: (token: JWT, keySet: JWKS) => Promise<boolean>;
|
|
@@ -23,6 +57,7 @@ export type JWKValidator = {
|
|
|
23
57
|
/** @internal */
|
|
24
58
|
export declare const DefaultJWKValidator: JWKValidator;
|
|
25
59
|
/**
|
|
60
|
+
* {@inheritDoc JWK}
|
|
26
61
|
* @group JWT
|
|
27
62
|
*/
|
|
28
63
|
export declare namespace JWK {
|
package/dist/types/jwt/JWT.d.ts
CHANGED
|
@@ -6,41 +6,129 @@ import type { JsonRecord, RawRepresentable, Expires, TimeInterval } from '../typ
|
|
|
6
6
|
import { JWKS } from './JWK.ts';
|
|
7
7
|
import { IDTokenValidator } from './IDTokenValidator.ts';
|
|
8
8
|
/**
|
|
9
|
+
* Defines registered `JWT` header parameters.
|
|
10
|
+
*
|
|
9
11
|
* @group JWT
|
|
12
|
+
* @interface
|
|
13
|
+
* @useDeclaredType
|
|
14
|
+
* @see
|
|
15
|
+
* * {@link https://datatracker.ietf.org/doc/html/rfc7515#section-4.1 | RFC 7515 - Registered Header Parameter Names}
|
|
16
|
+
* * {@link https://datatracker.ietf.org/doc/html/rfc7519#section-5 | RFC 7519 - JOSE Header}
|
|
10
17
|
*/
|
|
11
18
|
export interface JWTHeader {
|
|
19
|
+
/**
|
|
20
|
+
* Algorithm
|
|
21
|
+
* @see {@link https://datatracker.ietf.org/doc/html/rfc7515#section-4.1.1 | RFC 7515 - "alg" (Algorithm) Header Parameter}
|
|
22
|
+
*/
|
|
12
23
|
alg: string;
|
|
24
|
+
/**
|
|
25
|
+
* Key ID
|
|
26
|
+
* @see {@link https://datatracker.ietf.org/doc/html/rfc7515#section-4.1.4 | RFC 7515 - "kid" (Key ID) Header Parameter}
|
|
27
|
+
*/
|
|
13
28
|
kid?: string;
|
|
29
|
+
/**
|
|
30
|
+
* Type
|
|
31
|
+
* @see {@link https://datatracker.ietf.org/doc/html/rfc7515#section-4.1.9 | RFC 7515 - "typ" (Type) Header Parameter}
|
|
32
|
+
*/
|
|
14
33
|
typ?: string;
|
|
34
|
+
/**
|
|
35
|
+
* JWK Set URL
|
|
36
|
+
* @see {@link https://datatracker.ietf.org/doc/html/rfc7515#section-4.1.2 | RFC 7515 - "jku" (JWK Set URL) Header Parameter}
|
|
37
|
+
*/
|
|
38
|
+
jku?: string;
|
|
39
|
+
/**
|
|
40
|
+
* X.509 URL
|
|
41
|
+
* @see {@link https://datatracker.ietf.org/doc/html/rfc7515#section-4.1.5 | RFC 7515 - "x5u" (X.509 URL) Header Parameter}
|
|
42
|
+
*/
|
|
43
|
+
x5u?: string;
|
|
44
|
+
/**
|
|
45
|
+
* X.509 Certificate SHA-1 Thumbprint
|
|
46
|
+
* @see {@link https://datatracker.ietf.org/doc/html/rfc7515#section-4.1.7 | RFC 7515 - "x5t" (X.509 Certificate SHA-1 Thumbprint) Header Parameter}
|
|
47
|
+
*/
|
|
48
|
+
x5t?: string;
|
|
49
|
+
/**
|
|
50
|
+
* X.509 Certificate Chain
|
|
51
|
+
* @see {@link https://datatracker.ietf.org/doc/html/rfc7515#section-4.1.6 | RFC 7515 - "x5c" (X.509 Certificate Chain) Header Parameter}
|
|
52
|
+
*/
|
|
53
|
+
x5c?: string;
|
|
15
54
|
}
|
|
16
55
|
/**
|
|
56
|
+
* Defines registered `JWT` claim names.
|
|
57
|
+
*
|
|
17
58
|
* @group JWT
|
|
59
|
+
* @interface
|
|
60
|
+
* @useDeclaredType
|
|
61
|
+
* @see
|
|
62
|
+
* * {@link https://datatracker.ietf.org/doc/html/rfc7519#section-4 | RFC 7519 - Registered Claim Names}
|
|
18
63
|
*/
|
|
19
64
|
export type JWTPayload = {
|
|
65
|
+
/**
|
|
66
|
+
* Audience
|
|
67
|
+
* @see {@link https://datatracker.ietf.org/doc/html/rfc7519#section-4.1.3 | RFC 7519 - "aud" (Audience) Claim}
|
|
68
|
+
*/
|
|
20
69
|
aud?: string;
|
|
70
|
+
/**
|
|
71
|
+
* Issuer
|
|
72
|
+
* @see {@link https://datatracker.ietf.org/doc/html/rfc7519#section-4.1.1 | RFC 7519 - "iss" (Issuer) Claim}
|
|
73
|
+
*/
|
|
21
74
|
iss?: string;
|
|
75
|
+
/**
|
|
76
|
+
* Subject
|
|
77
|
+
* @see {@link https://datatracker.ietf.org/doc/html/rfc7519#section-4.1.2 | RFC 7519 - "sub" (Subject) Claim}
|
|
78
|
+
*/
|
|
22
79
|
sub?: string;
|
|
80
|
+
/**
|
|
81
|
+
* Expiration Time
|
|
82
|
+
* @see {@link https://datatracker.ietf.org/doc/html/rfc7519#section-4.1.4 | RFC 7519 - "exp" (Expiration Time) Claim}
|
|
83
|
+
*/
|
|
23
84
|
exp?: number;
|
|
85
|
+
/**
|
|
86
|
+
* Issued At
|
|
87
|
+
* @see {@link https://datatracker.ietf.org/doc/html/rfc7519#section-4.1.6 | RFC 7519 - "iat" (Issued At) Claim}
|
|
88
|
+
*/
|
|
24
89
|
iat?: number;
|
|
90
|
+
/**
|
|
91
|
+
* Not Before
|
|
92
|
+
* @see {@link https://datatracker.ietf.org/doc/html/rfc7519#section-4.1.5 | RFC 7519 - "nbf" (Not Before) Claim}
|
|
93
|
+
*/
|
|
25
94
|
nbf?: number;
|
|
95
|
+
/**
|
|
96
|
+
* JWT ID
|
|
97
|
+
* @see {@link https://datatracker.ietf.org/doc/html/rfc7519#section-4.1.7 | RFC 7519 - "jti" (JWT ID) Claim}
|
|
98
|
+
*/
|
|
26
99
|
jti?: string;
|
|
100
|
+
/**
|
|
101
|
+
* Scopes
|
|
102
|
+
* @see {@link https://datatracker.ietf.org/doc/html/rfc8693#section-4.2 | RFC 8693 - "scope" (Scopes) Claim}
|
|
103
|
+
*/
|
|
27
104
|
scp?: string[];
|
|
105
|
+
/**
|
|
106
|
+
* Authentication Context Class Reference
|
|
107
|
+
* @see {@link https://openid.net/specs/openid-connect-core-1_0.html#IDToken | OIDC Core - ID Token}
|
|
108
|
+
*/
|
|
28
109
|
acr?: string;
|
|
110
|
+
/**
|
|
111
|
+
* Access Token hash value
|
|
112
|
+
* @see {@link https://openid.net/specs/openid-connect-core-1_0.html#CodeIDToken | OIDC Core - "at_hash" Claim}
|
|
113
|
+
*/
|
|
29
114
|
at_hash?: string;
|
|
30
115
|
} & JsonRecord;
|
|
31
116
|
/**
|
|
32
|
-
* A class representation of a JWT
|
|
117
|
+
* A class representation of a `JWT`
|
|
33
118
|
*
|
|
34
119
|
* @group JWT
|
|
35
120
|
*
|
|
36
121
|
* @see
|
|
37
|
-
* https://datatracker.ietf.org/doc/html/rfc7519
|
|
122
|
+
* * {@link https://datatracker.ietf.org/doc/html/rfc7519 | RFC 7519 - JSON Web Token (JWT)}
|
|
123
|
+
* * {@link https://datatracker.ietf.org/doc/html/rfc7515 | RFC 7515 - JSON Web Signature (JWS)}
|
|
124
|
+
* * {@link https://datatracker.ietf.org/doc/html/rfc7517 | RFC 7517 - JSON Web Key (JWK)}
|
|
38
125
|
*/
|
|
39
126
|
export declare class JWT implements RawRepresentable, Expires {
|
|
40
127
|
#private;
|
|
41
128
|
constructor(jwtStr: string);
|
|
42
129
|
/**
|
|
43
|
-
* Writes a
|
|
130
|
+
* Writes and signs a {@link JWT} as a `string`.
|
|
131
|
+
* @group Static Methods
|
|
44
132
|
*/
|
|
45
133
|
static write(header: JWTHeader, claims: JsonRecord, signingKey: CryptoKey): Promise<string>;
|
|
46
134
|
get header(): JWTHeader;
|
|
@@ -49,52 +137,85 @@ export declare class JWT implements RawRepresentable, Expires {
|
|
|
49
137
|
/**
|
|
50
138
|
* @remarks
|
|
51
139
|
* `RawRepresentable`
|
|
52
|
-
* @returns stringified representation of the JWT
|
|
140
|
+
* @returns stringified representation of the {@link JWT}
|
|
53
141
|
*/
|
|
54
142
|
get rawValue(): string;
|
|
55
143
|
/**
|
|
144
|
+
* Alias for `JWT.claims.aud`.
|
|
56
145
|
* @group JWT Claim accessor
|
|
146
|
+
* @see {@link https://datatracker.ietf.org/doc/html/rfc7519#section-4.1.3 | RFC 7519 - "aud" (Audience) Claim}
|
|
57
147
|
*/
|
|
58
148
|
get audience(): string | undefined;
|
|
59
149
|
/**
|
|
150
|
+
* Alias for `JWT.claims.exp`, converted to a {@link !Date}.
|
|
60
151
|
* @group JWT Claim accessor
|
|
152
|
+
* @see {@link https://datatracker.ietf.org/doc/html/rfc7519#section-4.1.4 | RFC 7519 - "exp" (Expiration Time) Claim}
|
|
61
153
|
*/
|
|
62
154
|
get expirationTime(): Date | undefined;
|
|
63
155
|
/**
|
|
156
|
+
* Alias for `JWT.claims.exp`.
|
|
64
157
|
* @group JWT Claim accessor
|
|
158
|
+
* @see {@link https://datatracker.ietf.org/doc/html/rfc7519#section-4.1.4 | RFC 7519 - "exp" (Expiration Time) Claim}
|
|
65
159
|
*/
|
|
66
160
|
get expiresIn(): TimeInterval;
|
|
67
161
|
/**
|
|
162
|
+
* Alias for `JWT.claims.iss`.
|
|
68
163
|
* @group JWT Claim accessor
|
|
164
|
+
* @see {@link https://datatracker.ietf.org/doc/html/rfc7519#section-4.1.1 | RFC 7519 - "iss" (Issuer) Claim}
|
|
69
165
|
*/
|
|
70
166
|
get issuer(): string | undefined;
|
|
71
167
|
/**
|
|
168
|
+
* Alias for `JWT.claims.iat`, converted to a {@link !Date}.
|
|
72
169
|
* @group JWT Claim accessor
|
|
170
|
+
* @see {@link https://datatracker.ietf.org/doc/html/rfc7519#section-4.1.6 | RFC 7519 - "iat" (Issued At) Claim}
|
|
73
171
|
*/
|
|
74
172
|
get issuedAt(): Date | undefined;
|
|
75
173
|
/**
|
|
174
|
+
* Alias for `JWT.claims.nbf`, converted to a {@link !Date}.
|
|
76
175
|
* @group JWT Claim accessor
|
|
176
|
+
* @see {@link https://datatracker.ietf.org/doc/html/rfc7519#section-4.1.5 | RFC 7519 - "nbf" (Not Before) Claim}
|
|
77
177
|
*/
|
|
78
178
|
get notBefore(): Date | undefined;
|
|
79
179
|
/**
|
|
180
|
+
* Alias for `JWT.claims.scp` and `JWT.scopes`.
|
|
80
181
|
* @group JWT Claim accessor
|
|
182
|
+
* @see {@link https://datatracker.ietf.org/doc/html/rfc8693#section-4.2 | RFC 8693 - "scope" (Scopes) Claim}
|
|
81
183
|
*/
|
|
82
184
|
get scope(): string[] | undefined;
|
|
83
185
|
/**
|
|
186
|
+
* Alias for `JWT.claims.scp` and `JWT.scope`.
|
|
84
187
|
* @group JWT Claim accessor
|
|
188
|
+
* @see {@link https://datatracker.ietf.org/doc/html/rfc8693#section-4.2 | RFC 8693 - "scope" (Scopes) Claim}
|
|
85
189
|
*/
|
|
86
190
|
get scopes(): string[] | undefined;
|
|
87
191
|
/**
|
|
192
|
+
* Alias for `JWT.claims.sub`.
|
|
88
193
|
* @group JWT Claim accessor
|
|
194
|
+
* @see {@link https://datatracker.ietf.org/doc/html/rfc7519#section-4.1.2 | RFC 7519 - "sub" (Subject) Claim}
|
|
89
195
|
*/
|
|
90
196
|
get subject(): string | undefined;
|
|
91
197
|
/**
|
|
198
|
+
* Alias for `JWT.expirationTime`.
|
|
92
199
|
* @group JWT Claim accessor
|
|
93
200
|
*/
|
|
94
201
|
get expiresAt(): Date | undefined;
|
|
202
|
+
/**
|
|
203
|
+
* Compares the current time with the {@link JWT.expirationTime}.
|
|
204
|
+
*
|
|
205
|
+
* @see {@link Platform.TimeCoordinator}
|
|
206
|
+
*/
|
|
95
207
|
get isExpired(): boolean;
|
|
208
|
+
/**
|
|
209
|
+
* Returns `true`, if the token is not expired, compared to the {@link JWT.expirationTime}
|
|
210
|
+
*/
|
|
96
211
|
get isValid(): boolean;
|
|
212
|
+
/**
|
|
213
|
+
* Alias for {@link JWT.validate}.
|
|
214
|
+
*/
|
|
97
215
|
verifySignature(keySet: JWKS): Promise<boolean>;
|
|
216
|
+
/**
|
|
217
|
+
*
|
|
218
|
+
*/
|
|
98
219
|
validate(keySet: JWKS): Promise<boolean>;
|
|
99
220
|
toJSON(): {
|
|
100
221
|
rawValue: string;
|
|
@@ -103,5 +224,6 @@ export declare class JWT implements RawRepresentable, Expires {
|
|
|
103
224
|
}
|
|
104
225
|
/**
|
|
105
226
|
* @group JWT
|
|
227
|
+
* @internal
|
|
106
228
|
*/
|
|
107
229
|
export type JWTValidator = IDTokenValidator;
|
|
@@ -4,7 +4,13 @@
|
|
|
4
4
|
*/
|
|
5
5
|
import type { JWT } from './JWT.ts';
|
|
6
6
|
/**
|
|
7
|
+
* A validator for validating tokens via hash claims. Used in OIDC to validate access tokens (`at_hash`) and
|
|
8
|
+
* device secrets (`ds_hash`) associated with an ID token
|
|
9
|
+
*
|
|
7
10
|
* @group JWT
|
|
11
|
+
* @see
|
|
12
|
+
* * {@link https://openid.net/specs/openid-connect-core-1_0.html#CodeFlowTokenValidation | OIDC Spec: Access Token Validation}
|
|
13
|
+
* * {@link https://openid.net/specs/openid-connect-native-sso-1_0.html#section-3.4.1-2.1.2.2 | OIDC Native SSO: ID Token Claims }
|
|
8
14
|
*/
|
|
9
15
|
export interface TokenHashValidator {
|
|
10
16
|
validate: (token: string, idToken: JWT) => Promise<void>;
|
|
@@ -1,5 +1,21 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @module OAuth2
|
|
3
|
+
*
|
|
4
|
+
* @groupDescription DPoP
|
|
5
|
+
* Defined in {@link https://datatracker.ietf.org/doc/html/rfc9449 | RFC 9449}, Demonstrating Proof of Possession (DPoP)
|
|
6
|
+
* is a **significant** security improvement which binds OAuth2 tokens to a private/public key pair. The private key is only
|
|
7
|
+
* accessible to the requesting client. Any resource server (or `refresh_token` grant) requests made with bound tokens are
|
|
8
|
+
* required to be signed by the private key. Any requests which attempt to use bound tokens without a valid signature will be
|
|
9
|
+
* rejected. This results in a significantly improved security posture against token theft-based attacks, as tokens are nearly
|
|
10
|
+
* useless without access to the private key they are bound to.
|
|
11
|
+
*
|
|
12
|
+
* @groupDescription PKCE
|
|
13
|
+
* Defined in {@link https://datatracker.ietf.org/doc/html/rfc7636 | RFC 7636}, Proof Key for Code Exchange (PKCE) helps protect
|
|
14
|
+
* authorization codes (returned as the query paramter `code`) when performing `Authorization Code Flow`.
|
|
15
|
+
* The client generates a cryptographically-random string and hashes it (the challenge). Both the challenge andhashing algorithm are
|
|
16
|
+
* provided to the authorization server as parameters to `/authorize`. When the client receives the `code` from the authorization server,
|
|
17
|
+
* it must provide a `code_verifier`, the orginial pre-hashed string when the `code` is exchanged for tokens. The token exchange will fail
|
|
18
|
+
* if an incorrect verifier is provided.
|
|
3
19
|
*/
|
|
4
20
|
import type { OpenIdConfiguration, OAuth2ErrorResponse, JsonRecord } from '../types/index.ts';
|
|
5
21
|
import { JWKS, IDTokenValidator, TokenHashValidator } from '../jwt/index.ts';
|
|
@@ -11,21 +27,30 @@ import { PromiseQueue } from '../utils/PromiseQueue.ts';
|
|
|
11
27
|
import { EventEmitter } from '../utils/EventEmitter.ts';
|
|
12
28
|
/**
|
|
13
29
|
* @group OAuth2Client
|
|
30
|
+
* @typeParam E - Map of all events fired from {@link APIClient.emitter}
|
|
14
31
|
* @noInheritDoc
|
|
15
32
|
*/
|
|
16
33
|
export declare class OAuth2Client<E extends OAuth2Client.Events = OAuth2Client.Events> extends APIClient<E> {
|
|
17
34
|
#private;
|
|
18
35
|
/**
|
|
19
|
-
* @group
|
|
36
|
+
* @group Validators
|
|
20
37
|
*/
|
|
21
38
|
static readonly idTokenValidator: IDTokenValidator;
|
|
22
39
|
/**
|
|
23
|
-
* @group
|
|
40
|
+
* @group Validators
|
|
24
41
|
*/
|
|
25
42
|
static readonly accessTokenValidator: TokenHashValidator;
|
|
26
43
|
/** @internal */
|
|
27
44
|
protected readonly queue: PromiseQueue;
|
|
45
|
+
/**
|
|
46
|
+
* Possible events: {@link OAuth2Client.Events}
|
|
47
|
+
*/
|
|
28
48
|
readonly emitter: EventEmitter<E>;
|
|
49
|
+
/**
|
|
50
|
+
* Configuration of client
|
|
51
|
+
*
|
|
52
|
+
* @remarks
|
|
53
|
+
*/
|
|
29
54
|
readonly configuration: OAuth2Client.Configuration;
|
|
30
55
|
constructor(params: ConfigurationParams | OAuth2Client.Configuration);
|
|
31
56
|
/** @internal */
|
|
@@ -43,16 +68,28 @@ export declare class OAuth2Client<E extends OAuth2Client.Events = OAuth2Client.E
|
|
|
43
68
|
protected checkForDPoPNonceErrorResponse(response: Response): Promise<string | undefined>;
|
|
44
69
|
/** @internal */
|
|
45
70
|
protected prepareDPoPNonceRetry(request: APIRequest, nonce: string): Promise<void>;
|
|
71
|
+
/** @internal */
|
|
46
72
|
protected signTokenRequestWithDPoP(request: APIRequest, nonce?: string): Promise<void>;
|
|
73
|
+
/** @internal */
|
|
47
74
|
protected processResponse(response: Response, request: APIRequest): Promise<void>;
|
|
48
75
|
/** @internal */
|
|
49
76
|
protected getJson(url: URL, options?: OAuth2Client.GetJsonOptions): Promise<JsonRecord>;
|
|
77
|
+
/**
|
|
78
|
+
* Cleans up resources associated with the client instance to prevent leaks.
|
|
79
|
+
*/
|
|
80
|
+
dispose(): void;
|
|
50
81
|
/**
|
|
51
82
|
* Retrieves the Authorization Server's OpenID configuration
|
|
83
|
+
*
|
|
84
|
+
* @see
|
|
85
|
+
* {@link https://datatracker.ietf.org/doc/html/rfc8414#section-3 | RFC 8414: Obtaining Authorization Server Metadata}
|
|
52
86
|
*/
|
|
53
87
|
openIdConfiguration(options?: OAuth2Client.GetJsonOptions): Promise<OpenIdConfiguration>;
|
|
54
88
|
/**
|
|
55
|
-
* Retrieves
|
|
89
|
+
* Retrieves authorization server's `jwks_uri` endpoint.
|
|
90
|
+
* Resulting {@link Core.JWKS | JWKS} are used to perform `id_token` validation
|
|
91
|
+
*
|
|
92
|
+
* @see {@link https://datatracker.ietf.org/doc/html/rfc8414#section-2 | RFC 8414 - Authorization Server Metadata}
|
|
56
93
|
*/
|
|
57
94
|
jwks(options?: OAuth2Client.GetJsonOptions): Promise<JWKS>;
|
|
58
95
|
/** @internal */
|
|
@@ -60,29 +97,53 @@ export declare class OAuth2Client<E extends OAuth2Client.Events = OAuth2Client.E
|
|
|
60
97
|
/** @internal */
|
|
61
98
|
protected validateToken(request: Token.TokenRequest, keySet: JWKS, token: Token): Promise<Token | OAuth2ErrorResponse>;
|
|
62
99
|
/**
|
|
63
|
-
* Attempts
|
|
100
|
+
* Attempts a `token_endpoint` request. If the request is sucessful, the resulting tokens are validated
|
|
101
|
+
*
|
|
102
|
+
* @see
|
|
103
|
+
* * {@link https://datatracker.ietf.org/doc/html/rfc8414#section-2 | RFC 8414 - Authorization Server Metadata}
|
|
104
|
+
* * {@link https://openid.net/specs/openid-connect-core-1_0.html#IDTokenValidation | OIDC 1.0 - ID Token Validation}
|
|
64
105
|
*/
|
|
65
106
|
exchange(request: Token.TokenRequest): Promise<Token | OAuth2ErrorResponse>;
|
|
66
107
|
/**
|
|
67
|
-
* Attempts to refresh the provided token, using the {@link Token.
|
|
108
|
+
* Attempts to refresh the provided token, using the {@link Token.refreshToken | refreshToken}
|
|
109
|
+
*
|
|
110
|
+
* @remarks
|
|
111
|
+
* Requires `offline_access` to a scope in the orginial authentication request
|
|
112
|
+
*
|
|
113
|
+
* @see {@link https://datatracker.ietf.org/doc/html/rfc6749#section-6 | RFC 6749 - Refreshing an Access Token}
|
|
68
114
|
*/
|
|
69
115
|
refresh(token: Token, scopes?: string[]): Promise<Token | OAuth2ErrorResponse>;
|
|
70
116
|
/** @internal */
|
|
71
|
-
protected
|
|
117
|
+
protected sendRefreshRequest(request: Token.RefreshRequest, context: OAuth2Client.TokenRequestContext): Promise<OAuth2ErrorResponse | Token>;
|
|
72
118
|
/** @internal */
|
|
73
119
|
protected performRefresh(token: Token, scopes?: string[]): Promise<OAuth2ErrorResponse | Token>;
|
|
74
120
|
/**
|
|
75
|
-
* Attempts
|
|
121
|
+
* Attempts a `revocation_endpoint` request with the provided {@link Token}
|
|
122
|
+
* @param token - The token to be revoked
|
|
123
|
+
* @param type - Possible values:<br/>
|
|
124
|
+
* * `'ALL'` - revokes both the `access_token` and `refresh_token`.<br/>
|
|
125
|
+
* * `'ACCESS'` - revokes **only** the `access_token`.<br/>
|
|
126
|
+
* * `'REFRESH'` - revokes **only** the `refresh_token`.
|
|
127
|
+
*
|
|
128
|
+
* @see {@link https://datatracker.ietf.org/doc/html/rfc7009 | RFC 7009 - OAuth 2.0 Token Revocation }
|
|
76
129
|
*/
|
|
77
130
|
revoke(token: Token, type: Token.RevokeType): Promise<void | OAuth2ErrorResponse>;
|
|
78
131
|
/** @internal */
|
|
79
132
|
protected revokeAll(token: Token): Promise<void | OAuth2ErrorResponse>;
|
|
80
133
|
/**
|
|
81
|
-
*
|
|
134
|
+
* Attempts an `introspection_endpoint` request with the provided {@link Token}
|
|
135
|
+
*
|
|
136
|
+
* @see {@link https://datatracker.ietf.org/doc/html/rfc7662 | RFC 7662 - OAuth 2.0 Token Introspection }
|
|
82
137
|
*/
|
|
83
138
|
introspect(token: Token, kind: Token.Kind): Promise<Token.IntrospectResponse | OAuth2ErrorResponse>;
|
|
84
139
|
/**
|
|
85
|
-
*
|
|
140
|
+
* Attempts an `userinfo_endpoint` request with the provided {@link Token}
|
|
141
|
+
*
|
|
142
|
+
* @remarks
|
|
143
|
+
* The user profile returned by this method will vary based on user's profle data and organization settings
|
|
144
|
+
* @inlineType UserInfo
|
|
145
|
+
*
|
|
146
|
+
* @see {@link https://openid.net/specs/openid-connect-core-1_0.html#UserInfo | OIDC 1.0 - UserInfo Endpoint}
|
|
86
147
|
*/
|
|
87
148
|
userInfo(token: Token): Promise<UserInfo | OAuth2ErrorResponse>;
|
|
88
149
|
}
|
|
@@ -90,8 +151,22 @@ export declare class OAuth2Client<E extends OAuth2Client.Events = OAuth2Client.E
|
|
|
90
151
|
* @group OAuth2Client
|
|
91
152
|
*/
|
|
92
153
|
export declare namespace OAuth2Client {
|
|
93
|
-
|
|
94
|
-
|
|
154
|
+
/** @reexport */
|
|
155
|
+
const Configuration: typeof ConfigurationConstructor;
|
|
156
|
+
type Configuration = InstanceType<typeof ConfigurationConstructor>;
|
|
157
|
+
/**
|
|
158
|
+
* @interface
|
|
159
|
+
* Map of events fired from {@link OAuth2Client.emitter}
|
|
160
|
+
*
|
|
161
|
+
* @example
|
|
162
|
+
* ```ts
|
|
163
|
+
* // key = Event name
|
|
164
|
+
* // value = Event Type
|
|
165
|
+
* client.emitter.on('will_send', ({ request }) => {
|
|
166
|
+
* console.log(request.url.href);
|
|
167
|
+
* });
|
|
168
|
+
* ```
|
|
169
|
+
*/
|
|
95
170
|
type Events = {
|
|
96
171
|
/**
|
|
97
172
|
* Triggered when a token refresh attempt begins
|
|
@@ -116,5 +191,14 @@ export declare namespace OAuth2Client {
|
|
|
116
191
|
type GetJsonOptions = {
|
|
117
192
|
skipCache?: boolean;
|
|
118
193
|
};
|
|
194
|
+
/**
|
|
195
|
+
* When a client has the incorrect time, all DPoP JWTs signed by the client will be rejected by the
|
|
196
|
+
* authorization or resource server because the JWT's claims cannot be validated. This method checks
|
|
197
|
+
* server responses for this specific error condition.
|
|
198
|
+
*
|
|
199
|
+
* @remarks
|
|
200
|
+
* This method has only been tested against Okta authorization servers. Different IDPs may use a
|
|
201
|
+
* different `error_description`.
|
|
202
|
+
*/
|
|
119
203
|
function isDPoPProofClockSkewError(error: OAuth2ErrorResponse): boolean;
|
|
120
204
|
}
|