@tsed/oidc-provider 8.11.0 → 8.11.2-rc.1

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 (112) hide show
  1. package/lib/esm/OidcModule.js +0 -1
  2. package/lib/esm/constants/constants.js +0 -1
  3. package/lib/esm/decorators/grantId.js +0 -1
  4. package/lib/esm/decorators/interaction.js +0 -1
  5. package/lib/esm/decorators/interactions.js +0 -1
  6. package/lib/esm/decorators/noCache.js +0 -1
  7. package/lib/esm/decorators/oidcCtx.js +0 -1
  8. package/lib/esm/decorators/oidcSession.js +0 -1
  9. package/lib/esm/decorators/params.js +0 -1
  10. package/lib/esm/decorators/prompt.js +0 -1
  11. package/lib/esm/decorators/uid.js +0 -1
  12. package/lib/esm/domain/InteractionMethods.js +0 -1
  13. package/lib/esm/domain/OidcAccountsMethods.js +0 -1
  14. package/lib/esm/domain/OidcBadInteractionName.js +0 -1
  15. package/lib/esm/domain/OidcInteractionMethods.js +0 -1
  16. package/lib/esm/domain/OidcInteractionOptions.js +0 -1
  17. package/lib/esm/domain/OidcInteractionPromptProps.js +0 -1
  18. package/lib/esm/domain/OidcSettings.js +0 -1
  19. package/lib/esm/domain/interfaces.js +0 -1
  20. package/lib/esm/index.js +0 -1
  21. package/lib/esm/middlewares/OidcInteractionMiddleware.js +0 -1
  22. package/lib/esm/middlewares/OidcNoCacheMiddleware.js +0 -1
  23. package/lib/esm/middlewares/OidcSecureMiddleware.js +0 -1
  24. package/lib/esm/services/OidcAdapters.js +0 -1
  25. package/lib/esm/services/OidcInteractionContext.js +0 -1
  26. package/lib/esm/services/OidcInteractions.js +0 -1
  27. package/lib/esm/services/OidcJwks.js +0 -1
  28. package/lib/esm/services/OidcPolicy.js +0 -1
  29. package/lib/esm/services/OidcProvider.js +0 -1
  30. package/lib/esm/utils/debug.js +0 -1
  31. package/lib/esm/utils/events.js +0 -1
  32. package/package.json +13 -10
  33. package/lib/esm/OidcModule.js.map +0 -1
  34. package/lib/esm/constants/constants.js.map +0 -1
  35. package/lib/esm/decorators/grantId.js.map +0 -1
  36. package/lib/esm/decorators/interaction.js.map +0 -1
  37. package/lib/esm/decorators/interactions.js.map +0 -1
  38. package/lib/esm/decorators/noCache.js.map +0 -1
  39. package/lib/esm/decorators/oidcCtx.js.map +0 -1
  40. package/lib/esm/decorators/oidcSession.js.map +0 -1
  41. package/lib/esm/decorators/params.js.map +0 -1
  42. package/lib/esm/decorators/prompt.js.map +0 -1
  43. package/lib/esm/decorators/uid.js.map +0 -1
  44. package/lib/esm/domain/InteractionMethods.js.map +0 -1
  45. package/lib/esm/domain/OidcAccountsMethods.js.map +0 -1
  46. package/lib/esm/domain/OidcBadInteractionName.js.map +0 -1
  47. package/lib/esm/domain/OidcInteractionMethods.js.map +0 -1
  48. package/lib/esm/domain/OidcInteractionOptions.js.map +0 -1
  49. package/lib/esm/domain/OidcInteractionPromptProps.js.map +0 -1
  50. package/lib/esm/domain/OidcSettings.js.map +0 -1
  51. package/lib/esm/domain/interfaces.js.map +0 -1
  52. package/lib/esm/index.js.map +0 -1
  53. package/lib/esm/middlewares/OidcInteractionMiddleware.js.map +0 -1
  54. package/lib/esm/middlewares/OidcNoCacheMiddleware.js.map +0 -1
  55. package/lib/esm/middlewares/OidcSecureMiddleware.js.map +0 -1
  56. package/lib/esm/services/OidcAdapters.js.map +0 -1
  57. package/lib/esm/services/OidcInteractionContext.js.map +0 -1
  58. package/lib/esm/services/OidcInteractions.js.map +0 -1
  59. package/lib/esm/services/OidcJwks.js.map +0 -1
  60. package/lib/esm/services/OidcPolicy.js.map +0 -1
  61. package/lib/esm/services/OidcProvider.js.map +0 -1
  62. package/lib/esm/utils/debug.js.map +0 -1
  63. package/lib/esm/utils/events.js.map +0 -1
  64. package/src/OidcModule.spec.ts +0 -116
  65. package/src/OidcModule.ts +0 -70
  66. package/src/constants/constants.ts +0 -10
  67. package/src/decorators/grantId.spec.ts +0 -17
  68. package/src/decorators/grantId.ts +0 -10
  69. package/src/decorators/interaction.spec.ts +0 -27
  70. package/src/decorators/interaction.ts +0 -18
  71. package/src/decorators/interactions.spec.ts +0 -23
  72. package/src/decorators/interactions.ts +0 -21
  73. package/src/decorators/noCache.ts +0 -7
  74. package/src/decorators/oidcCtx.spec.ts +0 -17
  75. package/src/decorators/oidcCtx.ts +0 -11
  76. package/src/decorators/oidcSession.spec.ts +0 -17
  77. package/src/decorators/oidcSession.ts +0 -14
  78. package/src/decorators/params.spec.ts +0 -17
  79. package/src/decorators/params.ts +0 -10
  80. package/src/decorators/prompt.spec.ts +0 -17
  81. package/src/decorators/prompt.ts +0 -11
  82. package/src/decorators/uid.spec.ts +0 -17
  83. package/src/decorators/uid.ts +0 -10
  84. package/src/domain/InteractionMethods.ts +0 -11
  85. package/src/domain/OidcAccountsMethods.ts +0 -10
  86. package/src/domain/OidcBadInteractionName.ts +0 -3
  87. package/src/domain/OidcInteractionMethods.ts +0 -3
  88. package/src/domain/OidcInteractionOptions.ts +0 -8
  89. package/src/domain/OidcInteractionPromptProps.ts +0 -11
  90. package/src/domain/OidcSettings.ts +0 -72
  91. package/src/domain/interfaces.ts +0 -13
  92. package/src/index.ts +0 -33
  93. package/src/middlewares/OidcInteractionMiddleware.spec.ts +0 -40
  94. package/src/middlewares/OidcInteractionMiddleware.ts +0 -14
  95. package/src/middlewares/OidcNoCacheMiddleware.spec.ts +0 -18
  96. package/src/middlewares/OidcNoCacheMiddleware.ts +0 -10
  97. package/src/middlewares/OidcSecureMiddleware.spec.ts +0 -106
  98. package/src/middlewares/OidcSecureMiddleware.ts +0 -30
  99. package/src/services/OidcAdapters.spec.ts +0 -100
  100. package/src/services/OidcAdapters.ts +0 -92
  101. package/src/services/OidcInteractionContext.spec.ts +0 -304
  102. package/src/services/OidcInteractionContext.ts +0 -206
  103. package/src/services/OidcInteractions.ts +0 -57
  104. package/src/services/OidcJwks.ts +0 -22
  105. package/src/services/OidcPolicy.spec.ts +0 -156
  106. package/src/services/OidcPolicy.ts +0 -92
  107. package/src/services/OidcProvider.spec.ts +0 -116
  108. package/src/services/OidcProvider.ts +0 -198
  109. package/src/utils/debug.spec.ts +0 -12
  110. package/src/utils/debug.ts +0 -26
  111. package/src/utils/events.ts +0 -61
  112. package/vitest.config.mts +0 -21
@@ -1,10 +0,0 @@
1
- import {useDecorators} from "@tsed/core";
2
- import {Context} from "@tsed/platform-params";
3
-
4
- import {INTERACTION_GRANT_ID, INTERACTION_PARAMS} from "../constants/constants.js";
5
-
6
- export function GrantId(): ParameterDecorator {
7
- return useDecorators(Context(INTERACTION_GRANT_ID));
8
- }
9
-
10
- export type GrantId = string;
@@ -1,27 +0,0 @@
1
- import {Store} from "@tsed/core";
2
- import {GlobalProviders} from "@tsed/di";
3
-
4
- import {INTERACTION_OPTIONS} from "../constants/constants.js";
5
- import {OidcInteractionMethods} from "../domain/OidcInteractionMethods.js";
6
- import {Interaction} from "./interaction.js";
7
-
8
- describe("@Interaction", () => {
9
- it("should create an interaction", () => {
10
- @Interaction({
11
- name: "login",
12
- requestable: true,
13
- priority: 0
14
- })
15
- class CustomInteraction implements OidcInteractionMethods {}
16
-
17
- const store = Store.from(CustomInteraction);
18
- const provider = GlobalProviders.get(CustomInteraction)!;
19
-
20
- expect(provider.subType).toEqual("interaction");
21
- expect(store.get(INTERACTION_OPTIONS)).toEqual({
22
- name: "login",
23
- requestable: true,
24
- priority: 0
25
- });
26
- });
27
- });
@@ -1,18 +0,0 @@
1
- import {StoreMerge, useDecorators} from "@tsed/core";
2
- import {Controller} from "@tsed/di";
3
-
4
- import {INTERACTION, INTERACTION_OPTIONS} from "../constants/constants.js";
5
- import {OidcInteractionOptions} from "../domain/OidcInteractionOptions.js";
6
-
7
- /**
8
- * @Oidc
9
- */
10
- export function Interaction(options: OidcInteractionOptions): ClassDecorator {
11
- return useDecorators(
12
- Controller({
13
- path: "/",
14
- subType: INTERACTION
15
- }),
16
- StoreMerge(INTERACTION_OPTIONS, options)
17
- );
18
- }
@@ -1,23 +0,0 @@
1
- import "../../test/app/controllers/oidc/InteractionsCtrl.js";
2
-
3
- import {PlatformTest} from "@tsed/platform-http/testing";
4
-
5
- describe("@Interactions", () => {
6
- beforeEach(() =>
7
- PlatformTest.create({
8
- oidc: {
9
- options: {
10
- claims: {}
11
- }
12
- } as any
13
- })
14
- );
15
- afterEach(() => PlatformTest.create());
16
- it("should create interactions", () => {
17
- PlatformTest.injector.resolveConfiguration();
18
-
19
- const oidc = PlatformTest.injector.settings.get("oidc");
20
-
21
- expect(oidc.options.claims).toEqual({});
22
- });
23
- });
@@ -1,21 +0,0 @@
1
- import {Type, useDecorators} from "@tsed/core";
2
- import {Controller} from "@tsed/di";
3
- import {UseBefore} from "@tsed/platform-middlewares";
4
-
5
- import {INTERACTIONS} from "../constants/constants.js";
6
- import {OidcInteractionMiddleware} from "../middlewares/OidcInteractionMiddleware.js";
7
- import {NoCache} from "./noCache.js";
8
-
9
- export interface InteractionsOptions {
10
- path: string;
11
- children: Type<any>[];
12
- }
13
-
14
- export function Interactions(options: InteractionsOptions): ClassDecorator {
15
- const {path} = options;
16
- return useDecorators(
17
- Controller({path, children: options.children, subType: INTERACTIONS}),
18
- NoCache(),
19
- UseBefore(OidcInteractionMiddleware)
20
- );
21
- }
@@ -1,7 +0,0 @@
1
- import {UseBefore} from "@tsed/platform-middlewares";
2
-
3
- import {OidcNoCacheMiddleware} from "../middlewares/OidcNoCacheMiddleware.js";
4
-
5
- export function NoCache(): ClassDecorator {
6
- return UseBefore(OidcNoCacheMiddleware) as ClassDecorator;
7
- }
@@ -1,17 +0,0 @@
1
- import {JsonParameterStore} from "@tsed/schema";
2
-
3
- import {INTERACTION_CONTEXT} from "../constants/constants.js";
4
- import {OidcCtx} from "./oidcCtx.js";
5
-
6
- describe("@OidcCtx", () => {
7
- it("should inject uid", () => {
8
- class MyInteraction {
9
- $prompt(@OidcCtx() oidcCtx: OidcCtx) {}
10
- }
11
-
12
- const entity = JsonParameterStore.get(MyInteraction, "$prompt", 0);
13
-
14
- expect(entity.paramType).toEqual("$CTX");
15
- expect(entity.expression).toEqual(INTERACTION_CONTEXT);
16
- });
17
- });
@@ -1,11 +0,0 @@
1
- import {useDecorators} from "@tsed/core";
2
- import {Context} from "@tsed/platform-params";
3
-
4
- import {INTERACTION_CONTEXT} from "../constants/constants.js";
5
- import {OidcInteractionContext} from "../services/OidcInteractionContext.js";
6
-
7
- export function OidcCtx(): ParameterDecorator {
8
- return useDecorators(Context(INTERACTION_CONTEXT));
9
- }
10
-
11
- export type OidcCtx = OidcInteractionContext;
@@ -1,17 +0,0 @@
1
- import {JsonParameterStore} from "@tsed/schema";
2
-
3
- import {INTERACTION_SESSION} from "../constants/constants.js";
4
- import {OidcSession} from "./oidcSession.js";
5
-
6
- describe("@OidcSession", () => {
7
- it("should inject uid", () => {
8
- class MyInteraction {
9
- $prompt(@OidcSession() session: OidcSession) {}
10
- }
11
-
12
- const entity = JsonParameterStore.get(MyInteraction, "$prompt", 0);
13
-
14
- expect(entity.paramType).toEqual("$CTX");
15
- expect(entity.expression).toEqual(INTERACTION_SESSION);
16
- });
17
- });
@@ -1,14 +0,0 @@
1
- import {useDecorators} from "@tsed/core";
2
- import {Context} from "@tsed/platform-params";
3
- import type {default as Provider} from "oidc-provider";
4
-
5
- import {INTERACTION_SESSION} from "../constants/constants.js";
6
-
7
- /**
8
- * @decorator
9
- */
10
- export function OidcSession(expression?: string): ParameterDecorator {
11
- return useDecorators(Context([INTERACTION_SESSION, expression].filter(Boolean).join(".")));
12
- }
13
-
14
- export type OidcSession = InstanceType<Provider["Session"]>;
@@ -1,17 +0,0 @@
1
- import {JsonParameterStore} from "@tsed/schema";
2
-
3
- import {INTERACTION_PARAMS} from "../constants/constants.js";
4
- import {Params} from "./params.js";
5
-
6
- describe("@Params", () => {
7
- it("should inject uid", () => {
8
- class MyInteraction {
9
- $prompt(@Params() params: Params) {}
10
- }
11
-
12
- const entity = JsonParameterStore.get(MyInteraction, "$prompt", 0);
13
-
14
- expect(entity.paramType).toEqual("$CTX");
15
- expect(entity.expression).toEqual(INTERACTION_PARAMS);
16
- });
17
- });
@@ -1,10 +0,0 @@
1
- import {useDecorators} from "@tsed/core";
2
- import {Context} from "@tsed/platform-params";
3
-
4
- import {INTERACTION_PARAMS} from "../constants/constants.js";
5
-
6
- export function Params(expression?: string): ParameterDecorator {
7
- return useDecorators(Context([INTERACTION_PARAMS, expression].filter(Boolean).join(".")));
8
- }
9
-
10
- export type Params = Record<string, any>;
@@ -1,17 +0,0 @@
1
- import {JsonParameterStore} from "@tsed/schema";
2
-
3
- import {INTERACTION_PROMPT} from "../constants/constants.js";
4
- import {Prompt} from "./prompt.js";
5
-
6
- describe("@Prompt", () => {
7
- it("should inject uid", () => {
8
- class MyInteraction {
9
- $prompt(@Prompt() uid: Prompt) {}
10
- }
11
-
12
- const entity = JsonParameterStore.get(MyInteraction, "$prompt", 0);
13
-
14
- expect(entity.paramType).toEqual("$CTX");
15
- expect(entity.expression).toEqual(INTERACTION_PROMPT);
16
- });
17
- });
@@ -1,11 +0,0 @@
1
- import {useDecorators} from "@tsed/core";
2
- import {Context} from "@tsed/platform-params";
3
- import type {PromptDetail as P} from "oidc-provider";
4
-
5
- import {INTERACTION_PROMPT} from "../constants/constants.js";
6
-
7
- export function Prompt(): ParameterDecorator {
8
- return useDecorators(Context(INTERACTION_PROMPT));
9
- }
10
-
11
- export type Prompt = P;
@@ -1,17 +0,0 @@
1
- import {JsonParameterStore} from "@tsed/schema";
2
-
3
- import {INTERACTION_UID} from "../constants/constants.js";
4
- import {Uid} from "./uid.js";
5
-
6
- describe("@Uid", () => {
7
- it("should inject uid", () => {
8
- class MyInteraction {
9
- $prompt(@Uid() uid: string) {}
10
- }
11
-
12
- const entity = JsonParameterStore.get(MyInteraction, "$prompt", 0);
13
-
14
- expect(entity.paramType).toEqual("$CTX");
15
- expect(entity.expression).toEqual(INTERACTION_UID);
16
- });
17
- });
@@ -1,10 +0,0 @@
1
- import {useDecorators} from "@tsed/core";
2
- import {Context} from "@tsed/platform-params";
3
-
4
- import {INTERACTION_UID} from "../constants/constants.js";
5
-
6
- export function Uid(): ParameterDecorator {
7
- return useDecorators(Context(INTERACTION_UID));
8
- }
9
-
10
- export type Uid = string;
@@ -1,11 +0,0 @@
1
- import type {CanBePromise, interactionPolicy, KoaContextWithOIDC, UnknownObject} from "oidc-provider";
2
-
3
- export interface InteractionMethods {
4
- details?: (ctx: KoaContextWithOIDC) => CanBePromise<UnknownObject>;
5
- checks?: () => interactionPolicy.Check[];
6
- $onCreate?: (prompt: interactionPolicy.Prompt) => void | Promise<void>;
7
- /**
8
- * @param args Injectable parameters
9
- */
10
- $prompt?: (...args: any[]) => any | Promise<any>;
11
- }
@@ -1,10 +0,0 @@
1
- import type {Account, default as Provider} from "oidc-provider";
2
-
3
- import {AccessToken, AuthorizationCode, BackchannelAuthenticationRequest, DeviceCode} from "./interfaces.js";
4
-
5
- export interface OidcAccountsMethods {
6
- findAccount(
7
- id: string,
8
- token: AuthorizationCode | AccessToken | DeviceCode | BackchannelAuthenticationRequest | undefined
9
- ): Promise<Account | undefined>;
10
- }
@@ -1,3 +0,0 @@
1
- import {BadRequest} from "@tsed/exceptions";
2
-
3
- export class OidcBadInteractionName extends BadRequest {}
@@ -1,3 +0,0 @@
1
- export interface OidcInteractionMethods {
2
- $prompts?(...args: unknown[]): void | unknown | Promise<unknown>;
3
- }
@@ -1,8 +0,0 @@
1
- import type {CanBePromise, interactionPolicy, KoaContextWithOIDC, UnknownObject} from "oidc-provider";
2
- export interface OidcInteractionOptions {
3
- name: string;
4
- requestable?: boolean | undefined;
5
- priority?: number;
6
- details?: (ctx: KoaContextWithOIDC) => CanBePromise<UnknownObject>;
7
- checks?: interactionPolicy.Check[];
8
- }
@@ -1,11 +0,0 @@
1
- import type {UnknownObject} from "oidc-provider";
2
-
3
- import {OidcClient} from "./interfaces.js";
4
-
5
- export type OidcInteractionPromptProps<Props = Record<string, any>> = {
6
- client: OidcClient;
7
- uid: string;
8
- grantId: string;
9
- details: UnknownObject;
10
- params: Record<string, any>;
11
- } & Props;
@@ -1,72 +0,0 @@
1
- import type {Adapter} from "@tsed/adapters";
2
- import type {Type} from "@tsed/core";
3
- import type {JwksKeyParameters} from "@tsed/jwks";
4
- import type {Configuration} from "oidc-provider";
5
-
6
- import type {OidcAccountsMethods} from "./OidcAccountsMethods.js";
7
-
8
- export interface OidcSettings extends Configuration {
9
- /**
10
- * force the secure cookie. By default, in dev mode it's disabled and in production it's enabled.
11
- */
12
- secureCookies?: boolean;
13
- /**
14
- * Path on which the oidc-provider instance is mounted.
15
- */
16
- path?: string;
17
- /**
18
- * Issuer URI. By default, Ts.ED create issuer with http://localhost:${httpPort}
19
- */
20
- issuer?: string;
21
- /**
22
- * Path to store jwks keys.
23
- */
24
- jwksPath?: string;
25
- /**
26
- * Generate jwks from given certificates
27
- */
28
- certificates?: JwksKeyParameters[];
29
- /**
30
- * Secure keys.
31
- */
32
- secureKey?: string[];
33
- /**
34
- * Enable proxy.
35
- */
36
- proxy?: boolean;
37
- /**
38
- * Allow redirect_uri on HTTP protocol and localhost domain.
39
- */
40
- allowHttpLocalhost?: boolean;
41
- /**
42
- * Injectable service to manage accounts.
43
- */
44
- Accounts?: Type<OidcAccountsMethods>;
45
- /**
46
- * Injectable adapter to manage database connexion.
47
- */
48
- Adapter?: Type<Adapter>;
49
- /**
50
- * Use the connection name for the OIDCRedisAdapter.
51
- */
52
- connectionName?: string;
53
-
54
- plugins?: TsED.OIDCPluginSettings;
55
-
56
- render?: {
57
- /**
58
- * By default ["clientSecret"] is omitted
59
- */
60
- omitClientProps?: string[];
61
- };
62
- }
63
-
64
- declare global {
65
- namespace TsED {
66
- interface OIDCPluginSettings {}
67
-
68
- interface Configuration {
69
- oidc: OidcSettings;
70
- }
71
- }
72
- }
@@ -1,13 +0,0 @@
1
- import type {default as Provider, interactionPolicy} from "oidc-provider";
2
-
3
- export type OIDCContext = InstanceType<Provider["OIDCContext"]>;
4
- export type OidcClient = InstanceType<Provider["Client"]>;
5
- export type DefaultPolicy = interactionPolicy.DefaultPolicy;
6
- export type AuthorizationCode = InstanceType<Provider["AuthorizationCode"]>;
7
- export type AccessToken = InstanceType<Provider["AccessToken"]>;
8
- export type ClientCredentials = InstanceType<Provider["ClientCredentials"]>;
9
- export type DeviceCode = InstanceType<Provider["DeviceCode"]>;
10
- export type RefreshToken = InstanceType<Provider["RefreshToken"]>;
11
- export type BackchannelAuthenticationRequest = InstanceType<Provider["BackchannelAuthenticationRequest"]>;
12
- export type Grant = InstanceType<Provider["Grant"]>;
13
- export type OidcInteraction = InstanceType<Provider["Interaction"]>;
package/src/index.ts DELETED
@@ -1,33 +0,0 @@
1
- /**
2
- * @file Automatically generated by @tsed/barrels.
3
- */
4
- export * from "./constants/constants.js";
5
- export * from "./decorators/grantId.js";
6
- export * from "./decorators/interaction.js";
7
- export * from "./decorators/interactions.js";
8
- export * from "./decorators/noCache.js";
9
- export * from "./decorators/oidcCtx.js";
10
- export * from "./decorators/oidcSession.js";
11
- export * from "./decorators/params.js";
12
- export * from "./decorators/prompt.js";
13
- export * from "./decorators/uid.js";
14
- export * from "./domain/InteractionMethods.js";
15
- export * from "./domain/interfaces.js";
16
- export * from "./domain/OidcAccountsMethods.js";
17
- export * from "./domain/OidcBadInteractionName.js";
18
- export * from "./domain/OidcInteractionMethods.js";
19
- export * from "./domain/OidcInteractionOptions.js";
20
- export * from "./domain/OidcInteractionPromptProps.js";
21
- export * from "./domain/OidcSettings.js";
22
- export * from "./middlewares/OidcInteractionMiddleware.js";
23
- export * from "./middlewares/OidcNoCacheMiddleware.js";
24
- export * from "./middlewares/OidcSecureMiddleware.js";
25
- export * from "./OidcModule.js";
26
- export * from "./services/OidcAdapters.js";
27
- export * from "./services/OidcInteractionContext.js";
28
- export * from "./services/OidcInteractions.js";
29
- export * from "./services/OidcJwks.js";
30
- export * from "./services/OidcPolicy.js";
31
- export * from "./services/OidcProvider.js";
32
- export * from "./utils/debug.js";
33
- export * from "./utils/events.js";
@@ -1,40 +0,0 @@
1
- import {faker} from "@faker-js/faker";
2
- import {PlatformTest} from "@tsed/platform-http/testing";
3
-
4
- import {
5
- INTERACTION_CONTEXT,
6
- INTERACTION_DETAILS,
7
- INTERACTION_PARAMS,
8
- INTERACTION_PROMPT,
9
- INTERACTION_SESSION,
10
- INTERACTION_UID
11
- } from "../constants/constants.js";
12
- import {OidcInteractionContext} from "../services/OidcInteractionContext.js";
13
- import {OidcInteractionMiddleware} from "./OidcInteractionMiddleware.js";
14
-
15
- describe("OidcInteractionMiddleware", () => {
16
- beforeEach(() => PlatformTest.create());
17
- afterEach(() => PlatformTest.reset());
18
- it("should create interaction details and store it to the context", async () => {
19
- const interactionDetails = {
20
- uid: faker.string.uuid(),
21
- prompt: {},
22
- params: {},
23
- session: {}
24
- };
25
- const oidcInteractionContext = {
26
- interactionDetails: vi.fn().mockReturnValue(interactionDetails)
27
- };
28
-
29
- const middleware = await PlatformTest.invoke<OidcInteractionMiddleware>(OidcInteractionMiddleware, [
30
- {
31
- token: OidcInteractionContext,
32
- use: oidcInteractionContext
33
- }
34
- ]);
35
-
36
- await middleware.use();
37
-
38
- expect(oidcInteractionContext.interactionDetails).toHaveBeenCalledWith();
39
- });
40
- });
@@ -1,14 +0,0 @@
1
- import {Inject} from "@tsed/di";
2
- import {Middleware} from "@tsed/platform-middlewares";
3
-
4
- import {OidcInteractionContext} from "../services/OidcInteractionContext.js";
5
-
6
- @Middleware()
7
- export class OidcInteractionMiddleware {
8
- @Inject()
9
- protected oidcInteractionContext: OidcInteractionContext;
10
-
11
- async use() {
12
- await this.oidcInteractionContext.interactionDetails();
13
- }
14
- }
@@ -1,18 +0,0 @@
1
- import {PlatformTest} from "@tsed/platform-http/testing";
2
-
3
- import {OidcNoCacheMiddleware} from "./OidcNoCacheMiddleware.js";
4
-
5
- describe("OidcNoCacheMiddleware", () => {
6
- beforeEach(() => PlatformTest.create());
7
- afterEach(() => PlatformTest.reset());
8
- it("should add headers", () => {
9
- const middleware = PlatformTest.get<OidcNoCacheMiddleware>(OidcNoCacheMiddleware);
10
- const ctx = PlatformTest.createRequestContext();
11
- vi.spyOn(ctx.response, "setHeader").mockReturnThis();
12
-
13
- middleware.use(ctx);
14
-
15
- expect(ctx.response.setHeader).toHaveBeenCalledWith("Pragma", "no-cache");
16
- expect(ctx.response.setHeader).toHaveBeenCalledWith("Cache-Control", "no-cache, no-store");
17
- });
18
- });
@@ -1,10 +0,0 @@
1
- import {Middleware, MiddlewareMethods} from "@tsed/platform-middlewares";
2
- import {Context} from "@tsed/platform-params";
3
-
4
- @Middleware()
5
- export class OidcNoCacheMiddleware implements MiddlewareMethods {
6
- use(@Context() ctx: Context) {
7
- ctx.response.setHeader("Pragma", "no-cache");
8
- ctx.response.setHeader("Cache-Control", "no-cache, no-store");
9
- }
10
- }
@@ -1,106 +0,0 @@
1
- import {PlatformTest} from "@tsed/platform-http/testing";
2
-
3
- import {OidcSecureMiddleware} from "./OidcSecureMiddleware.js";
4
-
5
- describe("OidcSecureMiddleware", () => {
6
- beforeEach(() => PlatformTest.create());
7
- afterEach(() => PlatformTest.reset());
8
-
9
- it("should check if the request is not secure on GET verb", async () => {
10
- const middleware = await PlatformTest.invoke<OidcSecureMiddleware>(OidcSecureMiddleware);
11
- const request = PlatformTest.createRequest({
12
- secure: false,
13
- method: "GET",
14
- url: "/path",
15
- headers: {
16
- host: "host"
17
- }
18
- });
19
-
20
- const ctx = PlatformTest.createRequestContext({
21
- event: {
22
- request
23
- }
24
- });
25
- vi.spyOn(ctx.response, "redirect").mockReturnValue(undefined as any);
26
-
27
- middleware.use(ctx);
28
-
29
- expect(ctx.response.redirect).toHaveBeenCalledWith(302, "https://host/path");
30
- });
31
-
32
- it("should check if the request is not secure on HEAD verb", async () => {
33
- const middleware = await PlatformTest.invoke<OidcSecureMiddleware>(OidcSecureMiddleware);
34
- const ctx = PlatformTest.createRequestContext({
35
- event: {
36
- request: PlatformTest.createRequest({
37
- secure: false,
38
- method: "GET",
39
- url: "/path",
40
- headers: {
41
- host: "host"
42
- }
43
- })
44
- }
45
- });
46
-
47
- vi.spyOn(ctx.response, "redirect").mockReturnValue(undefined as any);
48
-
49
- middleware.use(ctx);
50
-
51
- expect(ctx.response.redirect).toHaveBeenCalledWith(302, "https://host/path");
52
- });
53
-
54
- it("should check if the request is not secure on POST verb", async () => {
55
- const middleware = await PlatformTest.invoke<OidcSecureMiddleware>(OidcSecureMiddleware);
56
- const ctx = PlatformTest.createRequestContext({
57
- event: {
58
- request: PlatformTest.createRequest({
59
- secure: false,
60
- method: "POST",
61
- url: "/path",
62
- headers: {
63
- host: "host"
64
- }
65
- })
66
- }
67
- });
68
-
69
- let actualError: any;
70
- try {
71
- middleware.use(ctx);
72
- } catch (er) {
73
- actualError = er;
74
- }
75
-
76
- expect(actualError.status).toEqual(400);
77
- expect(actualError.message).toEqual("InvalidRequest");
78
- expect(actualError.body).toEqual({
79
- error: "invalid_request",
80
- error_description: "Do yourself a favor and only use https"
81
- });
82
- });
83
-
84
- it("should check if the request is secure on GET verb", async () => {
85
- const middleware = await PlatformTest.invoke<OidcSecureMiddleware>(OidcSecureMiddleware);
86
-
87
- const ctx = PlatformTest.createRequestContext({
88
- event: {
89
- request: PlatformTest.createRequest({
90
- secure: true,
91
- method: "GET",
92
- url: "/path",
93
- headers: {
94
- host: "host"
95
- }
96
- })
97
- }
98
- });
99
-
100
- vi.spyOn(ctx.response, "redirect").mockReturnValue(undefined as any);
101
-
102
- middleware.use(ctx);
103
-
104
- expect(ctx.response.redirect).not.toHaveBeenCalled();
105
- });
106
- });