@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,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @group APIClient
|
|
3
|
+
*/
|
|
4
|
+
export type APIRequestInit = RequestInit & {
|
|
5
|
+
context?: object;
|
|
6
|
+
};
|
|
7
|
+
/**
|
|
8
|
+
* @group APIClient
|
|
9
|
+
*/
|
|
10
|
+
export declare class APIRequest extends Request {
|
|
11
|
+
#private;
|
|
12
|
+
static MaxRetryAttempts: number;
|
|
13
|
+
readonly context: Record<string, any>;
|
|
14
|
+
constructor(input: string | URL | Request, init?: APIRequestInit);
|
|
15
|
+
get retryAttempt(): number;
|
|
16
|
+
canRetry(): boolean;
|
|
17
|
+
markRetry(): void;
|
|
18
|
+
clone(): APIRequest;
|
|
19
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module
|
|
3
|
+
* @mergeModuleWith OAuth2
|
|
4
|
+
*/
|
|
5
|
+
import type { OpenIdConfiguration } from '../../types/index.ts';
|
|
6
|
+
import type { OAuth2Client } from '../../oauth2/client.ts';
|
|
7
|
+
import { APIRequest } from './APIRequest.ts';
|
|
8
|
+
/**
|
|
9
|
+
* @group OAuth2Request
|
|
10
|
+
*/
|
|
11
|
+
export declare abstract class OAuth2Request {
|
|
12
|
+
headers: Headers;
|
|
13
|
+
body: URLSearchParams;
|
|
14
|
+
openIdConfiguration: OpenIdConfiguration;
|
|
15
|
+
clientConfiguration: OAuth2Client.Configuration;
|
|
16
|
+
clientAuthentication: any;
|
|
17
|
+
constructor(params: OAuth2Request.RequestParams);
|
|
18
|
+
abstract get url(): string;
|
|
19
|
+
prepare(context?: object): APIRequest;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* @group OAuth2Request
|
|
23
|
+
*/
|
|
24
|
+
export declare namespace OAuth2Request {
|
|
25
|
+
interface RequestParams {
|
|
26
|
+
openIdConfiguration: OpenIdConfiguration;
|
|
27
|
+
clientConfiguration: OAuth2Client.Configuration;
|
|
28
|
+
clientAuthentication?: any;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module
|
|
3
|
+
* @mergeModuleWith Networking
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* @group WWWAuthenticate
|
|
7
|
+
*/
|
|
8
|
+
export interface WWWAuthenticateError {
|
|
9
|
+
readonly error: string;
|
|
10
|
+
readonly errorDescription: string;
|
|
11
|
+
readonly scheme: string;
|
|
12
|
+
[key: string]: string;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* @group WWWAuthenticate
|
|
16
|
+
*/
|
|
17
|
+
export declare function isWWWAuthenticateError(input: unknown): input is WWWAuthenticateError;
|
|
18
|
+
/**
|
|
19
|
+
* parses a www-authenticate header and builds an object representation of the error condition
|
|
20
|
+
*
|
|
21
|
+
* @group WWWAuthenticate
|
|
22
|
+
*/
|
|
23
|
+
export declare function parse(header: string | Headers | Response): WWWAuthenticateError | null;
|
|
24
|
+
/**
|
|
25
|
+
* Returns string value of a `www-authenticate` header
|
|
26
|
+
*
|
|
27
|
+
* @remarks
|
|
28
|
+
* `HeadersInit` allows for a few different representations of headers with different access patterns (.get vs [key])
|
|
29
|
+
*
|
|
30
|
+
* @group WWWAuthenticate
|
|
31
|
+
*/
|
|
32
|
+
export declare function getHeader(headers: HeadersInit): string | null;
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module
|
|
3
|
+
* @mergeModuleWith Core
|
|
4
|
+
*/
|
|
5
|
+
import type { AcrValues } from '../types/index.ts';
|
|
6
|
+
import type { JWT } from './JWT.ts';
|
|
7
|
+
/**
|
|
8
|
+
* @group JWT
|
|
9
|
+
*/
|
|
10
|
+
export interface IDTokenValidatorContext {
|
|
11
|
+
nonce?: string;
|
|
12
|
+
maxAge?: number;
|
|
13
|
+
acrValues?: AcrValues;
|
|
14
|
+
supportedAlgs?: string[];
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* @group JWT
|
|
18
|
+
*/
|
|
19
|
+
export interface IDTokenValidator {
|
|
20
|
+
issuedAtGraceInterval: number;
|
|
21
|
+
checks: IDTokenValidator.ValidationCheck[];
|
|
22
|
+
validate: (token: JWT, issuer: URL, clientId: string, context?: IDTokenValidatorContext) => void;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* @group JWT
|
|
26
|
+
*
|
|
27
|
+
* @remarks
|
|
28
|
+
* https://openid.net/specs/openid-connect-core-1_0-final.html#IDToken
|
|
29
|
+
*/
|
|
30
|
+
export declare namespace IDTokenValidator {
|
|
31
|
+
/**
|
|
32
|
+
* A list of validition checks which will be performed to validate a {@link JWT}
|
|
33
|
+
*/
|
|
34
|
+
const allValidationChecks: readonly ["issuer", "audience", "scheme", "algorithm", "expirationTime", "issuedAtTime", "nonce", "maxAge", "subject", "acr"];
|
|
35
|
+
type ValidationCheck = (typeof allValidationChecks)[number];
|
|
36
|
+
}
|
|
37
|
+
/** @internal */
|
|
38
|
+
export declare const DefaultIDTokenValidator: IDTokenValidator;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module
|
|
3
|
+
* @mergeModuleWith Core
|
|
4
|
+
*/
|
|
5
|
+
import type { JWT } from './JWT.ts';
|
|
6
|
+
/**
|
|
7
|
+
* @group JWT
|
|
8
|
+
*/
|
|
9
|
+
export interface JWK extends JsonWebKey {
|
|
10
|
+
alg: JWK.Algorithm;
|
|
11
|
+
kid: string;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* @group JWT
|
|
15
|
+
*/
|
|
16
|
+
export type JWKS = JWK[];
|
|
17
|
+
/**
|
|
18
|
+
* @group JWT
|
|
19
|
+
*/
|
|
20
|
+
export type JWKValidator = {
|
|
21
|
+
validate: (token: JWT, keySet: JWKS) => Promise<boolean>;
|
|
22
|
+
};
|
|
23
|
+
/** @internal */
|
|
24
|
+
export declare const DefaultJWKValidator: JWKValidator;
|
|
25
|
+
/**
|
|
26
|
+
* @group JWT
|
|
27
|
+
*/
|
|
28
|
+
export declare namespace JWK {
|
|
29
|
+
type Algorithm = 'RS256';
|
|
30
|
+
const validator: JWKValidator;
|
|
31
|
+
}
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module
|
|
3
|
+
* @mergeModuleWith Core
|
|
4
|
+
*/
|
|
5
|
+
import type { JsonRecord, RawRepresentable, Expires, TimeInterval } from '../types/index.ts';
|
|
6
|
+
import { JWKS } from './JWK.ts';
|
|
7
|
+
import { IDTokenValidator } from './IDTokenValidator.ts';
|
|
8
|
+
/**
|
|
9
|
+
* @group JWT
|
|
10
|
+
*/
|
|
11
|
+
export interface JWTHeader {
|
|
12
|
+
alg: string;
|
|
13
|
+
kid?: string;
|
|
14
|
+
typ?: string;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* @group JWT
|
|
18
|
+
*/
|
|
19
|
+
export type JWTPayload = {
|
|
20
|
+
aud?: string;
|
|
21
|
+
iss?: string;
|
|
22
|
+
sub?: string;
|
|
23
|
+
exp?: number;
|
|
24
|
+
iat?: number;
|
|
25
|
+
nbf?: number;
|
|
26
|
+
jti?: string;
|
|
27
|
+
scp?: string[];
|
|
28
|
+
acr?: string;
|
|
29
|
+
at_hash?: string;
|
|
30
|
+
} & JsonRecord;
|
|
31
|
+
/**
|
|
32
|
+
* A class representation of a JWT
|
|
33
|
+
*
|
|
34
|
+
* @group JWT
|
|
35
|
+
*
|
|
36
|
+
* @see
|
|
37
|
+
* https://datatracker.ietf.org/doc/html/rfc7519
|
|
38
|
+
*/
|
|
39
|
+
export declare class JWT implements RawRepresentable, Expires {
|
|
40
|
+
#private;
|
|
41
|
+
constructor(jwtStr: string);
|
|
42
|
+
/**
|
|
43
|
+
* Writes a signed JWT string
|
|
44
|
+
*/
|
|
45
|
+
static write(header: JWTHeader, claims: JsonRecord, signingKey: CryptoKey): Promise<string>;
|
|
46
|
+
get header(): JWTHeader;
|
|
47
|
+
get claims(): JWTPayload;
|
|
48
|
+
get payload(): JWTPayload;
|
|
49
|
+
/**
|
|
50
|
+
* @remarks
|
|
51
|
+
* `RawRepresentable`
|
|
52
|
+
* @returns stringified representation of the JWT
|
|
53
|
+
*/
|
|
54
|
+
get rawValue(): string;
|
|
55
|
+
/**
|
|
56
|
+
* @group JWT Claim accessor
|
|
57
|
+
*/
|
|
58
|
+
get audience(): string | undefined;
|
|
59
|
+
/**
|
|
60
|
+
* @group JWT Claim accessor
|
|
61
|
+
*/
|
|
62
|
+
get expirationTime(): Date | undefined;
|
|
63
|
+
/**
|
|
64
|
+
* @group JWT Claim accessor
|
|
65
|
+
*/
|
|
66
|
+
get expiresIn(): TimeInterval;
|
|
67
|
+
/**
|
|
68
|
+
* @group JWT Claim accessor
|
|
69
|
+
*/
|
|
70
|
+
get issuer(): string | undefined;
|
|
71
|
+
/**
|
|
72
|
+
* @group JWT Claim accessor
|
|
73
|
+
*/
|
|
74
|
+
get issuedAt(): Date | undefined;
|
|
75
|
+
/**
|
|
76
|
+
* @group JWT Claim accessor
|
|
77
|
+
*/
|
|
78
|
+
get notBefore(): Date | undefined;
|
|
79
|
+
/**
|
|
80
|
+
* @group JWT Claim accessor
|
|
81
|
+
*/
|
|
82
|
+
get scope(): string[] | undefined;
|
|
83
|
+
/**
|
|
84
|
+
* @group JWT Claim accessor
|
|
85
|
+
*/
|
|
86
|
+
get scopes(): string[] | undefined;
|
|
87
|
+
/**
|
|
88
|
+
* @group JWT Claim accessor
|
|
89
|
+
*/
|
|
90
|
+
get subject(): string | undefined;
|
|
91
|
+
/**
|
|
92
|
+
* @group JWT Claim accessor
|
|
93
|
+
*/
|
|
94
|
+
get expiresAt(): Date | undefined;
|
|
95
|
+
get isExpired(): boolean;
|
|
96
|
+
get isValid(): boolean;
|
|
97
|
+
verifySignature(keySet: JWKS): Promise<boolean>;
|
|
98
|
+
validate(keySet: JWKS): Promise<boolean>;
|
|
99
|
+
toJSON(): {
|
|
100
|
+
rawValue: string;
|
|
101
|
+
};
|
|
102
|
+
toString(): string;
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* @group JWT
|
|
106
|
+
*/
|
|
107
|
+
export type JWTValidator = IDTokenValidator;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module
|
|
3
|
+
* @mergeModuleWith Core
|
|
4
|
+
*/
|
|
5
|
+
import type { JWT } from './JWT.ts';
|
|
6
|
+
/**
|
|
7
|
+
* @group JWT
|
|
8
|
+
*/
|
|
9
|
+
export interface TokenHashValidator {
|
|
10
|
+
validate: (token: string, idToken: JWT) => Promise<void>;
|
|
11
|
+
}
|
|
12
|
+
/** @internal */
|
|
13
|
+
export declare function DefaultTokenHashValidator(hashKey: string): TokenHashValidator;
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module OAuth2
|
|
3
|
+
*/
|
|
4
|
+
import type { OpenIdConfiguration, OAuth2ErrorResponse, JsonRecord } from '../types/index.ts';
|
|
5
|
+
import { JWKS, IDTokenValidator, TokenHashValidator } from '../jwt/index.ts';
|
|
6
|
+
import { APIClient, APIRequest } from '../http/index.ts';
|
|
7
|
+
import { Configuration as ConfigurationConstructor, type ConfigurationParams } from './configuration.ts';
|
|
8
|
+
import { Token } from '../Token.ts';
|
|
9
|
+
import { UserInfo } from './requests/UserInfo.ts';
|
|
10
|
+
import { PromiseQueue } from '../utils/PromiseQueue.ts';
|
|
11
|
+
import { EventEmitter } from '../utils/EventEmitter.ts';
|
|
12
|
+
/**
|
|
13
|
+
* @group OAuth2Client
|
|
14
|
+
* @noInheritDoc
|
|
15
|
+
*/
|
|
16
|
+
export declare class OAuth2Client<E extends OAuth2Client.Events = OAuth2Client.Events> extends APIClient<E> {
|
|
17
|
+
#private;
|
|
18
|
+
/**
|
|
19
|
+
* @group Customizations
|
|
20
|
+
*/
|
|
21
|
+
static readonly idTokenValidator: IDTokenValidator;
|
|
22
|
+
/**
|
|
23
|
+
* @group Customizations
|
|
24
|
+
*/
|
|
25
|
+
static readonly accessTokenValidator: TokenHashValidator;
|
|
26
|
+
/** @internal */
|
|
27
|
+
protected readonly queue: PromiseQueue;
|
|
28
|
+
readonly emitter: EventEmitter<E>;
|
|
29
|
+
readonly configuration: OAuth2Client.Configuration;
|
|
30
|
+
constructor(params: ConfigurationParams | OAuth2Client.Configuration);
|
|
31
|
+
/** @internal */
|
|
32
|
+
protected getDPoPNonceCacheKey(request: APIRequest): string;
|
|
33
|
+
/**
|
|
34
|
+
* @remarks
|
|
35
|
+
* Auth Servers return a 400 with dpop-nonce header and a json body identifying the error
|
|
36
|
+
*
|
|
37
|
+
* @see
|
|
38
|
+
* - https://datatracker.ietf.org/doc/html/rfc9449#section-8
|
|
39
|
+
* - https://datatracker.ietf.org/doc/html/rfc9449#figure-20
|
|
40
|
+
*
|
|
41
|
+
* @internal
|
|
42
|
+
*/
|
|
43
|
+
protected checkForDPoPNonceErrorResponse(response: Response): Promise<string | undefined>;
|
|
44
|
+
/** @internal */
|
|
45
|
+
protected prepareDPoPNonceRetry(request: APIRequest, nonce: string): Promise<void>;
|
|
46
|
+
protected signTokenRequestWithDPoP(request: APIRequest, nonce?: string): Promise<void>;
|
|
47
|
+
protected processResponse(response: Response, request: APIRequest): Promise<void>;
|
|
48
|
+
/** @internal */
|
|
49
|
+
protected getJson(url: URL, options?: OAuth2Client.GetJsonOptions): Promise<JsonRecord>;
|
|
50
|
+
/**
|
|
51
|
+
* Retrieves the Authorization Server's OpenID configuration
|
|
52
|
+
*/
|
|
53
|
+
openIdConfiguration(options?: OAuth2Client.GetJsonOptions): Promise<OpenIdConfiguration>;
|
|
54
|
+
/**
|
|
55
|
+
* Retrieves the Authorization Server's {@link Core.JWKS | JWKS} key configuration
|
|
56
|
+
*/
|
|
57
|
+
jwks(options?: OAuth2Client.GetJsonOptions): Promise<JWKS>;
|
|
58
|
+
/** @internal */
|
|
59
|
+
protected sendTokenRequest(tokenRequest: Token.TokenRequest, requestContext?: OAuth2Client.TokenRequestContext): Promise<Token | OAuth2ErrorResponse>;
|
|
60
|
+
/** @internal */
|
|
61
|
+
protected validateToken(request: Token.TokenRequest, keySet: JWKS, token: Token): Promise<Token | OAuth2ErrorResponse>;
|
|
62
|
+
/**
|
|
63
|
+
* Attempts to exchange, and verify, a token from the provided request
|
|
64
|
+
*/
|
|
65
|
+
exchange(request: Token.TokenRequest): Promise<Token | OAuth2ErrorResponse>;
|
|
66
|
+
/**
|
|
67
|
+
* Attempts to refresh the provided token, using the {@link Token.Token.refreshToken | refreshToken} if it is available
|
|
68
|
+
*/
|
|
69
|
+
refresh(token: Token, scopes?: string[]): Promise<Token | OAuth2ErrorResponse>;
|
|
70
|
+
/** @internal */
|
|
71
|
+
protected prepareRefreshRequest(token: Token, scopes?: string[]): Promise<Token | OAuth2ErrorResponse>;
|
|
72
|
+
/** @internal */
|
|
73
|
+
protected performRefresh(token: Token, scopes?: string[]): Promise<OAuth2ErrorResponse | Token>;
|
|
74
|
+
/**
|
|
75
|
+
* Attempts to revoke the provided token
|
|
76
|
+
*/
|
|
77
|
+
revoke(token: Token, type: Token.RevokeType): Promise<void | OAuth2ErrorResponse>;
|
|
78
|
+
/** @internal */
|
|
79
|
+
protected revokeAll(token: Token): Promise<void | OAuth2ErrorResponse>;
|
|
80
|
+
/**
|
|
81
|
+
* Introspects the provided token information
|
|
82
|
+
*/
|
|
83
|
+
introspect(token: Token, kind: Token.Kind): Promise<Token.IntrospectResponse | OAuth2ErrorResponse>;
|
|
84
|
+
/**
|
|
85
|
+
* Fetches the {@link UserInfo} associated with the provided token
|
|
86
|
+
*/
|
|
87
|
+
userInfo(token: Token): Promise<UserInfo | OAuth2ErrorResponse>;
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* @group OAuth2Client
|
|
91
|
+
*/
|
|
92
|
+
export declare namespace OAuth2Client {
|
|
93
|
+
class Configuration extends ConfigurationConstructor {
|
|
94
|
+
}
|
|
95
|
+
type Events = {
|
|
96
|
+
/**
|
|
97
|
+
* Triggered when a token refresh attempt begins
|
|
98
|
+
*/
|
|
99
|
+
'token_will_refresh': {
|
|
100
|
+
token: Token;
|
|
101
|
+
};
|
|
102
|
+
/**
|
|
103
|
+
* Triggered when a token refresh attempt succeeds
|
|
104
|
+
*/
|
|
105
|
+
'token_did_refresh': {
|
|
106
|
+
token: Token;
|
|
107
|
+
};
|
|
108
|
+
} & APIClient.Events;
|
|
109
|
+
/** @internal */
|
|
110
|
+
type TokenRequestContext = {
|
|
111
|
+
dpopPairId?: string;
|
|
112
|
+
};
|
|
113
|
+
/** @internal */
|
|
114
|
+
const DefaultGetJsonOptions: GetJsonOptions;
|
|
115
|
+
/** @internal */
|
|
116
|
+
type GetJsonOptions = {
|
|
117
|
+
skipCache?: boolean;
|
|
118
|
+
};
|
|
119
|
+
function isDPoPProofClockSkewError(error: OAuth2ErrorResponse): boolean;
|
|
120
|
+
}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module
|
|
3
|
+
* @mergeModuleWith OAuth2
|
|
4
|
+
*/
|
|
5
|
+
import type { ClientAuthentication, APIClientConfiguration, JSONSerializable, JsonRecord, OAuth2Params, DiscrimUnion } from '../types/index.ts';
|
|
6
|
+
import { APIClient } from '../http/index.ts';
|
|
7
|
+
export type OAuth2ClientConfigurations = DiscrimUnion<OAuth2Params & {
|
|
8
|
+
baseURL: URL | string;
|
|
9
|
+
discoveryURL?: URL | string;
|
|
10
|
+
}, 'issuer' | 'baseURL'>;
|
|
11
|
+
export type OAuth2ClientOptions = {
|
|
12
|
+
authentication?: ClientAuthentication;
|
|
13
|
+
allowHTTP?: boolean;
|
|
14
|
+
syncClockWithAuthorizationServer?: boolean;
|
|
15
|
+
};
|
|
16
|
+
/**
|
|
17
|
+
* @group Configuration
|
|
18
|
+
* @useDeclaredType
|
|
19
|
+
*/
|
|
20
|
+
export type ConfigurationParams = OAuth2ClientConfigurations & OAuth2ClientOptions;
|
|
21
|
+
/**
|
|
22
|
+
* @group Configuration
|
|
23
|
+
*/
|
|
24
|
+
export declare class Configuration extends APIClient.Configuration implements APIClientConfiguration, JSONSerializable {
|
|
25
|
+
readonly issuer: URL;
|
|
26
|
+
readonly discoveryURL: URL;
|
|
27
|
+
readonly clientId: string;
|
|
28
|
+
scopes: string;
|
|
29
|
+
authentication: ClientAuthentication;
|
|
30
|
+
/**
|
|
31
|
+
* When `true`, issuer and other .well-known endpoints can be HTTP. Defaults to `false`
|
|
32
|
+
*/
|
|
33
|
+
allowHTTP: boolean;
|
|
34
|
+
/**
|
|
35
|
+
* When `true`, the `Date` header from HTTP requests made to the Authorization Server will be
|
|
36
|
+
* used to calculate a clock skew between the Authorization Server and the system clock. This is
|
|
37
|
+
* useful for situations when the client's system clock is set to something other than the "true time".
|
|
38
|
+
*
|
|
39
|
+
* Defaults to `true`.
|
|
40
|
+
*
|
|
41
|
+
* @remarks
|
|
42
|
+
* By default, the `Date` header is not safelisted for CORS requests. The Authorization Server will need
|
|
43
|
+
* to include the `Date` header in the `allow-control-exppose-headers` for this feature to work properly.
|
|
44
|
+
*
|
|
45
|
+
* Reference: https://developer.mozilla.org/en-US/docs/Glossary/CORS-safelisted_response_header
|
|
46
|
+
*/
|
|
47
|
+
syncClockWithAuthorizationServer: boolean;
|
|
48
|
+
static DefaultOptions: Required<OAuth2ClientOptions> & typeof APIClient.Configuration.DefaultOptions;
|
|
49
|
+
constructor(params: ConfigurationParams);
|
|
50
|
+
/**
|
|
51
|
+
* Alias to {@link issuer} for backwards compatibility
|
|
52
|
+
*/
|
|
53
|
+
get baseURL(): URL;
|
|
54
|
+
matches(params: OAuth2Params): boolean;
|
|
55
|
+
toJSON(): JsonRecord;
|
|
56
|
+
}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module
|
|
3
|
+
* @mergeModuleWith OAuth2
|
|
4
|
+
*/
|
|
5
|
+
import type { DPoPHeaders, DPoPClaims, DPoPProofParams } from './types.ts';
|
|
6
|
+
import { DPoPStorage } from './storage.ts';
|
|
7
|
+
import { DPoPNonceCache } from './nonceCache.ts';
|
|
8
|
+
export { DPoPNonceCache, DPoPStorage };
|
|
9
|
+
export type { DPoPHeaders, DPoPClaims, DPoPProofParams };
|
|
10
|
+
/**
|
|
11
|
+
* @group DPoP
|
|
12
|
+
*
|
|
13
|
+
*/
|
|
14
|
+
export interface DPoPSigningAuthority {
|
|
15
|
+
createDPoPKeyPair: () => Promise<string>;
|
|
16
|
+
deleteDPoPKeyPair: (keyPairId: string) => Promise<void>;
|
|
17
|
+
clearDPoPKeyPairs: () => Promise<void>;
|
|
18
|
+
sign: (request: Request, params: Omit<DPoPProofParams, 'request'>) => Promise<Request>;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* @internal
|
|
22
|
+
* @group DPoP
|
|
23
|
+
* Default implementation of a DPoP Signing Authority.
|
|
24
|
+
* Signs outgoing network requests with a dpop proof (private key JWT) as well as
|
|
25
|
+
* creates, stores and retrieves the Crypto Key Pairs necessary for the signing operation
|
|
26
|
+
*
|
|
27
|
+
*/
|
|
28
|
+
export declare class DPoPSigningAuthorityImpl implements DPoPSigningAuthority {
|
|
29
|
+
private readonly store;
|
|
30
|
+
constructor(store: DPoPStorage);
|
|
31
|
+
/**
|
|
32
|
+
* @internal
|
|
33
|
+
* @group DPoP
|
|
34
|
+
* @returns a public/private key pair. The private key will be non-extractable
|
|
35
|
+
*/
|
|
36
|
+
private generateKeyPair;
|
|
37
|
+
/**
|
|
38
|
+
* Generates a (non-extractable) key pair and writes it to storage, to be used for `DPoP` signatures
|
|
39
|
+
*
|
|
40
|
+
* @group DPoP
|
|
41
|
+
* @returns `id` representing the generated key pair
|
|
42
|
+
*/
|
|
43
|
+
createDPoPKeyPair(): Promise<string>;
|
|
44
|
+
/**
|
|
45
|
+
* Removes a `DPoP` key pair from storage
|
|
46
|
+
*
|
|
47
|
+
* @group DPoP
|
|
48
|
+
*/
|
|
49
|
+
deleteDPoPKeyPair(keyPairId: string): Promise<void>;
|
|
50
|
+
/**
|
|
51
|
+
* Clears `DPoP` storage of all key pairs
|
|
52
|
+
*
|
|
53
|
+
* @group DPoP
|
|
54
|
+
*/
|
|
55
|
+
clearDPoPKeyPairs(): Promise<void>;
|
|
56
|
+
/**
|
|
57
|
+
* TODO: Document method
|
|
58
|
+
*
|
|
59
|
+
* @group DPoP
|
|
60
|
+
* @returns A `DPoP` `JWT` proof for the provided `Request`
|
|
61
|
+
*/
|
|
62
|
+
private generateDPoPProof;
|
|
63
|
+
/**
|
|
64
|
+
* Signs an outgoing network requests with a DPoP proof
|
|
65
|
+
* @param request - outgoing network request to be sign with a DPoP proof
|
|
66
|
+
* @param params - the required component necessary to generate the DPoP proof
|
|
67
|
+
* @returns
|
|
68
|
+
*/
|
|
69
|
+
sign(request: Request, params: Omit<DPoPProofParams, 'request'>): Promise<Request>;
|
|
70
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module
|
|
3
|
+
* @mergeModuleWith OAuth2
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* @group DPoP
|
|
7
|
+
*/
|
|
8
|
+
export interface DPoPNonceCache {
|
|
9
|
+
getNonce(key: string): Promise<string | undefined>;
|
|
10
|
+
cacheNonce(key: string, nonce: string): Promise<void>;
|
|
11
|
+
clear(): Promise<void>;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* @internal
|
|
15
|
+
*/
|
|
16
|
+
export declare namespace DPoPNonceCache {
|
|
17
|
+
/**
|
|
18
|
+
* @internal
|
|
19
|
+
* Implementation of an in-memory cache; backed via `Map`
|
|
20
|
+
*/
|
|
21
|
+
class InMemoryCache implements DPoPNonceCache {
|
|
22
|
+
#private;
|
|
23
|
+
getNonce(key: string): Promise<string | undefined>;
|
|
24
|
+
cacheNonce(key: string, nonce: string): Promise<void>;
|
|
25
|
+
clear(): Promise<void>;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module
|
|
3
|
+
* @mergeModuleWith OAuth2
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* @group DPoP
|
|
7
|
+
*/
|
|
8
|
+
export interface DPoPStorage {
|
|
9
|
+
add(id: string, keyPair: CryptoKeyPair): Promise<void>;
|
|
10
|
+
get(id: string): Promise<CryptoKeyPair | null>;
|
|
11
|
+
remove(id: string): Promise<void>;
|
|
12
|
+
clear(): Promise<void>;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* @group DPoP
|
|
16
|
+
* @internal
|
|
17
|
+
*/
|
|
18
|
+
export declare namespace DPoPStorage {
|
|
19
|
+
/** @internal */
|
|
20
|
+
class MemoryStore implements DPoPStorage {
|
|
21
|
+
#private;
|
|
22
|
+
add(id: string, keyPair: CryptoKeyPair): Promise<void>;
|
|
23
|
+
get(id: string): Promise<CryptoKeyPair | null>;
|
|
24
|
+
remove(id: string): Promise<void>;
|
|
25
|
+
clear(): Promise<void>;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module
|
|
3
|
+
* @mergeModuleWith OAuth2
|
|
4
|
+
*/
|
|
5
|
+
import type { JsonRecord } from '../../types/index.ts';
|
|
6
|
+
/**
|
|
7
|
+
* @group DPoP
|
|
8
|
+
*/
|
|
9
|
+
export interface DPoPClaims extends JsonRecord {
|
|
10
|
+
/**
|
|
11
|
+
* (http) request method (verb)
|
|
12
|
+
*/
|
|
13
|
+
htm: string;
|
|
14
|
+
/**
|
|
15
|
+
* (http) request url
|
|
16
|
+
*/
|
|
17
|
+
htu: string;
|
|
18
|
+
/**
|
|
19
|
+
* issued at (timestamp)
|
|
20
|
+
*/
|
|
21
|
+
iat: number;
|
|
22
|
+
/**
|
|
23
|
+
* unique identifier
|
|
24
|
+
*/
|
|
25
|
+
jti: string;
|
|
26
|
+
/**
|
|
27
|
+
* nonce value (provided by dpop-nonce header)
|
|
28
|
+
*/
|
|
29
|
+
nonce?: string;
|
|
30
|
+
/**
|
|
31
|
+
* access token hash
|
|
32
|
+
*/
|
|
33
|
+
ath?: string;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* @group DPoP
|
|
37
|
+
*/
|
|
38
|
+
export interface DPoPHeaders {
|
|
39
|
+
alg: 'RS256';
|
|
40
|
+
typ: 'dpop+jwt';
|
|
41
|
+
jwk: JsonWebKey;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* @group DPoP
|
|
45
|
+
*/
|
|
46
|
+
export interface DPoPProofParams {
|
|
47
|
+
request: Request;
|
|
48
|
+
keyPairId?: string;
|
|
49
|
+
keyPair?: CryptoKeyPair;
|
|
50
|
+
nonce?: string;
|
|
51
|
+
accessToken?: string;
|
|
52
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module
|
|
3
|
+
* @mergeModuleWith OAuth2
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* @group PKCE
|
|
7
|
+
*/
|
|
8
|
+
export type PKCE = PKCE.Challenge & PKCE.Verifier;
|
|
9
|
+
declare function generatePKCE(method?: string): Promise<PKCE>;
|
|
10
|
+
/**
|
|
11
|
+
* @group PKCE
|
|
12
|
+
*/
|
|
13
|
+
export declare namespace PKCE {
|
|
14
|
+
type Challenge = {
|
|
15
|
+
challenge: string;
|
|
16
|
+
method: string;
|
|
17
|
+
};
|
|
18
|
+
type Verifier = {
|
|
19
|
+
verifier: string;
|
|
20
|
+
};
|
|
21
|
+
const generate: typeof generatePKCE;
|
|
22
|
+
}
|
|
23
|
+
export {};
|