@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: string;
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: process.env.CEMIAR_AUTH_TENANT_ID || ""
49
+ tenantId: claim.tenantId
51
50
  };
52
51
  }
@@ -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";
@@ -4,6 +4,7 @@ export interface Claim {
4
4
  iss: string;
5
5
  raw: Record<string, any>;
6
6
  actor_type: ActorType;
7
+ tenantId: string;
7
8
  }
8
9
  export declare enum ActorType {
9
10
  INTERNAL_USER = "internal_user",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cemiar/auth-sdk",
3
- "version": "1.0.18",
3
+ "version": "1.0.20",
4
4
  "description": "Cemiar Auth integration helpers for web apps and APIs.",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",