@riao/iam 4.0.0 → 5.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 +1 -1
- package/authentication/authentication.d.ts +3 -0
- package/authentication/authentication.js.map +1 -1
- package/authentication/errors.d.ts +7 -0
- package/authentication/errors.js +20 -0
- package/authentication/errors.js.map +1 -0
- package/authentication/index.d.ts +1 -0
- package/authentication/index.js +4 -1
- package/authentication/index.js.map +1 -1
- package/authorization/authorization.d.ts +14 -6
- package/authorization/authorization.js.map +1 -1
- package/authorization/index.d.ts +1 -1
- package/authorization/index.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -71,7 +71,7 @@ class PasswordAuthentication extends Authentication<Principal> {
|
|
|
71
71
|
|
|
72
72
|
// Implement the isActiveQuery if needed for custom active status logic
|
|
73
73
|
protected isActiveQuery() {
|
|
74
|
-
return {
|
|
74
|
+
return { deactivate_timestamp: null };
|
|
75
75
|
}
|
|
76
76
|
}
|
|
77
77
|
|
|
@@ -11,6 +11,9 @@ export declare abstract class Authentication<TPrincipal extends Principal> exten
|
|
|
11
11
|
protected recordAuthenticationFailure(attempt: AuthenticationAttempt): Promise<void>;
|
|
12
12
|
protected recordAuthenticationSuccess(attempt: AuthenticationAttempt): Promise<void>;
|
|
13
13
|
createPrincipal(principal: Omit<TPrincipal, 'id' | 'create_timestamp'>): Promise<DatabaseRecordId>;
|
|
14
|
+
/**
|
|
15
|
+
* Return an active principal or null for ordinary credential rejection.
|
|
16
|
+
*/
|
|
14
17
|
abstract authenticate(credentials: any): Promise<TPrincipal | null>;
|
|
15
18
|
findActivePrincipal(query: SelectQuery<TPrincipal>): Promise<TPrincipal | null>;
|
|
16
19
|
deactivatePrincipal(principalId: DatabaseRecordId): Promise<void>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"authentication.js","sourceRoot":"","sources":["../../../src/authentication/authentication.ts"],"names":[],"mappings":";;;AAAA,qC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,aAAa;QACtB,OAAO;YACN,oBAAoB,EAAE,IAAI;SACM,CAAC;IACnC,CAAC;CACD;AAjFD,wCAiFC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export declare class AuthenticationRejectedError extends Error {
|
|
2
|
+
constructor(message?: string);
|
|
3
|
+
}
|
|
4
|
+
export declare class AuthenticationBlockedError extends AuthenticationRejectedError {
|
|
5
|
+
readonly retryAfterSeconds?: number | undefined;
|
|
6
|
+
constructor(retryAfterSeconds?: number | undefined);
|
|
7
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.AuthenticationBlockedError = exports.AuthenticationRejectedError = void 0;
|
|
4
|
+
class AuthenticationRejectedError extends Error {
|
|
5
|
+
constructor(message = 'Authentication rejected') {
|
|
6
|
+
super(message);
|
|
7
|
+
this.name = 'AuthenticationRejectedError';
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
exports.AuthenticationRejectedError = AuthenticationRejectedError;
|
|
11
|
+
class AuthenticationBlockedError extends AuthenticationRejectedError {
|
|
12
|
+
retryAfterSeconds;
|
|
13
|
+
constructor(retryAfterSeconds) {
|
|
14
|
+
super('Authentication temporarily unavailable');
|
|
15
|
+
this.retryAfterSeconds = retryAfterSeconds;
|
|
16
|
+
this.name = 'AuthenticationBlockedError';
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
exports.AuthenticationBlockedError = AuthenticationBlockedError;
|
|
20
|
+
//# sourceMappingURL=errors.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../../../src/authentication/errors.ts"],"names":[],"mappings":";;;AAAA,MAAa,2BAA4B,SAAQ,KAAK;IACrD,YAAmB,OAAO,GAAG,yBAAyB;QACrD,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,6BAA6B,CAAC;IAC3C,CAAC;CACD;AALD,kEAKC;AAED,MAAa,0BAA2B,SAAQ,2BAA2B;IACvC;IAAnC,YAAmC,iBAA0B;QAC5D,KAAK,CAAC,wCAAwC,CAAC,CAAC;QADd,sBAAiB,GAAjB,iBAAiB,CAAS;QAE5D,IAAI,CAAC,IAAI,GAAG,4BAA4B,CAAC;IAC1C,CAAC;CACD;AALD,gEAKC"}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
1
|
export { Authentication } from './authentication';
|
|
2
2
|
export { AuthenticationOptions } from './authentication';
|
|
3
|
+
export { AuthenticationRejectedError, AuthenticationBlockedError, } from './errors';
|
|
3
4
|
export { AuthenticationAttempt, AuthenticationProtection, AuthenticationProtectionResult, NoopAuthenticationProtection, } from './protection';
|
package/authentication/index.js
CHANGED
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.NoopAuthenticationProtection = exports.Authentication = void 0;
|
|
3
|
+
exports.NoopAuthenticationProtection = exports.AuthenticationBlockedError = exports.AuthenticationRejectedError = exports.Authentication = void 0;
|
|
4
4
|
var authentication_1 = require("./authentication");
|
|
5
5
|
Object.defineProperty(exports, "Authentication", { enumerable: true, get: function () { return authentication_1.Authentication; } });
|
|
6
|
+
var errors_1 = require("./errors");
|
|
7
|
+
Object.defineProperty(exports, "AuthenticationRejectedError", { enumerable: true, get: function () { return errors_1.AuthenticationRejectedError; } });
|
|
8
|
+
Object.defineProperty(exports, "AuthenticationBlockedError", { enumerable: true, get: function () { return errors_1.AuthenticationBlockedError; } });
|
|
6
9
|
var protection_1 = require("./protection");
|
|
7
10
|
Object.defineProperty(exports, "NoopAuthenticationProtection", { enumerable: true, get: function () { return protection_1.NoopAuthenticationProtection; } });
|
|
8
11
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/authentication/index.ts"],"names":[],"mappings":";;;AAAA,mDAAkD;AAAzC,gHAAA,cAAc,OAAA;AAEvB,2CAKsB;AADrB,0HAAA,4BAA4B,OAAA"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/authentication/index.ts"],"names":[],"mappings":";;;AAAA,mDAAkD;AAAzC,gHAAA,cAAc,OAAA;AAEvB,mCAGkB;AAFjB,qHAAA,2BAA2B,OAAA;AAC3B,oHAAA,0BAA0B,OAAA;AAE3B,2CAKsB;AADrB,0HAAA,4BAA4B,OAAA"}
|
|
@@ -1,16 +1,24 @@
|
|
|
1
1
|
import { DatabaseRecordId } from '@riao/dbal';
|
|
2
2
|
import { Auth, AuthOptions, Principal } from '../auth';
|
|
3
3
|
export type AuthorizationOptions = AuthOptions;
|
|
4
|
-
export interface
|
|
5
|
-
|
|
4
|
+
export interface AuthorizationSubject {
|
|
5
|
+
id: string;
|
|
6
|
+
}
|
|
7
|
+
export interface AuthorizationRequirement {
|
|
6
8
|
resource?: string | Record<string, unknown>;
|
|
7
9
|
action: string;
|
|
8
10
|
metadata?: Record<string, unknown>;
|
|
9
11
|
}
|
|
12
|
+
export interface AuthorizationContext<TSubject extends AuthorizationSubject = Principal> extends AuthorizationRequirement {
|
|
13
|
+
principal: TSubject;
|
|
14
|
+
}
|
|
10
15
|
export interface AuthorizationResult {
|
|
11
16
|
allowed: boolean;
|
|
12
17
|
reason?: string;
|
|
13
18
|
}
|
|
19
|
+
export interface AuthorizationService<TSubject extends AuthorizationSubject = AuthorizationSubject> {
|
|
20
|
+
evaluate(context: AuthorizationContext<TSubject>): Promise<AuthorizationResult>;
|
|
21
|
+
}
|
|
14
22
|
export interface GrantPermissionOptions {
|
|
15
23
|
principalId: DatabaseRecordId;
|
|
16
24
|
action: string;
|
|
@@ -23,27 +31,27 @@ export interface RevokePermissionOptions {
|
|
|
23
31
|
resource?: string;
|
|
24
32
|
metadata?: Record<string, unknown>;
|
|
25
33
|
}
|
|
26
|
-
export declare abstract class Authorization<TPrincipal extends Principal> extends Auth<TPrincipal> {
|
|
34
|
+
export declare abstract class Authorization<TPrincipal extends Principal, TSubject extends AuthorizationSubject = TPrincipal> extends Auth<TPrincipal> implements AuthorizationService<TSubject> {
|
|
27
35
|
/**
|
|
28
36
|
* Evaluate authorization for a given context
|
|
29
37
|
* @param context The authorization context containing principal,
|
|
30
38
|
* resource, action, and optional metadata
|
|
31
39
|
* @returns Authorization result with allowed status and optional reason
|
|
32
40
|
*/
|
|
33
|
-
abstract evaluate(context: AuthorizationContext<
|
|
41
|
+
abstract evaluate(context: AuthorizationContext<TSubject>): Promise<AuthorizationResult>;
|
|
34
42
|
/**
|
|
35
43
|
* Check if a principal is authorized for a specific action on a resource
|
|
36
44
|
* @param context The authorization context
|
|
37
45
|
* @returns True if authorized, false otherwise
|
|
38
46
|
*/
|
|
39
|
-
isAuthorized(context: AuthorizationContext<
|
|
47
|
+
isAuthorized(context: AuthorizationContext<TSubject>): Promise<boolean>;
|
|
40
48
|
/**
|
|
41
49
|
* Check if a principal has permission for an action
|
|
42
50
|
* Subclasses should override this for specific authorization models
|
|
43
51
|
* @param context The authorization context
|
|
44
52
|
* @returns Authorization result
|
|
45
53
|
*/
|
|
46
|
-
protected checkPermission(context: AuthorizationContext<
|
|
54
|
+
protected checkPermission(context: AuthorizationContext<TSubject>): Promise<AuthorizationResult>;
|
|
47
55
|
/**
|
|
48
56
|
* Grant a permission to a principal
|
|
49
57
|
* Subclasses should implement this based on their model
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"authorization.js","sourceRoot":"","sources":["../../../src/authorization/authorization.ts"],"names":[],"mappings":";;;AACA,kCAAuD;
|
|
1
|
+
{"version":3,"file":"authorization.js","sourceRoot":"","sources":["../../../src/authorization/authorization.ts"],"names":[],"mappings":";;;AACA,kCAAuD;AA+CvD,MAAsB,aAGpB,SAAQ,WAAgB;IAWzB;;;;OAIG;IACI,KAAK,CAAC,YAAY,CACxB,OAAuC;QAEvC,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC;QAC5C,OAAO,MAAM,CAAC,OAAO,CAAC;IACvB,CAAC;IAED;;;;;OAKG;IACO,KAAK,CAAC,eAAe;IAC9B,6DAA6D;IAC7D,OAAuC;QAEvC,uCAAuC;QACvC,OAAO;YACN,OAAO,EAAE,KAAK;YACd,MAAM,EAAE,mCAAmC;SAC3C,CAAC;IACH,CAAC;CAmBD;AA5DD,sCA4DC"}
|
package/authorization/index.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export { Authorization, AuthorizationContext, AuthorizationOptions, AuthorizationResult, GrantPermissionOptions, RevokePermissionOptions, } from './authorization';
|
|
1
|
+
export { Authorization, AuthorizationSubject, AuthorizationRequirement, AuthorizationService, AuthorizationContext, AuthorizationOptions, AuthorizationResult, GrantPermissionOptions, RevokePermissionOptions, } from './authorization';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/authorization/index.ts"],"names":[],"mappings":";;;AAAA,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/authorization/index.ts"],"names":[],"mappings":";;;AAAA,iDAUyB;AATxB,8GAAA,aAAa,OAAA"}
|