@judo/auth 0.1.0
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/LICENSE +277 -0
- package/README.md +131 -0
- package/dist/components/actor-auth-boundary.d.ts +38 -0
- package/dist/components/actor-auth-boundary.d.ts.map +1 -0
- package/dist/components/actor-switch-dialog.d.ts +38 -0
- package/dist/components/actor-switch-dialog.d.ts.map +1 -0
- package/dist/components/index.d.ts +3 -0
- package/dist/components/index.d.ts.map +1 -0
- package/dist/config/auth-config.d.ts +34 -0
- package/dist/config/auth-config.d.ts.map +1 -0
- package/dist/config/index.d.ts +3 -0
- package/dist/config/index.d.ts.map +1 -0
- package/dist/config/oidc-config.d.ts +58 -0
- package/dist/config/oidc-config.d.ts.map +1 -0
- package/dist/hooks/index.d.ts +4 -0
- package/dist/hooks/index.d.ts.map +1 -0
- package/dist/hooks/use-actor-switch.d.ts +44 -0
- package/dist/hooks/use-actor-switch.d.ts.map +1 -0
- package/dist/hooks/use-auth.d.ts +54 -0
- package/dist/hooks/use-auth.d.ts.map +1 -0
- package/dist/hooks/use-require-auth.d.ts +14 -0
- package/dist/hooks/use-require-auth.d.ts.map +1 -0
- package/dist/index.d.ts +12 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +315 -0
- package/dist/index.js.map +1 -0
- package/dist/provider/auth-config-context.d.ts +36 -0
- package/dist/provider/auth-config-context.d.ts.map +1 -0
- package/dist/provider/index.d.ts +5 -0
- package/dist/provider/index.d.ts.map +1 -0
- package/dist/provider/judo-auth-provider.d.ts +19 -0
- package/dist/provider/judo-auth-provider.d.ts.map +1 -0
- package/dist/provider/principal-context.d.ts +54 -0
- package/dist/provider/principal-context.d.ts.map +1 -0
- package/dist/provider/realm-cache.d.ts +37 -0
- package/dist/provider/realm-cache.d.ts.map +1 -0
- package/dist/utils/claim-mapping.d.ts +18 -0
- package/dist/utils/claim-mapping.d.ts.map +1 -0
- package/dist/utils/index.d.ts +2 -0
- package/dist/utils/index.d.ts.map +1 -0
- package/package.json +62 -0
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { ReactNode } from 'react';
|
|
2
|
+
import { PrincipalData } from '../hooks/use-auth';
|
|
3
|
+
/**
|
|
4
|
+
* Context providing backend principal data with refresh/override capabilities.
|
|
5
|
+
*
|
|
6
|
+
* This is separate from `useAuth().principal` which provides OIDC-claim-mapped data.
|
|
7
|
+
* `usePrincipal()` provides the **backend** principal fetched from `GET /~principal`.
|
|
8
|
+
*/
|
|
9
|
+
export interface PrincipalContextType {
|
|
10
|
+
/** Backend principal data, or null if not yet fetched / not authenticated */
|
|
11
|
+
principal: PrincipalData | null;
|
|
12
|
+
/** Whether the principal is currently being fetched */
|
|
13
|
+
isLoading: boolean;
|
|
14
|
+
/** Re-fetch principal from the backend. Triggers a re-render of the subtree. */
|
|
15
|
+
refreshPrincipal: () => Promise<void>;
|
|
16
|
+
/** Override principal data locally. Pass null to clear. */
|
|
17
|
+
setPrincipal: (data: PrincipalData | null) => void;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Props for PrincipalProvider.
|
|
21
|
+
*/
|
|
22
|
+
export interface PrincipalProviderProps {
|
|
23
|
+
/**
|
|
24
|
+
* Async function that fetches the principal from the backend.
|
|
25
|
+
* If omitted, the provider will not auto-fetch and principal stays null.
|
|
26
|
+
*
|
|
27
|
+
* Typically wired as: `() => api.getPrincipal().then(r => r.data)`
|
|
28
|
+
*/
|
|
29
|
+
fetchPrincipal?: () => Promise<Record<string, unknown>>;
|
|
30
|
+
children: ReactNode;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Access the backend principal context.
|
|
34
|
+
* Must be used within a PrincipalProvider.
|
|
35
|
+
*
|
|
36
|
+
* @throws Error if used outside PrincipalProvider
|
|
37
|
+
*/
|
|
38
|
+
export declare function usePrincipal(): PrincipalContextType;
|
|
39
|
+
/**
|
|
40
|
+
* Optionally access the backend principal context.
|
|
41
|
+
* Returns null when used outside PrincipalProvider (safe for optional auth scenarios).
|
|
42
|
+
*/
|
|
43
|
+
export declare function usePrincipalOptional(): PrincipalContextType | null;
|
|
44
|
+
/**
|
|
45
|
+
* Provides backend principal state with auto-fetch, refresh, and local override.
|
|
46
|
+
*
|
|
47
|
+
* On mount, if `fetchPrincipal` is provided, the principal is fetched automatically.
|
|
48
|
+
* Use `refreshPrincipal()` to re-fetch and `setPrincipal()` for local overrides.
|
|
49
|
+
*
|
|
50
|
+
* Place inside the auth boundary (after authentication is confirmed) and inside
|
|
51
|
+
* the API provider (so `fetchPrincipal` can call API methods).
|
|
52
|
+
*/
|
|
53
|
+
export declare function PrincipalProvider({ fetchPrincipal, children }: PrincipalProviderProps): import("react/jsx-runtime").JSX.Element;
|
|
54
|
+
//# sourceMappingURL=principal-context.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"principal-context.d.ts","sourceRoot":"","sources":["../../src/provider/principal-context.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,SAAS,EAAgF,MAAM,OAAO,CAAC;AACrH,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAMvD;;;;;GAKG;AACH,MAAM,WAAW,oBAAoB;IACpC,6EAA6E;IAC7E,SAAS,EAAE,aAAa,GAAG,IAAI,CAAC;IAChC,uDAAuD;IACvD,SAAS,EAAE,OAAO,CAAC;IACnB,gFAAgF;IAChF,gBAAgB,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;IACtC,2DAA2D;IAC3D,YAAY,EAAE,CAAC,IAAI,EAAE,aAAa,GAAG,IAAI,KAAK,IAAI,CAAC;CACnD;AAED;;GAEG;AACH,MAAM,WAAW,sBAAsB;IACtC;;;;;OAKG;IACH,cAAc,CAAC,EAAE,MAAM,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC;IACxD,QAAQ,EAAE,SAAS,CAAC;CACpB;AAYD;;;;;GAKG;AACH,wBAAgB,YAAY,IAAI,oBAAoB,CAMnD;AAED;;;GAGG;AACH,wBAAgB,oBAAoB,IAAI,oBAAoB,GAAG,IAAI,CAElE;AAMD;;;;;;;;GAQG;AACH,wBAAgB,iBAAiB,CAAC,EAAE,cAAc,EAAE,QAAQ,EAAE,EAAE,sBAAsB,2CAyCrF"}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { UserManager, UserManagerSettings } from 'oidc-client-ts';
|
|
2
|
+
/**
|
|
3
|
+
* Get or create a UserManager for the given realm.
|
|
4
|
+
* Uses caching to ensure actors with the same realm share sessions.
|
|
5
|
+
*
|
|
6
|
+
* @param realm - The realm identifier
|
|
7
|
+
* @param config - UserManager configuration
|
|
8
|
+
* @returns UserManager instance for the realm
|
|
9
|
+
*/
|
|
10
|
+
export declare function getOrCreateUserManager(realm: string, config: UserManagerSettings): UserManager;
|
|
11
|
+
/**
|
|
12
|
+
* Clear a specific realm from the cache.
|
|
13
|
+
* Useful for testing or when a realm needs to be re-initialized.
|
|
14
|
+
*
|
|
15
|
+
* @param realm - The realm to clear
|
|
16
|
+
*/
|
|
17
|
+
export declare function clearRealmCache(realm: string): void;
|
|
18
|
+
/**
|
|
19
|
+
* Clear all realms from the cache.
|
|
20
|
+
* Useful for testing.
|
|
21
|
+
*/
|
|
22
|
+
export declare function clearAllRealmCache(): void;
|
|
23
|
+
/**
|
|
24
|
+
* Check if a realm exists in the cache.
|
|
25
|
+
*
|
|
26
|
+
* @param realm - The realm to check
|
|
27
|
+
* @returns true if the realm is cached
|
|
28
|
+
*/
|
|
29
|
+
export declare function hasRealmInCache(realm: string): boolean;
|
|
30
|
+
/**
|
|
31
|
+
* Get the number of cached realms.
|
|
32
|
+
* Useful for testing.
|
|
33
|
+
*
|
|
34
|
+
* @returns Number of cached realms
|
|
35
|
+
*/
|
|
36
|
+
export declare function getCachedRealmCount(): number;
|
|
37
|
+
//# sourceMappingURL=realm-cache.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"realm-cache.d.ts","sourceRoot":"","sources":["../../src/provider/realm-cache.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAC7C,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,gBAAgB,CAAC;AAQ1D;;;;;;;GAOG;AACH,wBAAgB,sBAAsB,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,mBAAmB,GAAG,WAAW,CAK9F;AAED;;;;;GAKG;AACH,wBAAgB,eAAe,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI,CAEnD;AAED;;;GAGG;AACH,wBAAgB,kBAAkB,IAAI,IAAI,CAEzC;AAED;;;;;GAKG;AACH,wBAAgB,eAAe,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAEtD;AAED;;;;;GAKG;AACH,wBAAgB,mBAAmB,IAAI,MAAM,CAE5C"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { ClaimType } from '@judo/model-api';
|
|
2
|
+
import { ClaimMapping } from '../config';
|
|
3
|
+
/**
|
|
4
|
+
* Map ClaimType enum to OIDC claim key.
|
|
5
|
+
*
|
|
6
|
+
* @param type - ClaimType enum value
|
|
7
|
+
* @returns OIDC claim key string
|
|
8
|
+
*/
|
|
9
|
+
export declare function claimTypeToKey(type: ClaimType): string;
|
|
10
|
+
/**
|
|
11
|
+
* Map OIDC claims profile to principal data using claim mappings.
|
|
12
|
+
*
|
|
13
|
+
* @param profile - OIDC user profile claims
|
|
14
|
+
* @param mappings - Claim mappings from auth config
|
|
15
|
+
* @returns Mapped principal data
|
|
16
|
+
*/
|
|
17
|
+
export declare function mapClaimsToPrincipal(profile: Record<string, unknown> | undefined, mappings: ClaimMapping[]): Record<string, unknown>;
|
|
18
|
+
//# sourceMappingURL=claim-mapping.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"claim-mapping.d.ts","sourceRoot":"","sources":["../../src/utils/claim-mapping.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAC5C,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AAE9C;;;;;GAKG;AACH,wBAAgB,cAAc,CAAC,IAAI,EAAE,SAAS,GAAG,MAAM,CAOtD;AAED;;;;;;GAMG;AACH,wBAAgB,oBAAoB,CACnC,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,SAAS,EAC5C,QAAQ,EAAE,YAAY,EAAE,GACtB,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAiCzB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,oBAAoB,EAAE,MAAM,iBAAiB,CAAC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@judo/auth",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "OIDC authentication layer for JUDO UI Runtime",
|
|
5
|
+
"license": "EPL-2.0",
|
|
6
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "https://github.com/BlackBeltTechnology/judo-frontend-runtime.git",
|
|
9
|
+
"directory": "packages/auth"
|
|
10
|
+
},
|
|
11
|
+
"files": [
|
|
12
|
+
"dist",
|
|
13
|
+
"LICENSE",
|
|
14
|
+
"README.md"
|
|
15
|
+
],
|
|
16
|
+
"type": "module",
|
|
17
|
+
"sideEffects": false,
|
|
18
|
+
"main": "./dist/index.js",
|
|
19
|
+
"module": "./dist/index.js",
|
|
20
|
+
"types": "./dist/index.d.ts",
|
|
21
|
+
"exports": {
|
|
22
|
+
".": {
|
|
23
|
+
"types": "./dist/index.d.ts",
|
|
24
|
+
"import": "./dist/index.js"
|
|
25
|
+
}
|
|
26
|
+
},
|
|
27
|
+
"publishConfig": {
|
|
28
|
+
"access": "public"
|
|
29
|
+
},
|
|
30
|
+
"dependencies": {
|
|
31
|
+
"@judo/model-api": "0.1.0",
|
|
32
|
+
"@judo/model-loader": "0.1.0"
|
|
33
|
+
},
|
|
34
|
+
"devDependencies": {
|
|
35
|
+
"@emotion/react": "^11.14.0",
|
|
36
|
+
"@emotion/styled": "^11.14.1",
|
|
37
|
+
"@testing-library/react": "^16.3.2",
|
|
38
|
+
"@types/react": "^19.2.14",
|
|
39
|
+
"oidc-client-ts": "^3.4.1",
|
|
40
|
+
"react-oidc-context": "^3.3.0",
|
|
41
|
+
"typescript": "^5.9.3",
|
|
42
|
+
"vitest": "^4.0.18",
|
|
43
|
+
"@judo/model-api": "0.1.0",
|
|
44
|
+
"@judo/model-loader": "0.1.0",
|
|
45
|
+
"@judo/testing": "0.1.0"
|
|
46
|
+
},
|
|
47
|
+
"peerDependencies": {
|
|
48
|
+
"@mui/material": "^7.0.0",
|
|
49
|
+
"oidc-client-ts": "^3.0.0",
|
|
50
|
+
"react": "^19.0.0",
|
|
51
|
+
"react-oidc-context": "^3.0.0",
|
|
52
|
+
"@judo/model-api": "0.1.0",
|
|
53
|
+
"@judo/model-loader": "0.1.0"
|
|
54
|
+
},
|
|
55
|
+
"scripts": {
|
|
56
|
+
"build": "vite build",
|
|
57
|
+
"test": "vitest run",
|
|
58
|
+
"test:watch": "vitest",
|
|
59
|
+
"test:coverage": "vitest run --coverage",
|
|
60
|
+
"type-check": "tsgo --noEmit"
|
|
61
|
+
}
|
|
62
|
+
}
|