
Research
/Security News
Weaponizing Discord for Command and Control Across npm, PyPI, and RubyGems.org
Socket researchers uncover how threat actors weaponize Discord across the npm, PyPI, and RubyGems ecosystems to exfiltrate sensitive data.
@twoday/react-keycloak
Advanced tools
Keycloak helper components, hooks, etc.
useCurrentUser
import { useCurrentUser } from '@twoday/react-keycloak';
const user = useCurrentUser();
HasRole
fallback
and children
props are optional.
import { HasRole } from '@twoday/react-keycloak';
<HasRole realm="admin" fallback={<Unauthorized />}>
<AdminPanel />
</HasRole>;
<HasRole realm={['foo', 'bar']}>...</HasRole>
<HasRole resource={{ 'my-app': 'editor' }} /* fallback={<Unauthorized />} */>
<EditButton />
</HasRole>
Shorthand to check for realm and current clientId
resource roles:
<HasRole admin>
<AdminPanel />
</HasRole>
IsAuthenticated
fallback
and children
props are optional.
import { IsAuthenticated } from '@twoday/react-keycloak';
<IsAuthenticated fallback={<Public />}>
<Private />
</IsAuthenticated>;
useHasRole
import { useHasRole } from '@twoday/react-keycloak';
const isAdmin = useHasRole({ realm: 'admin' });
const isFooOrBar = useHasRole({ realm: ['foo', 'bar'] });
const useIsAdmin = () => useHasRole({ realm: 'admin' });
const isEditor = useHasRole({ resource: { 'my-app': 'editor' } });
const useIsEditor = () => useHasRole({ resource: { 'my-app': 'editor' } });
Shorthand to check for realm and current clientId
resource roles:
const isAdmin = useHasRole('admin');
const isFooOrBar = useHasRole(['foo', 'bar']);
useIsAuthenticated
import { useIsAuthenticated } from '@twoday/react-keycloak';
const isAuthenticated = useIsAuthenticated();
ReactKeycloakProvider
ReactKeycloakProvider
with all of the extensions below integrated.
withPageRefreshSupport
Stores token
and refreshToken
in localStorage
. Authentication is shared live between browser tabs.
import { withPageRefreshSupport } from '@twoday/react-keycloak';
import { ReactKeycloakProvider as Provider } from '@react-keycloak/web';
const ReactKeycloakProvider = withPageRefreshSupport(Provider);
On logout, use useKeycloak
from @twoday/react-keycloak
, to sync logout with other tabs:
import { useKeycloak } from '@twoday/react-keycloak';
const { keycloak } = useKeycloak();
<button
onClick={() => {
keycloak.logout();
}}
>
Log out
</button>;
withAxiosAuthorizationHeaderUpdater
Updates Authorization: Bearer <token>
in given axios instance.
import { withAxiosAuthorizationHeaderUpdater } from '@twoday/react-keycloak';
import { ReactKeycloakProvider as Provider } from '@react-keycloak/web';
import axios from 'axios';
const ReactKeycloakProvider = withAxiosAuthorizationHeaderUpdater(Provider);
<ReactKeycloakProvider
axios={
axios /* AxiosStatic | Promise<AxiosStatic>, default: global axios instance */
}
/* … */
>
...
</ReactKeycloakProvider>;
withMockProvider
If REACT_APP_KEYCLOAK_MOCK_USER
environment variable is set, mock implementation of ReactKeycloakProvider
is used.
Example:
REACT_APP_KEYCLOAK_MOCK_USER={"name":"John Doe","email":"john.doe@example.com","realm_access":{"roles":[]},"resource_access":{"super-template":{"roles":["admin"]}}}
FAQs
Keycloak helper components, hooks, etc.
We found that @twoday/react-keycloak demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 2 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
/Security News
Socket researchers uncover how threat actors weaponize Discord across the npm, PyPI, and RubyGems ecosystems to exfiltrate sensitive data.
Security News
Socket now integrates with Bun 1.3’s Security Scanner API to block risky packages at install time and enforce your organization’s policies in local dev and CI.
Research
The Socket Threat Research Team is tracking weekly intrusions into the npm registry that follow a repeatable adversarial playbook used by North Korean state-sponsored actors.