Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

react-oidc-context

Package Overview
Dependencies
Maintainers
2
Versions
30
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-oidc-context

OpenID Connect & OAuth2 authentication using react context api as state management

  • 3.0.0-rc.1
  • next
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
56K
decreased by-48.71%
Maintainers
2
Weekly downloads
 
Created

What is react-oidc-context?

The react-oidc-context package is a React library that provides context and hooks for handling OpenID Connect (OIDC) authentication. It simplifies the process of integrating OIDC authentication into React applications by managing the authentication state, tokens, and user information.

What are react-oidc-context's main functionalities?

Authentication Provider

The AuthProvider component is used to wrap your application and provide the OIDC context. It takes configuration options such as authority, client_id, redirect_uri, response_type, and scope.

import { AuthProvider } from 'react-oidc-context';

const oidcConfig = {
  authority: 'https://example.com',
  client_id: 'your-client-id',
  redirect_uri: 'http://localhost:3000/callback',
  response_type: 'code',
  scope: 'openid profile email'
};

function App() {
  return (
    <AuthProvider {...oidcConfig}>
      <YourAppComponents />
    </AuthProvider>
  );
}

Using Authentication Hooks

The useAuth hook provides access to the authentication state and methods such as login and logout. It also provides the authenticated user's information.

import { useAuth } from 'react-oidc-context';

function UserProfile() {
  const { user, isAuthenticated, login, logout } = useAuth();

  if (!isAuthenticated) {
    return <button onClick={login}>Login</button>;
  }

  return (
    <div>
      <h1>Welcome, {user.profile.name}</h1>
      <button onClick={logout}>Logout</button>
    </div>
  );
}

Handling Authentication Callback

The AuthCallback component handles the redirect URI after the user has authenticated. It processes the authentication response and updates the authentication state.

import { AuthProvider, AuthCallback } from 'react-oidc-context';

function App() {
  return (
    <AuthProvider {...oidcConfig}>
      <Route path='/callback' component={AuthCallback} />
      <YourAppComponents />
    </AuthProvider>
  );
}

Other packages similar to react-oidc-context

Keywords

FAQs

Package last updated on 10 Jan 2024

Did you know?

Socket

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc