@kaapi/oauth2-auth-design 0.0.14 → 0.0.16
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/docs/.nojekyll +1 -0
- package/docs/assets/hierarchy.js +1 -0
- package/docs/assets/highlight.css +78 -0
- package/docs/assets/icons.js +18 -0
- package/docs/assets/icons.svg +1 -0
- package/docs/assets/main.js +60 -0
- package/docs/assets/navigation.js +1 -0
- package/docs/assets/search.js +1 -0
- package/docs/assets/style.css +1633 -0
- package/docs/classes/BearerToken.html +7 -0
- package/docs/classes/ClientSecretBasic.html +6 -0
- package/docs/classes/ClientSecretJwt.html +10 -0
- package/docs/classes/ClientSecretPost.html +6 -0
- package/docs/classes/DPoPToken.html +12 -0
- package/docs/classes/DefaultJWKSRoute.html +9 -0
- package/docs/classes/DefaultOAuth2ACAuthorizationRoute.html +28 -0
- package/docs/classes/DefaultOAuth2ACTokenRoute.html +10 -0
- package/docs/classes/DefaultOAuth2ClientCredentialsTokenRoute.html +10 -0
- package/docs/classes/DefaultOAuth2DeviceAuthTokenRoute.html +10 -0
- package/docs/classes/DefaultOAuth2DeviceAuthorizationRoute.html +11 -0
- package/docs/classes/DefaultOAuth2RefreshTokenRoute.html +10 -0
- package/docs/classes/InMemoryKeyStore.html +12 -0
- package/docs/classes/InMemoryReplayStore.html +5 -0
- package/docs/classes/JWKSRoute.html +7 -0
- package/docs/classes/JwksRotator.html +5 -0
- package/docs/classes/JwtAuthority.html +18 -0
- package/docs/classes/MultipleFlows.html +30 -0
- package/docs/classes/MultipleFlowsBuilder.html +15 -0
- package/docs/classes/NoneAuthMethod.html +6 -0
- package/docs/classes/OAuth2ACAuthorizationRoute.html +9 -0
- package/docs/classes/OAuth2ACTokenRoute.html +7 -0
- package/docs/classes/OAuth2AuthDesign.html +49 -0
- package/docs/classes/OAuth2AuthorizationCode.html +61 -0
- package/docs/classes/OAuth2AuthorizationCodeBuilder.html +30 -0
- package/docs/classes/OAuth2ClientCredentials.html +53 -0
- package/docs/classes/OAuth2ClientCredentialsBuilder.html +28 -0
- package/docs/classes/OAuth2ClientCredentialsTokenRoute.html +7 -0
- package/docs/classes/OAuth2DeviceAuthTokenRoute.html +7 -0
- package/docs/classes/OAuth2DeviceAuthorization.html +57 -0
- package/docs/classes/OAuth2DeviceAuthorizationBuilder.html +30 -0
- package/docs/classes/OAuth2DeviceAuthorizationRoute.html +7 -0
- package/docs/classes/OAuth2RefreshTokenRoute.html +7 -0
- package/docs/classes/OAuth2TokenResponse.html +25 -0
- package/docs/classes/OAuth2TokenRoute.html +6 -0
- package/docs/classes/OIDCAuthUtil.html +117 -0
- package/docs/classes/OIDCAuthorizationCode.html +63 -0
- package/docs/classes/OIDCAuthorizationCodeBuilder.html +32 -0
- package/docs/classes/OIDCClientCredentials.html +55 -0
- package/docs/classes/OIDCClientCredentialsBuilder.html +30 -0
- package/docs/classes/OIDCDeviceAuthorization.html +59 -0
- package/docs/classes/OIDCDeviceAuthorizationBuilder.html +32 -0
- package/docs/classes/PrivateKeyJwt.html +10 -0
- package/docs/enums/ClientSecretJwtAlgorithms.html +4 -0
- package/docs/enums/PrivateKeyJwtAlgorithms.html +11 -0
- package/docs/functions/createIdToken.html +1 -0
- package/docs/functions/createInMemoryKeyStore.html +1 -0
- package/docs/functions/createInMemoryReplayStore.html +1 -0
- package/docs/functions/createJwtAccessToken.html +1 -0
- package/docs/functions/createMatchAuthCodeResult.html +1 -0
- package/docs/functions/createMatchOAuth2ErrorCode.html +1 -0
- package/docs/functions/matchAuthCodeResult.html +1 -0
- package/docs/functions/sortTokenEndpointAuthMethods.html +1 -0
- package/docs/functions/verifyCodeVerifier.html +2 -0
- package/docs/functions/verifyJwt.html +1 -0
- package/docs/hierarchy.html +1 -0
- package/docs/index.html +2 -0
- package/docs/interfaces/ClientAuthMethod.html +6 -0
- package/docs/interfaces/DefaultOAuth2TokenRoute.html +8 -0
- package/docs/interfaces/IBearerToken.html +5 -0
- package/docs/interfaces/IDPoPToken.html +5 -0
- package/docs/interfaces/IJWKSRoute.html +3 -0
- package/docs/interfaces/IOAuth2ACAuthorizationRoute.html +4 -0
- package/docs/interfaces/IOAuth2DeviceAuthorizationRoute.html +3 -0
- package/docs/interfaces/IOAuth2TokenResponse.html +2 -0
- package/docs/interfaces/IOAuth2TokenRoute.html +3 -0
- package/docs/interfaces/JWKSParams.html +2 -0
- package/docs/interfaces/JwksKeyStore.html +9 -0
- package/docs/interfaces/JwksRotationTimestampStore.html +3 -0
- package/docs/interfaces/JwksRotatorOptions.html +5 -0
- package/docs/interfaces/KeyGenerator.html +2 -0
- package/docs/interfaces/MultipleFlowsArg.html +7 -0
- package/docs/interfaces/OAuth2ACAuthorizationParams.html +8 -0
- package/docs/interfaces/OAuth2ACTokenParams.html +13 -0
- package/docs/interfaces/OAuth2AuthDesignBuilder.html +4 -0
- package/docs/interfaces/OAuth2AuthDesignOptions.html +6 -0
- package/docs/interfaces/OAuth2AuthorizationCodeArg.html +9 -0
- package/docs/interfaces/OAuth2AuthorizationCodeBuilderArg.html +10 -0
- package/docs/interfaces/OAuth2ClientCredentialsArg.html +7 -0
- package/docs/interfaces/OAuth2ClientCredentialsBuilderArg.html +8 -0
- package/docs/interfaces/OAuth2ClientCredentialsTokenParams.html +9 -0
- package/docs/interfaces/OAuth2DeviceAuthTokenParams.html +9 -0
- package/docs/interfaces/OAuth2DeviceAuthorizationArg.html +9 -0
- package/docs/interfaces/OAuth2DeviceAuthorizationBuilderArg.html +10 -0
- package/docs/interfaces/OAuth2DeviceAuthorizationParams.html +3 -0
- package/docs/interfaces/OAuth2JwksOptions.html +6 -0
- package/docs/interfaces/OAuth2JwtPayload.html +24 -0
- package/docs/interfaces/OAuth2RefreshTokenParams.html +11 -0
- package/docs/interfaces/OAuth2SingleAuthFlow.html +6 -0
- package/docs/interfaces/OAuth2SingleAuthFlowBuilder.html +5 -0
- package/docs/interfaces/OAuth2TokenParams.html +6 -0
- package/docs/interfaces/OAuth2TokenResponseBody.html +8 -0
- package/docs/interfaces/OpenIDHelpers.html +3 -0
- package/docs/interfaces/ReplayStore.html +4 -0
- package/docs/interfaces/TokenType.html +5 -0
- package/docs/modules.html +1 -0
- package/docs/types/AnyOAuth2ErrorCodeType.html +1 -0
- package/docs/types/AuthCodeGenerator.html +2 -0
- package/docs/types/AuthCodeGeneratorResult.html +1 -0
- package/docs/types/AuthCodeResultMatchHandlers.html +4 -0
- package/docs/types/AuthCodeTokenGenerator.html +2 -0
- package/docs/types/AuthResponseHandler.html +5 -0
- package/docs/types/AuthResponseRenderer.html +1 -0
- package/docs/types/ClientAuthMethodResponse.html +5 -0
- package/docs/types/ClientCredentialsTokenGenerator.html +2 -0
- package/docs/types/DefaultOAuth2DeviceAuthRefreshTokenRoute.html +1 -0
- package/docs/types/DeviceAuthTokenGenerator.html +2 -0
- package/docs/types/DeviceCodeGenerator.html +2 -0
- package/docs/types/DeviceCodeResponse.html +23 -0
- package/docs/types/DeviceFlowOAuth2ErrorCodeType.html +1 -0
- package/docs/types/ExtendedOAuth2ErrorCodeType.html +1 -0
- package/docs/types/IOAuth2ACTokenRoute.html +1 -0
- package/docs/types/IOAuth2ClientCredentialsTokenRoute.html +1 -0
- package/docs/types/IOAuth2DeviceAuthTokenRoute.html +1 -0
- package/docs/types/IOAuth2RefreshTokenRoute.html +1 -0
- package/docs/types/JWKSHandler.html +1 -0
- package/docs/types/MultipleFlowsBuilderArg.html +1 -0
- package/docs/types/OAuth2ACAuthorizationHandler.html +1 -0
- package/docs/types/OAuth2ACTokenHandler.html +1 -0
- package/docs/types/OAuth2AuthOptions.html +7 -0
- package/docs/types/OAuth2ClientAuthentication.html +1 -0
- package/docs/types/OAuth2ClientCredentialsTokenHandler.html +1 -0
- package/docs/types/OAuth2DeviceAuthTokenHandler.html +1 -0
- package/docs/types/OAuth2DeviceAuthorizationHandler.html +1 -0
- package/docs/types/OAuth2DeviceCodeTokenErrorBody.html +4 -0
- package/docs/types/OAuth2ErrorBody.html +4 -0
- package/docs/types/OAuth2ErrorCodeType.html +1 -0
- package/docs/types/OAuth2RefreshTokenHandler.html +1 -0
- package/docs/types/OAuth2TokenErrorCodeType.html +1 -0
- package/docs/types/OAuth2TokenHandler.html +1 -0
- package/docs/types/OIDCAuthorizationCodeArg.html +2 -0
- package/docs/types/OIDCAuthorizationCodeBuilderArg.html +2 -0
- package/docs/types/OIDCClientCredentialsArg.html +2 -0
- package/docs/types/OIDCClientCredentialsBuilderArg.html +2 -0
- package/docs/types/OIDCDeviceAuthorizationArg.html +2 -0
- package/docs/types/OIDCDeviceAuthorizationBuilderArg.html +2 -0
- package/docs/types/PathValue.html +1 -0
- package/docs/types/ReplayDetector.html +1 -0
- package/docs/types/SingleCodeFlow.html +1 -0
- package/docs/types/StandardOAuth2ErrorCodeType.html +1 -0
- package/docs/types/TokenEndpointAuthMethod.html +1 -0
- package/docs/types/TokenGenerator.html +1 -0
- package/docs/types/TokenRequestValidation.html +1 -0
- package/docs/types/TokenTypeValidation.html +1 -0
- package/docs/types/TokenTypeValidationResponse.html +3 -0
- package/docs/types/WithRequired.html +1 -0
- package/docs/variables/AllOAuth2ErrorCode.html +1 -0
- package/docs/variables/AuthCodeResult.html +1 -0
- package/docs/variables/DeviceFlowOAuth2ErrorCode.html +1 -0
- package/docs/variables/ExtendedOAuth2ErrorCode.html +1 -0
- package/docs/variables/OAuth2ErrorCode.html +1 -0
- package/docs/variables/OAuth2TokenErrorCode.html +1 -0
- package/docs/variables/StandardOAuth2ErrorCode.html +1 -0
- package/kaukau.config.mjs +20 -0
- package/lib/cli.js +7 -7
- package/lib/flows/auth-code/authorization-route.d.ts +61 -10
- package/lib/flows/auth-code/authorization-route.js +152 -65
- package/lib/flows/auth-code/authorization-route.js.map +1 -1
- package/lib/flows/auth-code/authorization-utils.d.ts +35 -0
- package/lib/flows/auth-code/authorization-utils.js +44 -0
- package/lib/flows/auth-code/authorization-utils.js.map +1 -0
- package/lib/flows/auth-code/token-route.d.ts +10 -18
- package/lib/flows/auth-code/token-route.js +6 -15
- package/lib/flows/auth-code/token-route.js.map +1 -1
- package/lib/flows/authorization-code.d.ts +112 -0
- package/lib/flows/authorization-code.js +570 -0
- package/lib/flows/authorization-code.js.map +1 -0
- package/lib/flows/client-credentials.d.ts +79 -39
- package/lib/flows/client-credentials.js +324 -257
- package/lib/flows/client-credentials.js.map +1 -1
- package/lib/flows/client-creds/token-route.d.ts +23 -0
- package/lib/flows/client-creds/token-route.js +52 -0
- package/lib/flows/client-creds/token-route.js.map +1 -0
- package/lib/flows/common.d.ts +265 -28
- package/lib/flows/common.js +293 -29
- package/lib/flows/common.js.map +1 -1
- package/lib/flows/device-auth/authorization-route.d.ts +83 -0
- package/lib/flows/device-auth/authorization-route.js +68 -0
- package/lib/flows/device-auth/authorization-route.js.map +1 -0
- package/lib/flows/device-auth/token-route.d.ts +29 -0
- package/lib/flows/device-auth/token-route.js +49 -0
- package/lib/flows/device-auth/token-route.js.map +1 -0
- package/lib/flows/device-authorization.d.ts +112 -0
- package/lib/flows/device-authorization.js +523 -0
- package/lib/flows/device-authorization.js.map +1 -0
- package/lib/flows/oidc-multiple-flows.d.ts +59 -0
- package/lib/flows/oidc-multiple-flows.js +268 -0
- package/lib/flows/oidc-multiple-flows.js.map +1 -0
- package/lib/index.d.ts +12 -6
- package/lib/index.js +12 -6
- package/lib/index.js.map +1 -1
- package/lib/utils/client-auth-methods.d.ts +2 -2
- package/lib/utils/client-auth-methods.js +5 -6
- package/lib/utils/client-auth-methods.js.map +1 -1
- package/lib/utils/in-memory-key-store.d.ts +12 -0
- package/lib/utils/in-memory-key-store.js +46 -0
- package/lib/utils/in-memory-key-store.js.map +1 -0
- package/lib/utils/jwt-authority.d.ts +81 -0
- package/lib/utils/jwt-authority.js +186 -0
- package/lib/utils/jwt-authority.js.map +1 -0
- package/lib/utils/jwt-utils.d.ts +33 -0
- package/lib/utils/jwt-utils.js +24 -0
- package/lib/utils/jwt-utils.js.map +1 -0
- package/lib/utils/replay-store.d.ts +13 -0
- package/lib/utils/{cache-set.js → replay-store.js} +8 -4
- package/lib/utils/replay-store.js.map +1 -0
- package/lib/utils/token-types.d.ts +6 -3
- package/lib/utils/token-types.js +13 -10
- package/lib/utils/token-types.js.map +1 -1
- package/lib/utils/verify-code-verifier.d.ts +4 -0
- package/lib/utils/verify-code-verifier.js +18 -0
- package/lib/utils/verify-code-verifier.js.map +1 -0
- package/package.json +7 -7
- package/typedoc.json +11 -0
- package/lib/flows/auth-code/open-id.d.ts +0 -53
- package/lib/flows/auth-code/open-id.js +0 -199
- package/lib/flows/auth-code/open-id.js.map +0 -1
- package/lib/flows/auth-code.ts/open-id.d.ts +0 -52
- package/lib/flows/auth-code.ts/open-id.js +0 -169
- package/lib/flows/auth-code.ts/open-id.js.map +0 -1
- package/lib/flows/authentication-code.d.ts +0 -53
- package/lib/flows/authentication-code.js +0 -380
- package/lib/flows/authentication-code.js.map +0 -1
- package/lib/utils/cache-set.d.ts +0 -12
- package/lib/utils/cache-set.js.map +0 -1
- package/lib/utils/in-memory-cache.d.ts +0 -5
- package/lib/utils/in-memory-cache.js +0 -30
- package/lib/utils/in-memory-cache.js.map +0 -1
- package/lib/utils/in-memory-jwks-store.d.ts +0 -12
- package/lib/utils/in-memory-jwks-store.js +0 -46
- package/lib/utils/in-memory-jwks-store.js.map +0 -1
- package/lib/utils/jwks-generator.d.ts +0 -58
- package/lib/utils/jwks-generator.js +0 -141
- package/lib/utils/jwks-generator.js.map +0 -1
- package/lib/utils/jwks-store.d.ts +0 -13
- package/lib/utils/jwks-store.js +0 -3
- package/lib/utils/jwks-store.js.map +0 -1
|
@@ -0,0 +1,268 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.MultipleFlowsBuilder = exports.MultipleFlows = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const kaapi_1 = require("@kaapi/kaapi");
|
|
6
|
+
const common_1 = require("./common");
|
|
7
|
+
const jwt_authority_1 = require("../utils/jwt-authority");
|
|
8
|
+
const in_memory_key_store_1 = require("../utils/in-memory-key-store");
|
|
9
|
+
class MultipleFlows extends kaapi_1.AuthDesign {
|
|
10
|
+
constructor(_a) {
|
|
11
|
+
var _b, _c, _d, _e, _f, _g;
|
|
12
|
+
var { flows, tokenEndpoint, jwksRoute, openidConfiguration, logger } = _a, props = tslib_1.__rest(_a, ["flows", "tokenEndpoint", "jwksRoute", "openidConfiguration", "logger"]);
|
|
13
|
+
super();
|
|
14
|
+
this.securitySchemeName = 'OIDC Multiple Flows';
|
|
15
|
+
this.logger = logger;
|
|
16
|
+
this.flows = [...flows];
|
|
17
|
+
this.tokenEndpoint = tokenEndpoint;
|
|
18
|
+
this.jwksRoute = jwksRoute;
|
|
19
|
+
this.openidConfiguration = openidConfiguration || {};
|
|
20
|
+
this.jwksKeyStore = (_b = props === null || props === void 0 ? void 0 : props.jwksOptions) === null || _b === void 0 ? void 0 : _b.keyStore;
|
|
21
|
+
this.jwksPublicKeyTtl = (_c = props === null || props === void 0 ? void 0 : props.jwksOptions) === null || _c === void 0 ? void 0 : _c.ttl;
|
|
22
|
+
this.jwksRotationIntervalMs = (_e = (_d = props === null || props === void 0 ? void 0 : props.jwksOptions) === null || _d === void 0 ? void 0 : _d.rotation) === null || _e === void 0 ? void 0 : _e.intervalMs;
|
|
23
|
+
this.jwksRotationTimestampStore = (_g = (_f = props === null || props === void 0 ? void 0 : props.jwksOptions) === null || _f === void 0 ? void 0 : _f.rotation) === null || _g === void 0 ? void 0 : _g.timestampStore;
|
|
24
|
+
}
|
|
25
|
+
getJwtAuthority() {
|
|
26
|
+
if (this.jwtAuthority)
|
|
27
|
+
return this.jwtAuthority;
|
|
28
|
+
if (this.jwksRoute || this.jwksKeyStore /*|| this.options.useAccessTokenJwks*/) {
|
|
29
|
+
this.jwtAuthority = new jwt_authority_1.JwtAuthority(this.jwksKeyStore || new in_memory_key_store_1.InMemoryKeyStore(), this.jwksPublicKeyTtl);
|
|
30
|
+
}
|
|
31
|
+
return this.jwtAuthority;
|
|
32
|
+
}
|
|
33
|
+
getJwksRotator() {
|
|
34
|
+
if (this.jwksRotator)
|
|
35
|
+
return this.jwksRotator;
|
|
36
|
+
const jwtAuthority = this.getJwtAuthority();
|
|
37
|
+
if (jwtAuthority && this.jwksRotationIntervalMs) {
|
|
38
|
+
this.jwksRotator = new jwt_authority_1.JwksRotator({
|
|
39
|
+
keyGenerator: jwtAuthority,
|
|
40
|
+
rotationIntervalMs: this.jwksRotationIntervalMs,
|
|
41
|
+
rotatorKeyStore: this.jwksRotationTimestampStore || new in_memory_key_store_1.InMemoryKeyStore(),
|
|
42
|
+
logger: this.logger
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
return this.jwksRotator;
|
|
46
|
+
}
|
|
47
|
+
checkAndRotateKeys() {
|
|
48
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
49
|
+
var _a;
|
|
50
|
+
return (_a = this.getJwksRotator()) === null || _a === void 0 ? void 0 : _a.checkAndRotateKeys();
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
generateKeyPair() {
|
|
54
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
55
|
+
var _a;
|
|
56
|
+
return (_a = this.getJwtAuthority()) === null || _a === void 0 ? void 0 : _a.generateKeyPair();
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Name used in the documentation
|
|
61
|
+
*/
|
|
62
|
+
setSecuritySchemeName(name) {
|
|
63
|
+
if (name)
|
|
64
|
+
this.securitySchemeName = name;
|
|
65
|
+
}
|
|
66
|
+
docs() {
|
|
67
|
+
return new common_1.OIDCAuthUtil(this.securitySchemeName);
|
|
68
|
+
}
|
|
69
|
+
integrateStrategy(t) {
|
|
70
|
+
for (const flow of this.flows) {
|
|
71
|
+
flow.integrateStrategy(t);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
integrateHook(t) {
|
|
75
|
+
var _a;
|
|
76
|
+
const jwtAuthority = this.getJwtAuthority();
|
|
77
|
+
const host = ((_a = t.postman) === null || _a === void 0 ? void 0 : _a.getHost()[0]) || '';
|
|
78
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
79
|
+
const routesOptions = {
|
|
80
|
+
plugins: {
|
|
81
|
+
kaapi: {
|
|
82
|
+
docs: false
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
};
|
|
86
|
+
const refreshTokenHandlerFlows = [];
|
|
87
|
+
for (const flow of this.flows) {
|
|
88
|
+
if (typeof flow.handleRefreshToken === 'function') {
|
|
89
|
+
refreshTokenHandlerFlows.push(flow);
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
for (const flow of this.flows) {
|
|
93
|
+
if (typeof flow.registerAuthorizationEndpoint === 'function') {
|
|
94
|
+
flow.registerAuthorizationEndpoint(t);
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
// token
|
|
98
|
+
t
|
|
99
|
+
.route({
|
|
100
|
+
options: routesOptions,
|
|
101
|
+
path: this.tokenEndpoint,
|
|
102
|
+
method: 'POST',
|
|
103
|
+
handler: (req, h) => tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
104
|
+
const grantType = req.payload.grant_type;
|
|
105
|
+
if (grantType && typeof grantType === 'string') {
|
|
106
|
+
if (grantType != 'refresh_token') {
|
|
107
|
+
for (const flow of this.flows) {
|
|
108
|
+
if (grantType === flow.grantType) {
|
|
109
|
+
return yield flow.handleToken(t, req, h);
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
else {
|
|
114
|
+
if (refreshTokenHandlerFlows.length) {
|
|
115
|
+
// iterate to find the right method
|
|
116
|
+
for (const flow of refreshTokenHandlerFlows) {
|
|
117
|
+
if (typeof flow.handleRefreshToken === 'function') {
|
|
118
|
+
const result = yield flow.handleRefreshToken(t, req, h);
|
|
119
|
+
if (result === h.continue) {
|
|
120
|
+
continue;
|
|
121
|
+
}
|
|
122
|
+
else {
|
|
123
|
+
return result;
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
return h.response({ error: common_1.OAuth2ErrorCode.INVALID_GRANT, error_description: 'Token was not validated by any handler.' }).code(400);
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
return h.response({ error: common_1.OAuth2ErrorCode.UNSUPPORTED_GRANT_TYPE, error_description: `Request does not support the 'grant_type' '${req.payload.grant_type}'.` }).code(400);
|
|
132
|
+
})
|
|
133
|
+
});
|
|
134
|
+
// jwks
|
|
135
|
+
if (this.jwksRoute && jwtAuthority) {
|
|
136
|
+
t.route({
|
|
137
|
+
path: this.jwksRoute.path,
|
|
138
|
+
method: 'GET',
|
|
139
|
+
options: {
|
|
140
|
+
plugins: {
|
|
141
|
+
kaapi: {
|
|
142
|
+
docs: false
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
},
|
|
146
|
+
handler: (req, h) => tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
147
|
+
var _a;
|
|
148
|
+
const jwks = yield jwtAuthority.getJwksEndpointResponse();
|
|
149
|
+
if ((_a = this.jwksRoute) === null || _a === void 0 ? void 0 : _a.handler) {
|
|
150
|
+
return this.jwksRoute.handler({
|
|
151
|
+
jwks
|
|
152
|
+
}, req, h);
|
|
153
|
+
}
|
|
154
|
+
return jwks;
|
|
155
|
+
})
|
|
156
|
+
});
|
|
157
|
+
}
|
|
158
|
+
// discovery endpoint
|
|
159
|
+
t.route({
|
|
160
|
+
path: '/.well-known/openid-configuration',
|
|
161
|
+
method: 'GET',
|
|
162
|
+
options: {
|
|
163
|
+
plugins: {
|
|
164
|
+
kaapi: {
|
|
165
|
+
docs: false
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
},
|
|
169
|
+
handler: () => {
|
|
170
|
+
let wellKnownOpenIDConfig = {
|
|
171
|
+
issuer: `${host}`,
|
|
172
|
+
authorization_endpoint: undefined,
|
|
173
|
+
device_authorization_endpoint: undefined,
|
|
174
|
+
token_endpoint: `${host}${this.tokenEndpoint}`,
|
|
175
|
+
jwks_uri: this.jwksRoute ? `${host}${this.jwksRoute.path}` : undefined,
|
|
176
|
+
grant_types_supported: [],
|
|
177
|
+
token_endpoint_auth_methods_supported: []
|
|
178
|
+
};
|
|
179
|
+
for (const flow of this.flows) {
|
|
180
|
+
if (typeof flow.getDiscoveryConfiguration === 'function') {
|
|
181
|
+
const _a = flow.getDiscoveryConfiguration(t), {
|
|
182
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
183
|
+
token_endpoint: _unused_token_endpoint,
|
|
184
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
185
|
+
jwks_uri: _unused_jwks_uri } = _a, more = tslib_1.__rest(_a, ["token_endpoint", "jwks_uri"]);
|
|
186
|
+
// merge properties
|
|
187
|
+
wellKnownOpenIDConfig = Object.assign(Object.assign({}, wellKnownOpenIDConfig), Object.fromEntries(Object.entries(more).map(([key, val]) => [
|
|
188
|
+
key,
|
|
189
|
+
// merge arrays and ensure unique values (Set)
|
|
190
|
+
Array.isArray(wellKnownOpenIDConfig[key]) && Array.isArray(val) ? [...new Set([
|
|
191
|
+
...wellKnownOpenIDConfig[key],
|
|
192
|
+
...val
|
|
193
|
+
])] : val
|
|
194
|
+
])));
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
return Object.assign(Object.assign({}, wellKnownOpenIDConfig), this.openidConfiguration);
|
|
198
|
+
}
|
|
199
|
+
});
|
|
200
|
+
}
|
|
201
|
+
getStrategyName() {
|
|
202
|
+
return this.flows.map(f => f.getStrategyName()).flat();
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
exports.MultipleFlows = MultipleFlows;
|
|
206
|
+
class MultipleFlowsBuilder {
|
|
207
|
+
constructor(params) {
|
|
208
|
+
this.builders = [];
|
|
209
|
+
this.params = params;
|
|
210
|
+
}
|
|
211
|
+
static create(params) {
|
|
212
|
+
const paramsComplete = Object.assign({ tokenEndpoint: params && params.tokenEndpoint || '/oauth2/token', jwksOptions: {} }, (params || {}));
|
|
213
|
+
paramsComplete.jwksOptions = paramsComplete.jwksOptions || {};
|
|
214
|
+
if (!paramsComplete.jwksOptions.keyStore) {
|
|
215
|
+
paramsComplete.jwksOptions.keyStore = new in_memory_key_store_1.InMemoryKeyStore();
|
|
216
|
+
}
|
|
217
|
+
return new MultipleFlowsBuilder(paramsComplete);
|
|
218
|
+
}
|
|
219
|
+
additionalConfiguration(openidConfiguration) {
|
|
220
|
+
this.params.openidConfiguration = openidConfiguration;
|
|
221
|
+
return this;
|
|
222
|
+
}
|
|
223
|
+
setJwksKeyStore(keyStore) {
|
|
224
|
+
this.params.jwksOptions = this.params.jwksOptions || {};
|
|
225
|
+
this.params.jwksOptions.keyStore = keyStore;
|
|
226
|
+
return this;
|
|
227
|
+
}
|
|
228
|
+
/**
|
|
229
|
+
* Should be greater than token TTL for all flows included
|
|
230
|
+
* @param ttl seconds
|
|
231
|
+
*/
|
|
232
|
+
setPublicKeyExpiry(ttl) {
|
|
233
|
+
this.params.jwksOptions = this.params.jwksOptions || {};
|
|
234
|
+
this.params.jwksOptions.ttl = ttl;
|
|
235
|
+
return this;
|
|
236
|
+
}
|
|
237
|
+
setJwksRotatorOptions(jwksRotatorOptions) {
|
|
238
|
+
this.params.jwksOptions = this.params.jwksOptions || {};
|
|
239
|
+
this.params.jwksOptions.rotation = jwksRotatorOptions;
|
|
240
|
+
return this;
|
|
241
|
+
}
|
|
242
|
+
jwksRoute(handler) {
|
|
243
|
+
this.params.jwksRoute = this.params.jwksRoute || common_1.JWKSRoute.buildDefault();
|
|
244
|
+
handler(this.params.jwksRoute);
|
|
245
|
+
return this;
|
|
246
|
+
}
|
|
247
|
+
tokenEndpoint(path) {
|
|
248
|
+
if (path)
|
|
249
|
+
this.params.tokenEndpoint = path;
|
|
250
|
+
return this;
|
|
251
|
+
}
|
|
252
|
+
add(builder) {
|
|
253
|
+
this.builders.push(builder);
|
|
254
|
+
return this;
|
|
255
|
+
}
|
|
256
|
+
build() {
|
|
257
|
+
const result = new MultipleFlows(Object.assign(Object.assign({}, this.params), { flows: this.builders.map(b => {
|
|
258
|
+
b.setJwksKeyStore(this.params.jwksOptions.keyStore);
|
|
259
|
+
if (this.params.jwksOptions.ttl)
|
|
260
|
+
b.setPublicKeyExpiry(this.params.jwksOptions.ttl);
|
|
261
|
+
return b.build();
|
|
262
|
+
}) }));
|
|
263
|
+
return result;
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
exports.MultipleFlowsBuilder = MultipleFlowsBuilder;
|
|
267
|
+
//#endregion Builder
|
|
268
|
+
//# sourceMappingURL=oidc-multiple-flows.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"oidc-multiple-flows.js","sourceRoot":"","sources":["../../src/flows/oidc-multiple-flows.ts"],"names":[],"mappings":";;;;AAAA,wCAOqB;AACrB,qCAUiB;AAEjB,0DAA4G;AAC5G,sEAA+D;AAgB/D,MAAa,aAAc,SAAQ,kBAAU;IAoBzC,YAAY,EAOO;;YAPP,EACR,KAAK,EACL,aAAa,EACb,SAAS,EACT,mBAAmB,EACnB,MAAM,OAES,EADZ,KAAK,sBANA,wEAOX,CADW;QAER,KAAK,EAAE,CAAC;QAvBF,uBAAkB,GAAG,qBAAqB,CAAC;QAwBjD,IAAI,CAAC,MAAM,GAAG,MAAM,CAAA;QACpB,IAAI,CAAC,KAAK,GAAG,CAAC,GAAG,KAAK,CAAC,CAAA;QACvB,IAAI,CAAC,aAAa,GAAG,aAAa,CAAA;QAClC,IAAI,CAAC,SAAS,GAAG,SAAS,CAAA;QAC1B,IAAI,CAAC,mBAAmB,GAAG,mBAAmB,IAAI,EAAE,CAAA;QAEpD,IAAI,CAAC,YAAY,GAAG,MAAA,KAAK,aAAL,KAAK,uBAAL,KAAK,CAAE,WAAW,0CAAE,QAAQ,CAAA;QAChD,IAAI,CAAC,g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J,CAAC;QAEH,OAAO,MAAM,CAAA;IACjB,CAAC;CACJ;AAhFD,oDAgFC;AAED,oBAAoB"}
|
package/lib/index.d.ts
CHANGED
|
@@ -1,13 +1,19 @@
|
|
|
1
1
|
import '../types/overrides.d.ts'
|
|
2
2
|
export * from './flows/common';
|
|
3
3
|
export * from './flows/auth-code/authorization-route';
|
|
4
|
+
export * from './flows/auth-code/authorization-utils';
|
|
4
5
|
export * from './flows/auth-code/token-route';
|
|
5
|
-
export * from './flows/
|
|
6
|
-
export * from './flows/
|
|
6
|
+
export * from './flows/client-creds/token-route';
|
|
7
|
+
export * from './flows/device-auth/authorization-route';
|
|
8
|
+
export * from './flows/device-auth/token-route';
|
|
9
|
+
export * from './flows/authorization-code';
|
|
7
10
|
export * from './flows/client-credentials';
|
|
8
|
-
export * from './
|
|
11
|
+
export * from './flows/device-authorization';
|
|
12
|
+
export * from './flows/oidc-multiple-flows';
|
|
9
13
|
export * from './utils/client-auth-methods';
|
|
10
|
-
export * from './utils/in-memory-
|
|
11
|
-
export * from './utils/
|
|
12
|
-
export * from './utils/
|
|
14
|
+
export * from './utils/in-memory-key-store';
|
|
15
|
+
export * from './utils/jwt-authority';
|
|
16
|
+
export * from './utils/jwt-utils';
|
|
17
|
+
export * from './utils/replay-store';
|
|
13
18
|
export * from './utils/token-types';
|
|
19
|
+
export * from './utils/verify-code-verifier';
|
package/lib/index.js
CHANGED
|
@@ -3,14 +3,20 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
const tslib_1 = require("tslib");
|
|
4
4
|
tslib_1.__exportStar(require("./flows/common"), exports);
|
|
5
5
|
tslib_1.__exportStar(require("./flows/auth-code/authorization-route"), exports);
|
|
6
|
+
tslib_1.__exportStar(require("./flows/auth-code/authorization-utils"), exports);
|
|
6
7
|
tslib_1.__exportStar(require("./flows/auth-code/token-route"), exports);
|
|
7
|
-
tslib_1.__exportStar(require("./flows/
|
|
8
|
-
tslib_1.__exportStar(require("./flows/
|
|
8
|
+
tslib_1.__exportStar(require("./flows/client-creds/token-route"), exports);
|
|
9
|
+
tslib_1.__exportStar(require("./flows/device-auth/authorization-route"), exports);
|
|
10
|
+
tslib_1.__exportStar(require("./flows/device-auth/token-route"), exports);
|
|
11
|
+
tslib_1.__exportStar(require("./flows/authorization-code"), exports);
|
|
9
12
|
tslib_1.__exportStar(require("./flows/client-credentials"), exports);
|
|
10
|
-
tslib_1.__exportStar(require("./
|
|
13
|
+
tslib_1.__exportStar(require("./flows/device-authorization"), exports);
|
|
14
|
+
tslib_1.__exportStar(require("./flows/oidc-multiple-flows"), exports);
|
|
11
15
|
tslib_1.__exportStar(require("./utils/client-auth-methods"), exports);
|
|
12
|
-
tslib_1.__exportStar(require("./utils/in-memory-
|
|
13
|
-
tslib_1.__exportStar(require("./utils/
|
|
14
|
-
tslib_1.__exportStar(require("./utils/
|
|
16
|
+
tslib_1.__exportStar(require("./utils/in-memory-key-store"), exports);
|
|
17
|
+
tslib_1.__exportStar(require("./utils/jwt-authority"), exports);
|
|
18
|
+
tslib_1.__exportStar(require("./utils/jwt-utils"), exports);
|
|
19
|
+
tslib_1.__exportStar(require("./utils/replay-store"), exports);
|
|
15
20
|
tslib_1.__exportStar(require("./utils/token-types"), exports);
|
|
21
|
+
tslib_1.__exportStar(require("./utils/verify-code-verifier"), exports);
|
|
16
22
|
//# sourceMappingURL=index.js.map
|
package/lib/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAAA,yDAA8B;AAC9B,gFAAqD;AACrD,wEAA6C;AAC7C,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAAA,yDAA8B;AAC9B,gFAAqD;AACrD,gFAAqD;AACrD,wEAA6C;AAC7C,2EAAgD;AAChD,kFAAuD;AACvD,0EAA+C;AAC/C,qEAA0C;AAC1C,qEAA0C;AAC1C,uEAA4C;AAC5C,sEAA2C;AAE3C,sEAA2C;AAC3C,sEAA2C;AAC3C,gEAAqC;AACrC,4DAAiC;AACjC,+DAAoC;AACpC,8DAAmC;AACnC,uEAA4C"}
|
|
@@ -48,7 +48,7 @@ export declare class ClientSecretJwt implements ClientAuthMethod {
|
|
|
48
48
|
get secretIsOptional(): boolean;
|
|
49
49
|
get algorithms(): ClientSecretJwtAlgorithms[];
|
|
50
50
|
constructor();
|
|
51
|
-
|
|
51
|
+
addAlgorithm(algo: ClientSecretJwtAlgorithms): this;
|
|
52
52
|
getClientSecret(handler: (clientId: string, decoded: JWTPayload, clientAssertion: string) => Promise<Uint8Array | string | null>): this;
|
|
53
53
|
extractParams(req: Request<ReqRefDefaults>): Promise<ClientAuthMethodResponse>;
|
|
54
54
|
}
|
|
@@ -71,7 +71,7 @@ export declare class PrivateKeyJwt implements ClientAuthMethod {
|
|
|
71
71
|
get secretIsOptional(): boolean;
|
|
72
72
|
get algorithms(): PrivateKeyJwtAlgorithms[];
|
|
73
73
|
constructor();
|
|
74
|
-
|
|
74
|
+
addAlgorithm(algo: PrivateKeyJwtAlgorithms): this;
|
|
75
75
|
getPublicKeyForClient(handler: (clientId: string, decoded: JWTPayload, clientAssertion: string) => Promise<CryptoKey | KeyObject | JWK | Uint8Array | string | null>): this;
|
|
76
76
|
extractParams(req: Request<ReqRefDefaults>): Promise<ClientAuthMethodResponse>;
|
|
77
77
|
}
|
|
@@ -29,11 +29,10 @@ class ClientSecretBasic {
|
|
|
29
29
|
if (authType.toLowerCase() == 'basic') {
|
|
30
30
|
res.hasAuthMethod = true;
|
|
31
31
|
const decoded = Buffer.from(base64Credentials, 'base64').toString('utf-8').split(':');
|
|
32
|
-
if (
|
|
33
|
-
//
|
|
34
|
-
}
|
|
35
|
-
else {
|
|
32
|
+
if (decoded[0]) {
|
|
36
33
|
res.clientId = decoded[0];
|
|
34
|
+
}
|
|
35
|
+
if (decoded[1]) {
|
|
37
36
|
res.clientSecret = decoded[1];
|
|
38
37
|
}
|
|
39
38
|
}
|
|
@@ -107,7 +106,7 @@ class ClientSecretJwt {
|
|
|
107
106
|
_ClientSecretJwt_handler.set(this, void 0);
|
|
108
107
|
tslib_1.__classPrivateFieldSet(this, _ClientSecretJwt_handler, () => tslib_1.__awaiter(this, void 0, void 0, function* () { return null; }), "f");
|
|
109
108
|
}
|
|
110
|
-
|
|
109
|
+
addAlgorithm(algo) {
|
|
111
110
|
if (!tslib_1.__classPrivateFieldGet(this, _ClientSecretJwt_algorithms, "f").includes(algo)) {
|
|
112
111
|
tslib_1.__classPrivateFieldGet(this, _ClientSecretJwt_algorithms, "f").push(algo);
|
|
113
112
|
tslib_1.__classPrivateFieldGet(this, _ClientSecretJwt_algorithms, "f").sort();
|
|
@@ -179,7 +178,7 @@ class PrivateKeyJwt {
|
|
|
179
178
|
_PrivateKeyJwt_handler.set(this, void 0);
|
|
180
179
|
tslib_1.__classPrivateFieldSet(this, _PrivateKeyJwt_handler, () => tslib_1.__awaiter(this, void 0, void 0, function* () { return null; }), "f");
|
|
181
180
|
}
|
|
182
|
-
|
|
181
|
+
addAlgorithm(algo) {
|
|
183
182
|
if (!tslib_1.__classPrivateFieldGet(this, _PrivateKeyJwt_algorithms, "f").includes(algo)) {
|
|
184
183
|
tslib_1.__classPrivateFieldGet(this, _PrivateKeyJwt_algorithms, "f").push(algo);
|
|
185
184
|
tslib_1.__classPrivateFieldGet(this, _PrivateKeyJwt_algorithms, "f").sort();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client-auth-methods.js","sourceRoot":"","sources":["../../src/utils/client-auth-methods.ts"],"names":[],"mappings":";;;;AAcA,oEAIC;;AAdD,+BAAkF;AAOlF,MAAM,8BAA8B,GAA8B,CAAC,qBAAqB,EAAE,oBAAoB,EAAE,mBAAmB,EAAE,iBAAiB,EAAE,MAAM,CAAC,CAAC;AAChK,MAAM,gCAAgC,GAAG,IAAI,GAAG,CAAC,8BAA8B,CAAC,GAAG,CAAC,C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,CAAC,CAAC,CAAC,CAAC,SAAS,EAC/E;4BACI,UAAU,EAAE,IAAI,CAAC,UAAU;yBAC9B,CACJ,CAAA;wBACD,IAAI,OAAO,EAAE,CAAC;4BACV,GAAG,CAAC,YAAY,GAAG,GAAG,CAAC,OAAO,CAAC,gBAAgB,CAAA;wBACnD,CAAC;oBACL,CAAC;gBACL,CAAC;YACL,CAAC;YAED,OAAO,GAAG,CAAC;QACf,CAAC;KAAA;;AA5EL,sCA6EC;;AA3EU,kBAAI,GAAG,uBAAuB,AAA1B,CAA0B"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { JwksKeyStore, JwksRotationTimestampStore } from './jwt-authority';
|
|
2
|
+
export declare class InMemoryKeyStore implements JwksKeyStore, JwksRotationTimestampStore {
|
|
3
|
+
private privateKey?;
|
|
4
|
+
private publicKeys;
|
|
5
|
+
private lastRotation;
|
|
6
|
+
storeKeyPair(_kid: string, privateKey: object, publicKey: object, ttl: number): Promise<void>;
|
|
7
|
+
getPrivateKey(): Promise<object | undefined>;
|
|
8
|
+
getPublicKeys(): Promise<object[]>;
|
|
9
|
+
getLastRotationTimestamp(): Promise<number>;
|
|
10
|
+
setLastRotationTimestamp(msDate: number): Promise<void>;
|
|
11
|
+
}
|
|
12
|
+
export declare function createInMemoryKeyStore(): InMemoryKeyStore;
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.InMemoryKeyStore = void 0;
|
|
4
|
+
exports.createInMemoryKeyStore = createInMemoryKeyStore;
|
|
5
|
+
const tslib_1 = require("tslib");
|
|
6
|
+
// In-memory key store for testing
|
|
7
|
+
class InMemoryKeyStore {
|
|
8
|
+
constructor() {
|
|
9
|
+
this.publicKeys = [];
|
|
10
|
+
this.lastRotation = 0;
|
|
11
|
+
}
|
|
12
|
+
storeKeyPair(_kid, privateKey, publicKey, ttl) {
|
|
13
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
14
|
+
this.privateKey = privateKey;
|
|
15
|
+
const exp = Date.now() + ttl * 1000;
|
|
16
|
+
this.publicKeys.push({ key: publicKey, exp });
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
getPrivateKey() {
|
|
20
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
21
|
+
return this.privateKey;
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
getPublicKeys() {
|
|
25
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
26
|
+
const now = Date.now();
|
|
27
|
+
this.publicKeys = this.publicKeys.filter(k => k.exp > now);
|
|
28
|
+
return this.publicKeys.map(k => k.key);
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
getLastRotationTimestamp() {
|
|
32
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
33
|
+
return this.lastRotation;
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
setLastRotationTimestamp(msDate) {
|
|
37
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
38
|
+
this.lastRotation = msDate;
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
exports.InMemoryKeyStore = InMemoryKeyStore;
|
|
43
|
+
function createInMemoryKeyStore() {
|
|
44
|
+
return new InMemoryKeyStore();
|
|
45
|
+
}
|
|
46
|
+
//# sourceMappingURL=in-memory-key-store.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"in-memory-key-store.js","sourceRoot":"","sources":["../../src/utils/in-memory-key-store.ts"],"names":[],"mappings":";;;AAiCA,wDAEC;;AAjCD,kCAAkC;AAClC,MAAa,gBAAgB;IAA7B;QAEY,eAAU,GAAmC,EAAE,CAAC;QAChD,iBAAY,GAAW,CAAC,CAAC;IAyBrC,CAAC;IAvBS,YAAY,CAAC,IAAY,EAAE,UAAkB,EAAE,SAAiB,EAAE,GAAW;;YAC/E,IAAI,CAAC,UAAU,GAAG,UAAU,CAAC;YAC7B,MAAM,GAAG,GAAG,IAAI,CAAC,GAAG,EAAE,GAAG,GAAG,GAAG,IAAI,CAAC;YACpC,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,EAAE,GAAG,EAAE,SAAS,EAAE,GAAG,EAAE,CAAC,CAAC;QAClD,CAAC;KAAA;IAEK,aAAa;;YACf,OAAO,IAAI,CAAC,UAAU,CAAC;QAC3B,CAAC;KAAA;IAEK,aAAa;;YACf,MAAM,GAAG,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC;YACvB,IAAI,CAAC,UAAU,GAAG,IAAI,CAAC,UAAU,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,GAAG,GAAG,GAAG,CAAC,CAAA;YAC1D,OAAO,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC;QAC3C,CAAC;KAAA;IAEK,wBAAwB;;YAC1B,OAAO,IAAI,CAAC,YAAY,CAAC;QAC7B,CAAC;KAAA;IAEK,wBAAwB,CAAC,MAAc;;YACzC,IAAI,CAAC,YAAY,GAAG,MAAM,CAAC;QAC/B,CAAC;KAAA;CACJ;AA5BD,4CA4BC;AAED,SAAgB,sBAAsB;IAClC,OAAO,IAAI,gBAAgB,EAAE,CAAA;AACjC,CAAC"}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import jose from 'node-jose';
|
|
2
|
+
import jwktopem from 'jwk-to-pem';
|
|
3
|
+
import { JWTPayload } from 'jose';
|
|
4
|
+
import { ILogger } from '@kaapi/kaapi';
|
|
5
|
+
export interface JwksKeyStore {
|
|
6
|
+
/**
|
|
7
|
+
* Stores the current active private key and its corresponding public key.
|
|
8
|
+
* The public key will be kept for the duration of the TTL for JWKS purposes.
|
|
9
|
+
*/
|
|
10
|
+
storeKeyPair(kid: string, privateKey: object, publicKey: object, ttl: number): void | Promise<void>;
|
|
11
|
+
/**
|
|
12
|
+
* Retrieves the current private key used for signing.
|
|
13
|
+
*/
|
|
14
|
+
getPrivateKey(): Promise<object | undefined>;
|
|
15
|
+
/**
|
|
16
|
+
* Retrieves all valid public keys that have not expired.
|
|
17
|
+
* These are used for exposing in JWKS.
|
|
18
|
+
*/
|
|
19
|
+
getPublicKeys(): Promise<object[]>;
|
|
20
|
+
}
|
|
21
|
+
export interface KeyGenerator {
|
|
22
|
+
generateKeyPair(): Promise<void>;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* - Generates JWK key pairs
|
|
26
|
+
* - Signs JWTs
|
|
27
|
+
* - Verifies JWTs
|
|
28
|
+
* - Exposes public keys (for JWKS endpoint)
|
|
29
|
+
*/
|
|
30
|
+
export declare class JwtAuthority implements KeyGenerator {
|
|
31
|
+
#private;
|
|
32
|
+
/**
|
|
33
|
+
*
|
|
34
|
+
* @param store
|
|
35
|
+
* @param ttl seconds
|
|
36
|
+
*/
|
|
37
|
+
constructor(store: JwksKeyStore, ttl?: number);
|
|
38
|
+
getPublicKeys(): Promise<{
|
|
39
|
+
keys: jose.JWK.RawKey[];
|
|
40
|
+
}>;
|
|
41
|
+
/**
|
|
42
|
+
* Get current kid for observability/debugging
|
|
43
|
+
*/
|
|
44
|
+
getCurrentKid(): Promise<string | undefined>;
|
|
45
|
+
/**
|
|
46
|
+
* Helper for JWKS endpoint
|
|
47
|
+
*/
|
|
48
|
+
getJwksEndpointResponse(): Promise<{
|
|
49
|
+
keys: jose.JWK.RawKey[];
|
|
50
|
+
}>;
|
|
51
|
+
getPublicKey(kid: string): Promise<jwktopem.RSA | undefined>;
|
|
52
|
+
generateKeyPair(): Promise<void>;
|
|
53
|
+
sign(payload: JWTPayload): Promise<{
|
|
54
|
+
token: string;
|
|
55
|
+
kid: string;
|
|
56
|
+
}>;
|
|
57
|
+
verify<P extends JWTPayload = JWTPayload>(token: string): Promise<P>;
|
|
58
|
+
}
|
|
59
|
+
export interface JwksRotationTimestampStore {
|
|
60
|
+
getLastRotationTimestamp(): Promise<number>;
|
|
61
|
+
setLastRotationTimestamp(rotationTimestamp: number): Promise<void>;
|
|
62
|
+
}
|
|
63
|
+
export interface JwksRotatorOptions {
|
|
64
|
+
keyGenerator: KeyGenerator;
|
|
65
|
+
rotatorKeyStore: JwksRotationTimestampStore;
|
|
66
|
+
rotationIntervalMs: number;
|
|
67
|
+
logger?: ILogger;
|
|
68
|
+
}
|
|
69
|
+
export declare class JwksRotator {
|
|
70
|
+
private readonly keyGenerator;
|
|
71
|
+
private readonly rotatorKeyStore;
|
|
72
|
+
private readonly rotationIntervalMs;
|
|
73
|
+
private readonly logger;
|
|
74
|
+
constructor({ keyGenerator, rotationIntervalMs, rotatorKeyStore, logger }: JwksRotatorOptions);
|
|
75
|
+
/**
|
|
76
|
+
* Checks if rotation is due, and performs rotation if necessary.
|
|
77
|
+
* Should be called at service startup or on a schedule (e.g. every hour).
|
|
78
|
+
*/
|
|
79
|
+
checkAndRotateKeys(): Promise<void>;
|
|
80
|
+
private rotateKeys;
|
|
81
|
+
}
|