@riao/iam 2.0.0 → 3.1.0

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 (95) hide show
  1. package/README.md +67 -1
  2. package/auth/auth-migrations.d.ts +5 -3
  3. package/auth/auth-migrations.js +8 -5
  4. package/auth/auth-migrations.js.map +1 -1
  5. package/auth/auth.d.ts +6 -8
  6. package/auth/auth.js +5 -8
  7. package/auth/auth.js.map +1 -1
  8. package/auth/index.d.ts +1 -0
  9. package/auth/migrations/{001-create-accounts-table.d.ts → 001-create-principals-table.d.ts} +1 -1
  10. package/auth/migrations/001-create-principals-table.js +39 -0
  11. package/auth/migrations/001-create-principals-table.js.map +1 -0
  12. package/auth/principal.d.ts +8 -0
  13. package/auth/principal.js +3 -0
  14. package/auth/principal.js.map +1 -0
  15. package/authentication/authentication.d.ts +9 -0
  16. package/authentication/authentication.js +41 -0
  17. package/authentication/authentication.js.map +1 -0
  18. package/authentication/index.d.ts +1 -0
  19. package/authentication/index.js +6 -0
  20. package/authentication/index.js.map +1 -0
  21. package/authorization/authorization.d.ts +58 -0
  22. package/authorization/authorization.js +32 -0
  23. package/authorization/authorization.js.map +1 -0
  24. package/authorization/index.d.ts +1 -0
  25. package/authorization/index.js +6 -0
  26. package/authorization/index.js.map +1 -0
  27. package/crypto.d.ts +16 -0
  28. package/crypto.js +35 -0
  29. package/crypto.js.map +1 -0
  30. package/index.d.ts +5 -1
  31. package/index.js +12 -2
  32. package/index.js.map +1 -1
  33. package/jwt.d.ts +1 -1
  34. package/jwt.js +3 -9
  35. package/jwt.js.map +1 -1
  36. package/keypair.d.ts +5 -5
  37. package/keypair.js +21 -23
  38. package/keypair.js.map +1 -1
  39. package/package.json +9 -29
  40. package/auth/migrations/001-create-accounts-table.js +0 -27
  41. package/auth/migrations/001-create-accounts-table.js.map +0 -1
  42. package/authentication/authentication-base/authentication-base.d.ts +0 -10
  43. package/authentication/authentication-base/authentication-base.js +0 -33
  44. package/authentication/authentication-base/authentication-base.js.map +0 -1
  45. package/authentication/authentication-base/index.d.ts +0 -1
  46. package/authentication/authentication-base/index.js +0 -6
  47. package/authentication/authentication-base/index.js.map +0 -1
  48. package/authentication/authentication-fido2/authentication-fido2-migrations.d.ts +0 -5
  49. package/authentication/authentication-fido2/authentication-fido2-migrations.js +0 -17
  50. package/authentication/authentication-fido2/authentication-fido2-migrations.js.map +0 -1
  51. package/authentication/authentication-fido2/authentication-fido2.d.ts +0 -58
  52. package/authentication/authentication-fido2/authentication-fido2.js +0 -260
  53. package/authentication/authentication-fido2/authentication-fido2.js.map +0 -1
  54. package/authentication/authentication-fido2/index.d.ts +0 -1
  55. package/authentication/authentication-fido2/index.js +0 -6
  56. package/authentication/authentication-fido2/index.js.map +0 -1
  57. package/authentication/authentication-fido2/migrations/create-fido-challenges-table.d.ts +0 -5
  58. package/authentication/authentication-fido2/migrations/create-fido-challenges-table.js +0 -61
  59. package/authentication/authentication-fido2/migrations/create-fido-challenges-table.js.map +0 -1
  60. package/authentication/authentication-fido2/migrations/create-fido-credentials-table.d.ts +0 -5
  61. package/authentication/authentication-fido2/migrations/create-fido-credentials-table.js +0 -68
  62. package/authentication/authentication-fido2/migrations/create-fido-credentials-table.js.map +0 -1
  63. package/authentication/authentication-fido2/migrations/index.d.ts +0 -2
  64. package/authentication/authentication-fido2/migrations/index.js +0 -6
  65. package/authentication/authentication-fido2/migrations/index.js.map +0 -1
  66. package/authentication/authentication-magic-token/authentication-magic-token-migrations.d.ts +0 -5
  67. package/authentication/authentication-magic-token/authentication-magic-token-migrations.js +0 -16
  68. package/authentication/authentication-magic-token/authentication-magic-token-migrations.js.map +0 -1
  69. package/authentication/authentication-magic-token/authentication-magic-token.d.ts +0 -25
  70. package/authentication/authentication-magic-token/authentication-magic-token.js +0 -76
  71. package/authentication/authentication-magic-token/authentication-magic-token.js.map +0 -1
  72. package/authentication/authentication-magic-token/index.d.ts +0 -1
  73. package/authentication/authentication-magic-token/index.js +0 -6
  74. package/authentication/authentication-magic-token/index.js.map +0 -1
  75. package/authentication/authentication-magic-token/magic-token.d.ts +0 -17
  76. package/authentication/authentication-magic-token/magic-token.js +0 -7
  77. package/authentication/authentication-magic-token/magic-token.js.map +0 -1
  78. package/authentication/authentication-magic-token/migrations/001-create-magic-token-table.d.ts +0 -5
  79. package/authentication/authentication-magic-token/migrations/001-create-magic-token-table.js +0 -44
  80. package/authentication/authentication-magic-token/migrations/001-create-magic-token-table.js.map +0 -1
  81. package/authentication/authentication-password/authentication-password-migrations.d.ts +0 -5
  82. package/authentication/authentication-password/authentication-password-migrations.js +0 -16
  83. package/authentication/authentication-password/authentication-password-migrations.js.map +0 -1
  84. package/authentication/authentication-password/authentication-password.d.ts +0 -8
  85. package/authentication/authentication-password/authentication-password.js +0 -28
  86. package/authentication/authentication-password/authentication-password.js.map +0 -1
  87. package/authentication/authentication-password/index.d.ts +0 -1
  88. package/authentication/authentication-password/index.js +0 -6
  89. package/authentication/authentication-password/index.js.map +0 -1
  90. package/authentication/authentication-password/migrations/001-add-password-column.d.ts +0 -5
  91. package/authentication/authentication-password/migrations/001-add-password-column.js +0 -21
  92. package/authentication/authentication-password/migrations/001-add-password-column.js.map +0 -1
  93. package/encrypt.d.ts +0 -6
  94. package/encrypt.js +0 -18
  95. package/encrypt.js.map +0 -1
@@ -1,61 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.CreateFido2ChallengesTableMigration = void 0;
4
- const dbal_1 = require("@riao/dbal");
5
- const column_pack_1 = require("@riao/dbal/column-pack");
6
- const dbal_2 = require("@riao/dbal");
7
- class CreateFido2ChallengesTableMigration extends dbal_2.Migration {
8
- async up() {
9
- await this.ddl.createTable({
10
- name: 'iam_fido2_challenges',
11
- columns: [
12
- // The unique challenge string from WebAuthn (primary key)
13
- {
14
- name: 'id',
15
- type: dbal_1.ColumnType.VARCHAR,
16
- length: 512,
17
- primaryKey: true,
18
- },
19
- // Reference to the account who owns this challenge
20
- {
21
- name: 'account_id',
22
- type: dbal_1.ColumnType.UUID,
23
- required: true,
24
- fk: {
25
- referencesTable: 'iam_accounts',
26
- referencesColumn: 'id',
27
- onDelete: 'CASCADE',
28
- },
29
- },
30
- // Type of challenge: 'registration' or 'authentication'
31
- {
32
- name: 'challenge_type',
33
- type: dbal_1.ColumnType.VARCHAR,
34
- length: 20,
35
- required: true,
36
- },
37
- // Whether the challenge has been consumed/used
38
- {
39
- name: 'used',
40
- type: dbal_1.ColumnType.BOOL,
41
- required: true,
42
- },
43
- // When the challenge expires (typically 5 minutes)
44
- {
45
- name: 'expires',
46
- type: dbal_1.ColumnType.TIMESTAMP,
47
- required: true,
48
- },
49
- column_pack_1.CreateTimestampColumn,
50
- column_pack_1.UpdateTimestampColumn,
51
- ],
52
- });
53
- }
54
- async down() {
55
- await this.ddl.dropTable({
56
- tables: ['iam_fido2_challenges'],
57
- });
58
- }
59
- }
60
- exports.CreateFido2ChallengesTableMigration = CreateFido2ChallengesTableMigration;
61
- //# sourceMappingURL=create-fido-challenges-table.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"create-fido-challenges-table.js","sourceRoot":"","sources":["../../../../../src/authentication/authentication-fido2/migrations/create-fido-challenges-table.ts"],"names":[],"mappings":";;;AAAA,qCAAwC;AACxC,wDAGgC;AAChC,qCAAuC;AAEvC,MAAa,mCAAoC,SAAQ,gBAAS;IACxD,KAAK,CAAC,EAAE;QAChB,MAAM,IAAI,CAAC,GAAG,CAAC,WAAW,CAAC;YAC1B,IAAI,EAAE,sBAAsB;YAC5B,OAAO,EAAE;gBACR,0DAA0D;gBAC1D;oBACC,IAAI,EAAE,IAAI;oBACV,IAAI,EAAE,iBAAU,CAAC,OAAO;oBACxB,MAAM,EAAE,GAAG;oBACX,UAAU,EAAE,IAAI;iBAChB;gBACD,mDAAmD;gBACnD;oBACC,IAAI,EAAE,YAAY;oBAClB,IAAI,EAAE,iBAAU,CAAC,IAAI;oBACrB,QAAQ,EAAE,IAAI;oBACd,EAAE,EAAE;wBACH,eAAe,EAAE,cAAc;wBAC/B,gBAAgB,EAAE,IAAI;wBACtB,QAAQ,EAAE,SAAS;qBACnB;iBACD;gBACD,wDAAwD;gBACxD;oBACC,IAAI,EAAE,gBAAgB;oBACtB,IAAI,EAAE,iBAAU,CAAC,OAAO;oBACxB,MAAM,EAAE,EAAE;oBACV,QAAQ,EAAE,IAAI;iBACd;gBACD,+CAA+C;gBAC/C;oBACC,IAAI,EAAE,MAAM;oBACZ,IAAI,EAAE,iBAAU,CAAC,IAAI;oBACrB,QAAQ,EAAE,IAAI;iBACd;gBACD,mDAAmD;gBACnD;oBACC,IAAI,EAAE,SAAS;oBACf,IAAI,EAAE,iBAAU,CAAC,SAAS;oBAC1B,QAAQ,EAAE,IAAI;iBACd;gBACD,mCAAqB;gBACrB,mCAAqB;aACrB;SACD,CAAC,CAAC;IACJ,CAAC;IAEQ,KAAK,CAAC,IAAI;QAClB,MAAM,IAAI,CAAC,GAAG,CAAC,SAAS,CAAC;YACxB,MAAM,EAAE,CAAC,sBAAsB,CAAC;SAChC,CAAC,CAAC;IACJ,CAAC;CACD;AArDD,kFAqDC"}
@@ -1,5 +0,0 @@
1
- import { Migration } from '@riao/dbal';
2
- export declare class CreateFido2CredentialsTableMigration extends Migration {
3
- up(): Promise<void>;
4
- down(): Promise<void>;
5
- }
@@ -1,68 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.CreateFido2CredentialsTableMigration = void 0;
4
- const dbal_1 = require("@riao/dbal");
5
- const column_pack_1 = require("@riao/dbal/column-pack");
6
- const dbal_2 = require("@riao/dbal");
7
- class CreateFido2CredentialsTableMigration extends dbal_2.Migration {
8
- async up() {
9
- await this.ddl.createTable({
10
- name: 'iam_fido2_credentials',
11
- columns: [
12
- // Base64URL encoded credential ID from WebAuthn (primary key)
13
- {
14
- name: 'id',
15
- type: dbal_1.ColumnType.VARCHAR,
16
- length: 1024,
17
- primaryKey: true,
18
- },
19
- // Reference to the account who owns this credential
20
- {
21
- name: 'account_id',
22
- type: dbal_1.ColumnType.UUID,
23
- required: true,
24
- fk: {
25
- referencesTable: 'iam_accounts',
26
- referencesColumn: 'id',
27
- onDelete: 'CASCADE',
28
- },
29
- },
30
- // CBOR-encoded public key from the authenticator
31
- {
32
- name: 'public_key',
33
- type: dbal_1.ColumnType.TEXT,
34
- required: true,
35
- },
36
- // Signature counter for replay attack prevention
37
- {
38
- name: 'counter',
39
- type: dbal_1.ColumnType.BIGINT,
40
- required: true,
41
- },
42
- // JSON array of supported authenticator transports
43
- {
44
- name: 'transports',
45
- // TODO: Change to JSON when/if supported
46
- type: dbal_1.ColumnType.TEXT,
47
- required: false,
48
- },
49
- // User-friendly name for the authenticator device
50
- {
51
- name: 'device_name',
52
- type: dbal_1.ColumnType.VARCHAR,
53
- length: 255,
54
- required: false,
55
- },
56
- column_pack_1.CreateTimestampColumn,
57
- column_pack_1.UpdateTimestampColumn,
58
- ],
59
- });
60
- }
61
- async down() {
62
- await this.ddl.dropTable({
63
- tables: ['iam_fido2_credentials'],
64
- });
65
- }
66
- }
67
- exports.CreateFido2CredentialsTableMigration = CreateFido2CredentialsTableMigration;
68
- //# sourceMappingURL=create-fido-credentials-table.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"create-fido-credentials-table.js","sourceRoot":"","sources":["../../../../../src/authentication/authentication-fido2/migrations/create-fido-credentials-table.ts"],"names":[],"mappings":";;;AAAA,qCAAwC;AACxC,wDAGgC;AAChC,qCAAuC;AAEvC,MAAa,oCAAqC,SAAQ,gBAAS;IACzD,KAAK,CAAC,EAAE;QAChB,MAAM,IAAI,CAAC,GAAG,CAAC,WAAW,CAAC;YAC1B,IAAI,EAAE,uBAAuB;YAC7B,OAAO,EAAE;gBACR,8DAA8D;gBAC9D;oBACC,IAAI,EAAE,IAAI;oBACV,IAAI,EAAE,iBAAU,CAAC,OAAO;oBACxB,MAAM,EAAE,IAAI;oBACZ,UAAU,EAAE,IAAI;iBAChB;gBACD,oDAAoD;gBACpD;oBACC,IAAI,EAAE,YAAY;oBAClB,IAAI,EAAE,iBAAU,CAAC,IAAI;oBACrB,QAAQ,EAAE,IAAI;oBACd,EAAE,EAAE;wBACH,eAAe,EAAE,cAAc;wBAC/B,gBAAgB,EAAE,IAAI;wBACtB,QAAQ,EAAE,SAAS;qBACnB;iBACD;gBACD,iDAAiD;gBACjD;oBACC,IAAI,EAAE,YAAY;oBAClB,IAAI,EAAE,iBAAU,CAAC,IAAI;oBACrB,QAAQ,EAAE,IAAI;iBACd;gBACD,iDAAiD;gBACjD;oBACC,IAAI,EAAE,SAAS;oBACf,IAAI,EAAE,iBAAU,CAAC,MAAM;oBACvB,QAAQ,EAAE,IAAI;iBACd;gBACD,mDAAmD;gBACnD;oBACC,IAAI,EAAE,YAAY;oBAClB,yCAAyC;oBACzC,IAAI,EAAE,iBAAU,CAAC,IAAI;oBACrB,QAAQ,EAAE,KAAK;iBACf;gBACD,kDAAkD;gBAClD;oBACC,IAAI,EAAE,aAAa;oBACnB,IAAI,EAAE,iBAAU,CAAC,OAAO;oBACxB,MAAM,EAAE,GAAG;oBACX,QAAQ,EAAE,KAAK;iBACf;gBACD,mCAAqB;gBACrB,mCAAqB;aACrB;SACD,CAAC,CAAC;IACJ,CAAC;IAEQ,KAAK,CAAC,IAAI;QAClB,MAAM,IAAI,CAAC,GAAG,CAAC,SAAS,CAAC;YACxB,MAAM,EAAE,CAAC,uBAAuB,CAAC;SACjC,CAAC,CAAC;IACJ,CAAC;CACD;AA5DD,oFA4DC"}
@@ -1,2 +0,0 @@
1
- export * from './create-fido-credentials-table';
2
- export * from './create-fido-challenges-table';
@@ -1,6 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const tslib_1 = require("tslib");
4
- tslib_1.__exportStar(require("./create-fido-credentials-table"), exports);
5
- tslib_1.__exportStar(require("./create-fido-challenges-table"), exports);
6
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../src/authentication/authentication-fido2/migrations/index.ts"],"names":[],"mappings":";;;AAAA,0EAAgD;AAChD,yEAA+C"}
@@ -1,5 +0,0 @@
1
- import { Migration } from '@riao/dbal';
2
- import { AuthMigrations } from '../../auth/auth-migrations';
3
- export declare class AuthenticationMagicTokenMigrations extends AuthMigrations {
4
- getMigrations(): Record<string, typeof Migration<any>>;
5
- }
@@ -1,16 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.AuthenticationMagicTokenMigrations = void 0;
4
- const auth_migrations_1 = require("../../auth/auth-migrations");
5
- const _001_create_magic_token_table_1 = require("./migrations/001-create-magic-token-table");
6
- class AuthenticationMagicTokenMigrations extends auth_migrations_1.AuthMigrations {
7
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
8
- getMigrations() {
9
- return {
10
- ...super.getMigrations(),
11
- 'create-magic-token-table': _001_create_magic_token_table_1.CreateMagicTokenTable,
12
- };
13
- }
14
- }
15
- exports.AuthenticationMagicTokenMigrations = AuthenticationMagicTokenMigrations;
16
- //# sourceMappingURL=authentication-magic-token-migrations.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"authentication-magic-token-migrations.js","sourceRoot":"","sources":["../../../../src/authentication/authentication-magic-token/authentication-magic-token-migrations.ts"],"names":[],"mappings":";;;AACA,gEAA4D;AAC5D,6FAAkF;AAElF,MAAa,kCAAmC,SAAQ,gCAAc;IACrE,8DAA8D;IAC9C,aAAa;QAC5B,OAAO;YACN,GAAG,KAAK,CAAC,aAAa,EAAE;YACxB,0BAA0B,EAAE,qDAAqB;SACjD,CAAC;IACH,CAAC;CACD;AARD,gFAQC"}
@@ -1,25 +0,0 @@
1
- import { AuthenticationBase } from '../authentication-base';
2
- import { Token, Jwt, JwtOptions } from '../../jwt';
3
- import { MagicTokenPayload, MagicTokenRecord, TokenOptions } from './magic-token';
4
- import { Account } from '../../../test/account';
5
- import { QueryRepository } from '@riao/dbal';
6
- import { AuthOptions } from '../../auth/auth';
7
- export interface MagicTokenAuthenticationOptions<TAccount extends Account> extends AuthOptions<TAccount> {
8
- jwtOptions: JwtOptions;
9
- }
10
- export declare class MagicTokenAuthentication<TAccount extends Account = Account> extends AuthenticationBase<TAccount> {
11
- protected jwt: Jwt<MagicTokenPayload>;
12
- protected magicTokenTable: string;
13
- protected tokenColumn: string;
14
- protected magicTokenRepo: QueryRepository<MagicTokenRecord>;
15
- constructor(options: MagicTokenAuthenticationOptions<TAccount>);
16
- createMagicToken(credentials: {
17
- login: string;
18
- }, options?: TokenOptions & {
19
- type: string;
20
- }): Promise<Token>;
21
- authenticate(credentials: {
22
- token: string;
23
- type: string;
24
- }): Promise<TAccount | null>;
25
- }
@@ -1,76 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.MagicTokenAuthentication = void 0;
4
- const authentication_base_1 = require("../authentication-base");
5
- const jwt_1 = require("../../jwt");
6
- const magic_token_1 = require("./magic-token");
7
- class MagicTokenAuthentication extends authentication_base_1.AuthenticationBase {
8
- jwt;
9
- magicTokenTable = 'iam_magic_tokens';
10
- tokenColumn = 'token';
11
- magicTokenRepo;
12
- constructor(options) {
13
- super(options);
14
- this.jwt = new jwt_1.Jwt(options.jwtOptions);
15
- }
16
- async createMagicToken(credentials, options = {
17
- ...magic_token_1.defaultTokenOptions,
18
- type: 'auth',
19
- }) {
20
- const account = await this.findActiveAccount({
21
- where: {
22
- [this.loginColumn]: credentials.login,
23
- },
24
- });
25
- if (account === null) {
26
- throw new Error('Account not found or not active.');
27
- }
28
- const accountId = account[this.accountIdColumn];
29
- // Generate token
30
- const token = await this.jwt.generateToken({
31
- type: 'magic-token',
32
- accountId: account[this.accountIdColumn],
33
- }, {
34
- expiresIn: options.expiresIn,
35
- });
36
- await this.magicTokenRepo.insertOne({
37
- record: {
38
- account_id: accountId,
39
- token: token.token,
40
- type: options.type,
41
- },
42
- });
43
- return token;
44
- }
45
- async authenticate(credentials) {
46
- // Verify magic token
47
- const data = await this.jwt.decodeToken(credentials.token);
48
- if (data.type !== 'magic-token') {
49
- throw new Error('Wrong type of token provided for this operation.');
50
- }
51
- // Check account
52
- const account = await this.findActiveAccount({
53
- where: {
54
- [this.accountIdColumn]: data.accountId,
55
- },
56
- });
57
- // Check token exists
58
- const tokenRecord = await this.magicTokenRepo.findOne({
59
- where: {
60
- account_id: data.accountId,
61
- token: credentials.token,
62
- type: credentials.type,
63
- },
64
- });
65
- if (!tokenRecord) {
66
- throw new Error('Token is invalid or expired.');
67
- }
68
- // Delete token
69
- await this.magicTokenRepo.delete({
70
- where: { id: tokenRecord.id },
71
- });
72
- return account;
73
- }
74
- }
75
- exports.MagicTokenAuthentication = MagicTokenAuthentication;
76
- //# sourceMappingURL=authentication-magic-token.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"authentication-magic-token.js","sourceRoot":"","sources":["../../../../src/authentication/authentication-magic-token/authentication-magic-token.ts"],"names":[],"mappings":";;;AAAA,gEAA4D;AAC5D,mCAAmD;AACnD,+CAKuB;AAUvB,MAAa,wBAEX,SAAQ,wCAA4B;IAC3B,GAAG,CAAyB;IAC5B,eAAe,GAAG,kBAAkB,CAAC;IACrC,WAAW,GAAG,OAAO,CAAC;IACtB,cAAc,CAAoC;IAE5D,YAAmB,OAAkD;QACpE,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,GAAG,GAAG,IAAI,SAAG,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC;IACxC,CAAC;IAEM,KAAK,CAAC,gBAAgB,CAC5B,WAA8B,EAC9B,UAA2C;QAC1C,GAAG,iCAAmB;QACtB,IAAI,EAAE,MAAM;KACZ;QAED,MAAM,OAAO,GAAG,MAAM,IAAI,CAAC,iBAAiB,CAAC;YAC5C,KAAK,EAAO;gBACX,CAAC,IAAI,CAAC,WAAW,CAAC,EAAE,WAAW,CAAC,KAAK;aACrC;SACD,CAAC,CAAC;QAEH,IAAI,OAAO,KAAK,IAAI,EAAE,CAAC;YACtB,MAAM,IAAI,KAAK,CAAC,kCAAkC,CAAC,CAAC;QACrD,CAAC;QAED,MAAM,SAAS,GAAG,OAAO,CAAC,IAAI,CAAC,eAAe,CAAC,CAAC;QAEhD,iBAAiB;QACjB,MAAM,KAAK,GAAG,MAAM,IAAI,CAAC,GAAG,CAAC,aAAa,CACzC;YACC,IAAI,EAAE,aAAa;YACnB,SAAS,EAAE,OAAO,CAAC,IAAI,CAAC,eAAe,CAAC;SACxC,EACD;YACC,SAAS,EAAE,OAAO,CAAC,SAAS;SAC5B,CACD,CAAC;QAEF,MAAM,IAAI,CAAC,cAAc,CAAC,SAAS,CAAC;YACnC,MAAM,EAAE;gBACP,UAAU,EAAE,SAAS;gBACrB,KAAK,EAAE,KAAK,CAAC,KAAK;gBAClB,IAAI,EAAE,OAAO,CAAC,IAAI;aAClB;SACD,CAAC,CAAC;QAEH,OAAO,KAAK,CAAC;IACd,CAAC;IAEM,KAAK,CAAC,YAAY,CAAC,WAGzB;QACA,qBAAqB;QACrB,MAAM,IAAI,GAAG,MAAM,IAAI,CAAC,GAAG,CAAC,WAAW,CAAC,WAAW,CAAC,KAAK,CAAC,CAAC;QAE3D,IAAI,IAAI,CAAC,IAAI,KAAK,aAAa,EAAE,CAAC;YACjC,MAAM,IAAI,KAAK,CAAC,kDAAkD,CAAC,CAAC;QACrE,CAAC;QAED,gBAAgB;QAChB,MAAM,OAAO,GAAG,MAAM,IAAI,CAAC,iBAAiB,CAAC;YAC5C,KAAK,EAAY;gBAChB,CAAC,IAAI,CAAC,eAAe,CAAC,EAAE,IAAI,CAAC,SAAS;aACtC;SACD,CAAC,CAAC;QAEH,qBAAqB;QACrB,MAAM,WAAW,GAAG,MAAM,IAAI,CAAC,cAAc,CAAC,OAAO,CAAC;YACrD,KAAK,EAAE;gBACN,UAAU,EAAE,IAAI,CAAC,SAAS;gBAC1B,KAAK,EAAE,WAAW,CAAC,KAAK;gBACxB,IAAI,EAAE,WAAW,CAAC,IAAI;aACtB;SACD,CAAC,CAAC;QAEH,IAAI,CAAC,WAAW,EAAE,CAAC;YAClB,MAAM,IAAI,KAAK,CAAC,8BAA8B,CAAC,CAAC;QACjD,CAAC;QAED,eAAe;QACf,MAAM,IAAI,CAAC,cAAc,CAAC,MAAM,CAAC;YAChC,KAAK,EAAE,EAAE,EAAE,EAAE,WAAW,CAAC,EAAE,EAAE;SAC7B,CAAC,CAAC;QAEH,OAAO,OAAO,CAAC;IAChB,CAAC;CACD;AA5FD,4DA4FC"}
@@ -1 +0,0 @@
1
- export { MagicTokenAuthentication } from './authentication-magic-token';
@@ -1,6 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.MagicTokenAuthentication = void 0;
4
- var authentication_magic_token_1 = require("./authentication-magic-token");
5
- Object.defineProperty(exports, "MagicTokenAuthentication", { enumerable: true, get: function () { return authentication_magic_token_1.MagicTokenAuthentication; } });
6
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/authentication/authentication-magic-token/index.ts"],"names":[],"mappings":";;;AAAA,2EAAwE;AAA/D,sIAAA,wBAAwB,OAAA"}
@@ -1,17 +0,0 @@
1
- import { DatabaseRecordId } from '@riao/dbal';
2
- import ms from 'ms';
3
- export interface TokenOptions {
4
- expiresIn: ms.StringValue;
5
- }
6
- export declare const defaultTokenOptions: TokenOptions;
7
- export interface MagicTokenPayload {
8
- type: 'magic-token';
9
- accountId: DatabaseRecordId;
10
- }
11
- export interface MagicTokenRecord {
12
- id: DatabaseRecordId;
13
- account_id: DatabaseRecordId;
14
- created_at: Date;
15
- type: string;
16
- token: string;
17
- }
@@ -1,7 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.defaultTokenOptions = void 0;
4
- exports.defaultTokenOptions = {
5
- expiresIn: '5m',
6
- };
7
- //# sourceMappingURL=magic-token.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"magic-token.js","sourceRoot":"","sources":["../../../../src/authentication/authentication-magic-token/magic-token.ts"],"names":[],"mappings":";;;AAOa,QAAA,mBAAmB,GAAiB;IAChD,SAAS,EAAE,IAAI;CACf,CAAC"}
@@ -1,5 +0,0 @@
1
- import { Migration } from '@riao/dbal';
2
- export declare class CreateMagicTokenTable extends Migration {
3
- up(): Promise<void>;
4
- down(): Promise<void>;
5
- }
@@ -1,44 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.CreateMagicTokenTable = void 0;
4
- const dbal_1 = require("@riao/dbal");
5
- const column_pack_1 = require("@riao/dbal/column-pack");
6
- const dbal_2 = require("@riao/dbal");
7
- class CreateMagicTokenTable extends dbal_2.Migration {
8
- async up() {
9
- await this.ddl.createTable({
10
- name: 'iam_magic_tokens',
11
- columns: [
12
- column_pack_1.UUIDKeyColumn,
13
- column_pack_1.CreateTimestampColumn,
14
- {
15
- name: 'type',
16
- type: dbal_1.ColumnType.VARCHAR,
17
- length: 255,
18
- required: true,
19
- },
20
- {
21
- name: 'account_id',
22
- type: dbal_1.ColumnType.UUID,
23
- required: true,
24
- fk: {
25
- referencesTable: 'iam_accounts',
26
- referencesColumn: 'id',
27
- onDelete: 'CASCADE',
28
- },
29
- },
30
- {
31
- name: 'token',
32
- type: dbal_1.ColumnType.VARCHAR,
33
- length: 1024,
34
- required: true,
35
- },
36
- ],
37
- });
38
- }
39
- async down() {
40
- await this.ddl.dropTable({ tables: ['iam_magic_tokens'] });
41
- }
42
- }
43
- exports.CreateMagicTokenTable = CreateMagicTokenTable;
44
- //# sourceMappingURL=001-create-magic-token-table.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"001-create-magic-token-table.js","sourceRoot":"","sources":["../../../../../src/authentication/authentication-magic-token/migrations/001-create-magic-token-table.ts"],"names":[],"mappings":";;;AAAA,qCAAwC;AACxC,wDAIgC;AAChC,qCAAuC;AAEvC,MAAa,qBAAsB,SAAQ,gBAAS;IAC1C,KAAK,CAAC,EAAE;QAChB,MAAM,IAAI,CAAC,GAAG,CAAC,WAAW,CAAC;YAC1B,IAAI,EAAE,kBAAkB;YACxB,OAAO,EAAE;gBACR,2BAAa;gBACb,mCAAqB;gBACrB;oBACC,IAAI,EAAE,MAAM;oBACZ,IAAI,EAAE,iBAAU,CAAC,OAAO;oBACxB,MAAM,EAAE,GAAG;oBACX,QAAQ,EAAE,IAAI;iBACd;gBACD;oBACC,IAAI,EAAE,YAAY;oBAClB,IAAI,EAAE,iBAAU,CAAC,IAAI;oBACrB,QAAQ,EAAE,IAAI;oBACd,EAAE,EAAE;wBACH,eAAe,EAAE,cAAc;wBAC/B,gBAAgB,EAAE,IAAI;wBACtB,QAAQ,EAAE,SAAS;qBACnB;iBACD;gBACD;oBACC,IAAI,EAAE,OAAO;oBACb,IAAI,EAAE,iBAAU,CAAC,OAAO;oBACxB,MAAM,EAAE,IAAI;oBACZ,QAAQ,EAAE,IAAI;iBACd;aACD;SACD,CAAC,CAAC;IACJ,CAAC;IAEQ,KAAK,CAAC,IAAI;QAClB,MAAM,IAAI,CAAC,GAAG,CAAC,SAAS,CAAC,EAAE,MAAM,EAAE,CAAC,kBAAkB,CAAC,EAAE,CAAC,CAAC;IAC5D,CAAC;CACD;AApCD,sDAoCC"}
@@ -1,5 +0,0 @@
1
- import { Migration } from '@riao/dbal';
2
- import { AuthMigrations } from '../../auth/auth-migrations';
3
- export declare class AuthenticationPasswordMigrations extends AuthMigrations {
4
- getMigrations(): Record<string, typeof Migration<any>>;
5
- }
@@ -1,16 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.AuthenticationPasswordMigrations = void 0;
4
- const auth_migrations_1 = require("../../auth/auth-migrations");
5
- const _001_add_password_column_1 = require("./migrations/001-add-password-column");
6
- class AuthenticationPasswordMigrations extends auth_migrations_1.AuthMigrations {
7
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
8
- getMigrations() {
9
- return {
10
- ...super.getMigrations(),
11
- 'add-password-column': _001_add_password_column_1.AddPasswordColumn,
12
- };
13
- }
14
- }
15
- exports.AuthenticationPasswordMigrations = AuthenticationPasswordMigrations;
16
- //# sourceMappingURL=authentication-password-migrations.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"authentication-password-migrations.js","sourceRoot":"","sources":["../../../../src/authentication/authentication-password/authentication-password-migrations.ts"],"names":[],"mappings":";;;AACA,gEAA4D;AAC5D,mFAAyE;AAEzE,MAAa,gCAAiC,SAAQ,gCAAc;IACnE,8DAA8D;IACrD,aAAa;QACrB,OAAO;YACN,GAAG,KAAK,CAAC,aAAa,EAAE;YACxB,qBAAqB,EAAE,4CAAiB;SACxC,CAAC;IACH,CAAC;CACD;AARD,4EAQC"}
@@ -1,8 +0,0 @@
1
- import { DatabaseRecordId } from '@riao/dbal';
2
- import { AuthenticationBase } from '../authentication-base';
3
- import { Account } from '../../../test/account';
4
- export declare abstract class PasswordAuthentication<TAccount extends Account> extends AuthenticationBase<TAccount> {
5
- protected passwordColumn: string;
6
- createAccount(account: TAccount): Promise<DatabaseRecordId>;
7
- authenticate(credentials: Partial<TAccount>): Promise<TAccount | null>;
8
- }
@@ -1,28 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.PasswordAuthentication = void 0;
4
- const authentication_base_1 = require("../authentication-base");
5
- class PasswordAuthentication extends authentication_base_1.AuthenticationBase {
6
- passwordColumn = 'password';
7
- async createAccount(account) {
8
- const hash = await this.hash.make(account[this.passwordColumn]);
9
- return await super.createAccount({
10
- ...account,
11
- [this.passwordColumn]: hash,
12
- });
13
- }
14
- async authenticate(credentials) {
15
- const account = await this.findActiveAccount({
16
- where: {
17
- [this.loginColumn]: credentials[this.loginColumn],
18
- },
19
- });
20
- if (!account) {
21
- return null;
22
- }
23
- const isValid = await this.hash.check(credentials[this.passwordColumn], account[this.passwordColumn]);
24
- return isValid ? account : null;
25
- }
26
- }
27
- exports.PasswordAuthentication = PasswordAuthentication;
28
- //# sourceMappingURL=authentication-password.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"authentication-password.js","sourceRoot":"","sources":["../../../../src/authentication/authentication-password/authentication-password.ts"],"names":[],"mappings":";;;AACA,gEAA4D;AAG5D,MAAsB,sBAEpB,SAAQ,wCAA4B;IAC3B,cAAc,GAAG,UAAU,CAAC;IAEtB,KAAK,CAAC,aAAa,CAClC,OAAiB;QAEjB,MAAM,IAAI,GAAG,MAAM,IAAI,CAAC,IAAI,CAAC,IAAI,CAChC,OAAO,CAAC,IAAI,CAAC,cAAc,CAAW,CACtC,CAAC;QAEF,OAAO,MAAM,KAAK,CAAC,aAAa,CAAC;YAChC,GAAG,OAAO;YACV,CAAC,IAAI,CAAC,cAAc,CAAC,EAAE,IAAI;SAC3B,CAAC,CAAC;IACJ,CAAC;IAEM,KAAK,CAAC,YAAY,CACxB,WAA8B;QAE9B,MAAM,OAAO,GAAG,MAAM,IAAI,CAAC,iBAAiB,CAAC;YAC5C,KAAK,EAAY;gBAChB,CAAC,IAAI,CAAC,WAAW,CAAC,EAAE,WAAW,CAAC,IAAI,CAAC,WAAW,CAAC;aACjD;SACD,CAAC,CAAC;QAEH,IAAI,CAAC,OAAO,EAAE,CAAC;YACd,OAAO,IAAI,CAAC;QACb,CAAC;QAED,MAAM,OAAO,GAAG,MAAM,IAAI,CAAC,IAAI,CAAC,KAAK,CACpC,WAAW,CAAC,IAAI,CAAC,cAAc,CAAW,EAC1C,OAAO,CAAC,IAAI,CAAC,cAAc,CAAW,CACtC,CAAC;QAEF,OAAO,OAAO,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,IAAI,CAAC;IACjC,CAAC;CACD;AAtCD,wDAsCC"}
@@ -1 +0,0 @@
1
- export { PasswordAuthentication } from './authentication-password';
@@ -1,6 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.PasswordAuthentication = void 0;
4
- var authentication_password_1 = require("./authentication-password");
5
- Object.defineProperty(exports, "PasswordAuthentication", { enumerable: true, get: function () { return authentication_password_1.PasswordAuthentication; } });
6
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/authentication/authentication-password/index.ts"],"names":[],"mappings":";;;AAAA,qEAAmE;AAA1D,iIAAA,sBAAsB,OAAA"}
@@ -1,5 +0,0 @@
1
- import { Migration } from '@riao/dbal';
2
- export declare class AddPasswordColumn extends Migration {
3
- up(): Promise<void>;
4
- down(): Promise<void>;
5
- }
@@ -1,21 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.AddPasswordColumn = void 0;
4
- const column_pack_1 = require("@riao/dbal/column-pack");
5
- const dbal_1 = require("@riao/dbal");
6
- class AddPasswordColumn extends dbal_1.Migration {
7
- async up() {
8
- await this.ddl.addColumns({
9
- table: 'iam_accounts',
10
- columns: [{ ...column_pack_1.PasswordColumn, name: 'password' }],
11
- });
12
- }
13
- async down() {
14
- await this.ddl.dropColumn({
15
- table: 'iam_accounts',
16
- column: 'password',
17
- });
18
- }
19
- }
20
- exports.AddPasswordColumn = AddPasswordColumn;
21
- //# sourceMappingURL=001-add-password-column.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"001-add-password-column.js","sourceRoot":"","sources":["../../../../../src/authentication/authentication-password/migrations/001-add-password-column.ts"],"names":[],"mappings":";;;AAAA,wDAAwD;AACxD,qCAAuC;AAEvC,MAAa,iBAAkB,SAAQ,gBAAS;IACtC,KAAK,CAAC,EAAE;QAChB,MAAM,IAAI,CAAC,GAAG,CAAC,UAAU,CAAC;YACzB,KAAK,EAAE,cAAc;YACrB,OAAO,EAAE,CAAC,EAAE,GAAG,4BAAc,EAAE,IAAI,EAAE,UAAU,EAAE,CAAC;SAClD,CAAC,CAAC;IACJ,CAAC;IAEQ,KAAK,CAAC,IAAI;QAClB,MAAM,IAAI,CAAC,GAAG,CAAC,UAAU,CAAC;YACzB,KAAK,EAAE,cAAc;YACrB,MAAM,EAAE,UAAU;SAClB,CAAC,CAAC;IACJ,CAAC;CACD;AAdD,8CAcC"}
package/encrypt.d.ts DELETED
@@ -1,6 +0,0 @@
1
- /// <reference types="node" />
2
- /// <reference types="node" />
3
- /// <reference types="node" />
4
- import * as crypto from 'crypto';
5
- export declare function encrypt(publicKey: string | crypto.KeyObject, data: string | Buffer): Buffer;
6
- export declare function decrypt(privateKey: string | crypto.KeyObject, encryptedData: string | Buffer): Buffer;
package/encrypt.js DELETED
@@ -1,18 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.decrypt = exports.encrypt = void 0;
4
- const tslib_1 = require("tslib");
5
- const crypto = tslib_1.__importStar(require("crypto"));
6
- function encrypt(publicKey, data) {
7
- data = Buffer.isBuffer(data) ? data : Buffer.from(data);
8
- return crypto.publicEncrypt(publicKey, data);
9
- }
10
- exports.encrypt = encrypt;
11
- function decrypt(privateKey, encryptedData) {
12
- encryptedData = Buffer.isBuffer(encryptedData)
13
- ? encryptedData
14
- : Buffer.from(encryptedData);
15
- return crypto.privateDecrypt(privateKey, encryptedData);
16
- }
17
- exports.decrypt = decrypt;
18
- //# sourceMappingURL=encrypt.js.map
package/encrypt.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"encrypt.js","sourceRoot":"","sources":["../../src/encrypt.ts"],"names":[],"mappings":";;;;AAAA,uDAAiC;AAEjC,SAAgB,OAAO,CACtB,SAAoC,EACpC,IAAqB;IAErB,IAAI,GAAG,MAAM,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IACxD,OAAO,MAAM,CAAC,aAAa,CAAC,SAAS,EAAE,IAAI,CAAC,CAAC;AAC9C,CAAC;AAND,0BAMC;AAED,SAAgB,OAAO,CACtB,UAAqC,EACrC,aAA8B;IAE9B,aAAa,GAAG,MAAM,CAAC,QAAQ,CAAC,aAAa,CAAC;QAC7C,CAAC,CAAC,aAAa;QACf,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,aAAa,CAAC,CAAC;IAE9B,OAAO,MAAM,CAAC,cAAc,CAAC,UAAU,EAAE,aAAa,CAAC,CAAC;AACzD,CAAC;AATD,0BASC"}