@kaapi/oauth2-auth-design 0.0.14 → 0.0.15

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.
Files changed (83) hide show
  1. package/kaukau.config.mjs +20 -0
  2. package/lib/cli.js +6 -6
  3. package/lib/flows/auth-code/authorization-route.d.ts +58 -7
  4. package/lib/flows/auth-code/authorization-route.js +139 -52
  5. package/lib/flows/auth-code/authorization-route.js.map +1 -1
  6. package/lib/flows/auth-code/authorization-utils.d.ts +35 -0
  7. package/lib/flows/auth-code/authorization-utils.js +44 -0
  8. package/lib/flows/auth-code/authorization-utils.js.map +1 -0
  9. package/lib/flows/auth-code/token-route.d.ts +10 -18
  10. package/lib/flows/auth-code/token-route.js +6 -15
  11. package/lib/flows/auth-code/token-route.js.map +1 -1
  12. package/lib/flows/authorization-code.d.ts +112 -0
  13. package/lib/flows/authorization-code.js +570 -0
  14. package/lib/flows/authorization-code.js.map +1 -0
  15. package/lib/flows/client-credentials.d.ts +79 -39
  16. package/lib/flows/client-credentials.js +324 -257
  17. package/lib/flows/client-credentials.js.map +1 -1
  18. package/lib/flows/client-creds/token-route.d.ts +23 -0
  19. package/lib/flows/client-creds/token-route.js +52 -0
  20. package/lib/flows/client-creds/token-route.js.map +1 -0
  21. package/lib/flows/common.d.ts +265 -28
  22. package/lib/flows/common.js +293 -29
  23. package/lib/flows/common.js.map +1 -1
  24. package/lib/flows/device-auth/authorization-route.d.ts +83 -0
  25. package/lib/flows/device-auth/authorization-route.js +68 -0
  26. package/lib/flows/device-auth/authorization-route.js.map +1 -0
  27. package/lib/flows/device-auth/token-route.d.ts +29 -0
  28. package/lib/flows/device-auth/token-route.js +49 -0
  29. package/lib/flows/device-auth/token-route.js.map +1 -0
  30. package/lib/flows/device-authorization.d.ts +112 -0
  31. package/lib/flows/device-authorization.js +523 -0
  32. package/lib/flows/device-authorization.js.map +1 -0
  33. package/lib/flows/oidc-multiple-flows.d.ts +59 -0
  34. package/lib/flows/oidc-multiple-flows.js +268 -0
  35. package/lib/flows/oidc-multiple-flows.js.map +1 -0
  36. package/lib/index.d.ts +12 -6
  37. package/lib/index.js +12 -6
  38. package/lib/index.js.map +1 -1
  39. package/lib/utils/client-auth-methods.d.ts +2 -2
  40. package/lib/utils/client-auth-methods.js +5 -6
  41. package/lib/utils/client-auth-methods.js.map +1 -1
  42. package/lib/utils/in-memory-key-store.d.ts +12 -0
  43. package/lib/utils/in-memory-key-store.js +46 -0
  44. package/lib/utils/in-memory-key-store.js.map +1 -0
  45. package/lib/utils/jwt-authority.d.ts +81 -0
  46. package/lib/utils/jwt-authority.js +186 -0
  47. package/lib/utils/jwt-authority.js.map +1 -0
  48. package/lib/utils/jwt-utils.d.ts +33 -0
  49. package/lib/utils/jwt-utils.js +24 -0
  50. package/lib/utils/jwt-utils.js.map +1 -0
  51. package/lib/utils/replay-store.d.ts +13 -0
  52. package/lib/utils/{cache-set.js → replay-store.js} +8 -4
  53. package/lib/utils/replay-store.js.map +1 -0
  54. package/lib/utils/token-types.d.ts +6 -3
  55. package/lib/utils/token-types.js +13 -10
  56. package/lib/utils/token-types.js.map +1 -1
  57. package/lib/utils/verify-code-verifier.d.ts +4 -0
  58. package/lib/utils/verify-code-verifier.js +18 -0
  59. package/lib/utils/verify-code-verifier.js.map +1 -0
  60. package/package.json +6 -7
  61. package/lib/flows/auth-code/open-id.d.ts +0 -53
  62. package/lib/flows/auth-code/open-id.js +0 -199
  63. package/lib/flows/auth-code/open-id.js.map +0 -1
  64. package/lib/flows/auth-code.ts/open-id.d.ts +0 -52
  65. package/lib/flows/auth-code.ts/open-id.js +0 -169
  66. package/lib/flows/auth-code.ts/open-id.js.map +0 -1
  67. package/lib/flows/authentication-code.d.ts +0 -53
  68. package/lib/flows/authentication-code.js +0 -380
  69. package/lib/flows/authentication-code.js.map +0 -1
  70. package/lib/utils/cache-set.d.ts +0 -12
  71. package/lib/utils/cache-set.js.map +0 -1
  72. package/lib/utils/in-memory-cache.d.ts +0 -5
  73. package/lib/utils/in-memory-cache.js +0 -30
  74. package/lib/utils/in-memory-cache.js.map +0 -1
  75. package/lib/utils/in-memory-jwks-store.d.ts +0 -12
  76. package/lib/utils/in-memory-jwks-store.js +0 -46
  77. package/lib/utils/in-memory-jwks-store.js.map +0 -1
  78. package/lib/utils/jwks-generator.d.ts +0 -58
  79. package/lib/utils/jwks-generator.js +0 -141
  80. package/lib/utils/jwks-generator.js.map +0 -1
  81. package/lib/utils/jwks-store.d.ts +0 -13
  82. package/lib/utils/jwks-store.js +0 -3
  83. package/lib/utils/jwks-store.js.map +0 -1
@@ -1,199 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.OpenIDAuthDesign = exports.OpenIDUserInfoRoute = exports.OpenIDJWKSRoute = exports.OpenIDAuthUtil = void 0;
4
- const tslib_1 = require("tslib");
5
- const api_doc_generator_1 = require("@novice1/api-doc-generator");
6
- const authentication_code_1 = require("../authentication-code");
7
- //#region OpenIDAuthUtil
8
- class OpenIDAuthUtil extends api_doc_generator_1.OAuth2Util {
9
- setHost(host) {
10
- super.setHost(host);
11
- return this;
12
- }
13
- toOpenAPI() {
14
- const host = this.getHost();
15
- return {
16
- [this.securitySchemeName]: {
17
- type: 'openIdConnect',
18
- openIdConnectUrl: `${host || ''}/.well-known/openid-configuration`
19
- }
20
- };
21
- }
22
- }
23
- exports.OpenIDAuthUtil = OpenIDAuthUtil;
24
- class OpenIDJWKSRoute {
25
- get path() {
26
- return this._path;
27
- }
28
- get handler() {
29
- return this._handler;
30
- }
31
- constructor(path, handler) {
32
- this._path = path;
33
- this._handler = handler;
34
- }
35
- }
36
- exports.OpenIDJWKSRoute = OpenIDJWKSRoute;
37
- class OpenIDUserInfoRoute {
38
- get path() {
39
- return this._path;
40
- }
41
- get handler() {
42
- return this._handler;
43
- }
44
- constructor(path, handler) {
45
- this._path = path;
46
- this._handler = handler;
47
- }
48
- }
49
- exports.OpenIDUserInfoRoute = OpenIDUserInfoRoute;
50
- class OpenIDAuthDesign extends authentication_code_1.OAuth2AuthorizationCode {
51
- constructor(params) {
52
- const { strategyName, openidConfiguration, jwksRoute, userInfoRoute } = params, props = tslib_1.__rest(params, ["strategyName", "openidConfiguration", "jwksRoute", "userInfoRoute"]);
53
- super(props);
54
- this.openidConfiguration = {};
55
- this.withPkce();
56
- this.strategyName = strategyName || 'open-id-auth-design';
57
- this.jwksRoute = jwksRoute;
58
- this.userInfoRoute = userInfoRoute;
59
- if (openidConfiguration)
60
- this.openidConfiguration = openidConfiguration;
61
- }
62
- getScopes() {
63
- let scopes = {
64
- openid: 'enable OpenID Connect'
65
- };
66
- if (this.scopes) {
67
- if ('openid' in this.scopes) {
68
- scopes = this.scopes;
69
- }
70
- else {
71
- scopes = Object.assign(Object.assign({}, this.scopes), scopes);
72
- }
73
- }
74
- return scopes;
75
- }
76
- integrateHook(t) {
77
- var _a, _b;
78
- super.integrateHook(t);
79
- const docs = this.docs();
80
- const challengeAlgo = docs.getChallengeAlgorithm();
81
- const host = ((_a = t.postman) === null || _a === void 0 ? void 0 : _a.getHost()[0]) || '';
82
- t.route({
83
- path: '/.well-known/openid-configuration',
84
- method: 'GET',
85
- options: {
86
- plugins: {
87
- kaapi: {
88
- docs: false
89
- }
90
- }
91
- },
92
- handler: () => {
93
- var _a, _b, _c, _d;
94
- const wellKnownOpenIDConfig = {
95
- issuer: host,
96
- authorization_endpoint: `${host}${this.authorizationRoute.path}`,
97
- token_endpoint: `${host}${this.tokenRoute.path}`,
98
- userinfo_endpoint: this.userInfoRoute ? `${host}${this.userInfoRoute.path}` : undefined,
99
- jwks_uri: `${host}${this.jwksRoute.path}`,
100
- claims_supported: [
101
- 'aud',
102
- 'exp',
103
- 'iat',
104
- 'iss',
105
- 'sub'
106
- ],
107
- grant_types_supported: [
108
- 'authorization_code'
109
- ],
110
- response_types_supported: [
111
- 'code',
112
- 'token',
113
- 'code token',
114
- 'code token id_token'
115
- ],
116
- scopes_supported: Object.keys(docs.getScopes()),
117
- subject_types_supported: [
118
- 'public'
119
- ],
120
- id_token_signing_alg_values_supported: [
121
- 'RS256'
122
- ],
123
- code_challenge_methods_supported: challengeAlgo ? [
124
- challengeAlgo
125
- ] : [],
126
- token_endpoint_auth_methods_supported: this.getTokenEndpointAuthMethods()
127
- };
128
- if ((_b = (_a = this.clientAuthMethods.client_secret_jwt) === null || _a === void 0 ? void 0 : _a.algorithms) === null || _b === void 0 ? void 0 : _b.length) {
129
- wellKnownOpenIDConfig.token_endpoint_auth_signing_alg_values_supported = wellKnownOpenIDConfig.token_endpoint_auth_signing_alg_values_supported || [];
130
- wellKnownOpenIDConfig.token_endpoint_auth_signing_alg_values_supported = [
131
- ...wellKnownOpenIDConfig.token_endpoint_auth_signing_alg_values_supported,
132
- ...this.clientAuthMethods.client_secret_jwt.algorithms
133
- ];
134
- }
135
- if ((_d = (_c = this.clientAuthMethods.private_key_jwt) === null || _c === void 0 ? void 0 : _c.algorithms) === null || _d === void 0 ? void 0 : _d.length) {
136
- wellKnownOpenIDConfig.token_endpoint_auth_signing_alg_values_supported = wellKnownOpenIDConfig.token_endpoint_auth_signing_alg_values_supported || [];
137
- wellKnownOpenIDConfig.token_endpoint_auth_signing_alg_values_supported = [
138
- ...wellKnownOpenIDConfig.token_endpoint_auth_signing_alg_values_supported,
139
- ...this.clientAuthMethods.private_key_jwt.algorithms
140
- ];
141
- }
142
- return Object.assign(Object.assign({}, wellKnownOpenIDConfig), this.openidConfiguration);
143
- }
144
- });
145
- t.route({
146
- path: this.jwksRoute.path,
147
- method: 'GET',
148
- options: {
149
- plugins: {
150
- kaapi: {
151
- docs: false
152
- }
153
- }
154
- },
155
- handler: (req, h) => tslib_1.__awaiter(this, void 0, void 0, function* () {
156
- const jwks = yield this.jwksGenerator.generateIfEmpty();
157
- if (this.jwksRoute.handler) {
158
- return this.jwksRoute.handler({
159
- jwks
160
- }, req, h);
161
- }
162
- return jwks;
163
- })
164
- });
165
- if ((_b = this.userInfoRoute) === null || _b === void 0 ? void 0 : _b.path) {
166
- t.route({
167
- path: this.userInfoRoute.path,
168
- method: 'GET',
169
- auth: true,
170
- options: {
171
- auth: {
172
- strategy: this.strategyName,
173
- mode: 'required'
174
- }
175
- },
176
- handler: this.userInfoRoute.handler.bind(this.userInfoRoute)
177
- });
178
- }
179
- }
180
- docs() {
181
- var _a;
182
- const docs = new OpenIDAuthUtil(this.strategyName)
183
- .setGrantType(this.isWithPkce() ? api_doc_generator_1.GrantType.authorizationCodeWithPkce : api_doc_generator_1.GrantType.authorizationCode)
184
- .setScopes(this.getScopes())
185
- .setAuthUrl(this.authorizationRoute.path)
186
- .setAccessTokenUrl(this.tokenRoute.path || '')
187
- .setChallengeAlgorithm(api_doc_generator_1.ChallengeAlgorithm.S256);
188
- if ((_a = this.refreshTokenRoute) === null || _a === void 0 ? void 0 : _a.path) {
189
- docs.setRefreshUrl(this.refreshTokenRoute.path);
190
- }
191
- if (this.description) {
192
- docs.setDescription(this.description);
193
- }
194
- return docs;
195
- }
196
- }
197
- exports.OpenIDAuthDesign = OpenIDAuthDesign;
198
- //#endregion OpenIDAuthDesign
199
- //# sourceMappingURL=open-id.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"open-id.js","sourceRoot":"","sources":["../../../src/flows/auth-code/open-id.ts"],"names":[],"mappings":";;;;AACA,kEAAuF;AACvF,gEAA6F;AAI7F,wBAAwB;AAExB,MAAa,cAAe,SAAQ,8BAAU;IAE1C,OAAO,CAAC,IAAY;QAChB,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,CAAA;QACnB,OAAO,IAAI,CAAA;IACf,CAAC;IAED,SAAS;QACL,MAAM,IAAI,GAAG,IAAI,CAAC,OAAO,EAAE,CAAA;QAC3B,OAAO;YACH,CAAC,IAAI,CAAC,kBAAkB,CAAC,EAAE;gBACvB,IAAI,EAAE,eAAe;gBACrB,gBAAgB,EAAE,GAAG,IAAI,IAAI,EAAE,mCAAmC;aACrE;SACJ,CAAA;IACL,CAAC;CACJ;AAhB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AAU,CAAC,IAAI,CAAC,kBAAkB,CAAC,IAAI,CAAC;aACxC,iBAAiB,CAAC,IAAI,CAAC,UAAU,CAAC,IAAI,IAAI,EAAE,CAAC;aAC7C,qBAAqB,CAAC,sCAAkB,CAAC,IAAI,CAAC,CAAC;QAEpD,IAAI,MAAA,IAAI,CAAC,iBAAiB,0CAAE,IAAI,EAAE,CAAC;YAC/B,IAAI,CAAC,aAAa,CAAC,IAAI,CAAC,iBAAiB,CAAC,IAAI,CAAC,CAAA;QACnD,CAAC;QAED,IAAI,IAAI,CAAC,WAAW,EAAE,CAAC;YACnB,IAAI,CAAC,cAAc,CAAC,IAAI,CAAC,WAAW,CAAC,CAAA;QACzC,CAAC;QAED,OAAO,IAAI,CAAA;IACf,CAAC;CACJ;AAzKD,4CAyKC;AAED,6BAA6B"}
@@ -1,52 +0,0 @@
1
- import { SecuritySchemeObject } from '@novice1/api-doc-generator/lib/generators/openapi/definitions';
2
- import { OAuth2Util } from '@novice1/api-doc-generator';
3
- import { OAuth2AuthorizationCode, OAuth2AuthorizationCodeArg } from '../authentication-code';
4
- import { KaapiTools, Lifecycle, ReqRef, Request, ReqRefDefaults, ResponseToolkit } from '@kaapi/kaapi';
5
- import { JWKS } from '../../utils/jwks-store';
6
- export declare class OpenIDAuthUtil extends OAuth2Util {
7
- toOpenAPI(): Record<string, SecuritySchemeObject>;
8
- }
9
- export interface OpenIDJWKSParams {
10
- jwks: JWKS;
11
- }
12
- export type OpenIDJWKSHandler<Refs extends ReqRef = ReqRefDefaults, R extends Lifecycle.ReturnValue<any> = Lifecycle.ReturnValue<Refs>> = (params: OpenIDJWKSParams, request: Request<Refs>, h: ResponseToolkit<Refs>) => R;
13
- export interface IOpenIDJWKSRoute<Refs extends ReqRef = ReqRefDefaults> {
14
- path: string;
15
- handler?: OpenIDJWKSHandler<Refs>;
16
- }
17
- export declare class OpenIDJWKSRoute<Refs extends ReqRef = ReqRefDefaults> implements IOpenIDJWKSRoute<Refs> {
18
- protected _path: string;
19
- protected _handler: OpenIDJWKSHandler<Refs> | undefined;
20
- get path(): string;
21
- get handler(): OpenIDJWKSHandler<Refs, Lifecycle.ReturnValue<Refs>> | undefined;
22
- constructor(path: string, handler?: OpenIDJWKSHandler<Refs>);
23
- }
24
- export type OpenIDUserInfoHandler<Refs extends ReqRef = ReqRefDefaults, R extends Lifecycle.ReturnValue<any> = Lifecycle.ReturnValue<Refs>> = (request: Request<Refs>, h: ResponseToolkit<Refs>) => R;
25
- export interface IOpenIDUserInfoRoute<Refs extends ReqRef = ReqRefDefaults> {
26
- path: string;
27
- handler?: OpenIDUserInfoHandler<Refs>;
28
- }
29
- export declare class OpenIDUserInfoRoute<Refs extends ReqRef = ReqRefDefaults> implements IOpenIDUserInfoRoute<Refs> {
30
- protected _path: string;
31
- protected _handler: OpenIDUserInfoHandler<Refs>;
32
- get path(): string;
33
- get handler(): OpenIDUserInfoHandler<Refs, Lifecycle.ReturnValue<Refs>>;
34
- constructor(path: string, handler: OpenIDUserInfoHandler<Refs>);
35
- }
36
- export interface OpenIDAuthDesignArg extends OAuth2AuthorizationCodeArg {
37
- jwksRoute: OpenIDJWKSRoute<any>;
38
- userInfoRoute: OpenIDUserInfoRoute<any>;
39
- /**
40
- * Override the configuration served at /.well-known/openid-configuration
41
- */
42
- openidConfiguration?: Record<string, unknown>;
43
- }
44
- export declare class OpenIDAuthDesign extends OAuth2AuthorizationCode {
45
- protected jwksRoute: OpenIDJWKSRoute<any>;
46
- protected userInfoRoute: OpenIDUserInfoRoute<any>;
47
- protected openidConfiguration: Record<string, unknown>;
48
- constructor(params: OpenIDAuthDesignArg);
49
- getScopes(): Record<string, string>;
50
- integrateHook(t: KaapiTools): void;
51
- docs(): OAuth2Util;
52
- }
@@ -1,169 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.OpenIDAuthDesign = exports.OpenIDUserInfoRoute = exports.OpenIDJWKSRoute = exports.OpenIDAuthUtil = void 0;
4
- const tslib_1 = require("tslib");
5
- const api_doc_generator_1 = require("@novice1/api-doc-generator");
6
- const authentication_code_1 = require("../authentication-code");
7
- //#region OpenIDAuthUtil
8
- class OpenIDAuthUtil extends api_doc_generator_1.OAuth2Util {
9
- toOpenAPI() {
10
- const host = this.getHost();
11
- return {
12
- [this.securitySchemeName]: {
13
- type: 'openIdConnect',
14
- openIdConnectUrl: `${host || ''}/.well-known/openid-configuration`
15
- }
16
- };
17
- }
18
- }
19
- exports.OpenIDAuthUtil = OpenIDAuthUtil;
20
- class OpenIDJWKSRoute {
21
- get path() {
22
- return this._path;
23
- }
24
- get handler() {
25
- return this._handler;
26
- }
27
- constructor(path, handler) {
28
- this._path = path;
29
- this._handler = handler;
30
- }
31
- }
32
- exports.OpenIDJWKSRoute = OpenIDJWKSRoute;
33
- class OpenIDUserInfoRoute {
34
- get path() {
35
- return this._path;
36
- }
37
- get handler() {
38
- return this._handler;
39
- }
40
- constructor(path, handler) {
41
- this._path = path;
42
- this._handler = handler;
43
- }
44
- }
45
- exports.OpenIDUserInfoRoute = OpenIDUserInfoRoute;
46
- class OpenIDAuthDesign extends authentication_code_1.OAuth2AuthorizationCode {
47
- constructor(params) {
48
- const { strategyName, openidConfiguration, jwksRoute, userInfoRoute } = params, props = tslib_1.__rest(params, ["strategyName", "openidConfiguration", "jwksRoute", "userInfoRoute"]);
49
- super(props);
50
- this.openidConfiguration = {};
51
- this.pkce = true;
52
- this.strategyName = strategyName || 'open-id-auth-design';
53
- this.jwksRoute = jwksRoute;
54
- this.userInfoRoute = userInfoRoute;
55
- if (openidConfiguration)
56
- this.openidConfiguration = openidConfiguration;
57
- }
58
- getScopes() {
59
- let scopes = {
60
- openid: 'enable OpenID Connect'
61
- };
62
- if (this.scopes) {
63
- if ('openid' in this.scopes) {
64
- scopes = this.scopes;
65
- }
66
- else {
67
- scopes = Object.assign(Object.assign({}, this.scopes), scopes);
68
- }
69
- }
70
- return scopes;
71
- }
72
- integrateHook(t) {
73
- var _a;
74
- super.integrateHook(t);
75
- const docs = this.docs();
76
- const challengeAlgo = docs.getChallengeAlgorithm();
77
- const host = ((_a = t.postman) === null || _a === void 0 ? void 0 : _a.getHost()[0]) || '';
78
- t.route({
79
- path: '/.well-known/openid-configuration',
80
- method: 'GET',
81
- options: {
82
- plugins: {
83
- kaapi: {
84
- docs: false
85
- }
86
- }
87
- },
88
- handler: () => {
89
- return Object.assign({ issuer: host, authorization_endpoint: `${host}${this.authorizationRoute.path}`, token_endpoint: `${host}${this.tokenRoute.path}`, userinfo_endpoint: `${host}${this.userInfoRoute.path}`, jwks_uri: `${host}${this.jwksRoute.path}`, claims_supported: [
90
- 'aud',
91
- 'exp',
92
- 'iat',
93
- 'iss',
94
- 'sub'
95
- ], grant_types_supported: [
96
- 'authorization_code'
97
- ], response_types_supported: [
98
- 'code',
99
- 'token',
100
- 'code token',
101
- 'code token id_token'
102
- ], scopes_supported: Object.keys(docs.getScopes()), subject_types_supported: [
103
- 'public'
104
- ], id_token_signing_alg_values_supported: [
105
- 'RS256'
106
- ], code_challenge_methods_supported: challengeAlgo ? [
107
- challengeAlgo
108
- ] : [], token_endpoint_auth_methods_supported: [
109
- 'client_secret_post'
110
- ] }, this.openidConfiguration);
111
- }
112
- });
113
- t.route({
114
- path: this.jwksRoute.path,
115
- method: 'GET',
116
- options: {
117
- plugins: {
118
- kaapi: {
119
- docs: false
120
- }
121
- }
122
- },
123
- handler: (req, h) => tslib_1.__awaiter(this, void 0, void 0, function* () {
124
- const jwks = yield this.jwksGenerator.get();
125
- if (this.jwksRoute.handler) {
126
- return this.jwksRoute.handler({
127
- jwks
128
- }, req, h);
129
- }
130
- return jwks;
131
- })
132
- });
133
- t.route({
134
- path: this.userInfoRoute.path,
135
- method: 'GET',
136
- options: {
137
- auth: {
138
- strategy: this.strategyName,
139
- mode: 'required'
140
- },
141
- plugins: {
142
- kaapi: {
143
- docs: false
144
- }
145
- }
146
- },
147
- handler: this.userInfoRoute.handler.bind(this.userInfoRoute)
148
- });
149
- }
150
- docs() {
151
- var _a;
152
- const docs = new OpenIDAuthUtil(this.strategyName)
153
- .setGrantType(this.isWithPkce() ? api_doc_generator_1.GrantType.authorizationCodeWithPkce : api_doc_generator_1.GrantType.authorizationCode)
154
- .setScopes(this.getScopes())
155
- .setAuthUrl(this.authorizationRoute.path)
156
- .setAccessTokenUrl(this.tokenRoute.path || '')
157
- .setChallengeAlgorithm(api_doc_generator_1.ChallengeAlgorithm.S256);
158
- if ((_a = this.refreshTokenRoute) === null || _a === void 0 ? void 0 : _a.path) {
159
- docs.setRefreshUrl(this.refreshTokenRoute.path);
160
- }
161
- if (this.description) {
162
- docs.setDescription(this.description);
163
- }
164
- return docs;
165
- }
166
- }
167
- exports.OpenIDAuthDesign = OpenIDAuthDesign;
168
- //#endregion OpenIDAuthDesign
169
- //# sourceMappingURL=open-id.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"open-id.js","sourceRoot":"","sources":["../../../src/flows/auth-code.ts/open-id.ts"],"names":[],"mappings":";;;;AACA,kEAAuF;AACvF,gEAA6F;AAI7F,wBAAwB;AAExB,MAAa,cAAe,SAAQ,8BAAU;IAC1C,SAAS;QACL,MAAM,IAAI,GAAG,IAAI,CAAC,OAAO,EAAE,CAAA;QAC3B,OAAO;YACH,CAAC,IAAI,CAAC,kBAAkB,CAAC,EAAE;gBACvB,IAAI,EAAE,eAAe;gBACrB,gBAAgB,EAAE,GAAG,IAAI,IAAI,EAAE,mCAAmC;aACrE;SACJ,CAAA;IACL,CAAC;CACJ;AAVD,wCAUC;AAuBD,MAAa,eAAe;IAMxB,IAAI,IAAI;QACJ,OAAO,IAAI,CAAC,KAAK,CAAA;IACrB,CAAC;IAED,IAAI,OAAO;QACP,OAAO,IAAI,CAAC,QAAQ,CAAA;IACxB,CAAC;IAED,YACI,IAAY,EACZ,OAAiC;QAEjC,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC;QAClB,IAAI,CAAC,QAAQ,GAAG,OAAO,CAAC;IAC5B,CAAC;CACJ;AAr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B,CAAC,CAAC,CAAC,6BAAS,CAAC,iBAAiB,CAAC;aACnG,SAAS,CAAC,IAAI,CAAC,SAAS,EAAE,CAAC;aAC3B,UAAU,CAAC,IAAI,CAAC,kBAAkB,CAAC,IAAI,CAAC;aACxC,iBAAiB,CAAC,IAAI,CAAC,UAAU,CAAC,IAAI,IAAI,EAAE,CAAC;aAC7C,qBAAqB,CAAC,sCAAkB,CAAC,IAAI,CAAC,CAAC;QAEpD,IAAI,MAAA,IAAI,CAAC,iBAAiB,0CAAE,IAAI,EAAE,CAAC;YAC/B,IAAI,CAAC,aAAa,CAAC,IAAI,CAAC,iBAAiB,CAAC,IAAI,CAAC,CAAA;QACnD,CAAC;QAED,IAAI,IAAI,CAAC,WAAW,EAAE,CAAC;YACnB,IAAI,CAAC,cAAc,CAAC,IAAI,CAAC,WAAW,CAAC,CAAA;QACzC,CAAC;QAED,OAAO,IAAI,CAAA;IACf,CAAC;CACJ;AA7JD,4CA6JC;AAED,6BAA6B"}
@@ -1,53 +0,0 @@
1
- import { KaapiTools } from '@kaapi/kaapi';
2
- import { OAuth2Util } from '@novice1/api-doc-generator';
3
- import { IOAuth2RefreshTokenRoute, OAuth2WithJWKSAuthDesign, OAuth2AuthOptions } from './common';
4
- import { JWKSStore } from '../utils/jwks-store';
5
- import { IOAuth2ACAuthorizationRoute } from './auth-code/authorization-route';
6
- import { IOAuth2ACTokenRoute } from './auth-code/token-route';
7
- export interface OAuth2AuthorizationCodeArg {
8
- authorizationRoute: IOAuth2ACAuthorizationRoute<any, any>;
9
- tokenRoute: IOAuth2ACTokenRoute<any>;
10
- refreshTokenRoute?: IOAuth2RefreshTokenRoute<any>;
11
- options?: OAuth2AuthOptions;
12
- strategyName?: string;
13
- jwksStore?: JWKSStore;
14
- }
15
- export declare class OAuth2AuthorizationCode extends OAuth2WithJWKSAuthDesign {
16
- protected strategyName: string;
17
- protected description?: string;
18
- protected scopes?: Record<string, string>;
19
- protected options: OAuth2AuthOptions;
20
- protected pkce: boolean;
21
- protected clientAuthenticationMethods: {
22
- header: boolean;
23
- body: boolean;
24
- };
25
- protected authorizationRoute: IOAuth2ACAuthorizationRoute<any, any>;
26
- protected tokenRoute: IOAuth2ACTokenRoute<any>;
27
- protected refreshTokenRoute?: IOAuth2RefreshTokenRoute<any>;
28
- constructor({ authorizationRoute, tokenRoute, refreshTokenRoute, options, strategyName, jwksStore }: OAuth2AuthorizationCodeArg);
29
- withPkce(): this;
30
- withoutPkce(): this;
31
- isWithPkce(): boolean;
32
- noneAuthenticationMethod(): this;
33
- setDescription(description: string): this;
34
- /**
35
- *
36
- * @param scopes The scopes of the access request.
37
- * A map between the scope name and a short description for it. The map MAY be empty.
38
- * @returns
39
- */
40
- setScopes(scopes: Record<string, string>): this;
41
- getScopes(): Record<string, string> | undefined;
42
- getStrategyName(): string;
43
- getDescription(): string | undefined;
44
- /**
45
- * Returns the schema used for the documentation
46
- */
47
- docs(): OAuth2Util;
48
- /**
49
- * Where authentication schemes and strategies are registered.
50
- */
51
- integrateStrategy(t: KaapiTools): void;
52
- integrateHook(t: KaapiTools): void;
53
- }