@elogroup-sereduc/ser-front-core-client 2.0.1 → 2.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/auth/index.d.ts +1 -11
- package/dist/auth/index.d.ts.map +1 -1
- package/dist/auth/index.js +1 -17
- package/dist/auth/index.js.map +1 -1
- package/dist/auth/route-guards.d.ts +1 -13
- package/dist/auth/route-guards.d.ts.map +1 -1
- package/dist/auth/route-guards.js +9 -41
- package/dist/auth/route-guards.js.map +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/auth/index.d.ts
CHANGED
|
@@ -5,15 +5,5 @@ export type { TokenSet } from "./store";
|
|
|
5
5
|
export { createApiClient } from "./http-client";
|
|
6
6
|
export { createSerOAuth, createKeycloakAuthFromUrl, initAuth, } from "./bootstrap";
|
|
7
7
|
export type { CreateKeycloakAuthOptions, InitAuthOptions } from "./bootstrap";
|
|
8
|
-
export {
|
|
9
|
-
export type { RequireAuthOptions } from "./route-guards";
|
|
10
|
-
export declare function getAuthState(): {
|
|
11
|
-
authenticated: boolean;
|
|
12
|
-
ready: boolean;
|
|
13
|
-
loading: boolean;
|
|
14
|
-
handleOidcCallback(): Promise<void>;
|
|
15
|
-
};
|
|
16
|
-
export declare function getAuthStore(): {
|
|
17
|
-
getState: typeof getAuthState;
|
|
18
|
-
};
|
|
8
|
+
export { hasRoles } from "./route-guards";
|
|
19
9
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/auth/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/auth/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAC1C,YAAY,EACV,cAAc,EACd,WAAW,EACX,YAAY,EACZ,aAAa,GACd,MAAM,gBAAgB,CAAC;AAGxB,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACvC,YAAY,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/auth/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAC1C,YAAY,EACV,cAAc,EACd,WAAW,EACX,YAAY,EACZ,aAAa,GACd,MAAM,gBAAgB,CAAC;AAGxB,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACvC,YAAY,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAGxC,OAAO,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AAGhD,OAAO,EACL,cAAc,EACd,yBAAyB,EACzB,QAAQ,GACT,MAAM,aAAa,CAAC;AACrB,YAAY,EAAE,yBAAyB,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAG9E,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC"}
|
package/dist/auth/index.js
CHANGED
|
@@ -1,22 +1,6 @@
|
|
|
1
1
|
export { SerOAuth } from "./ser-oauth-js";
|
|
2
2
|
export { useAuthStore } from "./store";
|
|
3
|
-
import { useAuthStore } from "./store";
|
|
4
3
|
export { createApiClient } from "./http-client";
|
|
5
4
|
export { createSerOAuth, createKeycloakAuthFromUrl, initAuth, } from "./bootstrap";
|
|
6
|
-
export {
|
|
7
|
-
export function getAuthState() {
|
|
8
|
-
const store = useAuthStore.getState();
|
|
9
|
-
return {
|
|
10
|
-
authenticated: store.authenticated,
|
|
11
|
-
ready: true,
|
|
12
|
-
loading: false,
|
|
13
|
-
async handleOidcCallback() {
|
|
14
|
-
},
|
|
15
|
-
};
|
|
16
|
-
}
|
|
17
|
-
export function getAuthStore() {
|
|
18
|
-
return {
|
|
19
|
-
getState: getAuthState,
|
|
20
|
-
};
|
|
21
|
-
}
|
|
5
|
+
export { hasRoles } from "./route-guards";
|
|
22
6
|
//# sourceMappingURL=index.js.map
|
package/dist/auth/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/auth/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAS1C,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAIvC,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/auth/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAS1C,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAIvC,OAAO,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AAGhD,OAAO,EACL,cAAc,EACd,yBAAyB,EACzB,QAAQ,GACT,MAAM,aAAa,CAAC;AAIrB,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC"}
|
|
@@ -1,14 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
export type RequireAuthOptions = {
|
|
3
|
-
locationPath: string;
|
|
4
|
-
kc: SerOAuth;
|
|
5
|
-
};
|
|
6
|
-
export declare function requireAuth({ locationPath, kc }: RequireAuthOptions): Promise<void>;
|
|
7
|
-
export declare function createAuthGuard(kc: SerOAuth): ({ location }: {
|
|
8
|
-
location: {
|
|
9
|
-
pathname: string;
|
|
10
|
-
};
|
|
11
|
-
}) => Promise<void>;
|
|
12
|
-
export declare function requireAdmin({ locationPath, kc }: RequireAuthOptions): Promise<void>;
|
|
13
|
-
export declare function clearAuthSession(): void;
|
|
1
|
+
export declare function hasRoles(requiredRoles: string[]): boolean;
|
|
14
2
|
//# sourceMappingURL=route-guards.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"route-guards.d.ts","sourceRoot":"","sources":["../../src/auth/route-guards.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"route-guards.d.ts","sourceRoot":"","sources":["../../src/auth/route-guards.ts"],"names":[],"mappings":"AAOA,wBAAgB,QAAQ,CAAC,aAAa,EAAE,MAAM,EAAE,GAAG,OAAO,CAkCzD"}
|
|
@@ -1,59 +1,27 @@
|
|
|
1
1
|
import { useAuthStore } from "./store";
|
|
2
|
-
export
|
|
2
|
+
export function hasRoles(requiredRoles) {
|
|
3
3
|
const state = useAuthStore.getState();
|
|
4
|
-
if (state.authenticated)
|
|
5
|
-
return;
|
|
6
|
-
sessionStorage.setItem("postLoginRedirect", locationPath);
|
|
7
|
-
await kc.login({ redirectUri: window.location.origin + locationPath });
|
|
8
|
-
}
|
|
9
|
-
export function createAuthGuard(kc) {
|
|
10
|
-
return async ({ location }) => {
|
|
11
|
-
await requireAuth({
|
|
12
|
-
locationPath: location.pathname,
|
|
13
|
-
kc,
|
|
14
|
-
});
|
|
15
|
-
};
|
|
16
|
-
}
|
|
17
|
-
export async function requireAdmin({ locationPath, kc }) {
|
|
18
|
-
await requireAuth({ locationPath, kc });
|
|
19
|
-
const state = useAuthStore.getState();
|
|
20
|
-
if (!state.accessToken) {
|
|
21
|
-
throw new Error("User is authenticated but no access token found");
|
|
4
|
+
if (!state.authenticated || !state.accessToken) {
|
|
5
|
+
return false;
|
|
22
6
|
}
|
|
23
7
|
try {
|
|
24
8
|
const payload = JSON.parse(atob(state.accessToken.split(".")[1]));
|
|
25
|
-
const
|
|
9
|
+
const userRoles = [];
|
|
26
10
|
if (payload.realm_access?.roles) {
|
|
27
|
-
|
|
11
|
+
userRoles.push(...payload.realm_access.roles);
|
|
28
12
|
}
|
|
29
13
|
if (payload.resource_access) {
|
|
30
14
|
Object.values(payload.resource_access).forEach((access) => {
|
|
31
15
|
if (access.roles) {
|
|
32
|
-
|
|
16
|
+
userRoles.push(...access.roles);
|
|
33
17
|
}
|
|
34
18
|
});
|
|
35
19
|
}
|
|
36
|
-
|
|
37
|
-
"admin",
|
|
38
|
-
"administrator",
|
|
39
|
-
"realm-admin",
|
|
40
|
-
"manage-realm",
|
|
41
|
-
"manage-users",
|
|
42
|
-
];
|
|
43
|
-
const hasAdminRole = adminRoles.some((role) => roles.includes(role));
|
|
44
|
-
if (!hasAdminRole) {
|
|
45
|
-
throw new Error("Insufficient permissions: Admin role required");
|
|
46
|
-
}
|
|
20
|
+
return requiredRoles.some((role) => userRoles.includes(role));
|
|
47
21
|
}
|
|
48
22
|
catch (error) {
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
throw error;
|
|
52
|
-
}
|
|
53
|
-
throw new Error("Error validating admin permissions");
|
|
23
|
+
console.warn("Error parsing access token for role check:", error);
|
|
24
|
+
return false;
|
|
54
25
|
}
|
|
55
26
|
}
|
|
56
|
-
export function clearAuthSession() {
|
|
57
|
-
sessionStorage.removeItem("postLoginRedirect");
|
|
58
|
-
}
|
|
59
27
|
//# sourceMappingURL=route-guards.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"route-guards.js","sourceRoot":"","sources":["../../src/auth/route-guards.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;
|
|
1
|
+
{"version":3,"file":"route-guards.js","sourceRoot":"","sources":["../../src/auth/route-guards.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAOvC,MAAM,UAAU,QAAQ,CAAC,aAAuB;IAC9C,MAAM,KAAK,GAAG,YAAY,CAAC,QAAQ,EAAE,CAAC;IAGtC,IAAI,CAAC,KAAK,CAAC,aAAa,IAAI,CAAC,KAAK,CAAC,WAAW,EAAE,CAAC;QAC/C,OAAO,KAAK,CAAC;IACf,CAAC;IAED,IAAI,CAAC;QAEH,MAAM,OAAO,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,WAAW,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;QAClE,MAAM,SAAS,GAAa,EAAE,CAAC;QAG/B,IAAI,OAAO,CAAC,YAAY,EAAE,KAAK,EAAE,CAAC;YAChC,SAAS,CAAC,IAAI,CAAC,GAAG,OAAO,CAAC,YAAY,CAAC,KAAK,CAAC,CAAC;QAChD,CAAC;QAGD,IAAI,OAAO,CAAC,eAAe,EAAE,CAAC;YAC5B,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,eAAe,CAAC,CAAC,OAAO,CAAC,CAAC,MAAW,EAAE,EAAE;gBAC7D,IAAI,MAAM,CAAC,KAAK,EAAE,CAAC;oBACjB,SAAS,CAAC,IAAI,CAAC,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC;gBAClC,CAAC;YACH,CAAC,CAAC,CAAC;QACL,CAAC;QAGD,OAAO,aAAa,CAAC,IAAI,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,SAAS,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC;IAChE,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QAEf,OAAO,CAAC,IAAI,CAAC,4CAA4C,EAAE,KAAK,CAAC,CAAC;QAClE,OAAO,KAAK,CAAC;IACf,CAAC;AACH,CAAC"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
export * from "./auth";
|
|
2
|
-
export { SerOAuth, useAuthStore, createApiClient, createSerOAuth, createKeycloakAuthFromUrl, initAuth,
|
|
3
|
-
export type { SerOAuthConfig, InitOptions, LoginOptions, LogoutOptions, TokenSet,
|
|
2
|
+
export { SerOAuth, useAuthStore, createApiClient, createSerOAuth, createKeycloakAuthFromUrl, initAuth, hasRoles, } from "./auth";
|
|
3
|
+
export type { SerOAuthConfig, InitOptions, LoginOptions, LogoutOptions, TokenSet, } from "./auth";
|
|
4
4
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,cAAc,QAAQ,CAAC;AAGvB,OAAO,EACL,QAAQ,EACR,YAAY,EACZ,eAAe,EACf,cAAc,EACd,yBAAyB,EACzB,QAAQ,EACR,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,cAAc,QAAQ,CAAC;AAGvB,OAAO,EACL,QAAQ,EACR,YAAY,EACZ,eAAe,EACf,cAAc,EACd,yBAAyB,EACzB,QAAQ,EACR,QAAQ,GACT,MAAM,QAAQ,CAAC;AAEhB,YAAY,EACV,cAAc,EACd,WAAW,EACX,YAAY,EACZ,aAAa,EACb,QAAQ,GACT,MAAM,QAAQ,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
export * from "./auth";
|
|
2
|
-
export { SerOAuth, useAuthStore, createApiClient, createSerOAuth, createKeycloakAuthFromUrl, initAuth,
|
|
2
|
+
export { SerOAuth, useAuthStore, createApiClient, createSerOAuth, createKeycloakAuthFromUrl, initAuth, hasRoles, } from "./auth";
|
|
3
3
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,cAAc,QAAQ,CAAC;AAGvB,OAAO,EACL,QAAQ,EACR,YAAY,EACZ,eAAe,EACf,cAAc,EACd,yBAAyB,EACzB,QAAQ,EACR,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,cAAc,QAAQ,CAAC;AAGvB,OAAO,EACL,QAAQ,EACR,YAAY,EACZ,eAAe,EACf,cAAc,EACd,yBAAyB,EACzB,QAAQ,EACR,QAAQ,GACT,MAAM,QAAQ,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@elogroup-sereduc/ser-front-core-client",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.2",
|
|
4
4
|
"description": "Complete OAuth/OIDC authentication system with Silent SSO, PKCE, and API client for Ser Educacional applications",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|