@stackwright-pro/auth 0.2.0-alpha.13 → 0.2.0-alpha.15
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/client.d.mts +197 -0
- package/dist/client.d.ts +197 -0
- package/dist/client.js +345 -0
- package/dist/client.js.map +1 -0
- package/dist/client.mjs +334 -0
- package/dist/client.mjs.map +1 -0
- package/dist/index.d.mts +6 -200
- package/dist/index.d.ts +6 -200
- package/dist/index.js +0 -194
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +1 -185
- package/dist/index.mjs.map +1 -1
- package/package.json +7 -2
package/dist/index.d.ts
CHANGED
|
@@ -1,8 +1,6 @@
|
|
|
1
|
-
import { AuthProvider
|
|
1
|
+
import { AuthProvider, PKIConfig, AuthContext, AuthUser, AuthSession, OIDCConfig, RBACConfig, ComponentAuthConfig, CertRevocationConfig } from '@stackwright-pro/types';
|
|
2
2
|
export { AuthConfig, AuthSession, AuthUser, CertRevocationConfig, ComponentAuthConfig, OIDCConfig, PKIConfig, RBACConfig, authConfigSchema, authSessionSchema, authUserSchema, componentAuthSchema, oidcConfigSchema, pkiConfigSchema, rbacConfigSchema } from '@stackwright-pro/types';
|
|
3
3
|
import { X509Certificate } from '@peculiar/x509';
|
|
4
|
-
import * as React from 'react';
|
|
5
|
-
import React__default, { ReactNode, ReactElement } from 'react';
|
|
6
4
|
|
|
7
5
|
/**
|
|
8
6
|
* Authentication Audit Logging
|
|
@@ -107,12 +105,12 @@ declare function createAuditEvent(type: AuditEventType, outcome: 'success' | 'fa
|
|
|
107
105
|
* - Pluggable audit logging for SIEM integration
|
|
108
106
|
*/
|
|
109
107
|
|
|
110
|
-
declare class PKIProvider implements AuthProvider
|
|
108
|
+
declare class PKIProvider implements AuthProvider {
|
|
111
109
|
private config;
|
|
112
110
|
private auditLogger?;
|
|
113
111
|
private revocationChecker;
|
|
114
112
|
constructor(config: PKIConfig, auditLogger?: AuditLogger);
|
|
115
|
-
authenticate(context: AuthContext
|
|
113
|
+
authenticate(context: AuthContext): Promise<AuthUser | null>;
|
|
116
114
|
validate(session: AuthSession): Promise<boolean>;
|
|
117
115
|
/**
|
|
118
116
|
* Extract roles from certificate based on organizational units
|
|
@@ -160,7 +158,7 @@ interface AuthorizationRequest {
|
|
|
160
158
|
* - Session refresh
|
|
161
159
|
* - Provider-specific quirks (Keycloak, Cognito, etc.)
|
|
162
160
|
*/
|
|
163
|
-
declare class OIDCProvider implements AuthProvider
|
|
161
|
+
declare class OIDCProvider implements AuthProvider {
|
|
164
162
|
private config;
|
|
165
163
|
private metadata;
|
|
166
164
|
private auditLogger?;
|
|
@@ -190,7 +188,7 @@ declare class OIDCProvider implements AuthProvider$1 {
|
|
|
190
188
|
* @returns Authenticated user or null if no code present
|
|
191
189
|
* @throws Error if state mismatch (CSRF) or token exchange/validation fails
|
|
192
190
|
*/
|
|
193
|
-
authenticate(context: AuthContext
|
|
191
|
+
authenticate(context: AuthContext): Promise<AuthUser | null>;
|
|
194
192
|
/**
|
|
195
193
|
* Validate session (check if token is still valid)
|
|
196
194
|
*
|
|
@@ -771,92 +769,6 @@ declare class RBACEngine {
|
|
|
771
769
|
private matchPath;
|
|
772
770
|
}
|
|
773
771
|
|
|
774
|
-
/**
|
|
775
|
-
* Auth context value provided to component tree
|
|
776
|
-
*/
|
|
777
|
-
interface AuthContextValue {
|
|
778
|
-
/**
|
|
779
|
-
* Currently authenticated user (null if not authenticated)
|
|
780
|
-
*/
|
|
781
|
-
user: AuthUser | null;
|
|
782
|
-
/**
|
|
783
|
-
* Current session (null if not authenticated)
|
|
784
|
-
*/
|
|
785
|
-
session: AuthSession | null;
|
|
786
|
-
/**
|
|
787
|
-
* Whether user is authenticated
|
|
788
|
-
*/
|
|
789
|
-
isAuthenticated: boolean;
|
|
790
|
-
/**
|
|
791
|
-
* Whether auth is still loading
|
|
792
|
-
*/
|
|
793
|
-
isLoading: boolean;
|
|
794
|
-
/**
|
|
795
|
-
* Check if user has a specific role
|
|
796
|
-
*/
|
|
797
|
-
hasRole: (role: string) => boolean;
|
|
798
|
-
/**
|
|
799
|
-
* Check if user has a specific permission
|
|
800
|
-
*/
|
|
801
|
-
hasPermission: (permission: string) => boolean;
|
|
802
|
-
/**
|
|
803
|
-
* Check if user has any of the specified roles
|
|
804
|
-
*/
|
|
805
|
-
hasAnyRole: (roles: string[]) => boolean;
|
|
806
|
-
/**
|
|
807
|
-
* Check if user has all of the specified permissions
|
|
808
|
-
*/
|
|
809
|
-
hasAllPermissions: (permissions: string[]) => boolean;
|
|
810
|
-
}
|
|
811
|
-
/**
|
|
812
|
-
* Auth context - provides authentication state to components
|
|
813
|
-
*/
|
|
814
|
-
declare const AuthContext: React.Context<AuthContextValue | null>;
|
|
815
|
-
/**
|
|
816
|
-
* Hook to access auth context
|
|
817
|
-
* Throws error if used outside AuthProvider
|
|
818
|
-
*/
|
|
819
|
-
declare function useAuth(): AuthContextValue;
|
|
820
|
-
/**
|
|
821
|
-
* Hook to require authentication
|
|
822
|
-
* Returns null and logs warning if not authenticated
|
|
823
|
-
*/
|
|
824
|
-
declare function useRequireAuth(): AuthContextValue | null;
|
|
825
|
-
|
|
826
|
-
interface AuthProviderProps {
|
|
827
|
-
/**
|
|
828
|
-
* Current authenticated user (null if not authenticated)
|
|
829
|
-
*/
|
|
830
|
-
user: AuthUser | null;
|
|
831
|
-
/**
|
|
832
|
-
* Current session (null if not authenticated)
|
|
833
|
-
*/
|
|
834
|
-
session: AuthSession | null;
|
|
835
|
-
/**
|
|
836
|
-
* RBAC configuration for role/permission checking
|
|
837
|
-
*/
|
|
838
|
-
rbacConfig: RBACConfig;
|
|
839
|
-
/**
|
|
840
|
-
* Whether auth is still loading
|
|
841
|
-
*/
|
|
842
|
-
isLoading?: boolean;
|
|
843
|
-
/**
|
|
844
|
-
* Child components
|
|
845
|
-
*/
|
|
846
|
-
children: ReactNode;
|
|
847
|
-
}
|
|
848
|
-
/**
|
|
849
|
-
* AuthProvider - Provides authentication state to component tree
|
|
850
|
-
*
|
|
851
|
-
* @example
|
|
852
|
-
* ```tsx
|
|
853
|
-
* <AuthProvider user={user} session={session} rbacConfig={config}>
|
|
854
|
-
* <App />
|
|
855
|
-
* </AuthProvider>
|
|
856
|
-
* ```
|
|
857
|
-
*/
|
|
858
|
-
declare function AuthProvider({ user, session, rbacConfig, isLoading, children, }: AuthProviderProps): ReactElement;
|
|
859
|
-
|
|
860
772
|
/**
|
|
861
773
|
* HMAC Header Signing for PKI Gateway Authentication
|
|
862
774
|
*
|
|
@@ -1072,110 +984,4 @@ declare function createDoDCACConfig(overrides?: Partial<PKIConfig>): PKIConfig;
|
|
|
1072
984
|
*/
|
|
1073
985
|
declare function createDoDCACDevConfig(): PKIConfig;
|
|
1074
986
|
|
|
1075
|
-
|
|
1076
|
-
* Props that any component wrapped with withAuth will receive
|
|
1077
|
-
*/
|
|
1078
|
-
interface ComponentProps {
|
|
1079
|
-
id?: string;
|
|
1080
|
-
[key: string]: any;
|
|
1081
|
-
}
|
|
1082
|
-
/**
|
|
1083
|
-
* Higher-order component that wraps a component with authentication checks
|
|
1084
|
-
*
|
|
1085
|
-
* @example
|
|
1086
|
-
* ```tsx
|
|
1087
|
-
* const ProtectedButton = withAuth(Button, {
|
|
1088
|
-
* required_roles: ['ADMIN'],
|
|
1089
|
-
* fallback: 'message',
|
|
1090
|
-
* fallback_message: 'Only admins can see this button'
|
|
1091
|
-
* });
|
|
1092
|
-
* ```
|
|
1093
|
-
*
|
|
1094
|
-
* @param Component - The component to wrap
|
|
1095
|
-
* @param authConfig - Authentication requirements from YAML
|
|
1096
|
-
* @returns Wrapped component with auth enforcement
|
|
1097
|
-
*/
|
|
1098
|
-
declare function withAuth<P extends ComponentProps>(Component: React__default.ComponentType<P>, authConfig?: ComponentAuthConfig): React__default.ComponentType<P>;
|
|
1099
|
-
/**
|
|
1100
|
-
* Custom fallback component (for advanced use cases)
|
|
1101
|
-
*/
|
|
1102
|
-
declare function withAuthFallback<P extends ComponentProps>(Component: React__default.ComponentType<P>, authConfig: ComponentAuthConfig, FallbackComponent: React__default.ComponentType<any>): React__default.ComponentType<P>;
|
|
1103
|
-
|
|
1104
|
-
/**
|
|
1105
|
-
* Register the auth decorator for use by content renderers
|
|
1106
|
-
*
|
|
1107
|
-
* This should be called once in your app's initialization (e.g., _app.tsx)
|
|
1108
|
-
* to enable auth-aware component rendering.
|
|
1109
|
-
*
|
|
1110
|
-
* @example
|
|
1111
|
-
* ```tsx
|
|
1112
|
-
* // In pages/_app.tsx
|
|
1113
|
-
* import { registerAuthDecorator } from '@stackwright-pro/auth';
|
|
1114
|
-
*
|
|
1115
|
-
* registerAuthDecorator();
|
|
1116
|
-
*
|
|
1117
|
-
* function MyApp({ Component, pageProps }: AppProps) {
|
|
1118
|
-
* return (
|
|
1119
|
-
* <AuthProvider {...authProps}>
|
|
1120
|
-
* <Component {...pageProps} />
|
|
1121
|
-
* </AuthProvider>
|
|
1122
|
-
* );
|
|
1123
|
-
* }
|
|
1124
|
-
* ```
|
|
1125
|
-
*/
|
|
1126
|
-
declare function registerAuthDecorator(): void;
|
|
1127
|
-
/**
|
|
1128
|
-
* Get the registered auth decorator (for use by content renderers)
|
|
1129
|
-
*
|
|
1130
|
-
* Returns null if auth is not registered, allowing graceful degradation.
|
|
1131
|
-
* This is the function that OSS core would call to check if auth is available.
|
|
1132
|
-
*
|
|
1133
|
-
* @returns The withAuth decorator function, or null if not registered
|
|
1134
|
-
*/
|
|
1135
|
-
declare function getAuthDecorator(): typeof withAuth | null;
|
|
1136
|
-
/**
|
|
1137
|
-
* Wrap a component with auth if decorator is registered and config exists
|
|
1138
|
-
*
|
|
1139
|
-
* This is a safe wrapper that OSS packages can use without depending on auth.
|
|
1140
|
-
* If auth is not registered, returns the original component unchanged.
|
|
1141
|
-
* If auth config is missing/undefined, returns the original component unchanged.
|
|
1142
|
-
*
|
|
1143
|
-
* @example
|
|
1144
|
-
* ```tsx
|
|
1145
|
-
* // In content renderer (can live in OSS core!)\n * function renderContentItem(item: ContentItem) {
|
|
1146
|
-
* const Component = getComponentFromRegistry(item.type);
|
|
1147
|
-
*
|
|
1148
|
-
* // Apply auth if available
|
|
1149
|
-
* const WrappedComponent = maybeWrapWithAuth(Component, item.auth);
|
|
1150
|
-
*
|
|
1151
|
-
* return <WrappedComponent {...item} />;
|
|
1152
|
-
* }
|
|
1153
|
-
* ```
|
|
1154
|
-
*
|
|
1155
|
-
* @param Component - Component to wrap
|
|
1156
|
-
* @param authConfig - Auth configuration from YAML (optional)
|
|
1157
|
-
* @returns Wrapped component if auth is registered, original component otherwise
|
|
1158
|
-
*/
|
|
1159
|
-
declare function maybeWrapWithAuth<P extends {
|
|
1160
|
-
id?: string;
|
|
1161
|
-
[key: string]: any;
|
|
1162
|
-
}>(Component: React__default.ComponentType<P>, authConfig?: ComponentAuthConfig): React__default.ComponentType<P>;
|
|
1163
|
-
/**
|
|
1164
|
-
* Type guard to check if content item has auth config
|
|
1165
|
-
*
|
|
1166
|
-
* Useful for conditionally applying auth in renderers without
|
|
1167
|
-
* needing to import auth types.
|
|
1168
|
-
*
|
|
1169
|
-
* @example
|
|
1170
|
-
* ```tsx
|
|
1171
|
-
* if (hasAuthConfig(item)) {
|
|
1172
|
-
* // TypeScript knows item.auth exists
|
|
1173
|
-
* WrappedComponent = maybeWrapWithAuth(Component, item.auth);
|
|
1174
|
-
* }
|
|
1175
|
-
* ```
|
|
1176
|
-
*/
|
|
1177
|
-
declare function hasAuthConfig(item: any): item is {
|
|
1178
|
-
auth: ComponentAuthConfig;
|
|
1179
|
-
};
|
|
1180
|
-
|
|
1181
|
-
export { type AuditEvent, AuditEventType, type AuditLogger, AuthContext, type AuthContextValue, AuthProvider, type AuthProviderProps, type AuthorizationRequest, type BuildAuthorizationUrlOptions, CRLRevocationChecker, type CertRevocationChecker, type ComponentProps, CompositeAuditLogger, CompositeRevocationChecker, ConsoleAuditLogger, type CookieOptions, DOD_CAC_PROFILE, type HeaderSigningConfig, InMemoryRevocationStore, KeycloakAdapter, NoopAuditLogger, OCSPRevocationChecker, type OIDCMetadata, OIDCProvider, PKIProvider, type ParsedCertificate, RBACEngine, RevocationCache, type RevocationInput, type RevocationStatus, type RevocationStore, SessionManager, type SessionManagerConfig, SkipRevocationChecker, type TokenSet, buildAuthorizationUrl, clearCookie, createAuditEvent, createDoDCACConfig, createDoDCACDevConfig, createRevocationChecker, decryptToken, deriveEncryptionKey, discoverOIDC, encryptToken, exchangeCodeForTokens, extractEDIPI, generateCodeChallenge, generateCodeVerifier, generateJti, generateNonce, generateState, getAuthDecorator, hasAuthConfig, maybeWrapWithAuth, normalizeSerial, parseCertFromHeaders, parseCertificate, parseCookies, refreshAccessToken, registerAuthDecorator, serializeCookie, signCertHeaders, useAuth, useRequireAuth, validateDoDCAC, validateIdToken, verifyCertHeaders, verifyState, withAuth, withAuthFallback };
|
|
987
|
+
export { type AuditEvent, AuditEventType, type AuditLogger, type AuthorizationRequest, type BuildAuthorizationUrlOptions, CRLRevocationChecker, type CertRevocationChecker, CompositeAuditLogger, CompositeRevocationChecker, ConsoleAuditLogger, type CookieOptions, DOD_CAC_PROFILE, type HeaderSigningConfig, InMemoryRevocationStore, KeycloakAdapter, NoopAuditLogger, OCSPRevocationChecker, type OIDCMetadata, OIDCProvider, PKIProvider, type ParsedCertificate, RBACEngine, RevocationCache, type RevocationInput, type RevocationStatus, type RevocationStore, SessionManager, type SessionManagerConfig, SkipRevocationChecker, type TokenSet, buildAuthorizationUrl, clearCookie, createAuditEvent, createDoDCACConfig, createDoDCACDevConfig, createRevocationChecker, decryptToken, deriveEncryptionKey, discoverOIDC, encryptToken, exchangeCodeForTokens, extractEDIPI, generateCodeChallenge, generateCodeVerifier, generateJti, generateNonce, generateState, normalizeSerial, parseCertFromHeaders, parseCertificate, parseCookies, refreshAccessToken, serializeCookie, signCertHeaders, validateDoDCAC, validateIdToken, verifyCertHeaders, verifyState };
|
package/dist/index.js
CHANGED
|
@@ -5,8 +5,6 @@ var types = require('@stackwright-pro/types');
|
|
|
5
5
|
var x509 = require('@peculiar/x509');
|
|
6
6
|
var crypto3 = require('crypto');
|
|
7
7
|
var jose3 = require('jose');
|
|
8
|
-
var react = require('react');
|
|
9
|
-
var jsxRuntime = require('react/jsx-runtime');
|
|
10
8
|
|
|
11
9
|
function _interopNamespace(e) {
|
|
12
10
|
if (e && e.__esModule) return e;
|
|
@@ -1716,57 +1714,6 @@ var RBACEngine = class {
|
|
|
1716
1714
|
return regex.test(path);
|
|
1717
1715
|
}
|
|
1718
1716
|
};
|
|
1719
|
-
var AuthContext = react.createContext(null);
|
|
1720
|
-
function useAuth() {
|
|
1721
|
-
const context = react.useContext(AuthContext);
|
|
1722
|
-
if (!context) {
|
|
1723
|
-
throw new Error("useAuth must be used within AuthProvider");
|
|
1724
|
-
}
|
|
1725
|
-
return context;
|
|
1726
|
-
}
|
|
1727
|
-
function useRequireAuth() {
|
|
1728
|
-
const auth = useAuth();
|
|
1729
|
-
if (!auth.isAuthenticated) {
|
|
1730
|
-
console.warn("useRequireAuth: User is not authenticated");
|
|
1731
|
-
return null;
|
|
1732
|
-
}
|
|
1733
|
-
return auth;
|
|
1734
|
-
}
|
|
1735
|
-
function AuthProvider({
|
|
1736
|
-
user,
|
|
1737
|
-
session,
|
|
1738
|
-
rbacConfig,
|
|
1739
|
-
isLoading = false,
|
|
1740
|
-
children
|
|
1741
|
-
}) {
|
|
1742
|
-
const rbac = react.useMemo(() => new RBACEngine(rbacConfig), [rbacConfig]);
|
|
1743
|
-
const value = react.useMemo(
|
|
1744
|
-
() => ({
|
|
1745
|
-
user,
|
|
1746
|
-
session,
|
|
1747
|
-
isAuthenticated: user !== null,
|
|
1748
|
-
isLoading,
|
|
1749
|
-
hasRole: (role) => {
|
|
1750
|
-
if (!user) return false;
|
|
1751
|
-
return rbac.hasRole(user, role);
|
|
1752
|
-
},
|
|
1753
|
-
hasPermission: (permission) => {
|
|
1754
|
-
if (!user) return false;
|
|
1755
|
-
return rbac.hasPermission(user, permission);
|
|
1756
|
-
},
|
|
1757
|
-
hasAnyRole: (roles) => {
|
|
1758
|
-
if (!user) return false;
|
|
1759
|
-
return rbac.hasAnyRole(user, roles);
|
|
1760
|
-
},
|
|
1761
|
-
hasAllPermissions: (permissions) => {
|
|
1762
|
-
if (!user) return false;
|
|
1763
|
-
return rbac.hasAllPermissions(user, permissions);
|
|
1764
|
-
}
|
|
1765
|
-
}),
|
|
1766
|
-
[user, session, isLoading, rbac]
|
|
1767
|
-
);
|
|
1768
|
-
return /* @__PURE__ */ jsxRuntime.jsx(AuthContext.Provider, { value, children });
|
|
1769
|
-
}
|
|
1770
1717
|
|
|
1771
1718
|
// src/profiles/dod-cac.ts
|
|
1772
1719
|
var DOD_CAC_PROFILE = {
|
|
@@ -1840,137 +1787,6 @@ function createDoDCACDevConfig() {
|
|
|
1840
1787
|
allowedIssuers: void 0
|
|
1841
1788
|
};
|
|
1842
1789
|
}
|
|
1843
|
-
var FallbackComponents = {
|
|
1844
|
-
/**
|
|
1845
|
-
* Hide component (render nothing)
|
|
1846
|
-
*/
|
|
1847
|
-
hide: () => null,
|
|
1848
|
-
/**
|
|
1849
|
-
* Show placeholder message
|
|
1850
|
-
*/
|
|
1851
|
-
placeholder: ({ className }) => /* @__PURE__ */ jsxRuntime.jsx(
|
|
1852
|
-
"div",
|
|
1853
|
-
{
|
|
1854
|
-
className: className || "auth-placeholder",
|
|
1855
|
-
style: {
|
|
1856
|
-
padding: "1rem",
|
|
1857
|
-
border: "1px dashed #ccc",
|
|
1858
|
-
borderRadius: "4px",
|
|
1859
|
-
color: "#666",
|
|
1860
|
-
fontStyle: "italic",
|
|
1861
|
-
textAlign: "center"
|
|
1862
|
-
},
|
|
1863
|
-
children: "Content requires authorization"
|
|
1864
|
-
}
|
|
1865
|
-
),
|
|
1866
|
-
/**
|
|
1867
|
-
* Show custom message
|
|
1868
|
-
*/
|
|
1869
|
-
message: ({ message, className }) => /* @__PURE__ */ jsxRuntime.jsx(
|
|
1870
|
-
"div",
|
|
1871
|
-
{
|
|
1872
|
-
className: className || "auth-message",
|
|
1873
|
-
style: {
|
|
1874
|
-
padding: "1rem",
|
|
1875
|
-
border: "1px solid #f0ad4e",
|
|
1876
|
-
borderRadius: "4px",
|
|
1877
|
-
backgroundColor: "#fcf8e3",
|
|
1878
|
-
color: "#8a6d3b"
|
|
1879
|
-
},
|
|
1880
|
-
children: message || "Unauthorized"
|
|
1881
|
-
}
|
|
1882
|
-
)
|
|
1883
|
-
};
|
|
1884
|
-
function withAuth(Component, authConfig) {
|
|
1885
|
-
if (!authConfig) {
|
|
1886
|
-
return Component;
|
|
1887
|
-
}
|
|
1888
|
-
const WrappedComponent = (props) => {
|
|
1889
|
-
const auth = useAuth();
|
|
1890
|
-
if (authConfig.required_roles && authConfig.required_roles.length > 0) {
|
|
1891
|
-
if (!auth.hasAnyRole(authConfig.required_roles)) {
|
|
1892
|
-
return renderFallback(authConfig);
|
|
1893
|
-
}
|
|
1894
|
-
}
|
|
1895
|
-
if (authConfig.required_permissions && authConfig.required_permissions.length > 0) {
|
|
1896
|
-
if (!auth.hasAllPermissions(authConfig.required_permissions)) {
|
|
1897
|
-
return renderFallback(authConfig);
|
|
1898
|
-
}
|
|
1899
|
-
}
|
|
1900
|
-
return /* @__PURE__ */ jsxRuntime.jsx(Component, { ...props });
|
|
1901
|
-
};
|
|
1902
|
-
const componentName = Component.displayName || Component.name || "Component";
|
|
1903
|
-
WrappedComponent.displayName = `withAuth(${componentName})`;
|
|
1904
|
-
return WrappedComponent;
|
|
1905
|
-
}
|
|
1906
|
-
function renderFallback(authConfig) {
|
|
1907
|
-
const fallbackType = authConfig.fallback || "hide";
|
|
1908
|
-
switch (fallbackType) {
|
|
1909
|
-
case "hide":
|
|
1910
|
-
return FallbackComponents.hide();
|
|
1911
|
-
case "placeholder":
|
|
1912
|
-
return FallbackComponents.placeholder({});
|
|
1913
|
-
case "message":
|
|
1914
|
-
return FallbackComponents.message({
|
|
1915
|
-
message: authConfig.fallback_message
|
|
1916
|
-
});
|
|
1917
|
-
default:
|
|
1918
|
-
return null;
|
|
1919
|
-
}
|
|
1920
|
-
}
|
|
1921
|
-
function withAuthFallback(Component, authConfig, FallbackComponent) {
|
|
1922
|
-
const WrappedComponent = (props) => {
|
|
1923
|
-
const auth = useAuth();
|
|
1924
|
-
const isAuthorized = checkAuthorization(auth, authConfig);
|
|
1925
|
-
if (!isAuthorized) {
|
|
1926
|
-
return /* @__PURE__ */ jsxRuntime.jsx(FallbackComponent, {});
|
|
1927
|
-
}
|
|
1928
|
-
return /* @__PURE__ */ jsxRuntime.jsx(Component, { ...props });
|
|
1929
|
-
};
|
|
1930
|
-
const componentName = Component.displayName || Component.name || "Component";
|
|
1931
|
-
WrappedComponent.displayName = `withAuthFallback(${componentName})`;
|
|
1932
|
-
return WrappedComponent;
|
|
1933
|
-
}
|
|
1934
|
-
function checkAuthorization(auth, authConfig) {
|
|
1935
|
-
if (authConfig.required_roles && authConfig.required_roles.length > 0) {
|
|
1936
|
-
if (!auth.hasAnyRole(authConfig.required_roles)) {
|
|
1937
|
-
return false;
|
|
1938
|
-
}
|
|
1939
|
-
}
|
|
1940
|
-
if (authConfig.required_permissions && authConfig.required_permissions.length > 0) {
|
|
1941
|
-
if (!auth.hasAllPermissions(authConfig.required_permissions)) {
|
|
1942
|
-
return false;
|
|
1943
|
-
}
|
|
1944
|
-
}
|
|
1945
|
-
return true;
|
|
1946
|
-
}
|
|
1947
|
-
|
|
1948
|
-
// src/registration.ts
|
|
1949
|
-
var authDecoratorRegistry = {
|
|
1950
|
-
decorator: null
|
|
1951
|
-
};
|
|
1952
|
-
function registerAuthDecorator() {
|
|
1953
|
-
authDecoratorRegistry.decorator = withAuth;
|
|
1954
|
-
if (typeof window !== "undefined" && window.__STACKWRIGHT_DEBUG__) {
|
|
1955
|
-
console.log("\u{1F510} Auth decorator registered");
|
|
1956
|
-
}
|
|
1957
|
-
}
|
|
1958
|
-
function getAuthDecorator() {
|
|
1959
|
-
return authDecoratorRegistry.decorator;
|
|
1960
|
-
}
|
|
1961
|
-
function maybeWrapWithAuth(Component, authConfig) {
|
|
1962
|
-
const decorator = getAuthDecorator();
|
|
1963
|
-
if (!decorator || !authConfig) {
|
|
1964
|
-
return Component;
|
|
1965
|
-
}
|
|
1966
|
-
return decorator(Component, authConfig);
|
|
1967
|
-
}
|
|
1968
|
-
function hasAuthConfig(item) {
|
|
1969
|
-
if (!item || typeof item !== "object") {
|
|
1970
|
-
return false;
|
|
1971
|
-
}
|
|
1972
|
-
return "auth" in item;
|
|
1973
|
-
}
|
|
1974
1790
|
|
|
1975
1791
|
Object.defineProperty(exports, "authConfigSchema", {
|
|
1976
1792
|
enumerable: true,
|
|
@@ -2001,8 +1817,6 @@ Object.defineProperty(exports, "rbacConfigSchema", {
|
|
|
2001
1817
|
get: function () { return types.rbacConfigSchema; }
|
|
2002
1818
|
});
|
|
2003
1819
|
exports.AuditEventType = AuditEventType;
|
|
2004
|
-
exports.AuthContext = AuthContext;
|
|
2005
|
-
exports.AuthProvider = AuthProvider;
|
|
2006
1820
|
exports.CRLRevocationChecker = CRLRevocationChecker;
|
|
2007
1821
|
exports.CompositeAuditLogger = CompositeAuditLogger;
|
|
2008
1822
|
exports.CompositeRevocationChecker = CompositeRevocationChecker;
|
|
@@ -2035,24 +1849,16 @@ exports.generateCodeVerifier = generateCodeVerifier;
|
|
|
2035
1849
|
exports.generateJti = generateJti;
|
|
2036
1850
|
exports.generateNonce = generateNonce;
|
|
2037
1851
|
exports.generateState = generateState;
|
|
2038
|
-
exports.getAuthDecorator = getAuthDecorator;
|
|
2039
|
-
exports.hasAuthConfig = hasAuthConfig;
|
|
2040
|
-
exports.maybeWrapWithAuth = maybeWrapWithAuth;
|
|
2041
1852
|
exports.normalizeSerial = normalizeSerial;
|
|
2042
1853
|
exports.parseCertFromHeaders = parseCertFromHeaders;
|
|
2043
1854
|
exports.parseCertificate = parseCertificate;
|
|
2044
1855
|
exports.parseCookies = parseCookies;
|
|
2045
1856
|
exports.refreshAccessToken = refreshAccessToken;
|
|
2046
|
-
exports.registerAuthDecorator = registerAuthDecorator;
|
|
2047
1857
|
exports.serializeCookie = serializeCookie;
|
|
2048
1858
|
exports.signCertHeaders = signCertHeaders;
|
|
2049
|
-
exports.useAuth = useAuth;
|
|
2050
|
-
exports.useRequireAuth = useRequireAuth;
|
|
2051
1859
|
exports.validateDoDCAC = validateDoDCAC;
|
|
2052
1860
|
exports.validateIdToken = validateIdToken;
|
|
2053
1861
|
exports.verifyCertHeaders = verifyCertHeaders;
|
|
2054
1862
|
exports.verifyState = verifyState;
|
|
2055
|
-
exports.withAuth = withAuth;
|
|
2056
|
-
exports.withAuthFallback = withAuthFallback;
|
|
2057
1863
|
//# sourceMappingURL=index.js.map
|
|
2058
1864
|
//# sourceMappingURL=index.js.map
|