npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

react-native-oidc-auth

v0.1.3

Published

Bare React Native implementation using react-native-app-auth and react-native-keychain.

Readme

React Native OIDC Authentication

OIDC authentication for React Native with shared core and ready-to-use implementations for Expo and Bare React Native.

Npm Npm Npm

License Github Issues


Packages

  • react-native-oidc-auth-core: framework-agnostic core with login, logout, refresh, and secure token storage contracts.
  • react-native-oidc-auth-expo: Expo implementation using expo-auth-session and expo-secure-store.
  • react-native-oidc-auth: Bare React Native implementation using react-native-app-auth and react-native-keychain.

Table of Contents

Why

While integrating a React Native app with Keycloak, the only available library I found (react-native-keycloak) was unmaintained. I found other OIDC auth clients that worked well, such as:

  • react-native-app-auth
  • expo-auth-session

However, both lacked:

  • Automatic token refresh
  • Secure token storage integration

This library fills those gaps and provides an implementation for Expo and Bare React Native.

Features

  • Login, logout, and token refresh
  • Secure token storage
  • Automatic token refresh
  • Implementation for Expo and Bare RN
  • Optional registration flow (Keycloak-tested)

Install

Expo apps:

npm i react-native-oidc-auth-expo

Bare React Native apps:

npm i react-native-oidc-auth

Getting Started

Create an OidcAuth instance

Configure your OIDC provider:

import { createOidcAuth, type OidcConfiguration, setTracingLogger } from 'react-native-oidc-auth'; // or react-native-oidc-auth-expo

const issuer = `${OIDC_URL}/realms/${OIDC_REALM}`;

const config: OidcConfiguration = {
  issuer,
  clientId: CLIENT_ID ?? '',
  redirectUrl: REDIRECT_URI ?? '',
  postLogoutRedirectUrl: REDIRECT_URI ?? '',
  scopes: ['openid', 'profile'],
  // Bare RN only:
  dangerouslyAllowInsecureHttpRequests: __DEV__,
};

// Optional: Configure tracing
setTracingLogger(tracingLog);

export const oidcAuth = createOidcAuth(config);

Provider setup

Wrap your app with the provider:

import React from 'react';
import { OidcAuthProvider } from 'react-native-oidc-auth'; // or react-native-oidc-auth-expo
import { Main } from './components/main';
import { oidcAuth } from './lib/oidc-auth';

export default function App() {
  return (
    <OidcAuthProvider instance={oidcAuth}>
      <Main />
    </OidcAuthProvider>
  );
}

Hook usage

Use the hook to access auth state and actions:

import React from 'react';
import { View, Text, Button } from 'react-native';
import { useOidcAuth } from 'react-native-oidc-auth'; // or react-native-oidc-auth-expo

export const Main: React.FC = () => {
  const { isAuthenticated, user, login, logout } = useOidcAuth();

  return (
    <View>
      {isAuthenticated ? (
        <>
          <Text>Home</Text>
          <Text>Email: {user?.email}</Text>
          <Button onPress={logout} title="Logout" />
        </>
      ) : (
        <>
          <Text>Login</Text>
          <Button onPress={login} title="Login" />
        </>
      )}
    </View>
  );
};

Advanced

You can depend on react-native-oidc-auth-core to build your own adapter for alternative auth/secure storage libraries.

Experimental

This feature does not perform dynamic client registration.

Instead, it allows you to directly display the registration page and retrieve the token after completing the registration flow (tested with Keycloak only).

  1. Set the registration endpoint:
const config: OidcConfiguration = {
  // ...
  registrationPageEndpoint: `${issuer}/protocol/openid-connect/registrations`,
};
  1. Call register from your UI:
import React from "react";
import { View, Text, Button } from "react-native";
import { useOidcAuth } from "react-native-oidc-auth";

export const Main: React.FC = () => {
  const { isAuthenticated, login, register } = useOidcAuth();

  return (
    <View>
      {!isAuthenticated ? (
        <>
          <Text>Login</Text>
          <Button onPress={login} title="Login" />
          <Button onPress={register} title="Register" />
        </>
      ) : (
        <Text>Home</Text>
      )}
    </View>
  );
};

Keycloak flow overview:

  • User is redirected to the registration page.
  • After submitting, Keycloak sends a verification email.
  • The email link returns to the app; the token is stored, and the user is authenticated.

Examples

See examples/react-native and examples/expo for demo apps.

Notes

The logic in the core library is adapted from Keycloak JS.

License

MIT