@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.mjs
CHANGED
|
@@ -3,8 +3,6 @@ export { authConfigSchema, authSessionSchema, authUserSchema, componentAuthSchem
|
|
|
3
3
|
import { X509Certificate } from '@peculiar/x509';
|
|
4
4
|
import * as crypto3 from 'crypto';
|
|
5
5
|
import * as jose3 from 'jose';
|
|
6
|
-
import { createContext, useContext, useMemo } from 'react';
|
|
7
|
-
import { jsx } from 'react/jsx-runtime';
|
|
8
6
|
|
|
9
7
|
// src/index.ts
|
|
10
8
|
function parseCertificate(pemOrDer) {
|
|
@@ -1693,57 +1691,6 @@ var RBACEngine = class {
|
|
|
1693
1691
|
return regex.test(path);
|
|
1694
1692
|
}
|
|
1695
1693
|
};
|
|
1696
|
-
var AuthContext = createContext(null);
|
|
1697
|
-
function useAuth() {
|
|
1698
|
-
const context = useContext(AuthContext);
|
|
1699
|
-
if (!context) {
|
|
1700
|
-
throw new Error("useAuth must be used within AuthProvider");
|
|
1701
|
-
}
|
|
1702
|
-
return context;
|
|
1703
|
-
}
|
|
1704
|
-
function useRequireAuth() {
|
|
1705
|
-
const auth = useAuth();
|
|
1706
|
-
if (!auth.isAuthenticated) {
|
|
1707
|
-
console.warn("useRequireAuth: User is not authenticated");
|
|
1708
|
-
return null;
|
|
1709
|
-
}
|
|
1710
|
-
return auth;
|
|
1711
|
-
}
|
|
1712
|
-
function AuthProvider({
|
|
1713
|
-
user,
|
|
1714
|
-
session,
|
|
1715
|
-
rbacConfig,
|
|
1716
|
-
isLoading = false,
|
|
1717
|
-
children
|
|
1718
|
-
}) {
|
|
1719
|
-
const rbac = useMemo(() => new RBACEngine(rbacConfig), [rbacConfig]);
|
|
1720
|
-
const value = useMemo(
|
|
1721
|
-
() => ({
|
|
1722
|
-
user,
|
|
1723
|
-
session,
|
|
1724
|
-
isAuthenticated: user !== null,
|
|
1725
|
-
isLoading,
|
|
1726
|
-
hasRole: (role) => {
|
|
1727
|
-
if (!user) return false;
|
|
1728
|
-
return rbac.hasRole(user, role);
|
|
1729
|
-
},
|
|
1730
|
-
hasPermission: (permission) => {
|
|
1731
|
-
if (!user) return false;
|
|
1732
|
-
return rbac.hasPermission(user, permission);
|
|
1733
|
-
},
|
|
1734
|
-
hasAnyRole: (roles) => {
|
|
1735
|
-
if (!user) return false;
|
|
1736
|
-
return rbac.hasAnyRole(user, roles);
|
|
1737
|
-
},
|
|
1738
|
-
hasAllPermissions: (permissions) => {
|
|
1739
|
-
if (!user) return false;
|
|
1740
|
-
return rbac.hasAllPermissions(user, permissions);
|
|
1741
|
-
}
|
|
1742
|
-
}),
|
|
1743
|
-
[user, session, isLoading, rbac]
|
|
1744
|
-
);
|
|
1745
|
-
return /* @__PURE__ */ jsx(AuthContext.Provider, { value, children });
|
|
1746
|
-
}
|
|
1747
1694
|
|
|
1748
1695
|
// src/profiles/dod-cac.ts
|
|
1749
1696
|
var DOD_CAC_PROFILE = {
|
|
@@ -1817,138 +1764,7 @@ function createDoDCACDevConfig() {
|
|
|
1817
1764
|
allowedIssuers: void 0
|
|
1818
1765
|
};
|
|
1819
1766
|
}
|
|
1820
|
-
var FallbackComponents = {
|
|
1821
|
-
/**
|
|
1822
|
-
* Hide component (render nothing)
|
|
1823
|
-
*/
|
|
1824
|
-
hide: () => null,
|
|
1825
|
-
/**
|
|
1826
|
-
* Show placeholder message
|
|
1827
|
-
*/
|
|
1828
|
-
placeholder: ({ className }) => /* @__PURE__ */ jsx(
|
|
1829
|
-
"div",
|
|
1830
|
-
{
|
|
1831
|
-
className: className || "auth-placeholder",
|
|
1832
|
-
style: {
|
|
1833
|
-
padding: "1rem",
|
|
1834
|
-
border: "1px dashed #ccc",
|
|
1835
|
-
borderRadius: "4px",
|
|
1836
|
-
color: "#666",
|
|
1837
|
-
fontStyle: "italic",
|
|
1838
|
-
textAlign: "center"
|
|
1839
|
-
},
|
|
1840
|
-
children: "Content requires authorization"
|
|
1841
|
-
}
|
|
1842
|
-
),
|
|
1843
|
-
/**
|
|
1844
|
-
* Show custom message
|
|
1845
|
-
*/
|
|
1846
|
-
message: ({ message, className }) => /* @__PURE__ */ jsx(
|
|
1847
|
-
"div",
|
|
1848
|
-
{
|
|
1849
|
-
className: className || "auth-message",
|
|
1850
|
-
style: {
|
|
1851
|
-
padding: "1rem",
|
|
1852
|
-
border: "1px solid #f0ad4e",
|
|
1853
|
-
borderRadius: "4px",
|
|
1854
|
-
backgroundColor: "#fcf8e3",
|
|
1855
|
-
color: "#8a6d3b"
|
|
1856
|
-
},
|
|
1857
|
-
children: message || "Unauthorized"
|
|
1858
|
-
}
|
|
1859
|
-
)
|
|
1860
|
-
};
|
|
1861
|
-
function withAuth(Component, authConfig) {
|
|
1862
|
-
if (!authConfig) {
|
|
1863
|
-
return Component;
|
|
1864
|
-
}
|
|
1865
|
-
const WrappedComponent = (props) => {
|
|
1866
|
-
const auth = useAuth();
|
|
1867
|
-
if (authConfig.required_roles && authConfig.required_roles.length > 0) {
|
|
1868
|
-
if (!auth.hasAnyRole(authConfig.required_roles)) {
|
|
1869
|
-
return renderFallback(authConfig);
|
|
1870
|
-
}
|
|
1871
|
-
}
|
|
1872
|
-
if (authConfig.required_permissions && authConfig.required_permissions.length > 0) {
|
|
1873
|
-
if (!auth.hasAllPermissions(authConfig.required_permissions)) {
|
|
1874
|
-
return renderFallback(authConfig);
|
|
1875
|
-
}
|
|
1876
|
-
}
|
|
1877
|
-
return /* @__PURE__ */ jsx(Component, { ...props });
|
|
1878
|
-
};
|
|
1879
|
-
const componentName = Component.displayName || Component.name || "Component";
|
|
1880
|
-
WrappedComponent.displayName = `withAuth(${componentName})`;
|
|
1881
|
-
return WrappedComponent;
|
|
1882
|
-
}
|
|
1883
|
-
function renderFallback(authConfig) {
|
|
1884
|
-
const fallbackType = authConfig.fallback || "hide";
|
|
1885
|
-
switch (fallbackType) {
|
|
1886
|
-
case "hide":
|
|
1887
|
-
return FallbackComponents.hide();
|
|
1888
|
-
case "placeholder":
|
|
1889
|
-
return FallbackComponents.placeholder({});
|
|
1890
|
-
case "message":
|
|
1891
|
-
return FallbackComponents.message({
|
|
1892
|
-
message: authConfig.fallback_message
|
|
1893
|
-
});
|
|
1894
|
-
default:
|
|
1895
|
-
return null;
|
|
1896
|
-
}
|
|
1897
|
-
}
|
|
1898
|
-
function withAuthFallback(Component, authConfig, FallbackComponent) {
|
|
1899
|
-
const WrappedComponent = (props) => {
|
|
1900
|
-
const auth = useAuth();
|
|
1901
|
-
const isAuthorized = checkAuthorization(auth, authConfig);
|
|
1902
|
-
if (!isAuthorized) {
|
|
1903
|
-
return /* @__PURE__ */ jsx(FallbackComponent, {});
|
|
1904
|
-
}
|
|
1905
|
-
return /* @__PURE__ */ jsx(Component, { ...props });
|
|
1906
|
-
};
|
|
1907
|
-
const componentName = Component.displayName || Component.name || "Component";
|
|
1908
|
-
WrappedComponent.displayName = `withAuthFallback(${componentName})`;
|
|
1909
|
-
return WrappedComponent;
|
|
1910
|
-
}
|
|
1911
|
-
function checkAuthorization(auth, authConfig) {
|
|
1912
|
-
if (authConfig.required_roles && authConfig.required_roles.length > 0) {
|
|
1913
|
-
if (!auth.hasAnyRole(authConfig.required_roles)) {
|
|
1914
|
-
return false;
|
|
1915
|
-
}
|
|
1916
|
-
}
|
|
1917
|
-
if (authConfig.required_permissions && authConfig.required_permissions.length > 0) {
|
|
1918
|
-
if (!auth.hasAllPermissions(authConfig.required_permissions)) {
|
|
1919
|
-
return false;
|
|
1920
|
-
}
|
|
1921
|
-
}
|
|
1922
|
-
return true;
|
|
1923
|
-
}
|
|
1924
|
-
|
|
1925
|
-
// src/registration.ts
|
|
1926
|
-
var authDecoratorRegistry = {
|
|
1927
|
-
decorator: null
|
|
1928
|
-
};
|
|
1929
|
-
function registerAuthDecorator() {
|
|
1930
|
-
authDecoratorRegistry.decorator = withAuth;
|
|
1931
|
-
if (typeof window !== "undefined" && window.__STACKWRIGHT_DEBUG__) {
|
|
1932
|
-
console.log("\u{1F510} Auth decorator registered");
|
|
1933
|
-
}
|
|
1934
|
-
}
|
|
1935
|
-
function getAuthDecorator() {
|
|
1936
|
-
return authDecoratorRegistry.decorator;
|
|
1937
|
-
}
|
|
1938
|
-
function maybeWrapWithAuth(Component, authConfig) {
|
|
1939
|
-
const decorator = getAuthDecorator();
|
|
1940
|
-
if (!decorator || !authConfig) {
|
|
1941
|
-
return Component;
|
|
1942
|
-
}
|
|
1943
|
-
return decorator(Component, authConfig);
|
|
1944
|
-
}
|
|
1945
|
-
function hasAuthConfig(item) {
|
|
1946
|
-
if (!item || typeof item !== "object") {
|
|
1947
|
-
return false;
|
|
1948
|
-
}
|
|
1949
|
-
return "auth" in item;
|
|
1950
|
-
}
|
|
1951
1767
|
|
|
1952
|
-
export { AuditEventType,
|
|
1768
|
+
export { AuditEventType, CRLRevocationChecker, CompositeAuditLogger, CompositeRevocationChecker, ConsoleAuditLogger, DOD_CAC_PROFILE, InMemoryRevocationStore, KeycloakAdapter, NoopAuditLogger, OCSPRevocationChecker, OIDCProvider, PKIProvider, RBACEngine, RevocationCache, SessionManager, SkipRevocationChecker, 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 };
|
|
1953
1769
|
//# sourceMappingURL=index.mjs.map
|
|
1954
1770
|
//# sourceMappingURL=index.mjs.map
|