@breadstone/archipel-platform-authentication 0.0.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.
- package/README.md +47 -0
- package/package.json +67 -0
- package/src/AuthModule.d.ts +57 -0
- package/src/AuthModule.js +158 -0
- package/src/contracts/AuthSubjectPort.d.ts +33 -0
- package/src/contracts/AuthSubjectPort.js +15 -0
- package/src/contracts/IAuthSubject.d.ts +40 -0
- package/src/contracts/IAuthSubject.js +3 -0
- package/src/contracts/IMfaSubject.d.ts +48 -0
- package/src/contracts/IMfaSubject.js +3 -0
- package/src/contracts/IMfaSubjectUpdate.d.ts +16 -0
- package/src/contracts/IMfaSubjectUpdate.js +3 -0
- package/src/contracts/ISessionRecord.d.ts +22 -0
- package/src/contracts/ISessionRecord.js +3 -0
- package/src/contracts/ISocialProfile.d.ts +23 -0
- package/src/contracts/ISocialProfile.js +3 -0
- package/src/contracts/IStoreSessionArgs.d.ts +14 -0
- package/src/contracts/IStoreSessionArgs.js +4 -0
- package/src/contracts/IVerifiableSubject.d.ts +28 -0
- package/src/contracts/IVerifiableSubject.js +3 -0
- package/src/contracts/MfaSubjectPort.d.ts +26 -0
- package/src/contracts/MfaSubjectPort.js +15 -0
- package/src/contracts/SessionPersistencePort.d.ts +58 -0
- package/src/contracts/SessionPersistencePort.js +15 -0
- package/src/contracts/SocialAuthPort.d.ts +19 -0
- package/src/contracts/SocialAuthPort.js +15 -0
- package/src/contracts/TokenEnricherPort.d.ts +17 -0
- package/src/contracts/TokenEnricherPort.js +15 -0
- package/src/contracts/VerificationSubjectPort.d.ts +40 -0
- package/src/contracts/VerificationSubjectPort.js +15 -0
- package/src/contracts/index.d.ts +13 -0
- package/src/contracts/index.js +16 -0
- package/src/decorators/RolesDecorator.d.ts +12 -0
- package/src/decorators/RolesDecorator.js +23 -0
- package/src/decorators/TokenDecorator.d.ts +6 -0
- package/src/decorators/TokenDecorator.js +20 -0
- package/src/decorators/UserDecorator.d.ts +6 -0
- package/src/decorators/UserDecorator.js +16 -0
- package/src/decorators/index.d.ts +3 -0
- package/src/decorators/index.js +7 -0
- package/src/env.d.ts +57 -0
- package/src/env.js +179 -0
- package/src/guards/AnonymousAuthGuard.d.ts +9 -0
- package/src/guards/AnonymousAuthGuard.js +20 -0
- package/src/guards/GithubAuthGuard.d.ts +9 -0
- package/src/guards/GithubAuthGuard.js +20 -0
- package/src/guards/JwtAuthGuard.d.ts +9 -0
- package/src/guards/JwtAuthGuard.js +20 -0
- package/src/guards/LocalAuthGuard.d.ts +9 -0
- package/src/guards/LocalAuthGuard.js +20 -0
- package/src/guards/RolesGuard.d.ts +16 -0
- package/src/guards/RolesGuard.js +43 -0
- package/src/guards/SocialAuthGuard.d.ts +9 -0
- package/src/guards/SocialAuthGuard.js +35 -0
- package/src/guards/_RefreshTokenAuthGuard.d.ts +0 -0
- package/src/guards/_RefreshTokenAuthGuard.js +2 -0
- package/src/guards/_TwoFactorAuthGuard.d.ts +0 -0
- package/src/guards/_TwoFactorAuthGuard.js +2 -0
- package/src/guards/index.d.ts +6 -0
- package/src/guards/index.js +12 -0
- package/src/index.d.ts +9 -0
- package/src/index.js +13 -0
- package/src/mappers/SessionMappingProfile.d.ts +42 -0
- package/src/mappers/SessionMappingProfile.js +68 -0
- package/src/middlewares/LastActiveMiddleware.d.ts +29 -0
- package/src/middlewares/LastActiveMiddleware.js +55 -0
- package/src/middlewares/index.d.ts +1 -0
- package/src/middlewares/index.js +5 -0
- package/src/models/IMfaChallengePayload.d.ts +31 -0
- package/src/models/IMfaChallengePayload.js +3 -0
- package/src/models/IMfaConfirmation.d.ts +11 -0
- package/src/models/IMfaConfirmation.js +3 -0
- package/src/models/IMfaSetup.d.ts +23 -0
- package/src/models/IMfaSetup.js +3 -0
- package/src/models/ISignInResult.d.ts +31 -0
- package/src/models/ISignInResult.js +3 -0
- package/src/models/JwtPayloadBase.d.ts +44 -0
- package/src/models/JwtPayloadBase.js +55 -0
- package/src/models/index.d.ts +6 -0
- package/src/models/index.js +10 -0
- package/src/models/responses/SessionResponse.d.ts +20 -0
- package/src/models/responses/SessionResponse.js +164 -0
- package/src/models/responses/index.d.ts +1 -0
- package/src/models/responses/index.js +5 -0
- package/src/serializer/SessionSerializer.d.ts +5 -0
- package/src/serializer/SessionSerializer.js +23 -0
- package/src/services/AuthTokenService.d.ts +30 -0
- package/src/services/AuthTokenService.js +58 -0
- package/src/services/ChallengeService.d.ts +41 -0
- package/src/services/ChallengeService.js +89 -0
- package/src/services/MfaService.d.ts +60 -0
- package/src/services/MfaService.js +251 -0
- package/src/services/SessionService.d.ts +66 -0
- package/src/services/SessionService.js +108 -0
- package/src/services/VerificationService.d.ts +56 -0
- package/src/services/VerificationService.js +124 -0
- package/src/services/index.d.ts +5 -0
- package/src/services/index.js +9 -0
- package/src/services/mfa/IMfaChannel.d.ts +40 -0
- package/src/services/mfa/IMfaChannel.js +4 -0
- package/src/services/mfa/MfaEncryptionService.d.ts +23 -0
- package/src/services/mfa/MfaEncryptionService.js +59 -0
- package/src/services/mfa/MfaState.d.ts +38 -0
- package/src/services/mfa/MfaState.js +23 -0
- package/src/services/mfa/MfaTokens.d.ts +4 -0
- package/src/services/mfa/MfaTokens.js +8 -0
- package/src/services/mfa/channels/EmailOtpMfaChannel.d.ts +21 -0
- package/src/services/mfa/channels/EmailOtpMfaChannel.js +152 -0
- package/src/services/mfa/channels/PushMfaChannel.d.ts +25 -0
- package/src/services/mfa/channels/PushMfaChannel.js +150 -0
- package/src/services/mfa/channels/SmsMfaChannel.d.ts +21 -0
- package/src/services/mfa/channels/SmsMfaChannel.js +158 -0
- package/src/services/mfa/channels/TotpMfaChannel.d.ts +19 -0
- package/src/services/mfa/channels/TotpMfaChannel.js +100 -0
- package/src/strategies/AnonymousStrategy.d.ts +32 -0
- package/src/strategies/AnonymousStrategy.js +53 -0
- package/src/strategies/AppleStrategy.d.ts +38 -0
- package/src/strategies/AppleStrategy.js +79 -0
- package/src/strategies/GithubStrategy.d.ts +24 -0
- package/src/strategies/GithubStrategy.js +65 -0
- package/src/strategies/GoogleStrategy.d.ts +34 -0
- package/src/strategies/GoogleStrategy.js +74 -0
- package/src/strategies/JwtStrategy.d.ts +31 -0
- package/src/strategies/JwtStrategy.js +55 -0
- package/src/strategies/LocalStrategy.d.ts +31 -0
- package/src/strategies/LocalStrategy.js +56 -0
- package/src/strategies/MicrosoftStrategy.d.ts +35 -0
- package/src/strategies/MicrosoftStrategy.js +75 -0
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
declare const JwtAuthGuard_base: import("@nestjs/passport").Type<import("@nestjs/passport").IAuthGuard>;
|
|
2
|
+
/**
|
|
3
|
+
* The `JwtAuthGuard` protects routes using JWT-based authentication.
|
|
4
|
+
*
|
|
5
|
+
* @public
|
|
6
|
+
*/
|
|
7
|
+
export declare class JwtAuthGuard extends JwtAuthGuard_base {
|
|
8
|
+
}
|
|
9
|
+
export {};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// #region Imports
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.JwtAuthGuard = void 0;
|
|
5
|
+
const tslib_1 = require("tslib");
|
|
6
|
+
const common_1 = require("@nestjs/common");
|
|
7
|
+
const passport_1 = require("@nestjs/passport");
|
|
8
|
+
// #endregion
|
|
9
|
+
/**
|
|
10
|
+
* The `JwtAuthGuard` protects routes using JWT-based authentication.
|
|
11
|
+
*
|
|
12
|
+
* @public
|
|
13
|
+
*/
|
|
14
|
+
let JwtAuthGuard = class JwtAuthGuard extends (0, passport_1.AuthGuard)('jwt') {
|
|
15
|
+
};
|
|
16
|
+
exports.JwtAuthGuard = JwtAuthGuard;
|
|
17
|
+
exports.JwtAuthGuard = JwtAuthGuard = tslib_1.__decorate([
|
|
18
|
+
(0, common_1.Injectable)()
|
|
19
|
+
], JwtAuthGuard);
|
|
20
|
+
//# sourceMappingURL=JwtAuthGuard.js.map
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
declare const LocalAuthGuard_base: import("@nestjs/passport").Type<import("@nestjs/passport").IAuthGuard>;
|
|
2
|
+
/**
|
|
3
|
+
* The `LocalAuthGuard` protects routes using local authentication.
|
|
4
|
+
*
|
|
5
|
+
* @public
|
|
6
|
+
*/
|
|
7
|
+
export declare class LocalAuthGuard extends LocalAuthGuard_base {
|
|
8
|
+
}
|
|
9
|
+
export {};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// #region Imports
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.LocalAuthGuard = void 0;
|
|
5
|
+
const tslib_1 = require("tslib");
|
|
6
|
+
const common_1 = require("@nestjs/common");
|
|
7
|
+
const passport_1 = require("@nestjs/passport");
|
|
8
|
+
// #endregion
|
|
9
|
+
/**
|
|
10
|
+
* The `LocalAuthGuard` protects routes using local authentication.
|
|
11
|
+
*
|
|
12
|
+
* @public
|
|
13
|
+
*/
|
|
14
|
+
let LocalAuthGuard = class LocalAuthGuard extends (0, passport_1.AuthGuard)('local') {
|
|
15
|
+
};
|
|
16
|
+
exports.LocalAuthGuard = LocalAuthGuard;
|
|
17
|
+
exports.LocalAuthGuard = LocalAuthGuard = tslib_1.__decorate([
|
|
18
|
+
(0, common_1.Injectable)()
|
|
19
|
+
], LocalAuthGuard);
|
|
20
|
+
//# sourceMappingURL=LocalAuthGuard.js.map
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { CanActivate, ExecutionContext } from '@nestjs/common';
|
|
2
|
+
import { Reflector } from '@nestjs/core';
|
|
3
|
+
import { Observable } from 'rxjs';
|
|
4
|
+
export declare class RolesGuard implements CanActivate {
|
|
5
|
+
private readonly _reflector;
|
|
6
|
+
/**
|
|
7
|
+
* Constructs a new instance of the `RolesGuard` class.
|
|
8
|
+
*
|
|
9
|
+
* @public
|
|
10
|
+
*/
|
|
11
|
+
constructor(reflector: Reflector);
|
|
12
|
+
/**
|
|
13
|
+
* @public
|
|
14
|
+
*/
|
|
15
|
+
canActivate(context: ExecutionContext): boolean | Promise<boolean> | Observable<boolean>;
|
|
16
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// #region Imports
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.RolesGuard = void 0;
|
|
5
|
+
const tslib_1 = require("tslib");
|
|
6
|
+
const common_1 = require("@nestjs/common");
|
|
7
|
+
const core_1 = require("@nestjs/core");
|
|
8
|
+
const RolesDecorator_1 = require("../decorators/RolesDecorator");
|
|
9
|
+
// #endregion
|
|
10
|
+
let RolesGuard = class RolesGuard {
|
|
11
|
+
// #endregion
|
|
12
|
+
// #region Ctor
|
|
13
|
+
/**
|
|
14
|
+
* Constructs a new instance of the `RolesGuard` class.
|
|
15
|
+
*
|
|
16
|
+
* @public
|
|
17
|
+
*/
|
|
18
|
+
constructor(reflector) {
|
|
19
|
+
this._reflector = reflector;
|
|
20
|
+
}
|
|
21
|
+
// #endregion
|
|
22
|
+
// #region Methods
|
|
23
|
+
/**
|
|
24
|
+
* @public
|
|
25
|
+
*/
|
|
26
|
+
canActivate(context) {
|
|
27
|
+
const roles = this._reflector.getAllAndOverride(RolesDecorator_1.ROLES_KEY, [
|
|
28
|
+
context.getHandler(),
|
|
29
|
+
context.getClass(),
|
|
30
|
+
]);
|
|
31
|
+
if (roles.length === 0) {
|
|
32
|
+
return true;
|
|
33
|
+
}
|
|
34
|
+
const request = context.switchToHttp().getRequest();
|
|
35
|
+
return roles.some((role) => request.user.roles.includes(role));
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
exports.RolesGuard = RolesGuard;
|
|
39
|
+
exports.RolesGuard = RolesGuard = tslib_1.__decorate([
|
|
40
|
+
(0, common_1.Injectable)(),
|
|
41
|
+
tslib_1.__metadata("design:paramtypes", [core_1.Reflector])
|
|
42
|
+
], RolesGuard);
|
|
43
|
+
//# sourceMappingURL=RolesGuard.js.map
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { CanActivate, ExecutionContext } from '@nestjs/common';
|
|
2
|
+
import { Observable } from 'rxjs';
|
|
3
|
+
export declare class SocialAuthGuard implements CanActivate {
|
|
4
|
+
private static readonly _availableProviders;
|
|
5
|
+
private readonly _provider;
|
|
6
|
+
constructor(_provider: string);
|
|
7
|
+
canActivate(context: ExecutionContext): boolean | Promise<boolean> | Observable<boolean>;
|
|
8
|
+
}
|
|
9
|
+
export declare const socialAuthGuardFactory: (provider: string) => SocialAuthGuard;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// #region Imports
|
|
3
|
+
var SocialAuthGuard_1;
|
|
4
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
5
|
+
exports.socialAuthGuardFactory = exports.SocialAuthGuard = void 0;
|
|
6
|
+
const tslib_1 = require("tslib");
|
|
7
|
+
const common_1 = require("@nestjs/common");
|
|
8
|
+
const passport_1 = require("@nestjs/passport");
|
|
9
|
+
// #endregion
|
|
10
|
+
let SocialAuthGuard = SocialAuthGuard_1 = class SocialAuthGuard {
|
|
11
|
+
// #endregion
|
|
12
|
+
// #region Ctor
|
|
13
|
+
constructor(_provider) {
|
|
14
|
+
this._provider = _provider;
|
|
15
|
+
}
|
|
16
|
+
// #endregion
|
|
17
|
+
// #region Methods
|
|
18
|
+
canActivate(context) {
|
|
19
|
+
if (!SocialAuthGuard_1._availableProviders.includes(this._provider)) {
|
|
20
|
+
throw new Error(`Unsupported OAuth provider: ${this._provider}`);
|
|
21
|
+
}
|
|
22
|
+
const guard = new ((0, passport_1.AuthGuard)(this._provider))();
|
|
23
|
+
return guard.canActivate(context);
|
|
24
|
+
}
|
|
25
|
+
};
|
|
26
|
+
exports.SocialAuthGuard = SocialAuthGuard;
|
|
27
|
+
// #region Fields
|
|
28
|
+
SocialAuthGuard._availableProviders = ['github', 'google', 'microsoft', 'apple'];
|
|
29
|
+
exports.SocialAuthGuard = SocialAuthGuard = SocialAuthGuard_1 = tslib_1.__decorate([
|
|
30
|
+
(0, common_1.Injectable)(),
|
|
31
|
+
tslib_1.__metadata("design:paramtypes", [String])
|
|
32
|
+
], SocialAuthGuard);
|
|
33
|
+
const socialAuthGuardFactory = (provider) => new SocialAuthGuard(provider);
|
|
34
|
+
exports.socialAuthGuardFactory = socialAuthGuardFactory;
|
|
35
|
+
//# sourceMappingURL=SocialAuthGuard.js.map
|
|
File without changes
|
|
File without changes
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const tslib_1 = require("tslib");
|
|
4
|
+
tslib_1.__exportStar(require("./AnonymousAuthGuard"), exports);
|
|
5
|
+
tslib_1.__exportStar(require("./GithubAuthGuard"), exports);
|
|
6
|
+
tslib_1.__exportStar(require("./JwtAuthGuard"), exports);
|
|
7
|
+
tslib_1.__exportStar(require("./LocalAuthGuard"), exports);
|
|
8
|
+
tslib_1.__exportStar(require("./RolesGuard"), exports);
|
|
9
|
+
tslib_1.__exportStar(require("./SocialAuthGuard"), exports);
|
|
10
|
+
// export * from './_RefreshTokenAuthGuard';
|
|
11
|
+
// export * from './_TwoFactorAuthGuard';
|
|
12
|
+
//# sourceMappingURL=index.js.map
|
package/src/index.d.ts
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export * from './AuthModule';
|
|
2
|
+
export * from './contracts';
|
|
3
|
+
export * from './decorators';
|
|
4
|
+
export * from './env';
|
|
5
|
+
export * from './guards';
|
|
6
|
+
export * from './mappers/SessionMappingProfile';
|
|
7
|
+
export * from './middlewares';
|
|
8
|
+
export * from './models';
|
|
9
|
+
export * from './services';
|
package/src/index.js
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const tslib_1 = require("tslib");
|
|
4
|
+
tslib_1.__exportStar(require("./AuthModule"), exports);
|
|
5
|
+
tslib_1.__exportStar(require("./contracts"), exports);
|
|
6
|
+
tslib_1.__exportStar(require("./decorators"), exports);
|
|
7
|
+
tslib_1.__exportStar(require("./env"), exports);
|
|
8
|
+
tslib_1.__exportStar(require("./guards"), exports);
|
|
9
|
+
tslib_1.__exportStar(require("./mappers/SessionMappingProfile"), exports);
|
|
10
|
+
tslib_1.__exportStar(require("./middlewares"), exports);
|
|
11
|
+
tslib_1.__exportStar(require("./models"), exports);
|
|
12
|
+
tslib_1.__exportStar(require("./services"), exports);
|
|
13
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { IMappingBuilder, MappingProfileBase } from '@breadstone/archipel-platform-core';
|
|
2
|
+
import type { ISessionRecord } from '../contracts/ISessionRecord';
|
|
3
|
+
import { SessionResponse } from '../models/responses/SessionResponse';
|
|
4
|
+
interface ISessionMappingInput {
|
|
5
|
+
session: ISessionRecord;
|
|
6
|
+
isCurrent: boolean;
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* Type-safe mapping key for Session entity to response transformation.
|
|
10
|
+
*
|
|
11
|
+
* @public
|
|
12
|
+
*/
|
|
13
|
+
export declare const SESSION_MAPPING_KEY: import("@breadstone/archipel-platform-core").IMappingKey<ISessionMappingInput, SessionResponse>;
|
|
14
|
+
/**
|
|
15
|
+
* Type-safe mapping key for Session entity list to response list transformation.
|
|
16
|
+
*
|
|
17
|
+
* @public
|
|
18
|
+
*/
|
|
19
|
+
export declare const SESSION_LIST_MAPPING_KEY: import("@breadstone/archipel-platform-core").IMappingKey<ISessionMappingInput[], SessionResponse[]>;
|
|
20
|
+
/**
|
|
21
|
+
* Mapping profile for Session entity to response transformations.
|
|
22
|
+
*
|
|
23
|
+
* @public
|
|
24
|
+
*/
|
|
25
|
+
export declare class SessionMappingProfile extends MappingProfileBase {
|
|
26
|
+
/**
|
|
27
|
+
* Configure mappings for Session entity.
|
|
28
|
+
*
|
|
29
|
+
* @public
|
|
30
|
+
* @param builder - The mapping builder
|
|
31
|
+
*/
|
|
32
|
+
configure(builder: IMappingBuilder): void;
|
|
33
|
+
/**
|
|
34
|
+
* Map a single Session entity to response.
|
|
35
|
+
*
|
|
36
|
+
* @private
|
|
37
|
+
* @param entity - The entity to map
|
|
38
|
+
* @returns The mapped response
|
|
39
|
+
*/
|
|
40
|
+
private mapEntityToResponse;
|
|
41
|
+
}
|
|
42
|
+
export {};
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// #region Imports
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.SessionMappingProfile = exports.SESSION_LIST_MAPPING_KEY = exports.SESSION_MAPPING_KEY = 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 SessionResponse_1 = require("../models/responses/SessionResponse");
|
|
9
|
+
/**
|
|
10
|
+
* Type-safe mapping key for Session entity to response transformation.
|
|
11
|
+
*
|
|
12
|
+
* @public
|
|
13
|
+
*/
|
|
14
|
+
exports.SESSION_MAPPING_KEY = (0, archipel_platform_core_1.createMappingKey)('session.entity-to-response');
|
|
15
|
+
/**
|
|
16
|
+
* Type-safe mapping key for Session entity list to response list transformation.
|
|
17
|
+
*
|
|
18
|
+
* @public
|
|
19
|
+
*/
|
|
20
|
+
exports.SESSION_LIST_MAPPING_KEY = (0, archipel_platform_core_1.createMappingKey)('session.entity-list-to-response');
|
|
21
|
+
/**
|
|
22
|
+
* Mapping profile for Session entity to response transformations.
|
|
23
|
+
*
|
|
24
|
+
* @public
|
|
25
|
+
*/
|
|
26
|
+
let SessionMappingProfile = class SessionMappingProfile extends archipel_platform_core_1.MappingProfileBase {
|
|
27
|
+
// #region Methods
|
|
28
|
+
/**
|
|
29
|
+
* Configure mappings for Session entity.
|
|
30
|
+
*
|
|
31
|
+
* @public
|
|
32
|
+
* @param builder - The mapping builder
|
|
33
|
+
*/
|
|
34
|
+
configure(builder) {
|
|
35
|
+
builder
|
|
36
|
+
.createKeyedMap(exports.SESSION_MAPPING_KEY, (entity) => this.mapEntityToResponse(entity))
|
|
37
|
+
.createKeyedMap(exports.SESSION_LIST_MAPPING_KEY, (entities) => entities.map((e) => this.mapEntityToResponse(e)));
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Map a single Session entity to response.
|
|
41
|
+
*
|
|
42
|
+
* @private
|
|
43
|
+
* @param entity - The entity to map
|
|
44
|
+
* @returns The mapped response
|
|
45
|
+
*/
|
|
46
|
+
mapEntityToResponse(input) {
|
|
47
|
+
const response = new SessionResponse_1.SessionResponse();
|
|
48
|
+
response.id = input.session.id;
|
|
49
|
+
response.deviceType = input.session.deviceType ?? null;
|
|
50
|
+
response.deviceName = input.session.deviceName ?? null;
|
|
51
|
+
response.browserName = input.session.browserName ?? null;
|
|
52
|
+
response.browserVersion = input.session.browserVersion ?? null;
|
|
53
|
+
response.osName = input.session.osName ?? null;
|
|
54
|
+
response.osVersion = input.session.osVersion ?? null;
|
|
55
|
+
response.location = input.session.location ?? null;
|
|
56
|
+
response.ipAddress = input.session.ipAddress;
|
|
57
|
+
response.lastActive = input.session.lastActive;
|
|
58
|
+
response.createdAt = input.session.createdAt;
|
|
59
|
+
response.isCurrent = input.isCurrent;
|
|
60
|
+
response.clientName = input.session.clientName ?? null;
|
|
61
|
+
return response;
|
|
62
|
+
}
|
|
63
|
+
};
|
|
64
|
+
exports.SessionMappingProfile = SessionMappingProfile;
|
|
65
|
+
exports.SessionMappingProfile = SessionMappingProfile = tslib_1.__decorate([
|
|
66
|
+
(0, common_1.Injectable)()
|
|
67
|
+
], SessionMappingProfile);
|
|
68
|
+
//# sourceMappingURL=SessionMappingProfile.js.map
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { NestMiddleware } from '@nestjs/common';
|
|
2
|
+
import { Request, Response, NextFunction } from 'express';
|
|
3
|
+
import { SessionService } from '../services/SessionService';
|
|
4
|
+
/**
|
|
5
|
+
* Middleware to automatically update the lastActive timestamp for authenticated sessions.
|
|
6
|
+
* Extracts the JWT token from the Authorization header and updates the session asynchronously.
|
|
7
|
+
*
|
|
8
|
+
* @public
|
|
9
|
+
*/
|
|
10
|
+
export declare class LastActiveMiddleware implements NestMiddleware {
|
|
11
|
+
private readonly _sessionService;
|
|
12
|
+
/**
|
|
13
|
+
* Constructs a new instance of the `LastActiveMiddleware` class.
|
|
14
|
+
*
|
|
15
|
+
* @public
|
|
16
|
+
* @param sessionService - Session service instance
|
|
17
|
+
*/
|
|
18
|
+
constructor(sessionService: SessionService);
|
|
19
|
+
/**
|
|
20
|
+
* Middleware execution method.
|
|
21
|
+
* Extracts token from Authorization header and updates lastActive timestamp asynchronously.
|
|
22
|
+
*
|
|
23
|
+
* @public
|
|
24
|
+
* @param req - Express request object
|
|
25
|
+
* @param _res - Express response object (unused)
|
|
26
|
+
* @param next - Next middleware function
|
|
27
|
+
*/
|
|
28
|
+
use(req: Request, _res: Response, next: NextFunction): void;
|
|
29
|
+
}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// #region Imports
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.LastActiveMiddleware = void 0;
|
|
5
|
+
const tslib_1 = require("tslib");
|
|
6
|
+
const common_1 = require("@nestjs/common");
|
|
7
|
+
const SessionService_1 = require("../services/SessionService");
|
|
8
|
+
// #endregion
|
|
9
|
+
/**
|
|
10
|
+
* Middleware to automatically update the lastActive timestamp for authenticated sessions.
|
|
11
|
+
* Extracts the JWT token from the Authorization header and updates the session asynchronously.
|
|
12
|
+
*
|
|
13
|
+
* @public
|
|
14
|
+
*/
|
|
15
|
+
let LastActiveMiddleware = class LastActiveMiddleware {
|
|
16
|
+
// #endregion
|
|
17
|
+
// #region Ctor
|
|
18
|
+
/**
|
|
19
|
+
* Constructs a new instance of the `LastActiveMiddleware` class.
|
|
20
|
+
*
|
|
21
|
+
* @public
|
|
22
|
+
* @param sessionService - Session service instance
|
|
23
|
+
*/
|
|
24
|
+
constructor(sessionService) {
|
|
25
|
+
this._sessionService = sessionService;
|
|
26
|
+
}
|
|
27
|
+
// #endregion
|
|
28
|
+
// #region Methods
|
|
29
|
+
/**
|
|
30
|
+
* Middleware execution method.
|
|
31
|
+
* Extracts token from Authorization header and updates lastActive timestamp asynchronously.
|
|
32
|
+
*
|
|
33
|
+
* @public
|
|
34
|
+
* @param req - Express request object
|
|
35
|
+
* @param _res - Express response object (unused)
|
|
36
|
+
* @param next - Next middleware function
|
|
37
|
+
*/
|
|
38
|
+
use(req, _res, next) {
|
|
39
|
+
const authHeader = req.headers.authorization;
|
|
40
|
+
if (authHeader?.startsWith('Bearer ')) {
|
|
41
|
+
const token = authHeader.substring(7);
|
|
42
|
+
// Update lastActive asynchronously without blocking the request
|
|
43
|
+
this._sessionService.updateLastActive(token).catch(() => {
|
|
44
|
+
// Silently fail - we don't want to break the request if session update fails
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
next();
|
|
48
|
+
}
|
|
49
|
+
};
|
|
50
|
+
exports.LastActiveMiddleware = LastActiveMiddleware;
|
|
51
|
+
exports.LastActiveMiddleware = LastActiveMiddleware = tslib_1.__decorate([
|
|
52
|
+
(0, common_1.Injectable)(),
|
|
53
|
+
tslib_1.__metadata("design:paramtypes", [SessionService_1.SessionService])
|
|
54
|
+
], LastActiveMiddleware);
|
|
55
|
+
//# sourceMappingURL=LastActiveMiddleware.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './LastActiveMiddleware';
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Represents the MFA challenge payload encoded in a challenge token.
|
|
3
|
+
*
|
|
4
|
+
* @public
|
|
5
|
+
*/
|
|
6
|
+
export interface IMfaChallengePayload {
|
|
7
|
+
/**
|
|
8
|
+
* Defines the token discriminator used to validate challenge tokens.
|
|
9
|
+
*/
|
|
10
|
+
readonly type: 'mfa';
|
|
11
|
+
/**
|
|
12
|
+
* Identifies the authenticated user.
|
|
13
|
+
*/
|
|
14
|
+
readonly userId: string;
|
|
15
|
+
/**
|
|
16
|
+
* Captures the originating IP address for the challenge.
|
|
17
|
+
*/
|
|
18
|
+
readonly ipAddress: string;
|
|
19
|
+
/**
|
|
20
|
+
* Captures the originating user agent for the challenge.
|
|
21
|
+
*/
|
|
22
|
+
readonly userAgent?: string;
|
|
23
|
+
/**
|
|
24
|
+
* Optional location associated with the login attempt.
|
|
25
|
+
*/
|
|
26
|
+
readonly location?: string;
|
|
27
|
+
/**
|
|
28
|
+
* Optional client name associated with the login attempt.
|
|
29
|
+
*/
|
|
30
|
+
readonly clientName?: string;
|
|
31
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Represents the data required to onboard a multi-factor authenticator.
|
|
3
|
+
*
|
|
4
|
+
* @public
|
|
5
|
+
*/
|
|
6
|
+
export interface IMfaSetup {
|
|
7
|
+
/**
|
|
8
|
+
* Contains the shared secret in Base32 format.
|
|
9
|
+
*/
|
|
10
|
+
readonly secret?: string;
|
|
11
|
+
/**
|
|
12
|
+
* Identifies the MFA method being provisioned.
|
|
13
|
+
*/
|
|
14
|
+
readonly method: string;
|
|
15
|
+
/**
|
|
16
|
+
* Contains the provisioning URI compatible with authenticator applications.
|
|
17
|
+
*/
|
|
18
|
+
readonly otpauthUrl?: string;
|
|
19
|
+
/**
|
|
20
|
+
* Provides a pre-rendered QR code in data URL form.
|
|
21
|
+
*/
|
|
22
|
+
readonly quickResponseCodeDataUrl?: string;
|
|
23
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Represents the outcome of a sign-in attempt.
|
|
3
|
+
*
|
|
4
|
+
* @public
|
|
5
|
+
*/
|
|
6
|
+
export interface ISignInResult {
|
|
7
|
+
/**
|
|
8
|
+
* Indicates whether a multi-factor token is required.
|
|
9
|
+
*/
|
|
10
|
+
readonly mfaRequired: boolean;
|
|
11
|
+
/**
|
|
12
|
+
* Indicates whether email verification is required.
|
|
13
|
+
*/
|
|
14
|
+
readonly verificationRequired?: boolean;
|
|
15
|
+
/**
|
|
16
|
+
* Contains the issued access token when MFA is not required.
|
|
17
|
+
*/
|
|
18
|
+
readonly accessToken?: string;
|
|
19
|
+
/**
|
|
20
|
+
* Contains the challenge identifier required to complete MFA.
|
|
21
|
+
*/
|
|
22
|
+
readonly challengeId?: string;
|
|
23
|
+
/**
|
|
24
|
+
* Lists enabled MFA methods available for the challenge.
|
|
25
|
+
*/
|
|
26
|
+
readonly methods?: ReadonlyArray<string>;
|
|
27
|
+
/**
|
|
28
|
+
* Indicates the preferred MFA method.
|
|
29
|
+
*/
|
|
30
|
+
readonly preferredMethod?: string;
|
|
31
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Abstract base class for JWT payloads.
|
|
3
|
+
* Products extend this to add their own claims (e.g. `profileId`, `isPro`).
|
|
4
|
+
* Used as both a serialization contract and NestJS injection token.
|
|
5
|
+
*
|
|
6
|
+
* @public
|
|
7
|
+
*/
|
|
8
|
+
export declare abstract class JwtPayloadBase {
|
|
9
|
+
/**
|
|
10
|
+
* Subject identifier.
|
|
11
|
+
*/
|
|
12
|
+
readonly id: string;
|
|
13
|
+
/**
|
|
14
|
+
* Email address.
|
|
15
|
+
*/
|
|
16
|
+
readonly email: string | null;
|
|
17
|
+
/**
|
|
18
|
+
* Assigned roles.
|
|
19
|
+
*/
|
|
20
|
+
readonly roles: ReadonlyArray<string>;
|
|
21
|
+
/**
|
|
22
|
+
* Issued-at timestamp (set by JWT library).
|
|
23
|
+
*/
|
|
24
|
+
readonly iat?: number;
|
|
25
|
+
/**
|
|
26
|
+
* Expiration timestamp (set by JWT library).
|
|
27
|
+
*/
|
|
28
|
+
readonly exp?: number;
|
|
29
|
+
protected constructor(id: string, email: string | null, roles: ReadonlyArray<string>);
|
|
30
|
+
/**
|
|
31
|
+
* Serializes this payload to a plain object suitable for `JwtService.signAsync()`.
|
|
32
|
+
*
|
|
33
|
+
* @public
|
|
34
|
+
*/
|
|
35
|
+
toJSON(): Record<string, unknown>;
|
|
36
|
+
/**
|
|
37
|
+
* Creates an instance from a decoded JWT payload object.
|
|
38
|
+
* Subclasses **must** override this static-like factory on a per-product basis.
|
|
39
|
+
*
|
|
40
|
+
* @public
|
|
41
|
+
* @param raw - The raw decoded JWT payload.
|
|
42
|
+
*/
|
|
43
|
+
static fromJSON(raw: Record<string, unknown>): JwtPayloadBase;
|
|
44
|
+
}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.JwtPayloadBase = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Abstract base class for JWT payloads.
|
|
6
|
+
* Products extend this to add their own claims (e.g. `profileId`, `isPro`).
|
|
7
|
+
* Used as both a serialization contract and NestJS injection token.
|
|
8
|
+
*
|
|
9
|
+
* @public
|
|
10
|
+
*/
|
|
11
|
+
class JwtPayloadBase {
|
|
12
|
+
// #endregion
|
|
13
|
+
// #region Ctor
|
|
14
|
+
constructor(id, email, roles) {
|
|
15
|
+
this.id = id;
|
|
16
|
+
this.email = email;
|
|
17
|
+
this.roles = roles;
|
|
18
|
+
}
|
|
19
|
+
// #endregion
|
|
20
|
+
// #region Methods
|
|
21
|
+
/**
|
|
22
|
+
* Serializes this payload to a plain object suitable for `JwtService.signAsync()`.
|
|
23
|
+
*
|
|
24
|
+
* @public
|
|
25
|
+
*/
|
|
26
|
+
toJSON() {
|
|
27
|
+
return {
|
|
28
|
+
id: this.id,
|
|
29
|
+
email: this.email,
|
|
30
|
+
roles: [...this.roles],
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Creates an instance from a decoded JWT payload object.
|
|
35
|
+
* Subclasses **must** override this static-like factory on a per-product basis.
|
|
36
|
+
*
|
|
37
|
+
* @public
|
|
38
|
+
* @param raw - The raw decoded JWT payload.
|
|
39
|
+
*/
|
|
40
|
+
static fromJSON(raw) {
|
|
41
|
+
return new DefaultJwtPayload(raw['id'], raw['email'] ?? null, raw['roles'] ?? []);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
exports.JwtPayloadBase = JwtPayloadBase;
|
|
45
|
+
/**
|
|
46
|
+
* Default (minimal) JWT payload used when no product-specific subclass is registered.
|
|
47
|
+
*
|
|
48
|
+
* @internal
|
|
49
|
+
*/
|
|
50
|
+
class DefaultJwtPayload extends JwtPayloadBase {
|
|
51
|
+
constructor(id, email, roles) {
|
|
52
|
+
super(id, email, roles);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
//# sourceMappingURL=JwtPayloadBase.js.map
|