@cemiar/auth-sdk 1.0.19 → 1.0.21

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.
@@ -6,9 +6,6 @@ export declare class CemiarAuthClient implements CemiarAuthClientInstance {
6
6
  private readonly auds;
7
7
  private readonly redirectUrl?;
8
8
  private storage;
9
- private readonly onTokenChange?;
10
- private readonly onAuthFailure?;
11
- private readonly logoutRedirectUrl?;
12
9
  private loginMethod;
13
10
  private refreshPromise;
14
11
  constructor(config: CemiarAuthClientConfig);
@@ -26,7 +23,6 @@ export declare class CemiarAuthClient implements CemiarAuthClientInstance {
26
23
  private addAuthHeader;
27
24
  private handleResponseError;
28
25
  private queueTokenRefresh;
29
- private handleAuthFailure;
30
26
  private loadLoginMethodFromStorage;
31
27
  private persistLoginMethod;
32
28
  private getCurrentLoginMethod;
@@ -15,7 +15,7 @@ function extractAccessToken(data) {
15
15
  }
16
16
  export class CemiarAuthClient {
17
17
  constructor(config) {
18
- var _a, _b, _c;
18
+ var _a, _b;
19
19
  this.storage = createDefaultTokenStorage();
20
20
  this.refreshPromise = null;
21
21
  this.baseUrl = normalizeBaseUrl(config.baseUrl || "http://localhost:3000") + "/auth";
@@ -23,23 +23,17 @@ export class CemiarAuthClient {
23
23
  this.auds = parseAuds(config.auds);
24
24
  this.redirectUrl =
25
25
  (_a = config.redirectUrl) !== null && _a !== void 0 ? _a : (isBrowser ? `${window.location.origin}/auth/microsoft/callback` : undefined);
26
- this.onTokenChange = config.onTokenChange;
27
- this.onAuthFailure = config.onAuthFailure;
28
- this.logoutRedirectUrl =
29
- (_b = config.logoutRedirectUrl) !== null && _b !== void 0 ? _b : (isBrowser ? `${window.location.origin}/login` : undefined);
30
- this.storage = (_c = config.storage) !== null && _c !== void 0 ? _c : createDefaultTokenStorage();
26
+ this.storage = (_b = config.storage) !== null && _b !== void 0 ? _b : createDefaultTokenStorage();
31
27
  this.loginMethod = this.loadLoginMethodFromStorage();
32
28
  }
33
29
  getAccessToken() {
34
30
  return this.storage.getToken();
35
31
  }
36
32
  setAccessToken(token) {
37
- var _a;
38
33
  this.storage.setToken(token);
39
34
  if (token === null) {
40
35
  this.persistLoginMethod(null);
41
36
  }
42
- (_a = this.onTokenChange) === null || _a === void 0 ? void 0 : _a.call(this, token);
43
37
  }
44
38
  async authPost(path, body, withCredentials = true) {
45
39
  const url = `${this.baseUrl}${path}`;
@@ -149,7 +143,7 @@ export class CemiarAuthClient {
149
143
  return instance(originalRequest);
150
144
  }
151
145
  catch (refreshError) {
152
- this.handleAuthFailure();
146
+ this.setAccessToken(null);
153
147
  return Promise.reject(refreshError);
154
148
  }
155
149
  }
@@ -163,11 +157,6 @@ export class CemiarAuthClient {
163
157
  }
164
158
  return this.refreshPromise;
165
159
  }
166
- handleAuthFailure() {
167
- var _a;
168
- this.setAccessToken(null);
169
- (_a = this.onAuthFailure) === null || _a === void 0 ? void 0 : _a.call(this);
170
- }
171
160
  loadLoginMethodFromStorage() {
172
161
  if (!isBrowser || !("localStorage" in globalThis)) {
173
162
  return null;
@@ -1,5 +1,20 @@
1
1
  import { ReqRefDefaults, ResponseToolkit } from "@hapi/hapi";
2
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
+ }
3
18
  export declare function authorizeRoute({ resource, action }: {
4
19
  resource: string;
5
20
  action: Action;
@@ -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";
@@ -17,7 +17,6 @@ export interface CemiarAuthClientConfig {
17
17
  storage?: TokenStorage;
18
18
  onTokenChange?: (token: string | null) => void;
19
19
  onAuthFailure?: () => void;
20
- logoutRedirectUrl?: string;
21
20
  }
22
21
  export interface AuthTokens {
23
22
  accessToken: string;
@@ -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.19",
3
+ "version": "1.0.21",
4
4
  "description": "Cemiar Auth integration helpers for web apps and APIs.",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",