Security News
Research
Data Theft Repackaged: A Case Study in Malicious Wrapper Packages on npm
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
@forward-software/react-auth
Advanced tools
Simplify your Auth flow when working with React apps
This React package allows you to streamline the integration of user authentication flows in any React app by providing a single unified interface
yarn add @forward-software/react-auth
Create a new AuthClient
class which extends the BaseAuthClient
provided by this library and implements the 4 required methods:
login
method of the AuthClient gets calledrefresh
method of the AuthClient gets calledlogout
method of the AuthClient gets calledimport { BaseAuthClient } from '@forward-software/react-auth';
// The type for your credentials
type AuthCredentials = {
username: string;
password: string;
};
// The type for your tokens
type AuthTokens = {
authToken: string;
refreshToken: string;
};
class AuthClient extends BaseAuthClient<AuthTokens, AuthCredentials> {
protected onInit(): Promise<void> {
// Implement the initialization logic for your client
}
protected onLogin(credentials?: AuthCredentials): Promise<AuthTokens> {
// Implement the logic required to exchange the provided credentials for user tokens
}
protected onRefresh(minValidity?: number): Promise<AuthTokens> {
// Implement the logic required to refresh the current user tokens
}
protected onLogout(): Promise<void> {
// Implement the logic required to invalidate the current user tokens
}
}
Create an instance of the AuthClient
class defined
const authClient = new AuthClient();
isInitialized
, a boolean indicating if the AuthClient has been initializedisAuthenticated
, a boolean indicating if the login process has been successfull and the user is authenticatedtokens
, the current tokens returned by the login
or the refresh
processinit()
, initialize the AuthClient (N.B. this shouldn't be called if using AuthProvider
- see below)login(credentials)
, start the login processrefresh()
, refresh the current tokenslogout()
, logout and invalidate the current tokenson(eventName, listenerFn)
, subscribe to eventName
events emitted by the AuthClientoff(eventName, listenerFn)
, unsubscribe from eventName
events emitted by the AuthClientsubscribe(() => { })
, subscribe to AuthClient state changesgetSnapshot()
, returns the current state of the AuthClientSetup React components to interact with the AuthClient using the createAuth
function exported by this library
import { createAuth } from '@forward-software/react-auth';
export const { AuthProvider, useAuthClient } = createAuth(authClient);
the createAuth
function returns:
AuthProvider
, the context Provider component that should wrap your app and provide access to your AuthClientuseAuthClient
, the hook to retrieve and interact with your AuthClientThe context Provider component that should wrap your app and provide access to your AuthClient, this component also accepts 2 additional props
ErrorComponent
, displayed when the AuthClient initialization failsLoadingComponent
, displayed while the AuthClient is being initializedThe examples
folder contains some examples of how you can integrate this library in your React app.
This library has been inspired by react-keycloak
and similar libraries.
MIT
Made with ✨ & ❤️ by ForWarD Software and contributors
If you found this project to be helpful, please consider contacting us to develop your React and React Native projects.
FAQs
Simplify your Auth flow when working with React apps
We found that @forward-software/react-auth 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.
Security News
Research
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
Research
Security News
Attackers used a malicious npm package typosquatting a popular ESLint plugin to steal sensitive data, execute commands, and exploit developer systems.
Security News
The Ultralytics' PyPI Package was compromised four times in one weekend through GitHub Actions cache poisoning and failure to rotate previously compromised API tokens.