@breadstone/archipel-platform-authentication 0.0.8 → 0.0.9

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 (71) hide show
  1. package/package.json +35 -27
  2. package/src/AuthModule.d.ts +22 -8
  3. package/src/AuthModule.js +19 -24
  4. package/src/connectors/AnonymousConnector.d.ts +42 -0
  5. package/src/connectors/AnonymousConnector.js +54 -0
  6. package/src/{strategies/AppleStrategy.d.ts → connectors/AppleConnector.d.ts} +16 -5
  7. package/src/{strategies/AppleStrategy.js → connectors/AppleConnector.js} +16 -15
  8. package/src/connectors/ConnectorBase.d.ts +39 -0
  9. package/src/connectors/ConnectorBase.js +33 -0
  10. package/src/connectors/GithubConnector.d.ts +34 -0
  11. package/src/{strategies/GithubStrategy.js → connectors/GithubConnector.js} +13 -12
  12. package/src/{strategies/GoogleStrategy.d.ts → connectors/GoogleConnector.d.ts} +17 -6
  13. package/src/{strategies/GoogleStrategy.js → connectors/GoogleConnector.js} +14 -13
  14. package/src/{strategies/JwtStrategy.d.ts → connectors/JwtConnector.d.ts} +16 -6
  15. package/src/{strategies/JwtStrategy.js → connectors/JwtConnector.js} +11 -10
  16. package/src/{strategies/LocalStrategy.d.ts → connectors/LocalConnector.d.ts} +16 -6
  17. package/src/{strategies/LocalStrategy.js → connectors/LocalConnector.js} +9 -9
  18. package/src/{strategies/MicrosoftStrategy.d.ts → connectors/MicrosoftConnector.d.ts} +16 -6
  19. package/src/{strategies/MicrosoftStrategy.js → connectors/MicrosoftConnector.js} +15 -14
  20. package/src/{apple → connectors/apple}/env.js +1 -1
  21. package/src/connectors/apple/index.d.ts +2 -0
  22. package/src/connectors/apple/index.js +8 -0
  23. package/src/{github → connectors/github}/env.js +1 -1
  24. package/src/connectors/github/index.d.ts +2 -0
  25. package/src/connectors/github/index.js +8 -0
  26. package/src/{google → connectors/google}/env.js +1 -1
  27. package/src/connectors/google/index.d.ts +2 -0
  28. package/src/connectors/google/index.js +8 -0
  29. package/src/{microsoft → connectors/microsoft}/env.js +1 -1
  30. package/src/connectors/microsoft/index.d.ts +2 -0
  31. package/src/connectors/microsoft/index.js +8 -0
  32. package/src/env.d.ts +2 -0
  33. package/src/env.js +9 -3
  34. package/src/{services/mfa → mfa}/IMfaChannel.d.ts +1 -1
  35. package/src/{services/mfa → mfa}/MfaEncryptionService.js +4 -4
  36. package/src/{services → mfa}/MfaService.d.ts +3 -3
  37. package/src/{services → mfa}/MfaService.js +3 -3
  38. package/src/{services/mfa → mfa}/MfaState.js +2 -2
  39. package/src/{services/mfa → mfa}/channels/EmailOtpMfaChannel.d.ts +2 -2
  40. package/src/{services/mfa → mfa}/channels/EmailOtpMfaChannel.js +4 -3
  41. package/src/{services/mfa → mfa}/channels/PushMfaChannel.d.ts +2 -2
  42. package/src/{services/mfa → mfa}/channels/PushMfaChannel.js +4 -3
  43. package/src/{services/mfa → mfa}/channels/SmsMfaChannel.d.ts +2 -2
  44. package/src/{services/mfa → mfa}/channels/SmsMfaChannel.js +4 -3
  45. package/src/{services/mfa → mfa}/channels/TotpMfaChannel.d.ts +3 -3
  46. package/src/{services/mfa → mfa}/channels/TotpMfaChannel.js +5 -4
  47. package/src/mfa/totp/index.d.ts +22 -0
  48. package/src/mfa/totp/index.js +29 -0
  49. package/src/services/ChallengeService.js +4 -3
  50. package/src/services/VerificationService.js +2 -1
  51. package/src/services/index.d.ts +1 -1
  52. package/src/services/index.js +1 -1
  53. package/src/strategies/AnonymousStrategy.js +2 -1
  54. package/src/apple/index.d.ts +0 -2
  55. package/src/apple/index.js +0 -8
  56. package/src/github/index.d.ts +0 -2
  57. package/src/github/index.js +0 -8
  58. package/src/google/index.d.ts +0 -2
  59. package/src/google/index.js +0 -8
  60. package/src/microsoft/index.d.ts +0 -2
  61. package/src/microsoft/index.js +0 -8
  62. package/src/strategies/GithubStrategy.d.ts +0 -23
  63. /package/src/{apple → connectors/apple}/env.d.ts +0 -0
  64. /package/src/{github → connectors/github}/env.d.ts +0 -0
  65. /package/src/{google → connectors/google}/env.d.ts +0 -0
  66. /package/src/{microsoft → connectors/microsoft}/env.d.ts +0 -0
  67. /package/src/{services/mfa → mfa}/IMfaChannel.js +0 -0
  68. /package/src/{services/mfa → mfa}/MfaEncryptionService.d.ts +0 -0
  69. /package/src/{services/mfa → mfa}/MfaState.d.ts +0 -0
  70. /package/src/{services/mfa → mfa}/MfaTokens.d.ts +0 -0
  71. /package/src/{services/mfa → mfa}/MfaTokens.js +0 -0
package/package.json CHANGED
@@ -1,23 +1,26 @@
1
1
  {
2
2
  "name": "@breadstone/archipel-platform-authentication",
3
- "version": "0.0.8",
3
+ "version": "0.0.9",
4
4
  "description": "JWT and OAuth authentication, MFA, session management, and email verification for NestJS applications.",
5
5
  "type": "commonjs",
6
6
  "main": "./src/index.js",
7
7
  "types": "./src/index.d.ts",
8
8
  "typesVersions": {
9
9
  "*": {
10
- "apple": [
11
- "./src/apple/index.d.ts"
10
+ "connectors/apple": [
11
+ "./src/connectors/apple/index.d.ts"
12
12
  ],
13
- "github": [
14
- "./src/github/index.d.ts"
13
+ "connectors/github": [
14
+ "./src/connectors/github/index.d.ts"
15
15
  ],
16
- "google": [
17
- "./src/google/index.d.ts"
16
+ "connectors/google": [
17
+ "./src/connectors/google/index.d.ts"
18
18
  ],
19
- "microsoft": [
20
- "./src/microsoft/index.d.ts"
19
+ "connectors/microsoft": [
20
+ "./src/connectors/microsoft/index.d.ts"
21
+ ],
22
+ "mfa/totp": [
23
+ "./src/mfa/totp/index.d.ts"
21
24
  ]
22
25
  }
23
26
  },
@@ -26,27 +29,32 @@
26
29
  "types": "./src/index.d.ts",
27
30
  "default": "./src/index.js"
28
31
  },
29
- "./apple": {
30
- "types": "./src/apple/index.d.ts",
31
- "default": "./src/apple/index.js"
32
+ "./connectors/apple": {
33
+ "types": "./src/connectors/apple/index.d.ts",
34
+ "default": "./src/connectors/apple/index.js"
35
+ },
36
+ "./connectors/github": {
37
+ "types": "./src/connectors/github/index.d.ts",
38
+ "default": "./src/connectors/github/index.js"
32
39
  },
33
- "./github": {
34
- "types": "./src/github/index.d.ts",
35
- "default": "./src/github/index.js"
40
+ "./connectors/google": {
41
+ "types": "./src/connectors/google/index.d.ts",
42
+ "default": "./src/connectors/google/index.js"
36
43
  },
37
- "./google": {
38
- "types": "./src/google/index.d.ts",
39
- "default": "./src/google/index.js"
44
+ "./connectors/microsoft": {
45
+ "types": "./src/connectors/microsoft/index.d.ts",
46
+ "default": "./src/connectors/microsoft/index.js"
40
47
  },
41
- "./microsoft": {
42
- "types": "./src/microsoft/index.d.ts",
43
- "default": "./src/microsoft/index.js"
48
+ "./mfa/totp": {
49
+ "types": "./src/mfa/totp/index.d.ts",
50
+ "default": "./src/mfa/totp/index.js"
44
51
  },
45
52
  "./package.json": "./package.json",
46
- "./apple/index": "./src/apple/index.js",
47
- "./github/index": "./src/github/index.js",
48
- "./google/index": "./src/google/index.js",
49
- "./microsoft/index": "./src/microsoft/index.js"
53
+ "./connectors/apple/index": "./src/connectors/apple/index.js",
54
+ "./connectors/github/index": "./src/connectors/github/index.js",
55
+ "./connectors/google/index": "./src/connectors/google/index.js",
56
+ "./connectors/microsoft/index": "./src/connectors/microsoft/index.js",
57
+ "./mfa/totp/index": "./src/mfa/totp/index.js"
50
58
  },
51
59
  "license": "MIT",
52
60
  "repository": {
@@ -73,8 +81,8 @@
73
81
  "README.md"
74
82
  ],
75
83
  "dependencies": {
76
- "@breadstone/archipel-platform-core": "0.0.8",
77
- "@breadstone/archipel-platform-cryptography": "0.0.8",
84
+ "@breadstone/archipel-platform-core": "0.0.9",
85
+ "@breadstone/archipel-platform-cryptography": "0.0.9",
78
86
  "passport": "0.7.0",
79
87
  "passport-custom": "1.1.1",
80
88
  "passport-jwt": "4.0.1",
@@ -1,5 +1,5 @@
1
1
  import { type IConfigRegistryEntry } from '@breadstone/archipel-platform-core';
2
- import { DynamicModule, MiddlewareConsumer, Type } from '@nestjs/common';
2
+ import { DynamicModule, MiddlewareConsumer, Type, type Provider } from '@nestjs/common';
3
3
  import { AuthSubjectPort } from './contracts/AuthSubjectPort';
4
4
  import { MfaSubjectPort } from './contracts/MfaSubjectPort';
5
5
  import { SessionPersistencePort } from './contracts/SessionPersistencePort';
@@ -13,7 +13,7 @@ import { VerificationSubjectPort } from './contracts/VerificationSubjectPort';
13
13
  */
14
14
  export interface IAuthModuleOptions {
15
15
  /**
16
- * Implementation of the auth subject port (user lookup for JWT/Local/Anonymous strategies).
16
+ * Implementation of the auth subject port (user lookup for JWT/Local/Anonymous connectors).
17
17
  */
18
18
  authSubject: Type<AuthSubjectPort>;
19
19
  /**
@@ -29,21 +29,21 @@ export interface IAuthModuleOptions {
29
29
  */
30
30
  verificationSubject: Type<VerificationSubjectPort>;
31
31
  /**
32
- * Optional implementation of the social auth port (OAuth strategies).
33
- * When provided together with `socialStrategies`, the social auth flow is enabled.
32
+ * Optional implementation of the social auth port (OAuth connectors).
33
+ * When provided together with `socialConnectors`, the social auth flow is enabled.
34
34
  */
35
35
  socialAuth?: Type<SocialAuthPort>;
36
36
  /**
37
- * Optional array of social strategy types to register (e.g. `AppleStrategy`, `GithubStrategy`).
37
+ * Optional array of social connector types to register (e.g. `AppleConnector`, `GithubConnector`).
38
38
  * Import them from the provider-specific sub-paths
39
- * (e.g. `@breadstone/archipel-platform-authentication/apple`).
39
+ * (e.g. `@breadstone/archipel-platform-authentication/connectors/apple`).
40
40
  * Requires `socialAuth` to be set.
41
41
  */
42
- socialStrategies?: Array<Type>;
42
+ socialConnectors?: Array<Type>;
43
43
  /**
44
44
  * Optional additional configuration entries to register (e.g. provider-specific OAuth keys).
45
45
  * Import them from the provider-specific sub-paths
46
- * (e.g. `APPLE_AUTH_CONFIG_ENTRIES` from `@breadstone/archipel-platform-authentication/apple`).
46
+ * (e.g. `APPLE_AUTH_CONFIG_ENTRIES` from `@breadstone/archipel-platform-authentication/connectors/apple`).
47
47
  */
48
48
  additionalConfigEntries?: ReadonlyArray<Omit<IConfigRegistryEntry, 'module'>>;
49
49
  /**
@@ -51,6 +51,20 @@ export interface IAuthModuleOptions {
51
51
  * When provided, additional claims are added to JWT tokens.
52
52
  */
53
53
  tokenEnricher?: Type<TokenEnricherPort>;
54
+ /**
55
+ * Optional array of additional MFA channel types to register (e.g. `TotpMfaChannel`).
56
+ * Import them from the provider-specific sub-paths
57
+ * (e.g. `@breadstone/archipel-platform-authentication/mfa/totp`).
58
+ *
59
+ * Built-in channels (SMS, Email, Push) are always registered.
60
+ */
61
+ mfaChannels?: Array<Type>;
62
+ /**
63
+ * Optional additional providers required by optional features (e.g. TOTP MFA).
64
+ * Import them from the provider-specific sub-paths
65
+ * (e.g. `TOTP_MFA_PROVIDERS` from `@breadstone/archipel-platform-authentication/mfa/totp`).
66
+ */
67
+ additionalProviders?: Array<Provider>;
54
68
  }
55
69
  /**
56
70
  * The `AuthModule` handles JWT-based authentication,
package/src/AuthModule.js CHANGED
@@ -9,6 +9,9 @@ const archipel_platform_cryptography_1 = require("@breadstone/archipel-platform-
9
9
  const common_1 = require("@nestjs/common");
10
10
  const jwt_1 = require("@nestjs/jwt");
11
11
  const passport_1 = require("@nestjs/passport");
12
+ const AnonymousConnector_1 = require("./connectors/AnonymousConnector");
13
+ const JwtConnector_1 = require("./connectors/JwtConnector");
14
+ const LocalConnector_1 = require("./connectors/LocalConnector");
12
15
  const AuthSubjectPort_1 = require("./contracts/AuthSubjectPort");
13
16
  const MfaSubjectPort_1 = require("./contracts/MfaSubjectPort");
14
17
  const SessionPersistencePort_1 = require("./contracts/SessionPersistencePort");
@@ -22,22 +25,18 @@ const JwtAuthGuard_1 = require("./guards/JwtAuthGuard");
22
25
  const LocalAuthGuard_1 = require("./guards/LocalAuthGuard");
23
26
  const RolesGuard_1 = require("./guards/RolesGuard");
24
27
  const SessionMappingProfile_1 = require("./mappers/SessionMappingProfile");
28
+ const EmailOtpMfaChannel_1 = require("./mfa/channels/EmailOtpMfaChannel");
29
+ const PushMfaChannel_1 = require("./mfa/channels/PushMfaChannel");
30
+ const SmsMfaChannel_1 = require("./mfa/channels/SmsMfaChannel");
31
+ const MfaEncryptionService_1 = require("./mfa/MfaEncryptionService");
32
+ const MfaService_1 = require("./mfa/MfaService");
33
+ const MfaTokens_1 = require("./mfa/MfaTokens");
25
34
  const middlewares_1 = require("./middlewares");
26
35
  const SessionSerializer_1 = require("./serializer/SessionSerializer");
27
36
  const AuthTokenService_1 = require("./services/AuthTokenService");
28
37
  const ChallengeService_1 = require("./services/ChallengeService");
29
- const EmailOtpMfaChannel_1 = require("./services/mfa/channels/EmailOtpMfaChannel");
30
- const PushMfaChannel_1 = require("./services/mfa/channels/PushMfaChannel");
31
- const SmsMfaChannel_1 = require("./services/mfa/channels/SmsMfaChannel");
32
- const TotpMfaChannel_1 = require("./services/mfa/channels/TotpMfaChannel");
33
- const MfaEncryptionService_1 = require("./services/mfa/MfaEncryptionService");
34
- const MfaTokens_1 = require("./services/mfa/MfaTokens");
35
- const MfaService_1 = require("./services/MfaService");
36
38
  const SessionService_1 = require("./services/SessionService");
37
39
  const VerificationService_1 = require("./services/VerificationService");
38
- const AnonymousStrategy_1 = require("./strategies/AnonymousStrategy");
39
- const JwtStrategy_1 = require("./strategies/JwtStrategy");
40
- const LocalStrategy_1 = require("./strategies/LocalStrategy");
41
40
  /**
42
41
  * The `AuthModule` handles JWT-based authentication,
43
42
  * including token creation and validation.
@@ -66,10 +65,12 @@ let AuthModule = AuthModule_1 = class AuthModule {
66
65
  if (options.tokenEnricher) {
67
66
  portProviders.push({ provide: TokenEnricherPort_1.TokenEnricherPort, useClass: options.tokenEnricher });
68
67
  }
69
- const strategies = [JwtStrategy_1.JwtStrategy, LocalStrategy_1.LocalStrategy, AnonymousStrategy_1.AnonymousStrategy];
70
- if (options.socialStrategies) {
71
- strategies.push(...options.socialStrategies);
68
+ const connectors = [JwtConnector_1.JwtConnector, LocalConnector_1.LocalConnector, AnonymousConnector_1.AnonymousConnector];
69
+ if (options.socialConnectors) {
70
+ connectors.push(...options.socialConnectors);
72
71
  }
72
+ const builtInMfaChannels = [SmsMfaChannel_1.SmsMfaChannel, EmailOtpMfaChannel_1.EmailOtpMfaChannel, PushMfaChannel_1.PushMfaChannel];
73
+ const allMfaChannels = [...builtInMfaChannels, ...(options.mfaChannels ?? [])];
73
74
  const configEntries = [
74
75
  ...env_1.PLATFORM_AUTHENTICATION_CONFIG_ENTRIES,
75
76
  ...(options.additionalConfigEntries ?? []),
@@ -95,7 +96,9 @@ let AuthModule = AuthModule_1 = class AuthModule {
95
96
  ],
96
97
  providers: [
97
98
  ...portProviders,
98
- ...strategies,
99
+ ...connectors,
100
+ ...(options.additionalProviders ?? []),
101
+ ...allMfaChannels,
99
102
  SessionSerializer_1.SessionSerializer,
100
103
  JwtAuthGuard_1.JwtAuthGuard,
101
104
  LocalAuthGuard_1.LocalAuthGuard,
@@ -107,19 +110,11 @@ let AuthModule = AuthModule_1 = class AuthModule {
107
110
  SessionService_1.SessionService,
108
111
  MfaService_1.MfaService,
109
112
  ChallengeService_1.ChallengeService,
110
- TotpMfaChannel_1.TotpMfaChannel,
111
- SmsMfaChannel_1.SmsMfaChannel,
112
- EmailOtpMfaChannel_1.EmailOtpMfaChannel,
113
- PushMfaChannel_1.PushMfaChannel,
114
113
  MfaEncryptionService_1.MfaEncryptionService,
115
- {
116
- provide: archipel_platform_cryptography_1.OTP_SERVICE_TOKEN,
117
- useClass: archipel_platform_cryptography_1.OtpService,
118
- },
119
114
  {
120
115
  provide: MfaTokens_1.MFA_CHANNELS,
121
- useFactory: (totpChannel, smsChannel, emailChannel, pushChannel) => [totpChannel, smsChannel, emailChannel, pushChannel],
122
- inject: [TotpMfaChannel_1.TotpMfaChannel, SmsMfaChannel_1.SmsMfaChannel, EmailOtpMfaChannel_1.EmailOtpMfaChannel, PushMfaChannel_1.PushMfaChannel],
116
+ useFactory: (...channels) => channels,
117
+ inject: allMfaChannels,
123
118
  },
124
119
  archipel_platform_core_1.DeviceParserService,
125
120
  middlewares_1.LastActiveMiddleware,
@@ -0,0 +1,42 @@
1
+ import { ConfigService } from '@breadstone/archipel-platform-core';
2
+ import { AuthSubjectPort } from '../contracts/AuthSubjectPort';
3
+ import type { IAuthSubject } from '../contracts/IAuthSubject';
4
+ declare const AnonymousConnector_base: (abstract new (...args: any[]) => {
5
+ [x: string]: any;
6
+ validate(...args: unknown[]): Promise<unknown>;
7
+ }) & {
8
+ apply(this: Function, thisArg: any, argArray?: any): any;
9
+ call(this: Function, thisArg: any, ...argArray: any[]): any;
10
+ bind(this: Function, thisArg: any, ...argArray: any[]): any;
11
+ toString(): string;
12
+ readonly length: number;
13
+ arguments: any;
14
+ caller: Function;
15
+ readonly name: string;
16
+ [Symbol.hasInstance](value: any): boolean;
17
+ };
18
+ /**
19
+ * Anonymous connector for temporary user login.
20
+ *
21
+ * @public
22
+ */
23
+ export declare class AnonymousConnector extends AnonymousConnector_base {
24
+ private readonly _authSubject;
25
+ private readonly _configService;
26
+ /**
27
+ * Constructs a new instance of the `AnonymousConnector` class.
28
+ *
29
+ * @public
30
+ * @param authSubject Auth subject port instance.
31
+ * @param configService Configuration service instance.
32
+ */
33
+ constructor(authSubject: AuthSubjectPort, configService: ConfigService);
34
+ /**
35
+ * Validates the authentication credentials.
36
+ *
37
+ * @public
38
+ * @returns The authenticated user and this is also later available in the request.user object
39
+ */
40
+ validate(): Promise<IAuthSubject>;
41
+ }
42
+ export {};
@@ -0,0 +1,54 @@
1
+ "use strict";
2
+ // #region Imports
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ exports.AnonymousConnector = void 0;
5
+ const tslib_1 = require("tslib");
6
+ const archipel_platform_core_1 = require("@breadstone/archipel-platform-core");
7
+ const common_1 = require("@nestjs/common");
8
+ const passport_custom_1 = require("passport-custom");
9
+ const AuthSubjectPort_1 = require("../contracts/AuthSubjectPort");
10
+ const env_1 = require("../env");
11
+ const ConnectorBase_1 = require("./ConnectorBase");
12
+ // #endregion
13
+ /**
14
+ * Anonymous connector for temporary user login.
15
+ *
16
+ * @public
17
+ */
18
+ let AnonymousConnector = class AnonymousConnector extends (0, ConnectorBase_1.ConnectorBase)(passport_custom_1.Strategy, 'anonymous') {
19
+ // #endregion
20
+ // #region Ctor
21
+ /**
22
+ * Constructs a new instance of the `AnonymousConnector` class.
23
+ *
24
+ * @public
25
+ * @param authSubject Auth subject port instance.
26
+ * @param configService Configuration service instance.
27
+ */
28
+ constructor(authSubject, configService) {
29
+ super();
30
+ this._authSubject = authSubject;
31
+ this._configService = configService;
32
+ }
33
+ // #endregion
34
+ // #region Methods
35
+ /**
36
+ * Validates the authentication credentials.
37
+ *
38
+ * @public
39
+ * @returns The authenticated user and this is also later available in the request.user object
40
+ */
41
+ async validate() {
42
+ const user = await this._authSubject.findAnonymous(this._configService.get(env_1.SEED_ANONYMOUS_USERNAME.key));
43
+ if (!user) {
44
+ throw new common_1.NotFoundException('User not found');
45
+ }
46
+ return user;
47
+ }
48
+ };
49
+ exports.AnonymousConnector = AnonymousConnector;
50
+ exports.AnonymousConnector = AnonymousConnector = tslib_1.__decorate([
51
+ (0, common_1.Injectable)(),
52
+ tslib_1.__metadata("design:paramtypes", [AuthSubjectPort_1.AuthSubjectPort, archipel_platform_core_1.ConfigService])
53
+ ], AnonymousConnector);
54
+ //# sourceMappingURL=AnonymousConnector.js.map
@@ -5,18 +5,29 @@ import { SocialAuthPort } from '../contracts/SocialAuthPort';
5
5
  type IAppleProfile = PassportProfile & {
6
6
  email?: string;
7
7
  };
8
- declare const AppleStrategy_base: new (...args: [options: import("passport-apple").AuthenticateOptionsWithRequest] | [options: import("passport-apple").AuthenticateOptions]) => import("passport-apple") & {
9
- validate(...args: any[]): unknown;
8
+ declare const AppleConnector_base: (abstract new (...args: any[]) => {
9
+ [x: string]: any;
10
+ validate(...args: unknown[]): Promise<unknown>;
11
+ }) & {
12
+ apply(this: Function, thisArg: any, argArray?: any): any;
13
+ call(this: Function, thisArg: any, ...argArray: any[]): any;
14
+ bind(this: Function, thisArg: any, ...argArray: any[]): any;
15
+ toString(): string;
16
+ readonly length: number;
17
+ arguments: any;
18
+ caller: Function;
19
+ readonly name: string;
20
+ [Symbol.hasInstance](value: any): boolean;
10
21
  };
11
22
  /**
12
- * The `AppleStrategy` integrates Apple Sign In authentication.
23
+ * The `AppleConnector` integrates Apple Sign In authentication.
13
24
  *
14
25
  * @public
15
26
  */
16
- export declare class AppleStrategy extends AppleStrategy_base {
27
+ export declare class AppleConnector extends AppleConnector_base {
17
28
  private readonly _socialAuth;
18
29
  /**
19
- * Initializes a new instance of the `AppleStrategy` class.
30
+ * Initializes a new instance of the `AppleConnector` class.
20
31
  *
21
32
  * @public
22
33
  * @param socialAuth Social auth port instance.
@@ -1,41 +1,42 @@
1
1
  "use strict";
2
2
  // #region Imports
3
3
  Object.defineProperty(exports, "__esModule", { value: true });
4
- exports.AppleStrategy = void 0;
4
+ exports.AppleConnector = void 0;
5
5
  const tslib_1 = require("tslib");
6
6
  const archipel_platform_core_1 = require("@breadstone/archipel-platform-core");
7
7
  const common_1 = require("@nestjs/common");
8
- const passport_1 = require("@nestjs/passport");
9
8
  const passport_apple_1 = require("passport-apple");
10
9
  const SocialAuthPort_1 = require("../contracts/SocialAuthPort");
10
+ const env_1 = require("../env");
11
+ const ConnectorBase_1 = require("./ConnectorBase");
11
12
  /**
12
- * The `AppleStrategy` integrates Apple Sign In authentication.
13
+ * The `AppleConnector` integrates Apple Sign In authentication.
13
14
  *
14
15
  * @public
15
16
  */
16
- let AppleStrategy = class AppleStrategy extends (0, passport_1.PassportStrategy)(passport_apple_1.Strategy, 'apple') {
17
+ let AppleConnector = class AppleConnector extends (0, ConnectorBase_1.ConnectorBase)(passport_apple_1.Strategy, 'apple') {
17
18
  // #endregion
18
19
  // #region Ctor
19
20
  /**
20
- * Initializes a new instance of the `AppleStrategy` class.
21
+ * Initializes a new instance of the `AppleConnector` class.
21
22
  *
22
23
  * @public
23
24
  * @param socialAuth Social auth port instance.
24
25
  * @param configService Configuration service instance.
25
26
  */
26
27
  constructor(socialAuth, configService) {
27
- const rawPrivateKey = configService.get('AUTH_APPLE_PRIVATE_KEY');
28
+ const rawPrivateKey = configService.get(env_1.AUTH_APPLE_PRIVATE_KEY.key);
28
29
  const normalizedPrivateKey = rawPrivateKey.replace(/\r/g, '').replace(/\\n/g, '\n');
29
30
  const scope = configService
30
- .tryGet('AUTH_APPLE_SCOPE', 'name,email')
31
+ .tryGet(env_1.AUTH_APPLE_SCOPE.key, 'name,email')
31
32
  .split(',')
32
33
  .map((s) => s.trim())
33
34
  .filter(Boolean);
34
35
  super({
35
- clientID: configService.get('AUTH_APPLE_CLIENT_ID'),
36
- teamID: configService.get('AUTH_APPLE_TEAM_ID'),
37
- keyID: configService.get('AUTH_APPLE_KEY_ID'),
38
- callbackURL: configService.tryGet('AUTH_APPLE_CALLBACK_URL', '/auth/apple/callback'),
36
+ clientID: configService.get(env_1.AUTH_APPLE_CLIENT_ID.key),
37
+ teamID: configService.get(env_1.AUTH_APPLE_TEAM_ID.key),
38
+ keyID: configService.get(env_1.AUTH_APPLE_KEY_ID.key),
39
+ callbackURL: configService.tryGet(env_1.AUTH_APPLE_CALLBACK_URL.key, '/auth/apple/callback'),
39
40
  privateKeyString: normalizedPrivateKey,
40
41
  scope,
41
42
  state: true,
@@ -76,9 +77,9 @@ let AppleStrategy = class AppleStrategy extends (0, passport_1.PassportStrategy)
76
77
  return user;
77
78
  }
78
79
  };
79
- exports.AppleStrategy = AppleStrategy;
80
- exports.AppleStrategy = AppleStrategy = tslib_1.__decorate([
80
+ exports.AppleConnector = AppleConnector;
81
+ exports.AppleConnector = AppleConnector = tslib_1.__decorate([
81
82
  (0, common_1.Injectable)(),
82
83
  tslib_1.__metadata("design:paramtypes", [SocialAuthPort_1.SocialAuthPort, archipel_platform_core_1.ConfigService])
83
- ], AppleStrategy);
84
- //# sourceMappingURL=AppleStrategy.js.map
84
+ ], AppleConnector);
85
+ //# sourceMappingURL=AppleConnector.js.map
@@ -0,0 +1,39 @@
1
+ import type { Type } from '@nestjs/common';
2
+ /**
3
+ * Creates an abstract connector base class for authentication providers.
4
+ *
5
+ * Extend this to implement a custom authentication connector with a required `validate` method.
6
+ *
7
+ * @public
8
+ * @param strategy - The underlying authentication strategy constructor.
9
+ * @param name - Optional connector identifier (e.g. `'google'`, `'jwt'`).
10
+ * @returns An abstract class with a required `validate` method.
11
+ *
12
+ * @example
13
+ * ```typescript
14
+ * import { ConnectorBase } from '@breadstone/archipel-platform-authentication';
15
+ *
16
+ * export class MyConnector extends ConnectorBase(Strategy, 'my-provider') {
17
+ * public async validate(): Promise<IAuthSubject> { ... }
18
+ * }
19
+ * ```
20
+ */
21
+ export declare function ConnectorBase<T extends Type<any>>(strategy: T, name?: string): (abstract new (...args: any[]) => {
22
+ [x: string]: any;
23
+ /**
24
+ * Validates the authentication attempt and returns the authenticated subject.
25
+ *
26
+ * @public
27
+ */
28
+ validate(...args: unknown[]): Promise<unknown>;
29
+ }) & {
30
+ apply(this: Function, thisArg: any, argArray?: any): any;
31
+ call(this: Function, thisArg: any, ...argArray: any[]): any;
32
+ bind(this: Function, thisArg: any, ...argArray: any[]): any;
33
+ toString(): string;
34
+ readonly length: number;
35
+ arguments: any;
36
+ caller: Function;
37
+ readonly name: string;
38
+ [Symbol.hasInstance](value: any): boolean;
39
+ };
@@ -0,0 +1,33 @@
1
+ "use strict";
2
+ // #region Imports
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ exports.ConnectorBase = ConnectorBase;
5
+ const passport_1 = require("@nestjs/passport");
6
+ // #endregion
7
+ /**
8
+ * Creates an abstract connector base class for authentication providers.
9
+ *
10
+ * Extend this to implement a custom authentication connector with a required `validate` method.
11
+ *
12
+ * @public
13
+ * @param strategy - The underlying authentication strategy constructor.
14
+ * @param name - Optional connector identifier (e.g. `'google'`, `'jwt'`).
15
+ * @returns An abstract class with a required `validate` method.
16
+ *
17
+ * @example
18
+ * ```typescript
19
+ * import { ConnectorBase } from '@breadstone/archipel-platform-authentication';
20
+ *
21
+ * export class MyConnector extends ConnectorBase(Strategy, 'my-provider') {
22
+ * public async validate(): Promise<IAuthSubject> { ... }
23
+ * }
24
+ * ```
25
+ */
26
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
27
+ function ConnectorBase(strategy, name) {
28
+ const Base = (0, passport_1.PassportStrategy)(strategy, name);
29
+ class _ConnectorBase extends Base {
30
+ }
31
+ return _ConnectorBase;
32
+ }
33
+ //# sourceMappingURL=ConnectorBase.js.map
@@ -0,0 +1,34 @@
1
+ import { ConfigService } from '@breadstone/archipel-platform-core';
2
+ import { type Profile } from 'passport-github2';
3
+ import type { IAuthSubject } from '../contracts/IAuthSubject';
4
+ import { SocialAuthPort } from '../contracts/SocialAuthPort';
5
+ declare const GithubConnector_base: (abstract new (...args: any[]) => {
6
+ [x: string]: any;
7
+ validate(...args: unknown[]): Promise<unknown>;
8
+ }) & {
9
+ apply(this: Function, thisArg: any, argArray?: any): any;
10
+ call(this: Function, thisArg: any, ...argArray: any[]): any;
11
+ bind(this: Function, thisArg: any, ...argArray: any[]): any;
12
+ toString(): string;
13
+ readonly length: number;
14
+ arguments: any;
15
+ caller: Function;
16
+ readonly name: string;
17
+ [Symbol.hasInstance](value: any): boolean;
18
+ };
19
+ export declare class GithubConnector extends GithubConnector_base {
20
+ private readonly _socialAuth;
21
+ /**
22
+ * Constructs a new instance of the `GithubConnector` class.
23
+ *
24
+ * @public
25
+ * @param socialAuth Social auth port instance.
26
+ * @param configService Configuration service instance.
27
+ */
28
+ constructor(socialAuth: SocialAuthPort, configService: ConfigService);
29
+ /**
30
+ * @public
31
+ */
32
+ validate(_accessToken: string, _refreshToken: string, profile: Profile): Promise<IAuthSubject>;
33
+ }
34
+ export {};
@@ -1,19 +1,20 @@
1
1
  "use strict";
2
2
  // #region Imports
3
3
  Object.defineProperty(exports, "__esModule", { value: true });
4
- exports.GithubStrategy = void 0;
4
+ exports.GithubConnector = void 0;
5
5
  const tslib_1 = require("tslib");
6
6
  const archipel_platform_core_1 = require("@breadstone/archipel-platform-core");
7
7
  const common_1 = require("@nestjs/common");
8
- const passport_1 = require("@nestjs/passport");
9
8
  const passport_github2_1 = require("passport-github2");
10
9
  const SocialAuthPort_1 = require("../contracts/SocialAuthPort");
10
+ const env_1 = require("../env");
11
+ const ConnectorBase_1 = require("./ConnectorBase");
11
12
  // #endregion
12
- let GithubStrategy = class GithubStrategy extends (0, passport_1.PassportStrategy)(passport_github2_1.Strategy, 'github') {
13
+ let GithubConnector = class GithubConnector extends (0, ConnectorBase_1.ConnectorBase)(passport_github2_1.Strategy, 'github') {
13
14
  // #endregion
14
15
  // #region Ctor
15
16
  /**
16
- * Constructs a new instance of the `GithubStrategy` class.
17
+ * Constructs a new instance of the `GithubConnector` class.
17
18
  *
18
19
  * @public
19
20
  * @param socialAuth Social auth port instance.
@@ -21,14 +22,14 @@ let GithubStrategy = class GithubStrategy extends (0, passport_1.PassportStrateg
21
22
  */
22
23
  constructor(socialAuth, configService) {
23
24
  const scope = configService
24
- .tryGet('AUTH_GITHUB_SCOPE', 'user:email')
25
+ .tryGet(env_1.AUTH_GITHUB_SCOPE.key, 'user:email')
25
26
  .split(',')
26
27
  .map((s) => s.trim())
27
28
  .filter(Boolean);
28
29
  super({
29
- clientID: configService.get('AUTH_GITHUB_CLIENT_ID'),
30
- clientSecret: configService.get('AUTH_GITHUB_CLIENT_SECRET'),
31
- callbackURL: configService.tryGet('AUTH_GITHUB_CALLBACK_URL', '/auth/github/callback'),
30
+ clientID: configService.get(env_1.AUTH_GITHUB_CLIENT_ID.key),
31
+ clientSecret: configService.get(env_1.AUTH_GITHUB_CLIENT_SECRET.key),
32
+ callbackURL: configService.tryGet(env_1.AUTH_GITHUB_CALLBACK_URL.key, '/auth/github/callback'),
32
33
  scope,
33
34
  });
34
35
  this._socialAuth = socialAuth;
@@ -56,9 +57,9 @@ let GithubStrategy = class GithubStrategy extends (0, passport_1.PassportStrateg
56
57
  return user;
57
58
  }
58
59
  };
59
- exports.GithubStrategy = GithubStrategy;
60
- exports.GithubStrategy = GithubStrategy = tslib_1.__decorate([
60
+ exports.GithubConnector = GithubConnector;
61
+ exports.GithubConnector = GithubConnector = tslib_1.__decorate([
61
62
  (0, common_1.Injectable)(),
62
63
  tslib_1.__metadata("design:paramtypes", [SocialAuthPort_1.SocialAuthPort, archipel_platform_core_1.ConfigService])
63
- ], GithubStrategy);
64
- //# sourceMappingURL=GithubStrategy.js.map
64
+ ], GithubConnector);
65
+ //# sourceMappingURL=GithubConnector.js.map
@@ -1,19 +1,30 @@
1
1
  import { ConfigService } from '@breadstone/archipel-platform-core';
2
- import { Profile, Strategy } from 'passport-google-oauth20';
2
+ import { Profile } from 'passport-google-oauth20';
3
3
  import type { IAuthSubject } from '../contracts/IAuthSubject';
4
4
  import { SocialAuthPort } from '../contracts/SocialAuthPort';
5
- declare const GoogleStrategy_base: new (...args: [options: import("passport-google-oauth20").StrategyOptionsWithRequest] | [options: import("passport-google-oauth20").StrategyOptions] | [options: import("passport-google-oauth20").StrategyOptions] | [options: import("passport-google-oauth20").StrategyOptionsWithRequest]) => Strategy & {
6
- validate(...args: any[]): unknown;
5
+ declare const GoogleConnector_base: (abstract new (...args: any[]) => {
6
+ [x: string]: any;
7
+ validate(...args: unknown[]): Promise<unknown>;
8
+ }) & {
9
+ apply(this: Function, thisArg: any, argArray?: any): any;
10
+ call(this: Function, thisArg: any, ...argArray: any[]): any;
11
+ bind(this: Function, thisArg: any, ...argArray: any[]): any;
12
+ toString(): string;
13
+ readonly length: number;
14
+ arguments: any;
15
+ caller: Function;
16
+ readonly name: string;
17
+ [Symbol.hasInstance](value: any): boolean;
7
18
  };
8
19
  /**
9
- * The `GoogleStrategy` integrates Google OAuth authentication.
20
+ * The `GoogleConnector` integrates Google OAuth authentication.
10
21
  *
11
22
  * @public
12
23
  */
13
- export declare class GoogleStrategy extends GoogleStrategy_base {
24
+ export declare class GoogleConnector extends GoogleConnector_base {
14
25
  private readonly _socialAuth;
15
26
  /**
16
- * Initializes a new instance of the `GoogleStrategy` class.
27
+ * Initializes a new instance of the `GoogleConnector` class.
17
28
  *
18
29
  * @public
19
30
  * @param socialAuth Social auth port instance.