
Security News
Attackers Are Hunting High-Impact Node.js Maintainers in a Coordinated Social Engineering Campaign
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.
react-native-keycloak-plugin
Advanced tools
Functional React Native module for authentication between a client and the keycloak server.
This is a fork of mahomahoxd's react-native-login-keycloak module. I started from that to build some new feature using a functional style.
This plugin exposes some util methods to interact with Keycloak in order to handle the user session.
npm i --save react-native-keycloak-plugin
yarn add react-native-keycloak-plugin
Please configure Linking module, including steps for handling Universal links
This might get changed due to not being able to close the tab on leave, ending up with a lot of tabs in the browser.
[Not needed if you're using React Native >= 0.60]
Also, add the applinks: <APPSITE HOST> entry to the Associated Domains Capability of your app.
The plugin uses an export default statement, so you can import the variable with:
import Keycloak from 'react-native-keycloak-plugin';
From that variable, you have access to all the util methods the plugin implements.
Keycloak.keycloakUILogin(conf, [callback, { scope }])
.then((response) => /* Your resolve */ )
.catch((error) => /* Your reject*/ )
Method arguments:
config = {
"realm": "string",
"auth-server-url": "string",
"appsiteUri": "string",
"redirectUri": "string",
"ssl-required": "string",
"resource": "string",
"credentials": {
"secret": "string"
},
"confidential-port": "number",
}
Resolver arguments:
response.tokens = {
"access_token": "string",
"expires_in": "number",
"refresh_expires_in": "number",
"refresh_token": "string",
"token_type": "string",
"not-before-policy": "number",
"session_state": "string",
"scope": "string",
}
Keycloak.login(conf, username, password, options)
.then((response) => /* Your resolve */ )
.catch((error) => /* Your reject*/ )
Method arguments:
boolean, whether the plugin should save the result into the AsyncStorage. Defaults to trueKeycloak.refreshLogin(options)
.then((response) => /* Your resolve */ )
.catch((error) => /* Your reject*/ )
Method arguments:
{ username, password }Sometimes you may need to re-login your user w/ Keycloak via the login process but, for some reason, you don't want / can't display the login page.
This method will re-login your user.
import Keycloak, { TokenStorage } from 'react-native-keycloak-plugin'
Logging in by the login function will save the tokens information, and the configuration object into the AsyncStorage.
Through the TokenStorage object, the plugin exports some methods that can be used to interact with these objects.
Keycloak.retrieveUserInfo({ inputConf, inputTokens })
.then((userInfo) => /* Your resolve */ );
.catch((error) => /* Your reject*/ )
Passing a configuration JSON object, makes available into the resolve function the JSON that describes the user inside Keycloak.
Keycloak.refreshToken({ inputConf, inputTokens })
.then((response) => /* Your resolve */ );
.catch((error) => /* Your reject*/ )
Passing a configuration JSON object, makes available into the resolve function the JSON containing the refreshed tokens. This information are also saved into the AsyncStorage, as described above.
Keycloak.logout({ destroySession = true, inputConf, inputTokens })
.then(() => /* Your resolve */ );
.catch((error) => /* Your reject*/ )
destroySession: Since the /openid-connect/token simply returns an access token and doesn't create any session on Keycloak side, if you used the login method you want to pass false.
Passing true tries to destroy the session: pay attention that on newer Keycloak versions this raises an error if no session is present, preventing the logout.
import { TokensUtils } from 'react-native-keycloak-plugin';
TokensUtils.isAccessTokenExpired()
.then(() => /* Your resolve */ );
.catch((error) => /* Your reject*/ )
This utils method check if the access token saved into the AsyncStorage is still valid or if it's expired. Since it interact witht the AsyncStorage, a promise must be handled.
import { TokensUtils } from 'react-native-keycloak-plugin';
TokensUtils.willAccessTokenExpireInLessThan(seconds)
.then(() => /* Your resolve */ );
.catch((error) => /* Your reject*/ )
This utils method check if the access token saved into the AsyncStorage will expire in less than <seconds> seconds. Since it interacts with the AsyncStorage, a promise must be handled.
FAQs
Functional React Native module for authentication between a client and the keycloak server.
We found that react-native-keycloak-plugin 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
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.

Security News
Axios compromise traced to social engineering, showing how attacks on maintainers can bypass controls and expose the broader software supply chain.

Security News
Node.js has paused its bug bounty program after funding ended, removing payouts for vulnerability reports but keeping its security process unchanged.