All Projects → react-keycloak → react-native-keycloak

react-keycloak / react-native-keycloak

Licence: MIT License
React Native components for Keycloak

Programming Languages

typescript
32286 projects
java
68154 projects - #9 most used programming language
ruby
36898 projects - #4 most used programming language
objective c
16641 projects - #2 most used programming language
javascript
184084 projects - #8 most used programming language
c
50402 projects - #5 most used programming language
swift
15916 projects

Projects that are alternatives of or similar to react-native-keycloak

keycloak-kubernetes
Keycloak deployment into Kubernetes cluster
Stars: ✭ 25 (-78.07%)
Mutual labels:  keycloak
vertx-vue-keycloak
This repo holds the source codes for the Medium Article "Vert.x + VueJS + OAuth2 in 5 steps"
Stars: ✭ 20 (-82.46%)
Mutual labels:  keycloak
keycloak-heroku
Deploy Keycloak to Heroku using a slightly adapted version of the official docker image
Stars: ✭ 47 (-58.77%)
Mutual labels:  keycloak
keycloak-protocol-cas
CAS protocol provider for Keycloak
Stars: ✭ 67 (-41.23%)
Mutual labels:  keycloak
springboot-react-keycloak
The goal of this project is to secure movies-app using Keycloak(with PKCE). movies-app consists of two applications: one is a Spring Boot Rest API called movies-api and another is a ReactJS application called movies-ui.
Stars: ✭ 192 (+68.42%)
Mutual labels:  keycloak
springboot-keycloak-openldap
The goal of this project is to create a simple Spring Boot REST API, called simple-service, and secure it with Keycloak. Furthermore, the API users will be loaded into Keycloak from OpenLDAP server.
Stars: ✭ 96 (-15.79%)
Mutual labels:  keycloak
steam-openid-connect-provider
Steam OpenID Connect Identity Provider (IdP)
Stars: ✭ 40 (-64.91%)
Mutual labels:  keycloak
secure-oauth2-oidc-workshop
Hands-On Workshop for OAuth 2.0 and OpenID Connect 1.0
Stars: ✭ 58 (-49.12%)
Mutual labels:  keycloak
keycloak-admin-client
PHP Client to connect to Keycloak admin rest apis
Stars: ✭ 57 (-50%)
Mutual labels:  keycloak
beercloak
BeerCloak: a comprehensive Keycloak extension example
Stars: ✭ 110 (-3.51%)
Mutual labels:  keycloak
keycloak-admin-go
Keycloak Admin REST client for go
Stars: ✭ 17 (-85.09%)
Mutual labels:  keycloak
nest-keycloak-connect
keycloak-nodejs-connect module for Nest
Stars: ✭ 174 (+52.63%)
Mutual labels:  keycloak
keycloak-sso-configs
common keycloak single sign on configurations
Stars: ✭ 19 (-83.33%)
Mutual labels:  keycloak
keycloak-spring-boot-rest-angular-demo
Demo for configuring Keycloak authentication for a spring-boot rest service and AngularJs web client
Stars: ✭ 24 (-78.95%)
Mutual labels:  keycloak
horusec-platform
Horusec Platform is a set of web services that integrate with the Horusec CLI to facilitate the visualization and management of found vulnerabilities.
Stars: ✭ 32 (-71.93%)
Mutual labels:  keycloak
e-shop
Sample Spring Cloud microservices e-shop.
Stars: ✭ 48 (-57.89%)
Mutual labels:  keycloak
keycloak-home-idp-discovery
Keycloak: Home IdP Discovery - discover home identity provider or realm by email domain
Stars: ✭ 42 (-63.16%)
Mutual labels:  keycloak
keycloakify
🔏 Create Keycloak themes using React
Stars: ✭ 451 (+295.61%)
Mutual labels:  keycloak
kibana-keycloak
Secure kibana dashboards using keycloak
Stars: ✭ 40 (-64.91%)
Mutual labels:  keycloak
keycloak-radius-plugin
Make the radius server as part of keycloak SSO
Stars: ✭ 102 (-10.53%)
Mutual labels:  keycloak

React Native Keycloak

React Native Keycloak

React Native component for Keycloak

NPM (scoped)

License Github Issues

Gitter


Table of Contents


Install

yarn add @react-keycloak/native
yarn add react-native-inappbrowser-reborn

or

npm install @react-keycloak/native
npm install react-native-inappbrowser-reborn --save

You have to link react-native-inappbrowser-reborn. For more information about how to link it go to Official repo on github

Setup Deep links (iOS)

To navigate back from webview to you app, you have to configure deep linking.

image

And in AppDelegate.m, add these lines:

#import <React/RCTLinkingManager.h>

......
......

// Deep linking
- (BOOL)application:(UIApplication *)application
   openURL:(NSURL *)url
   options:(NSDictionary<UIApplicationOpenURLOptionsKey,id> *)options
{
  return [RCTLinkingManager application:application openURL:url options:options];
}

N.B.: replace myapp with the name of your app

Setup Deep links (Android)

To configure the external linking in Android, you can create a new intent in the manifest.

The easiest way to do this is with the uri-scheme package: npx uri-scheme add myapp --android

If you want to add it manually, open up YourApp/android/app/src/main/AndroidManifest.xml, and make the following adjustments:

  1. Set launchMode of MainActivity to singleTask in order to receive intent on existing MainActivity (this is the default on all new projects, so you may not need to actually change anything!). It is useful if you want to perform navigation using deep link you have been registered - details
  2. Add the new intent-filter inside the MainActivity entry with a VIEW type action:
<activity
    android:name=".MainActivity"
    android:launchMode="singleTask">
    <intent-filter>
        <action android:name="android.intent.action.MAIN" />
        <category android:name="android.intent.category.LAUNCHER" />
    </intent-filter>
    <intent-filter>
        <action android:name="android.intent.action.VIEW" />
        <category android:name="android.intent.category.DEFAULT" />
        <category android:name="android.intent.category.BROWSABLE" />
        <data android:scheme="myapp" />
    </intent-filter>
</activity>

N.B.: replace myapp with the name of your app

Getting Started

Setup RNKeycloak instance

Create a keycloak.ts file in the src folder of your project (where App.ts is located) with the following content

import { RNKeycloak } from '@react-keycloak/native';

// Setup Keycloak instance as needed
// Pass initialization options as required
const keycloak = new RNKeycloak({
  url: 'http://keycloak-server/auth',
  realm: 'kc-realm',
  clientId: 'web',
});

export default keycloak;

Setup ReactNativeKeycloakProvider

Wrap your App inside KeycloakProvider and pass the keycloak instance as prop

import { ReactNativeKeycloakProvider } from '@react-keycloak/native';

import keycloak from './keycloak';

// Wrap everything inside ReactNativeKeycloakProvider
const App = () => (
  <ReactNativeKeycloakProvider
    authClient={keycloak}
    initOptions={{
      redirectUri: 'myapp://Homepage',
      // if you need to customize "react-native-inappbrowser-reborn" View you can use the following attribute
      inAppBrowserOptions: {
        // For iOS check: https://github.com/proyecto26/react-native-inappbrowser#ios-options
        // For Android check: https://github.com/proyecto26/react-native-inappbrowser#android-options
      },
    }}
  >
    <Login />
  </ReactNativeKeycloakProvider>
);

export default App;

N.B. If your using other providers (such as react-redux) it is recommended to place them inside ReactNativeKeycloakProvider.

ReactNativeKeycloakProvider automatically invokes keycloak.init() method when needed and supports the following props:

  • initConfig, contains the object to be passed to keycloak.init() method, by default the following is used

    {
      onLoad: 'check-sso',
    }
    

    for more options see Keycloak docs.

  • LoadingComponent, a component to be displayed while keycloak is being initialized, if not provided child components will be rendered immediately. Defaults to null

  • isLoadingCheck, an optional loading check function to customize LoadingComponent display condition. Return true to display LoadingComponent, false to hide it.

    Can be implemented as follow

    (keycloak) => !keycloak.authenticated;
  • onEvent, an handler function that receives events launched by keycloak, defaults to null.

    It can be implemented as follow

    (event, error) => {
      console.log('onKeycloakEvent', event, error);
    };

    Published events are:

    • onReady
    • onInitError
    • onAuthSuccess
    • onAuthError
    • onAuthRefreshSuccess
    • onAuthRefreshError
    • onTokenExpired
    • onAuthLogout
  • onTokens, an handler function that receives keycloak tokens as an object every time they change, defaults to null.

    Keycloak tokens are returned as follow

    {
      "idToken": string,
      "refreshToken": string,
      "token": string
    }

Hook Usage

When a component requires access to Keycloak, you can use the useKeycloak Hook.

import { useKeycloak } from '@react-keycloak/native';

export default () => {
  // Using array destructuring
  const [keycloak, initialized] = useKeycloak();
  // or Object destructuring
  const { keycloak, initialized } = useKeycloak();

  // Here you can access all of keycloak methods and variables.
  // See https://www.keycloak.org/docs/latest/securing_apps/index.html#javascript-adapter-reference

  return (
    <View>
      <Text>
        {`User is ${!keycloak.authenticated ? 'NOT ' : ''}authenticated`}
      </Text>

      {!!keycloak.authenticated && (
        <Button onPress={() => keycloak.logout()} title="Logout" />
      )}
    </View>
  );
};

External Usage (Advanced)

If you need to access keycloak instance from non-React files (such as sagas, utils, providers ...), you can import the instance directly from the keycloak.ts file.

The instance will be initialized by react-keycloak but you'll need to be carefull when using the instance and avoid setting/overriding any props, you can however freely access the exposed methods (such as refreshToken, login, etc...).

Examples

See inside example folder for a demo app showcasing the main features.

Contributing

See the contributing guide to learn how to contribute to the repository and the development workflow.

License

MIT

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].