@cemiar/auth-sdk 1.0.18 → 1.0.20
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.
|
@@ -1,5 +1,21 @@
|
|
|
1
1
|
import { ReqRefDefaults, ResponseToolkit } from "@hapi/hapi";
|
|
2
|
+
import { Action } from "../shared/constants/AuthzConstants.js";
|
|
3
|
+
export interface AuthorizationContext {
|
|
4
|
+
tenantId: string;
|
|
5
|
+
email?: string;
|
|
6
|
+
domain?: string;
|
|
7
|
+
clientId?: string;
|
|
8
|
+
roles?: string[];
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Authorization request structure
|
|
12
|
+
*/
|
|
13
|
+
export interface AuthorizationRequest {
|
|
14
|
+
resource: string;
|
|
15
|
+
action: Action;
|
|
16
|
+
context: AuthorizationContext;
|
|
17
|
+
}
|
|
2
18
|
export declare function authorizeRoute({ resource, action }: {
|
|
3
19
|
resource: string;
|
|
4
|
-
action:
|
|
20
|
+
action: Action;
|
|
5
21
|
}): (request: any, h: ResponseToolkit<ReqRefDefaults>) => Promise<symbol | import("@hapi/hapi").ResponseObject>;
|
|
@@ -7,7 +7,6 @@ export function authorizeRoute({ resource, action }) {
|
|
|
7
7
|
return h.response({ error: "Unauthorized: Invalid token or missing context" }).code(401).takeover();
|
|
8
8
|
}
|
|
9
9
|
const authzRequest = {
|
|
10
|
-
tenantId: context.tenantId,
|
|
11
10
|
resource,
|
|
12
11
|
action,
|
|
13
12
|
context
|
|
@@ -47,6 +46,6 @@ function buildContextFromRequest(request) {
|
|
|
47
46
|
return {
|
|
48
47
|
email: claim.sub,
|
|
49
48
|
roles: [],
|
|
50
|
-
tenantId:
|
|
49
|
+
tenantId: claim.tenantId
|
|
51
50
|
};
|
|
52
51
|
}
|
package/dist/server/index.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
export { registerCemiarAuthHapi, createSigningKeyResolver } from "./ServerHandler.js";
|
|
2
2
|
export type { JwtValidateFn, JwtValidateResult, JwtParts, HapiJwtStrategyOptions } from "../shared/Types.js";
|
|
3
|
-
export { authorizeRoute } from "./AuthorizationHandler.js";
|
|
3
|
+
export { authorizeRoute, AuthorizationContext, AuthorizationRequest } from "./AuthorizationHandler.js";
|