@riao/iam 1.0.0 → 2.0.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.
- package/auth/auth-migrations.d.ts +4 -0
- package/auth/auth-migrations.js +12 -0
- package/auth/auth-migrations.js.map +1 -0
- package/auth/auth.d.ts +11 -0
- package/auth/auth.js +18 -0
- package/auth/auth.js.map +1 -0
- package/auth/index.d.ts +1 -0
- package/auth/index.js +6 -0
- package/auth/index.js.map +1 -0
- package/auth/migrations/001-create-accounts-table.d.ts +5 -0
- package/auth/migrations/001-create-accounts-table.js +27 -0
- package/auth/migrations/001-create-accounts-table.js.map +1 -0
- package/authentication/authentication-base/authentication-base.d.ts +10 -0
- package/authentication/authentication-base/authentication-base.js +33 -0
- package/authentication/authentication-base/authentication-base.js.map +1 -0
- package/authentication/authentication-base/index.d.ts +1 -0
- package/authentication/authentication-base/index.js +6 -0
- package/authentication/authentication-base/index.js.map +1 -0
- package/authentication/authentication-fido2/authentication-fido2-migrations.d.ts +5 -0
- package/authentication/authentication-fido2/authentication-fido2-migrations.js +17 -0
- package/authentication/authentication-fido2/authentication-fido2-migrations.js.map +1 -0
- package/authentication/authentication-fido2/authentication-fido2.d.ts +58 -0
- package/authentication/authentication-fido2/authentication-fido2.js +260 -0
- package/authentication/authentication-fido2/authentication-fido2.js.map +1 -0
- package/authentication/authentication-fido2/index.d.ts +1 -0
- package/authentication/authentication-fido2/index.js +6 -0
- package/authentication/authentication-fido2/index.js.map +1 -0
- package/authentication/authentication-fido2/migrations/create-fido-challenges-table.d.ts +5 -0
- package/authentication/authentication-fido2/migrations/create-fido-challenges-table.js +61 -0
- package/authentication/authentication-fido2/migrations/create-fido-challenges-table.js.map +1 -0
- package/authentication/authentication-fido2/migrations/create-fido-credentials-table.d.ts +5 -0
- package/authentication/authentication-fido2/migrations/create-fido-credentials-table.js +68 -0
- package/authentication/authentication-fido2/migrations/create-fido-credentials-table.js.map +1 -0
- package/authentication/authentication-fido2/migrations/index.d.ts +2 -0
- package/authentication/authentication-fido2/migrations/index.js +6 -0
- package/authentication/authentication-fido2/migrations/index.js.map +1 -0
- package/authentication/authentication-magic-token/authentication-magic-token-migrations.d.ts +5 -0
- package/authentication/authentication-magic-token/authentication-magic-token-migrations.js +16 -0
- package/authentication/authentication-magic-token/authentication-magic-token-migrations.js.map +1 -0
- package/authentication/authentication-magic-token/authentication-magic-token.d.ts +25 -0
- package/authentication/authentication-magic-token/authentication-magic-token.js +76 -0
- package/authentication/authentication-magic-token/authentication-magic-token.js.map +1 -0
- package/authentication/authentication-magic-token/index.d.ts +1 -0
- package/authentication/authentication-magic-token/index.js +6 -0
- package/authentication/authentication-magic-token/index.js.map +1 -0
- package/authentication/authentication-magic-token/magic-token.d.ts +17 -0
- package/authentication/authentication-magic-token/magic-token.js +7 -0
- package/authentication/authentication-magic-token/magic-token.js.map +1 -0
- package/authentication/authentication-magic-token/migrations/001-create-magic-token-table.d.ts +5 -0
- package/authentication/authentication-magic-token/migrations/001-create-magic-token-table.js +44 -0
- package/authentication/authentication-magic-token/migrations/001-create-magic-token-table.js.map +1 -0
- package/authentication/authentication-password/authentication-password-migrations.d.ts +5 -0
- package/authentication/authentication-password/authentication-password-migrations.js +16 -0
- package/authentication/authentication-password/authentication-password-migrations.js.map +1 -0
- package/authentication/authentication-password/authentication-password.d.ts +8 -0
- package/authentication/authentication-password/authentication-password.js +28 -0
- package/authentication/authentication-password/authentication-password.js.map +1 -0
- package/authentication/authentication-password/index.d.ts +1 -0
- package/authentication/authentication-password/index.js +6 -0
- package/authentication/authentication-password/index.js.map +1 -0
- package/authentication/authentication-password/migrations/001-add-password-column.d.ts +5 -0
- package/authentication/authentication-password/migrations/001-add-password-column.js +21 -0
- package/authentication/authentication-password/migrations/001-add-password-column.js.map +1 -0
- package/encrypt.d.ts +6 -0
- package/encrypt.js +18 -0
- package/encrypt.js.map +1 -0
- package/hash.d.ts +5 -0
- package/hash.js +15 -0
- package/hash.js.map +1 -0
- package/index.d.ts +1 -2
- package/index.js +4 -18
- package/index.js.map +1 -1
- package/jwt.d.ts +26 -28
- package/jwt.js +54 -83
- package/jwt.js.map +1 -1
- package/keypair.d.ts +24 -24
- package/keypair.js +72 -70
- package/keypair.js.map +1 -1
- package/package.json +31 -10
- package/secret.d.ts +5 -5
- package/secret.js +2 -2
- package/auth.d.ts +0 -11
- package/auth.js +0 -16
- package/auth.js.map +0 -1
- package/authentication-base.d.ts +0 -12
- package/authentication-base.js +0 -48
- package/authentication-base.js.map +0 -1
- package/authentication-password.d.ts +0 -11
- package/authentication-password.js +0 -43
- package/authentication-password.js.map +0 -1
- package/authentication-passwordless.d.ts +0 -24
- package/authentication-passwordless.js +0 -55
- package/authentication-passwordless.js.map +0 -1
- package/authorization-abac.d.ts +0 -8
- package/authorization-abac.js +0 -33
- package/authorization-abac.js.map +0 -1
- package/authorization-base.d.ts +0 -17
- package/authorization-base.js +0 -30
- package/authorization-base.js.map +0 -1
- package/authorization-hmm.d.ts +0 -0
- package/authorization-hmm.js +0 -173
- package/authorization-hmm.js.map +0 -1
- package/authorization-rbac.d.ts +0 -14
- package/authorization-rbac.js +0 -61
- package/authorization-rbac.js.map +0 -1
- package/errors/authentication-error.d.ts +0 -3
- package/errors/authentication-error.js +0 -8
- package/errors/authentication-error.js.map +0 -1
- package/errors/authorization-error.d.ts +0 -3
- package/errors/authorization-error.js +0 -8
- package/errors/authorization-error.js.map +0 -1
- package/errors/error.d.ts +0 -2
- package/errors/error.js +0 -7
- package/errors/error.js.map +0 -1
- package/iam.d.ts +0 -40
- package/iam.js +0 -73
- package/iam.js.map +0 -1
- package/migrations/1725221752756-create-users-table.d.ts +0 -7
- package/migrations/1725221752756-create-users-table.js +0 -36
- package/migrations/1725221752756-create-users-table.js.map +0 -1
- package/migrations/1725221859886-create-roles-table.d.ts +0 -7
- package/migrations/1725221859886-create-roles-table.js +0 -36
- package/migrations/1725221859886-create-roles-table.js.map +0 -1
- package/migrations/1725221896876-create-permissions-table.d.ts +0 -7
- package/migrations/1725221896876-create-permissions-table.js +0 -41
- package/migrations/1725221896876-create-permissions-table.js.map +0 -1
- package/migrations/1725221935064-create-role-permissions-table.d.ts +0 -7
- package/migrations/1725221935064-create-role-permissions-table.js +0 -56
- package/migrations/1725221935064-create-role-permissions-table.js.map +0 -1
- package/migrations/1725221951873-create-user-roles-table.d.ts +0 -7
- package/migrations/1725221951873-create-user-roles-table.js +0 -56
- package/migrations/1725221951873-create-user-roles-table.js.map +0 -1
- package/migrations/index.d.ts +0 -5
- package/migrations/index.js +0 -22
- package/migrations/index.js.map +0 -1
- package/token.d.ts +0 -13
- package/token.js +0 -3
- package/token.js.map +0 -1
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.AuthMigrations = void 0;
|
|
4
|
+
const _001_create_accounts_table_1 = require("./migrations/001-create-accounts-table");
|
|
5
|
+
class AuthMigrations {
|
|
6
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
7
|
+
getMigrations() {
|
|
8
|
+
return { 'create-accounts-table': _001_create_accounts_table_1.CreateAccountsTableMigration };
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
exports.AuthMigrations = AuthMigrations;
|
|
12
|
+
//# sourceMappingURL=auth-migrations.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"auth-migrations.js","sourceRoot":"","sources":["../../../src/auth/auth-migrations.ts"],"names":[],"mappings":";;;AACA,uFAAsF;AAEtF,MAAa,cAAc;IAC1B,8DAA8D;IACvD,aAAa;QACnB,OAAO,EAAE,uBAAuB,EAAE,yDAA4B,EAAE,CAAC;IAClE,CAAC;CACD;AALD,wCAKC"}
|
package/auth/auth.d.ts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { DatabaseRecord, QueryRepository } from '@riao/dbal';
|
|
2
|
+
export interface AuthOptions<TAccount extends DatabaseRecord> {
|
|
3
|
+
repo: QueryRepository<TAccount>;
|
|
4
|
+
}
|
|
5
|
+
export declare abstract class Auth<TAccount extends DatabaseRecord> {
|
|
6
|
+
protected accountRepo: QueryRepository<TAccount>;
|
|
7
|
+
protected accountTable: string;
|
|
8
|
+
protected accountIdColumn: string;
|
|
9
|
+
protected loginColumn: string;
|
|
10
|
+
constructor(options: AuthOptions<TAccount>);
|
|
11
|
+
}
|
package/auth/auth.js
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Auth = void 0;
|
|
4
|
+
class Auth {
|
|
5
|
+
accountRepo;
|
|
6
|
+
accountTable = 'iam_accounts';
|
|
7
|
+
accountIdColumn = 'id';
|
|
8
|
+
loginColumn = 'login';
|
|
9
|
+
constructor(options) {
|
|
10
|
+
this.accountRepo = options.repo;
|
|
11
|
+
this.accountTable =
|
|
12
|
+
this.accountRepo.getTableName() || this.accountTable;
|
|
13
|
+
this.accountIdColumn =
|
|
14
|
+
this.accountRepo.getIdentifier() || this.accountIdColumn;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
exports.Auth = Auth;
|
|
18
|
+
//# sourceMappingURL=auth.js.map
|
package/auth/auth.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"auth.js","sourceRoot":"","sources":["../../../src/auth/auth.ts"],"names":[],"mappings":";;;AAKA,MAAsB,IAAI;IACf,WAAW,CAA4B;IACvC,YAAY,GAAG,cAAc,CAAC;IAC9B,eAAe,GAAG,IAAI,CAAC;IACvB,WAAW,GAAG,OAAO,CAAC;IAEhC,YAAmB,OAA8B;QAChD,IAAI,CAAC,WAAW,GAAG,OAAO,CAAC,IAAI,CAAC;QAChC,IAAI,CAAC,YAAY;YAChB,IAAI,CAAC,WAAW,CAAC,YAAY,EAAE,IAAI,IAAI,CAAC,YAAY,CAAC;QACtD,IAAI,CAAC,eAAe;YACnB,IAAI,CAAC,WAAW,CAAC,aAAa,EAAE,IAAI,IAAI,CAAC,eAAe,CAAC;IAC3D,CAAC;CACD;AAbD,oBAaC"}
|
package/auth/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { Auth } from './auth';
|
package/auth/index.js
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Auth = void 0;
|
|
4
|
+
var auth_1 = require("./auth");
|
|
5
|
+
Object.defineProperty(exports, "Auth", { enumerable: true, get: function () { return auth_1.Auth; } });
|
|
6
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/auth/index.ts"],"names":[],"mappings":";;;AAAA,+BAA8B;AAArB,4FAAA,IAAI,OAAA"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.CreateAccountsTableMigration = void 0;
|
|
4
|
+
const column_pack_1 = require("@riao/dbal/column-pack");
|
|
5
|
+
const dbal_1 = require("@riao/dbal");
|
|
6
|
+
class CreateAccountsTableMigration extends dbal_1.Migration {
|
|
7
|
+
async up() {
|
|
8
|
+
await this.ddl.createTable({
|
|
9
|
+
name: 'iam_accounts',
|
|
10
|
+
columns: [
|
|
11
|
+
column_pack_1.UUIDKeyColumn,
|
|
12
|
+
{
|
|
13
|
+
...column_pack_1.UsernameColumn,
|
|
14
|
+
name: 'login',
|
|
15
|
+
},
|
|
16
|
+
column_pack_1.CreateTimestampColumn,
|
|
17
|
+
],
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
async down() {
|
|
21
|
+
await this.ddl.dropTable({
|
|
22
|
+
tables: ['iam_accounts'],
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
exports.CreateAccountsTableMigration = CreateAccountsTableMigration;
|
|
27
|
+
//# sourceMappingURL=001-create-accounts-table.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"001-create-accounts-table.js","sourceRoot":"","sources":["../../../../src/auth/migrations/001-create-accounts-table.ts"],"names":[],"mappings":";;;AAAA,wDAIgC;AAChC,qCAAuC;AAEvC,MAAa,4BAA6B,SAAQ,gBAAS;IACjD,KAAK,CAAC,EAAE;QAChB,MAAM,IAAI,CAAC,GAAG,CAAC,WAAW,CAAC;YAC1B,IAAI,EAAE,cAAc;YACpB,OAAO,EAAE;gBACR,2BAAa;gBACb;oBACC,GAAG,4BAAc;oBACjB,IAAI,EAAE,OAAO;iBACb;gBACD,mCAAqB;aACrB;SACD,CAAC,CAAC;IACJ,CAAC;IAEQ,KAAK,CAAC,IAAI;QAClB,MAAM,IAAI,CAAC,GAAG,CAAC,SAAS,CAAC;YACxB,MAAM,EAAE,CAAC,cAAc,CAAC;SACxB,CAAC,CAAC;IACJ,CAAC;CACD;AApBD,oEAoBC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { DatabaseRecord, DatabaseRecordId, Expression, SelectQuery } from '@riao/dbal';
|
|
2
|
+
import { Auth } from '../../auth/auth';
|
|
3
|
+
import { Hash } from '../../hash';
|
|
4
|
+
export declare abstract class AuthenticationBase<TAccount extends DatabaseRecord> extends Auth<TAccount> {
|
|
5
|
+
protected hash: Hash;
|
|
6
|
+
createAccount(account: TAccount): Promise<DatabaseRecordId>;
|
|
7
|
+
abstract authenticate(credentials: any): Promise<TAccount | null>;
|
|
8
|
+
findActiveAccount(query: SelectQuery<TAccount>): Promise<TAccount | null>;
|
|
9
|
+
protected isActiveQuery(): undefined | Expression<TAccount>;
|
|
10
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.AuthenticationBase = void 0;
|
|
4
|
+
const dbal_1 = require("@riao/dbal");
|
|
5
|
+
const auth_1 = require("../../auth/auth");
|
|
6
|
+
const hash_1 = require("../../hash");
|
|
7
|
+
class AuthenticationBase extends auth_1.Auth {
|
|
8
|
+
hash = new hash_1.Hash();
|
|
9
|
+
async createAccount(account) {
|
|
10
|
+
const inserted = await this.accountRepo.insertOne({
|
|
11
|
+
record: account,
|
|
12
|
+
});
|
|
13
|
+
return inserted[this.accountIdColumn];
|
|
14
|
+
}
|
|
15
|
+
async findActiveAccount(query) {
|
|
16
|
+
const isActiveQuery = this.isActiveQuery();
|
|
17
|
+
if (query.where && isActiveQuery !== undefined) {
|
|
18
|
+
query.where = [isActiveQuery, dbal_1.and, query.where];
|
|
19
|
+
}
|
|
20
|
+
else if (isActiveQuery !== undefined) {
|
|
21
|
+
query.where = isActiveQuery;
|
|
22
|
+
}
|
|
23
|
+
const account = await this.accountRepo.findOne({
|
|
24
|
+
...query,
|
|
25
|
+
});
|
|
26
|
+
return account;
|
|
27
|
+
}
|
|
28
|
+
isActiveQuery() {
|
|
29
|
+
return undefined;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
exports.AuthenticationBase = AuthenticationBase;
|
|
33
|
+
//# sourceMappingURL=authentication-base.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"authentication-base.js","sourceRoot":"","sources":["../../../../src/authentication/authentication-base/authentication-base.ts"],"names":[],"mappings":";;;AAAA,qCAMoB;AACpB,0CAAuC;AACvC,qCAAkC;AAElC,MAAsB,kBAEpB,SAAQ,WAAc;IACb,IAAI,GAAS,IAAI,WAAI,EAAE,CAAC;IAE3B,KAAK,CAAC,aAAa,CAAC,OAAiB;QAC3C,MAAM,QAAQ,GAAG,MAAM,IAAI,CAAC,WAAW,CAAC,SAAS,CAAC;YACjD,MAAM,EAAE,OAAO;SACf,CAAC,CAAC;QAEH,OAAO,QAAQ,CAAC,IAAI,CAAC,eAAe,CAAqB,CAAC;IAC3D,CAAC;IAIM,KAAK,CAAC,iBAAiB,CAC7B,KAA4B;QAE5B,MAAM,aAAa,GAAG,IAAI,CAAC,aAAa,EAAE,CAAC;QAE3C,IAAI,KAAK,CAAC,KAAK,IAAI,aAAa,KAAK,SAAS,EAAE,CAAC;YAChD,KAAK,CAAC,KAAK,GAAG,CAAC,aAAa,EAAE,UAAG,EAAE,KAAK,CAAC,KAAK,CAAC,CAAC;QACjD,CAAC;aACI,IAAI,aAAa,KAAK,SAAS,EAAE,CAAC;YACtC,KAAK,CAAC,KAAK,GAAG,aAAa,CAAC;QAC7B,CAAC;QAED,MAAM,OAAO,GAAG,MAAM,IAAI,CAAC,WAAW,CAAC,OAAO,CAAC;YAC9C,GAAG,KAAK;SACR,CAAC,CAAC;QAEH,OAAO,OAAO,CAAC;IAChB,CAAC;IAES,aAAa;QACtB,OAAO,SAAS,CAAC;IAClB,CAAC;CACD;AArCD,gDAqCC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { AuthenticationBase } from './authentication-base';
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.AuthenticationBase = void 0;
|
|
4
|
+
var authentication_base_1 = require("./authentication-base");
|
|
5
|
+
Object.defineProperty(exports, "AuthenticationBase", { enumerable: true, get: function () { return authentication_base_1.AuthenticationBase; } });
|
|
6
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/authentication/authentication-base/index.ts"],"names":[],"mappings":";;;AAAA,6DAA2D;AAAlD,yHAAA,kBAAkB,OAAA"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.AuthenticationFido2Migrations = void 0;
|
|
4
|
+
const auth_migrations_1 = require("../../auth/auth-migrations");
|
|
5
|
+
const migrations_1 = require("./migrations");
|
|
6
|
+
class AuthenticationFido2Migrations extends auth_migrations_1.AuthMigrations {
|
|
7
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
8
|
+
getMigrations() {
|
|
9
|
+
return {
|
|
10
|
+
...super.getMigrations(),
|
|
11
|
+
'create-fido2-credentials-table': migrations_1.CreateFido2CredentialsTableMigration,
|
|
12
|
+
'create-fido2-challenges-table': migrations_1.CreateFido2ChallengesTableMigration,
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
exports.AuthenticationFido2Migrations = AuthenticationFido2Migrations;
|
|
17
|
+
//# sourceMappingURL=authentication-fido2-migrations.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"authentication-fido2-migrations.js","sourceRoot":"","sources":["../../../../src/authentication/authentication-fido2/authentication-fido2-migrations.ts"],"names":[],"mappings":";;;AACA,gEAA4D;AAE5D,6CAGsB;AAEtB,MAAa,6BAA8B,SAAQ,gCAAc;IAChE,8DAA8D;IAC9C,aAAa;QAC5B,OAAO;YACN,GAAG,KAAK,CAAC,aAAa,EAAE;YACxB,gCAAgC,EAC/B,iDAAoC;YACrC,+BAA+B,EAC9B,gDAAmC;SACpC,CAAC;IACH,CAAC;CACD;AAXD,sEAWC"}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { DatabaseRecordId, QueryRepository } from '@riao/dbal';
|
|
2
|
+
import { Account } from '../../../test/account';
|
|
3
|
+
import { AuthenticationBase } from '../authentication-base';
|
|
4
|
+
import { Database } from '@riao/dbal';
|
|
5
|
+
import { type RegistrationResponseJSON, type AuthenticationResponseJSON, type PublicKeyCredentialCreationOptionsJSON, type PublicKeyCredentialRequestOptionsJSON, type AuthenticatorTransportFuture } from '@simplewebauthn/server';
|
|
6
|
+
import { AuthOptions } from '../../auth/auth';
|
|
7
|
+
export interface StoredChallenge {
|
|
8
|
+
id: string;
|
|
9
|
+
account_id: DatabaseRecordId;
|
|
10
|
+
challenge_type: 'registration' | 'authentication';
|
|
11
|
+
expires: Date;
|
|
12
|
+
used: boolean;
|
|
13
|
+
created_at?: Date;
|
|
14
|
+
}
|
|
15
|
+
export interface AuthenticatorCredential {
|
|
16
|
+
id: string;
|
|
17
|
+
account_id: DatabaseRecordId;
|
|
18
|
+
public_key: string;
|
|
19
|
+
counter: number;
|
|
20
|
+
transports?: string;
|
|
21
|
+
device_name?: string;
|
|
22
|
+
created_at?: Date;
|
|
23
|
+
updated_at?: Date;
|
|
24
|
+
}
|
|
25
|
+
export interface Fido2Credentials {
|
|
26
|
+
response: AuthenticationResponseJSON;
|
|
27
|
+
accountId: DatabaseRecordId;
|
|
28
|
+
}
|
|
29
|
+
export interface Fido2AuthenticationOptions<TAccount extends Account = Account> extends AuthOptions<TAccount> {
|
|
30
|
+
db: Database;
|
|
31
|
+
rpName: string;
|
|
32
|
+
rpID: string;
|
|
33
|
+
origin: string;
|
|
34
|
+
}
|
|
35
|
+
export declare class Fido2Authentication<TAccount extends Account> extends AuthenticationBase<TAccount> {
|
|
36
|
+
protected readonly rpName: string;
|
|
37
|
+
protected readonly rpID: string;
|
|
38
|
+
protected readonly origin: string;
|
|
39
|
+
protected challengeTable: string;
|
|
40
|
+
protected credentialTable: string;
|
|
41
|
+
protected challengeRepo: QueryRepository<StoredChallenge>;
|
|
42
|
+
protected credentialRepo: QueryRepository<AuthenticatorCredential>;
|
|
43
|
+
constructor(options: Fido2AuthenticationOptions<TAccount>);
|
|
44
|
+
generateRegistrationOptions(account: TAccount): Promise<PublicKeyCredentialCreationOptionsJSON>;
|
|
45
|
+
verifyRegistration(account: TAccount, response: RegistrationResponseJSON): Promise<{
|
|
46
|
+
verified: boolean;
|
|
47
|
+
registrationInfo?: object;
|
|
48
|
+
}>;
|
|
49
|
+
generateAuthenticationOptions(userID?: string): Promise<PublicKeyCredentialRequestOptionsJSON>;
|
|
50
|
+
createAccount(account: TAccount): Promise<DatabaseRecordId>;
|
|
51
|
+
authenticate(credentials: Fido2Credentials): Promise<TAccount | null>;
|
|
52
|
+
protected getExistingCredentials(accountId: string): Promise<{
|
|
53
|
+
id: string;
|
|
54
|
+
type: 'public-key';
|
|
55
|
+
transports?: AuthenticatorTransportFuture[];
|
|
56
|
+
}[]>;
|
|
57
|
+
protected getAuthenticatorByCredentialID(credentialID: string): Promise<AuthenticatorCredential | null>;
|
|
58
|
+
}
|
|
@@ -0,0 +1,260 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Fido2Authentication = void 0;
|
|
4
|
+
const authentication_base_1 = require("../authentication-base");
|
|
5
|
+
const server_1 = require("@simplewebauthn/server");
|
|
6
|
+
class Fido2Authentication extends authentication_base_1.AuthenticationBase {
|
|
7
|
+
rpName;
|
|
8
|
+
rpID;
|
|
9
|
+
origin;
|
|
10
|
+
challengeTable = 'iam_fido2_challenges';
|
|
11
|
+
credentialTable = 'iam_fido2_credentials';
|
|
12
|
+
challengeRepo;
|
|
13
|
+
credentialRepo;
|
|
14
|
+
constructor(options) {
|
|
15
|
+
super(options);
|
|
16
|
+
this.rpName = options.rpName;
|
|
17
|
+
this.rpID = options.rpID;
|
|
18
|
+
this.origin = options.origin;
|
|
19
|
+
this.challengeRepo = options.db.getQueryRepository({
|
|
20
|
+
table: this.challengeTable,
|
|
21
|
+
});
|
|
22
|
+
this.credentialRepo =
|
|
23
|
+
options.db.getQueryRepository({
|
|
24
|
+
table: this.credentialTable,
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
async generateRegistrationOptions(account) {
|
|
28
|
+
if (!account[this.accountIdColumn]) {
|
|
29
|
+
throw new Error('Account must have an ID');
|
|
30
|
+
}
|
|
31
|
+
const accountId = account[this.accountIdColumn].toString();
|
|
32
|
+
const login = account[this.loginColumn] || accountId;
|
|
33
|
+
// TODO: Display name?
|
|
34
|
+
const accountName = account[this.loginColumn] || accountId;
|
|
35
|
+
const options = {
|
|
36
|
+
rpName: this.rpName,
|
|
37
|
+
rpID: this.rpID,
|
|
38
|
+
userID: new Uint8Array(Buffer.from(accountId, 'utf8')),
|
|
39
|
+
userName: login,
|
|
40
|
+
userDisplayName: accountName,
|
|
41
|
+
attestationType: 'none',
|
|
42
|
+
authenticatorSelection: {
|
|
43
|
+
// Allow both platform and cross-platform authenticators
|
|
44
|
+
userVerification: 'preferred',
|
|
45
|
+
requireResidentKey: false,
|
|
46
|
+
},
|
|
47
|
+
excludeCredentials: await this.getExistingCredentials(accountId),
|
|
48
|
+
};
|
|
49
|
+
const registrationOptions = await (0, server_1.generateRegistrationOptions)(options);
|
|
50
|
+
const expiresAt = new Date(Date.now() + 5 * 60 * 1000); // 5 minutes
|
|
51
|
+
await this.challengeRepo.insert({
|
|
52
|
+
records: [
|
|
53
|
+
{
|
|
54
|
+
id: registrationOptions.challenge,
|
|
55
|
+
account_id: account[this.accountIdColumn],
|
|
56
|
+
challenge_type: 'registration',
|
|
57
|
+
expires: expiresAt,
|
|
58
|
+
used: false,
|
|
59
|
+
},
|
|
60
|
+
],
|
|
61
|
+
});
|
|
62
|
+
return registrationOptions;
|
|
63
|
+
}
|
|
64
|
+
async verifyRegistration(account, response) {
|
|
65
|
+
if (!account[this.accountIdColumn]) {
|
|
66
|
+
throw new Error('Account must have an ID');
|
|
67
|
+
}
|
|
68
|
+
// Find the challenge from database
|
|
69
|
+
const challengesRaw = await this.challengeRepo.find({
|
|
70
|
+
where: {
|
|
71
|
+
account_id: account[this.accountIdColumn],
|
|
72
|
+
challenge_type: 'registration',
|
|
73
|
+
used: false,
|
|
74
|
+
},
|
|
75
|
+
limit: 1,
|
|
76
|
+
});
|
|
77
|
+
if (challengesRaw.length === 0) {
|
|
78
|
+
return { verified: false };
|
|
79
|
+
}
|
|
80
|
+
const storedChallenge = challengesRaw[0];
|
|
81
|
+
const opts = {
|
|
82
|
+
response,
|
|
83
|
+
expectedChallenge: storedChallenge.id,
|
|
84
|
+
expectedOrigin: this.origin,
|
|
85
|
+
expectedRPID: this.rpID,
|
|
86
|
+
};
|
|
87
|
+
try {
|
|
88
|
+
const verification = await (0, server_1.verifyRegistrationResponse)(opts);
|
|
89
|
+
if (verification.verified && verification.registrationInfo) {
|
|
90
|
+
// Store the credential in database
|
|
91
|
+
const { credential } = verification.registrationInfo;
|
|
92
|
+
// Extract transports from the original response
|
|
93
|
+
let transports = [];
|
|
94
|
+
if (response.response.transports) {
|
|
95
|
+
transports = response.response.transports;
|
|
96
|
+
}
|
|
97
|
+
else {
|
|
98
|
+
// Default to common transports if not specified
|
|
99
|
+
transports = ['internal', 'hybrid'];
|
|
100
|
+
}
|
|
101
|
+
await this.credentialRepo.insert({
|
|
102
|
+
records: [
|
|
103
|
+
{
|
|
104
|
+
// Use the original credential ID from the response
|
|
105
|
+
id: response.id,
|
|
106
|
+
account_id: account[this.accountIdColumn],
|
|
107
|
+
public_key: Buffer.from(credential.publicKey).toString('base64'),
|
|
108
|
+
counter: credential.counter,
|
|
109
|
+
transports: JSON.stringify(transports),
|
|
110
|
+
},
|
|
111
|
+
],
|
|
112
|
+
});
|
|
113
|
+
// Mark challenge as used
|
|
114
|
+
await this.challengeRepo.update({
|
|
115
|
+
set: { used: true },
|
|
116
|
+
where: { id: storedChallenge.id },
|
|
117
|
+
});
|
|
118
|
+
return {
|
|
119
|
+
verified: true,
|
|
120
|
+
registrationInfo: verification.registrationInfo,
|
|
121
|
+
};
|
|
122
|
+
}
|
|
123
|
+
return { verified: false };
|
|
124
|
+
}
|
|
125
|
+
catch (error) {
|
|
126
|
+
return { verified: false };
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
async generateAuthenticationOptions(userID) {
|
|
130
|
+
const options = {
|
|
131
|
+
rpID: this.rpID,
|
|
132
|
+
// Use preferred to allow both platform and cross-platform
|
|
133
|
+
userVerification: 'preferred',
|
|
134
|
+
};
|
|
135
|
+
if (userID) {
|
|
136
|
+
options.allowCredentials =
|
|
137
|
+
await this.getExistingCredentials(userID);
|
|
138
|
+
}
|
|
139
|
+
const authenticationOptions = await (0, server_1.generateAuthenticationOptions)(options);
|
|
140
|
+
// Store challenge for verification
|
|
141
|
+
if (userID) {
|
|
142
|
+
const expiresAt = new Date(Date.now() + 5 * 60 * 1000); // 5 minutes
|
|
143
|
+
await this.challengeRepo.insert({
|
|
144
|
+
records: [
|
|
145
|
+
{
|
|
146
|
+
id: authenticationOptions.challenge,
|
|
147
|
+
account_id: userID,
|
|
148
|
+
challenge_type: 'authentication',
|
|
149
|
+
expires: expiresAt,
|
|
150
|
+
used: false,
|
|
151
|
+
},
|
|
152
|
+
],
|
|
153
|
+
});
|
|
154
|
+
}
|
|
155
|
+
return authenticationOptions;
|
|
156
|
+
}
|
|
157
|
+
async createAccount(account) {
|
|
158
|
+
// Store account data first
|
|
159
|
+
const accountId = await super.createAccount(account);
|
|
160
|
+
// Create a account object with the ID for registration options
|
|
161
|
+
const accountWithId = {
|
|
162
|
+
...account,
|
|
163
|
+
[this.accountIdColumn]: accountId,
|
|
164
|
+
};
|
|
165
|
+
// Generate and return registration options for client
|
|
166
|
+
// Credential stored when verifyRegistration is called
|
|
167
|
+
await this.generateRegistrationOptions(accountWithId);
|
|
168
|
+
return accountId;
|
|
169
|
+
}
|
|
170
|
+
async authenticate(credentials) {
|
|
171
|
+
const { response, accountId } = credentials;
|
|
172
|
+
// Find the challenge from database
|
|
173
|
+
const challengesRaw = await this.challengeRepo.find({
|
|
174
|
+
where: {
|
|
175
|
+
account_id: accountId,
|
|
176
|
+
challenge_type: 'authentication',
|
|
177
|
+
used: false,
|
|
178
|
+
},
|
|
179
|
+
limit: 1,
|
|
180
|
+
});
|
|
181
|
+
if (challengesRaw.length === 0) {
|
|
182
|
+
return null;
|
|
183
|
+
}
|
|
184
|
+
const storedChallenge = challengesRaw[0];
|
|
185
|
+
// Get the authenticator credential
|
|
186
|
+
const authenticator = await this.getAuthenticatorByCredentialID(response.id);
|
|
187
|
+
if (authenticator === null) {
|
|
188
|
+
return null;
|
|
189
|
+
}
|
|
190
|
+
const opts = {
|
|
191
|
+
response,
|
|
192
|
+
expectedChallenge: storedChallenge.id,
|
|
193
|
+
expectedOrigin: this.origin,
|
|
194
|
+
expectedRPID: this.rpID,
|
|
195
|
+
credential: {
|
|
196
|
+
id: authenticator.id,
|
|
197
|
+
publicKey: Buffer.from(authenticator.public_key, 'base64'),
|
|
198
|
+
counter: authenticator.counter,
|
|
199
|
+
transports: [],
|
|
200
|
+
},
|
|
201
|
+
};
|
|
202
|
+
const verification = await (0, server_1.verifyAuthenticationResponse)(opts);
|
|
203
|
+
if (!verification.verified) {
|
|
204
|
+
return null;
|
|
205
|
+
}
|
|
206
|
+
// Update counter in database
|
|
207
|
+
await this.credentialRepo.update({
|
|
208
|
+
set: {
|
|
209
|
+
counter: verification.authenticationInfo.newCounter,
|
|
210
|
+
},
|
|
211
|
+
where: { id: authenticator.id },
|
|
212
|
+
});
|
|
213
|
+
// Mark challenge as used
|
|
214
|
+
await this.challengeRepo.update({
|
|
215
|
+
set: { used: true },
|
|
216
|
+
where: { id: storedChallenge.id },
|
|
217
|
+
});
|
|
218
|
+
// Retrieve and return the account
|
|
219
|
+
return await this.findActiveAccount({
|
|
220
|
+
where: {
|
|
221
|
+
[this.accountIdColumn]: accountId,
|
|
222
|
+
},
|
|
223
|
+
});
|
|
224
|
+
}
|
|
225
|
+
async getExistingCredentials(accountId) {
|
|
226
|
+
const credentials = await this.credentialRepo.find({
|
|
227
|
+
where: { account_id: accountId },
|
|
228
|
+
});
|
|
229
|
+
return credentials.map((cred) => {
|
|
230
|
+
let transports = [];
|
|
231
|
+
// Parse transports from stored JSON string
|
|
232
|
+
if (cred.transports) {
|
|
233
|
+
try {
|
|
234
|
+
const parsed = JSON.parse(cred.transports);
|
|
235
|
+
transports = Array.isArray(parsed) ? parsed : [];
|
|
236
|
+
}
|
|
237
|
+
catch (error) {
|
|
238
|
+
// Default to internal for platform authenticators
|
|
239
|
+
transports = ['internal'];
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
else {
|
|
243
|
+
// If no transports stored, use common transports
|
|
244
|
+
transports = ['internal', 'hybrid'];
|
|
245
|
+
}
|
|
246
|
+
return {
|
|
247
|
+
id: cred.id,
|
|
248
|
+
type: 'public-key',
|
|
249
|
+
transports,
|
|
250
|
+
};
|
|
251
|
+
});
|
|
252
|
+
}
|
|
253
|
+
async getAuthenticatorByCredentialID(credentialID) {
|
|
254
|
+
return await this.credentialRepo.findOne({
|
|
255
|
+
where: { id: credentialID },
|
|
256
|
+
});
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
exports.Fido2Authentication = Fido2Authentication;
|
|
260
|
+
//# sourceMappingURL=authentication-fido2.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"authentication-fido2.js","sourceRoot":"","sources":["../../../../src/authentication/authentication-fido2/authentication-fido2.ts"],"names":[],"mappings":";;;AAEA,gEAA4D;AAE5D,mDAcgC;AAoChC,MAAa,mBAEX,SAAQ,wCAA4B;IAClB,MAAM,CAAS;IACf,IAAI,CAAS;IACb,MAAM,CAAS;IAExB,cAAc,GAAG,sBAAsB,CAAC;IACxC,eAAe,GAAG,uBAAuB,CAAC;IAE1C,aAAa,CAAmC;IAChD,cAAc,CAA2C;IAEnE,YAAY,OAA6C;QACxD,KAAK,CAAC,OAAO,CAAC,CAAC;QAEf,IAAI,CAAC,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;QAC7B,IAAI,CAAC,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC;QACzB,IAAI,CAAC,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;QAE7B,IAAI,CAAC,aAAa,GAAG,OAAO,CAAC,EAAE,CAAC,kBAAkB,CAAkB;YACnE,KAAK,EAAE,IAAI,CAAC,cAAc;SAC1B,CAAC,CAAC;QAEH,IAAI,CAAC,cAAc;YAClB,OAAO,CAAC,EAAE,CAAC,kBAAkB,CAA0B;gBACtD,KAAK,EAAE,IAAI,CAAC,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A8B,CAC7C,YAAoB;QAEpB,OAAO,MAAM,IAAI,CAAC,cAAc,CAAC,OAAO,CAAC;YACxC,KAAK,EAAE,EAAE,EAAE,EAAE,YAAY,EAAE;SAC3B,CAAC,CAAC;IACJ,CAAC;CACD;AAvUD,kDAuUC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { Fido2Authentication } from './authentication-fido2';
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Fido2Authentication = void 0;
|
|
4
|
+
var authentication_fido2_1 = require("./authentication-fido2");
|
|
5
|
+
Object.defineProperty(exports, "Fido2Authentication", { enumerable: true, get: function () { return authentication_fido2_1.Fido2Authentication; } });
|
|
6
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/authentication/authentication-fido2/index.ts"],"names":[],"mappings":";;;AAAA,+DAA6D;AAApD,2HAAA,mBAAmB,OAAA"}
|
|
@@ -0,0 +1,61 @@
|
|
|
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
|
|
@@ -0,0 +1 @@
|
|
|
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"}
|