nodecommons-esm-security 0.0.2
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/dist/helpers/commons-hash.d.mts +6 -0
- package/dist/helpers/commons-hash.mjs +29 -0
- package/dist/helpers/commons-hash.mjs.map +1 -0
- package/dist/index.d.mts +7 -0
- package/dist/index.mjs +8 -0
- package/dist/index.mjs.map +1 -0
- package/dist/interfaces/icommons-user-pw-hash.d.mts +6 -0
- package/dist/interfaces/icommons-user-pw-hash.mjs +12 -0
- package/dist/interfaces/icommons-user-pw-hash.mjs.map +1 -0
- package/dist/services/commons-session.service.d.mts +12 -0
- package/dist/services/commons-session.service.mjs +49 -0
- package/dist/services/commons-session.service.mjs.map +1 -0
- package/dist/services/commons-simple-single-pw-session.service.d.mts +13 -0
- package/dist/services/commons-simple-single-pw-session.service.mjs +20 -0
- package/dist/services/commons-simple-single-pw-session.service.mjs.map +1 -0
- package/dist/services/commons-user-pw-hash-session.service.d.mts +9 -0
- package/dist/services/commons-user-pw-hash-session.service.mjs +26 -0
- package/dist/services/commons-user-pw-hash-session.service.mjs.map +1 -0
- package/dist/services/commons-user-session.service.d.mts +9 -0
- package/dist/services/commons-user-session.service.mjs +25 -0
- package/dist/services/commons-user-session.service.mjs.map +1 -0
- package/package.json +32 -0
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export declare function commonsHashMd5(data: string | Buffer): string;
|
|
2
|
+
export declare function commonsHashSha1(data: string | Buffer): string;
|
|
3
|
+
export declare function commonsHashSha256(data: string | Buffer): string;
|
|
4
|
+
export declare function commonsHashRandomMd5(iterations?: number): string;
|
|
5
|
+
export declare function commonsHashRandomSha1(iterations?: number): string;
|
|
6
|
+
export declare function commonsHashRandomSha256(iterations?: number): string;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import * as crypto from 'crypto';
|
|
2
|
+
export function commonsHashMd5(data) {
|
|
3
|
+
return crypto.createHash('md5').update(data).digest('hex');
|
|
4
|
+
}
|
|
5
|
+
export function commonsHashSha1(data) {
|
|
6
|
+
return crypto.createHash('sha1').update(data).digest('hex');
|
|
7
|
+
}
|
|
8
|
+
export function commonsHashSha256(data) {
|
|
9
|
+
return crypto.createHash('sha256').update(data).digest('hex');
|
|
10
|
+
}
|
|
11
|
+
function generateRandomData(iterations = 10000) {
|
|
12
|
+
const rands = [new Date().getTime()];
|
|
13
|
+
for (let i = iterations; i-- > 0;) {
|
|
14
|
+
rands.push(Math.random());
|
|
15
|
+
}
|
|
16
|
+
return rands
|
|
17
|
+
.map((rand) => rand.toString(36))
|
|
18
|
+
.join('');
|
|
19
|
+
}
|
|
20
|
+
export function commonsHashRandomMd5(iterations = 10000) {
|
|
21
|
+
return commonsHashMd5(generateRandomData(iterations));
|
|
22
|
+
}
|
|
23
|
+
export function commonsHashRandomSha1(iterations = 10000) {
|
|
24
|
+
return commonsHashSha1(generateRandomData(iterations));
|
|
25
|
+
}
|
|
26
|
+
export function commonsHashRandomSha256(iterations = 10000) {
|
|
27
|
+
return commonsHashSha256(generateRandomData(iterations));
|
|
28
|
+
}
|
|
29
|
+
//# sourceMappingURL=commons-hash.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"commons-hash.mjs","sourceRoot":"","sources":["../../src/helpers/commons-hash.mts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,MAAM,QAAQ,CAAC;AAEjC,MAAM,UAAU,cAAc,CAAC,IAAmB;IACjD,OAAO,MAAM,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;AAC5D,CAAC;AAED,MAAM,UAAU,eAAe,CAAC,IAAmB;IAClD,OAAO,MAAM,CAAC,UAAU,CAAC,MAAM,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;AAC7D,CAAC;AAED,MAAM,UAAU,iBAAiB,CAAC,IAAmB;IACpD,OAAO,MAAM,CAAC,UAAU,CAAC,QAAQ,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;AAC/D,CAAC;AAED,SAAS,kBAAkB,CAAC,aAAqB,KAAK;IACrD,MAAM,KAAK,GAAa,CAAE,IAAI,IAAI,EAAE,CAAC,OAAO,EAAE,CAAE,CAAC;IACjD,KAAK,IAAI,CAAC,GAAG,UAAU,EAAE,CAAC,EAAE,GAAG,CAAC,GAAG,CAAC;QACnC,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,MAAM,EAAE,CAAC,CAAC;IAC3B,CAAC;IAED,OAAO,KAAK;SACT,GAAG,CAAC,CAAC,IAAY,EAAU,EAAE,CAAC,IAAI,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC;SAChD,IAAI,CAAC,EAAE,CAAC,CAAC;AACb,CAAC;AAED,MAAM,UAAU,oBAAoB,CAAC,aAAqB,KAAK;IAC9D,OAAO,cAAc,CAAC,kBAAkB,CAAC,UAAU,CAAC,CAAC,CAAC;AACvD,CAAC;AAED,MAAM,UAAU,qBAAqB,CAAC,aAAqB,KAAK;IAC/D,OAAO,eAAe,CAAC,kBAAkB,CAAC,UAAU,CAAC,CAAC,CAAC;AACxD,CAAC;AAED,MAAM,UAAU,uBAAuB,CAAC,aAAqB,KAAK;IACjE,OAAO,iBAAiB,CAAC,kBAAkB,CAAC,UAAU,CAAC,CAAC,CAAC;AAC1D,CAAC"}
|
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { commonsHashMd5, commonsHashSha1, commonsHashSha256, commonsHashRandomMd5, commonsHashRandomSha1, commonsHashRandomSha256 } from './helpers/commons-hash.mjs';
|
|
2
|
+
import { CommonsSimpleSinglePwSessionService } from './services/commons-simple-single-pw-session.service.mjs';
|
|
3
|
+
import { CommonsSessionService } from './services/commons-session.service.mjs';
|
|
4
|
+
import { CommonsUserPwHashSessionService } from './services/commons-user-pw-hash-session.service.mjs';
|
|
5
|
+
import { CommonsUserSessionService } from './services/commons-user-session.service.mjs';
|
|
6
|
+
import { ICommonsUserPwHash, isICommonsUserPwHash } from './interfaces/icommons-user-pw-hash.mjs';
|
|
7
|
+
export { commonsHashMd5, commonsHashSha1, commonsHashSha256, commonsHashRandomMd5, commonsHashRandomSha1, commonsHashRandomSha256, CommonsSimpleSinglePwSessionService, CommonsSessionService, CommonsUserPwHashSessionService, CommonsUserSessionService, ICommonsUserPwHash, isICommonsUserPwHash };
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { commonsHashMd5, commonsHashSha1, commonsHashSha256, commonsHashRandomMd5, commonsHashRandomSha1, commonsHashRandomSha256 } from './helpers/commons-hash.mjs';
|
|
2
|
+
import { CommonsSimpleSinglePwSessionService } from './services/commons-simple-single-pw-session.service.mjs';
|
|
3
|
+
import { CommonsSessionService } from './services/commons-session.service.mjs';
|
|
4
|
+
import { CommonsUserPwHashSessionService } from './services/commons-user-pw-hash-session.service.mjs';
|
|
5
|
+
import { CommonsUserSessionService } from './services/commons-user-session.service.mjs';
|
|
6
|
+
import { isICommonsUserPwHash } from './interfaces/icommons-user-pw-hash.mjs';
|
|
7
|
+
export { commonsHashMd5, commonsHashSha1, commonsHashSha256, commonsHashRandomMd5, commonsHashRandomSha1, commonsHashRandomSha256, CommonsSimpleSinglePwSessionService, CommonsSessionService, CommonsUserPwHashSessionService, CommonsUserSessionService, isICommonsUserPwHash };
|
|
8
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.mjs","sourceRoot":"","sources":["../src/index.mts"],"names":[],"mappings":"AAAA,OAAO,EACL,cAAc,EACd,eAAe,EACf,iBAAiB,EACjB,oBAAoB,EACpB,qBAAqB,EACrB,uBAAuB,EACxB,MAAM,4BAA4B,CAAC;AACpC,OAAO,EAAE,mCAAmC,EAAE,MAAM,yDAAyD,CAAC;AAC9G,OAAO,EAAE,qBAAqB,EAAE,MAAM,wCAAwC,CAAC;AAC/E,OAAO,EAAE,+BAA+B,EAAE,MAAM,qDAAqD,CAAC;AACtG,OAAO,EAAE,yBAAyB,EAAE,MAAM,6CAA6C,CAAC;AACxF,OAAO,EAAsB,oBAAoB,EAAE,MAAM,wCAAwC,CAAC;AAClG,OAAO,EACN,cAAc,EACd,eAAe,EACf,iBAAiB,EACjB,oBAAoB,EACpB,qBAAqB,EACrB,uBAAuB,EACvB,mCAAmC,EACnC,qBAAqB,EACrB,+BAA+B,EAC/B,yBAAyB,EAEzB,oBAAoB,EACpB,CAAC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { commonsTypeHasPropertyString } from 'tscommons-esm-core';
|
|
2
|
+
import { isICommonsUser } from 'tscommons-esm-session';
|
|
3
|
+
export function isICommonsUserPwHash(test) {
|
|
4
|
+
if (!isICommonsUser(test))
|
|
5
|
+
return false;
|
|
6
|
+
if (!commonsTypeHasPropertyString(test, 'pwHash'))
|
|
7
|
+
return false;
|
|
8
|
+
if (!commonsTypeHasPropertyString(test, 'salt'))
|
|
9
|
+
return false;
|
|
10
|
+
return true;
|
|
11
|
+
}
|
|
12
|
+
//# sourceMappingURL=icommons-user-pw-hash.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"icommons-user-pw-hash.mjs","sourceRoot":"","sources":["../../src/interfaces/icommons-user-pw-hash.mts"],"names":[],"mappings":"AAAA,OAAO,EAAE,4BAA4B,EAAE,MAAM,oBAAoB,CAAC;AAClE,OAAO,EAAgB,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAOrE,MAAM,UAAU,oBAAoB,CAClC,IAAa;IAEd,IAAI,CAAC,cAAc,CAAC,IAAI,CAAC;QAAE,OAAO,KAAK,CAAC;IAExC,IAAI,CAAC,4BAA4B,CAAC,IAAI,EAAE,QAAQ,CAAC;QAAE,OAAO,KAAK,CAAC;IAChE,IAAI,CAAC,4BAA4B,CAAC,IAAI,EAAE,MAAM,CAAC;QAAE,OAAO,KAAK,CAAC;IAE9D,OAAO,IAAI,CAAC;AACb,CAAC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { ICommonsSession } from 'tscommons-esm-session';
|
|
2
|
+
export declare abstract class CommonsSessionService<T> {
|
|
3
|
+
private allowMultipleSessionsForSameUser;
|
|
4
|
+
private sessions;
|
|
5
|
+
constructor(allowMultipleSessionsForSameUser?: boolean);
|
|
6
|
+
protected abstract isEqual(a: T, b: T): boolean;
|
|
7
|
+
protected abstract isStillValid(data: T): Promise<boolean>;
|
|
8
|
+
create(data: T): ICommonsSession<T>;
|
|
9
|
+
destroy(session: ICommonsSession<T>): boolean;
|
|
10
|
+
abort(data: T): boolean;
|
|
11
|
+
validate(sid: string): Promise<ICommonsSession<T> | undefined>;
|
|
12
|
+
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { commonsHashRandomSha256 } from '../helpers/commons-hash.mjs';
|
|
2
|
+
export class CommonsSessionService {
|
|
3
|
+
allowMultipleSessionsForSameUser;
|
|
4
|
+
sessions = [];
|
|
5
|
+
constructor(allowMultipleSessionsForSameUser = false) {
|
|
6
|
+
this.allowMultipleSessionsForSameUser = allowMultipleSessionsForSameUser;
|
|
7
|
+
}
|
|
8
|
+
create(data) {
|
|
9
|
+
if (!this.allowMultipleSessionsForSameUser)
|
|
10
|
+
this.abort(data); // clear out any existing sessions for the same user
|
|
11
|
+
const session = {
|
|
12
|
+
sid: commonsHashRandomSha256(),
|
|
13
|
+
start: new Date(),
|
|
14
|
+
last: new Date(),
|
|
15
|
+
data: data
|
|
16
|
+
};
|
|
17
|
+
this.sessions.push(session);
|
|
18
|
+
return session;
|
|
19
|
+
}
|
|
20
|
+
destroy(session) {
|
|
21
|
+
const match = this.sessions
|
|
22
|
+
.find((s) => s.sid === session.sid);
|
|
23
|
+
if (!match)
|
|
24
|
+
return false;
|
|
25
|
+
this.sessions = this.sessions
|
|
26
|
+
.filter((s) => s.sid !== session.sid);
|
|
27
|
+
return true;
|
|
28
|
+
}
|
|
29
|
+
abort(data) {
|
|
30
|
+
const existing = this.sessions
|
|
31
|
+
.find((s) => this.isEqual(data, s.data));
|
|
32
|
+
if (!existing)
|
|
33
|
+
return false;
|
|
34
|
+
this.destroy(existing);
|
|
35
|
+
return true;
|
|
36
|
+
}
|
|
37
|
+
async validate(sid) {
|
|
38
|
+
const session = this.sessions
|
|
39
|
+
.find((s) => s.sid === sid);
|
|
40
|
+
if (!session)
|
|
41
|
+
return undefined;
|
|
42
|
+
if (!(await this.isStillValid(session.data))) {
|
|
43
|
+
this.destroy(session);
|
|
44
|
+
return undefined;
|
|
45
|
+
}
|
|
46
|
+
return session;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
//# sourceMappingURL=commons-session.service.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"commons-session.service.mjs","sourceRoot":"","sources":["../../src/services/commons-session.service.mts"],"names":[],"mappings":"AAEA,OAAO,EAAE,uBAAuB,EAAE,MAAM,6BAA6B,CAAC;AAEtE,MAAM,OAAgB,qBAAqB;IAIhC;IAHF,QAAQ,GAAyB,EAAE,CAAC;IAE5C,YACU,mCAA4C,KAAK;QAAjD,qCAAgC,GAAhC,gCAAgC,CAAiB;IACxD,CAAC;IAKG,MAAM,CAAC,IAAO;QACpB,IAAI,CAAC,IAAI,CAAC,gCAAgC;YAAE,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,oDAAoD;QAElH,MAAM,OAAO,GAAuB;YAClC,GAAG,EAAE,uBAAuB,EAAE;YAC9B,KAAK,EAAE,IAAI,IAAI,EAAE;YACjB,IAAI,EAAE,IAAI,IAAI,EAAE;YAChB,IAAI,EAAE,IAAI;SACX,CAAC;QAEF,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;QAE5B,OAAO,OAAO,CAAC;IAChB,CAAC;IAEM,OAAO,CAAC,OAA2B;QACzC,MAAM,KAAK,GAAiC,IAAI,CAAC,QAAQ;aACtD,IAAI,CAAC,CAAC,CAAqB,EAAW,EAAE,CAAC,CAAC,CAAC,GAAG,KAAK,OAAO,CAAC,GAAG,CAAC,CAAC;QACnE,IAAI,CAAC,KAAK;YAAE,OAAO,KAAK,CAAC;QAEzB,IAAI,CAAC,QAAQ,GAAG,IAAI,CAAC,QAAQ;aAC1B,MAAM,CAAC,CAAC,CAAqB,EAAW,EAAE,CAAC,CAAC,CAAC,GAAG,KAAK,OAAO,CAAC,GAAG,CAAC,CAAC;QAErE,OAAO,IAAI,CAAC;IACb,CAAC;IAEM,KAAK,CAAC,IAAO;QACnB,MAAM,QAAQ,GAAiC,IAAI,CAAC,QAAQ;aACzD,IAAI,CAAC,CAAC,CAAqB,EAAW,EAAE,CAAC,IAAI,CAAC,OAAO,CAAC,IAAI,EAAE,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC;QACxE,IAAI,CAAC,QAAQ;YAAE,OAAO,KAAK,CAAC;QAE5B,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC;QACvB,OAAO,IAAI,CAAC;IACb,CAAC;IAEM,KAAK,CAAC,QAAQ,CAAC,GAAW;QAChC,MAAM,OAAO,GAAiC,IAAI,CAAC,QAAQ;aACxD,IAAI,CAAC,CAAC,CAAqB,EAAW,EAAE,CAAC,CAAC,CAAC,GAAG,KAAK,GAAG,CAAC,CAAC;QAE3D,IAAI,CAAC,OAAO;YAAE,OAAO,SAAS,CAAC;QAE/B,IAAI,CAAC,CAAC,MAAM,IAAI,CAAC,YAAY,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,EAAE,CAAC;YAC9C,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;YACtB,OAAO,SAAS,CAAC;QAClB,CAAC;QAED,OAAO,OAAO,CAAC;IAChB,CAAC;CACD"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { ICommonsSession } from 'tscommons-esm-session';
|
|
2
|
+
import { CommonsSessionService } from './commons-session.service.mjs';
|
|
3
|
+
type TEmptyObject = {
|
|
4
|
+
[key: string]: never;
|
|
5
|
+
};
|
|
6
|
+
export declare class CommonsSimpleSinglePwSessionService extends CommonsSessionService<TEmptyObject> {
|
|
7
|
+
private password;
|
|
8
|
+
constructor(password: string);
|
|
9
|
+
protected isEqual(_a: TEmptyObject, _b: TEmptyObject): boolean;
|
|
10
|
+
protected isStillValid(_user: TEmptyObject): Promise<boolean>;
|
|
11
|
+
authenticate(password: string): ICommonsSession<TEmptyObject> | undefined;
|
|
12
|
+
}
|
|
13
|
+
export {};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { CommonsSessionService } from './commons-session.service.mjs';
|
|
2
|
+
export class CommonsSimpleSinglePwSessionService extends CommonsSessionService {
|
|
3
|
+
password;
|
|
4
|
+
constructor(password) {
|
|
5
|
+
super(true);
|
|
6
|
+
this.password = password;
|
|
7
|
+
}
|
|
8
|
+
isEqual(_a, _b) {
|
|
9
|
+
return true;
|
|
10
|
+
}
|
|
11
|
+
async isStillValid(_user) {
|
|
12
|
+
return true;
|
|
13
|
+
}
|
|
14
|
+
authenticate(password) {
|
|
15
|
+
if (password !== this.password)
|
|
16
|
+
return undefined;
|
|
17
|
+
return this.create({});
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
//# sourceMappingURL=commons-simple-single-pw-session.service.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"commons-simple-single-pw-session.service.mjs","sourceRoot":"","sources":["../../src/services/commons-simple-single-pw-session.service.mts"],"names":[],"mappings":"AAEA,OAAO,EAAE,qBAAqB,EAAE,MAAM,+BAA+B,CAAC;AAItE,MAAM,OAAO,mCAAoC,SAAQ,qBAAmC;IAEjF;IADV,YACU,QAAgB;QAEzB,KAAK,CAAC,IAAI,CAAC,CAAC;QAFH,aAAQ,GAAR,QAAQ,CAAQ;IAG1B,CAAC;IAES,OAAO,CAAC,EAAgB,EAAE,EAAgB;QACnD,OAAO,IAAI,CAAC;IACb,CAAC;IAES,KAAK,CAAC,YAAY,CAAC,KAAmB;QAC/C,OAAO,IAAI,CAAC;IACb,CAAC;IAEM,YAAY,CAAC,QAAgB;QACnC,IAAI,QAAQ,KAAK,IAAI,CAAC,QAAQ;YAAE,OAAO,SAAS,CAAC;QAEjD,OAAO,IAAI,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC;IACxB,CAAC;CACD"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { ICommonsSession } from 'tscommons-esm-session';
|
|
2
|
+
import { ICommonsUserPwHash } from '../interfaces/icommons-user-pw-hash.mjs';
|
|
3
|
+
import { CommonsUserSessionService } from './commons-user-session.service.mjs';
|
|
4
|
+
export declare class CommonsUserPwHashSessionService<T extends ICommonsUserPwHash> extends CommonsUserSessionService<T> {
|
|
5
|
+
private pepper?;
|
|
6
|
+
constructor(pepper?: string | undefined, allowMultipleSessionsForSameUser?: boolean);
|
|
7
|
+
generatePwHash(pw: string, salt: string): string;
|
|
8
|
+
authenticateWithPwHash(user: T, pw: string): ICommonsSession<T> | undefined;
|
|
9
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { commonsHashSha256 } from '../helpers/commons-hash.mjs';
|
|
2
|
+
import { CommonsUserSessionService } from './commons-user-session.service.mjs';
|
|
3
|
+
export class CommonsUserPwHashSessionService extends CommonsUserSessionService {
|
|
4
|
+
pepper;
|
|
5
|
+
constructor(pepper, allowMultipleSessionsForSameUser = false) {
|
|
6
|
+
super(allowMultipleSessionsForSameUser);
|
|
7
|
+
this.pepper = pepper;
|
|
8
|
+
}
|
|
9
|
+
generatePwHash(pw, salt) {
|
|
10
|
+
const components = [
|
|
11
|
+
salt,
|
|
12
|
+
this.pepper || '',
|
|
13
|
+
pw
|
|
14
|
+
];
|
|
15
|
+
return commonsHashSha256(components.join(''));
|
|
16
|
+
}
|
|
17
|
+
authenticateWithPwHash(user, pw) {
|
|
18
|
+
const compare = this.generatePwHash(pw, user.salt);
|
|
19
|
+
if (user.pwHash !== compare) {
|
|
20
|
+
// don't abort existing sessions for subsequent failed logins
|
|
21
|
+
return undefined;
|
|
22
|
+
}
|
|
23
|
+
return this.authenticate(user);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
//# sourceMappingURL=commons-user-pw-hash-session.service.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"commons-user-pw-hash-session.service.mjs","sourceRoot":"","sources":["../../src/services/commons-user-pw-hash-session.service.mts"],"names":[],"mappings":"AAEA,OAAO,EAAE,iBAAiB,EAAE,MAAM,6BAA6B,CAAC;AAIhE,OAAO,EAAE,yBAAyB,EAAE,MAAM,oCAAoC,CAAC;AAE/E,MAAM,OAAO,+BAA8D,SAAQ,yBAA4B;IAEpG;IADV,YACU,MAAe,EACvB,mCAA4C,KAAK;QAElD,KAAK,CAAC,gCAAgC,CAAC,CAAC;QAH/B,WAAM,GAAN,MAAM,CAAS;IAIzB,CAAC;IAEM,cAAc,CAAC,EAAU,EAAE,IAAY;QAC7C,MAAM,UAAU,GAAa;YAC3B,IAAI;YACJ,IAAI,CAAC,MAAM,IAAI,EAAE;YACjB,EAAE;SACH,CAAC;QAEF,OAAO,iBAAiB,CAAC,UAAU,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC,CAAC;IAC/C,CAAC;IAEM,sBAAsB,CAAC,IAAO,EAAE,EAAU;QAChD,MAAM,OAAO,GAAW,IAAI,CAAC,cAAc,CAAC,EAAE,EAAE,IAAI,CAAC,IAAI,CAAC,CAAC;QAE3D,IAAI,IAAI,CAAC,MAAM,KAAK,OAAO,EAAE,CAAC;YAC7B,6DAA6D;YAC7D,OAAO,SAAS,CAAC;QAClB,CAAC;QAED,OAAO,IAAI,CAAC,YAAY,CAAC,IAAI,CAAC,CAAC;IAChC,CAAC;CACD"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { ICommonsSession } from 'tscommons-esm-session';
|
|
2
|
+
import { ICommonsUser } from 'tscommons-esm-session';
|
|
3
|
+
import { CommonsSessionService } from './commons-session.service.mjs';
|
|
4
|
+
export declare abstract class CommonsUserSessionService<T extends ICommonsUser> extends CommonsSessionService<T> {
|
|
5
|
+
constructor(allowMultipleSessionsForSameUser?: boolean);
|
|
6
|
+
protected isEqual(a: T, b: T): boolean;
|
|
7
|
+
protected isStillValid(user: T): Promise<boolean>;
|
|
8
|
+
authenticate(user: T): ICommonsSession<T> | undefined;
|
|
9
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { CommonsSessionService } from './commons-session.service.mjs';
|
|
2
|
+
export class CommonsUserSessionService extends CommonsSessionService {
|
|
3
|
+
constructor(allowMultipleSessionsForSameUser = false) {
|
|
4
|
+
super(allowMultipleSessionsForSameUser);
|
|
5
|
+
}
|
|
6
|
+
isEqual(a, b) {
|
|
7
|
+
if (a.username !== b.username)
|
|
8
|
+
return false;
|
|
9
|
+
return true;
|
|
10
|
+
}
|
|
11
|
+
async isStillValid(user) {
|
|
12
|
+
if (!user.enabled)
|
|
13
|
+
return false;
|
|
14
|
+
return true;
|
|
15
|
+
}
|
|
16
|
+
authenticate(user) {
|
|
17
|
+
if (!user.enabled) {
|
|
18
|
+
// if an account is disabled, abort any existing sessions
|
|
19
|
+
this.abort(user);
|
|
20
|
+
return undefined;
|
|
21
|
+
}
|
|
22
|
+
return this.create(user);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
//# sourceMappingURL=commons-user-session.service.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"commons-user-session.service.mjs","sourceRoot":"","sources":["../../src/services/commons-user-session.service.mts"],"names":[],"mappings":"AAGA,OAAO,EAAE,qBAAqB,EAAE,MAAM,+BAA+B,CAAC;AAEtE,MAAM,OAAgB,yBAAkD,SAAQ,qBAAwB;IACvG,YACE,mCAA4C,KAAK;QAElD,KAAK,CAAC,gCAAgC,CAAC,CAAC;IACzC,CAAC;IAES,OAAO,CAAC,CAAI,EAAE,CAAI;QAC3B,IAAI,CAAC,CAAC,QAAQ,KAAK,CAAC,CAAC,QAAQ;YAAE,OAAO,KAAK,CAAC;QAE5C,OAAO,IAAI,CAAC;IACb,CAAC;IAES,KAAK,CAAC,YAAY,CAAC,IAAO;QACnC,IAAI,CAAC,IAAI,CAAC,OAAO;YAAE,OAAO,KAAK,CAAC;QAEhC,OAAO,IAAI,CAAC;IACb,CAAC;IAEM,YAAY,CAAC,IAAO;QAC1B,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE,CAAC;YACnB,yDAAyD;YAEzD,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;YACjB,OAAO,SAAS,CAAC;QAClB,CAAC;QAED,OAAO,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;IAC1B,CAAC;CACD"}
|
package/package.json
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "nodecommons-esm-security",
|
|
3
|
+
"version": "0.0.2",
|
|
4
|
+
"description": "",
|
|
5
|
+
"scripts": {
|
|
6
|
+
"tsc": "./node_modules/typescript/bin/tsc",
|
|
7
|
+
"preprepare": "rm -rf ./dist; php ~/Dev/etim.php src/ && npm run tsc",
|
|
8
|
+
"publish-major": "rm -rf dist; npm run tsc && npx eslint . && npm run preprepare && npm version major && npm install && npm publish && git add . && git commit -m 'publish'",
|
|
9
|
+
"publish-minor": "rm -rf dist; npm run tsc && npx eslint . && npm run preprepare && npm version minor && npm install && npm publish && git add . && git commit -m 'publish'",
|
|
10
|
+
"publish-patch": "rm -rf dist; npm run tsc && npx eslint . && npm run preprepare && npm version patch && npm install && npm publish && git add . && git commit -m 'publish'"
|
|
11
|
+
},
|
|
12
|
+
"main": "dist/index.mjs",
|
|
13
|
+
"types": "dist/index.d.mjs",
|
|
14
|
+
"type": "module",
|
|
15
|
+
"author": "Pete Morris",
|
|
16
|
+
"license": "ISC",
|
|
17
|
+
"devDependencies": {
|
|
18
|
+
"@stylistic/eslint-plugin-ts": "^2.10.1",
|
|
19
|
+
"@types/node": "^22.9.0",
|
|
20
|
+
"eslint-plugin-import": "^2.31.0",
|
|
21
|
+
"eslint-plugin-prefer-arrow-functions": "^3.4.1",
|
|
22
|
+
"typescript": "^5.6.3",
|
|
23
|
+
"typescript-eslint": "^8.14.0"
|
|
24
|
+
},
|
|
25
|
+
"files": [
|
|
26
|
+
"dist/**/*"
|
|
27
|
+
],
|
|
28
|
+
"dependencies": {
|
|
29
|
+
"tscommons-esm-core": "^0.0.2",
|
|
30
|
+
"tscommons-esm-session": "^0.0.2"
|
|
31
|
+
}
|
|
32
|
+
}
|