All Projects → bsvveen → React-OpenIdConnect

bsvveen / React-OpenIdConnect

Licence: other
Simple React OpenIdConnect component

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to React-OpenIdConnect

ooproxy
A reverse OpenID Connect and OAuth 2 proxy, implementing the client-credentials flow.
Stars: ✭ 25 (-16.67%)
Mutual labels:  openidconnect
Lua Resty Openidc
OpenID Connect Relying Party and OAuth 2.0 Resource Server implementation in Lua for NGINX / OpenResty
Stars: ✭ 626 (+1986.67%)
Mutual labels:  openidconnect
Nginx Openid Connect
Reference implementation of OpenID Connect integration for NGINX Plus
Stars: ✭ 96 (+220%)
Mutual labels:  openidconnect
oidc-agent
oidc-agent for managing OpenID Connect tokens on the command line
Stars: ✭ 47 (+56.67%)
Mutual labels:  openidconnect
Aspnet.security.openidconnect.server
OpenID Connect/OAuth2 server framework for OWIN/Katana and ASP.NET Core
Stars: ✭ 544 (+1713.33%)
Mutual labels:  openidconnect
Servicestack Authentication Identityserver
A plugin for ServiceStack and IdentityServer that provides OpenIDConnect / OAuth 2.0 Single Sign-On Authentication
Stars: ✭ 28 (-6.67%)
Mutual labels:  openidconnect
lemonldap-ng
LemonLDAP::NG main code
Stars: ✭ 49 (+63.33%)
Mutual labels:  openidconnect
Openiddict Samples
ASP.NET Core, Microsoft.Owin/ASP.NET 4.x and JavaScript samples for OpenIddict
Stars: ✭ 214 (+613.33%)
Mutual labels:  openidconnect
Angular Auth Oidc Client
npm package for OpenID Connect, OAuth Code Flow with PKCE, Refresh tokens, Implicit Flow
Stars: ✭ 577 (+1823.33%)
Mutual labels:  openidconnect
Oauth2 Oidc Debugger
An OAuth2 and OpenID Connect Debugger
Stars: ✭ 78 (+160%)
Mutual labels:  openidconnect
Glewlwyd
Single Sign On server, OAuth2, Openid Connect, multiple factor authentication with, HOTP/TOTP, FIDO2, TLS Certificates, etc. extensible via plugins
Stars: ✭ 292 (+873.33%)
Mutual labels:  openidconnect
Portier Broker
Portier Broker reference implementation, written in Rust
Stars: ✭ 474 (+1480%)
Mutual labels:  openidconnect
Login Cidadao
Projeto Login Cidadão
Stars: ✭ 61 (+103.33%)
Mutual labels:  openidconnect
fastapi-oidc-react
React + FastApi + Mongo - Login with Google and Azure (OIDC authorisation code flow)
Stars: ✭ 42 (+40%)
Mutual labels:  openidconnect
Openiddict Core
Versatile OpenID Connect stack for ASP.NET Core and Microsoft.Owin (compatible with ASP.NET 4.6.1)
Stars: ✭ 2,275 (+7483.33%)
Mutual labels:  openidconnect
fastapi-azure-auth
Easy and secure implementation of Azure AD for your FastAPI APIs 🔒 B2C, single- and multi-tenant support.
Stars: ✭ 174 (+480%)
Mutual labels:  openidconnect
Jose Jwt
Ultimate Javascript Object Signing and Encryption (JOSE) and JSON Web Token (JWT) Implementation for .NET and .NET Core
Stars: ✭ 692 (+2206.67%)
Mutual labels:  openidconnect
fab-oidc
Flask-AppBuilder SecurityManager for OpenIDConnect
Stars: ✭ 28 (-6.67%)
Mutual labels:  openidconnect
Jose2go
Golang (GO) implementation of Javascript Object Signing and Encryption specification
Stars: ✭ 150 (+400%)
Mutual labels:  openidconnect
Cas
Apereo CAS - Enterprise Single Sign On for all earthlings and beyond.
Stars: ✭ 9,154 (+30413.33%)
Mutual labels:  openidconnect

Simple React Wrapper around OIDC-Client.

Install

NPM

npm install --save react-openidconnect

Usage

Import the component and add <Authenticate> to you react app. All its children will be rendered when the user is authenticated. Otherwise a text is show asking the user to login, this text is provided as a prop.

The JWT is provided trough the callback 'userLoaded' and is called at them moment the user is retrieved from the identityserver. 'userUnLoaded' is called when the user is removed from session. Its up to you to decided what to do with the JWT.

Depending on the IdentityServer used, the JWT has an acces_token and an id_token which can be used to add to your Fecth request headers as bearer token. This will grant you access to the resource server.

Example

Assuming a Create-React app.

1 - Change your app.js file to

import React, { Component } from 'react';
import Authenticate from 'react-openidconnect';
import OidcSettings from './oidcsettings';
 
class App extends Component {
 
  constructor(props) {
    super(props);
    this.userLoaded = this.userLoaded.bind(this); 
    this.userUnLoaded = this.userUnLoaded.bind(this);
 
    this.state = { user: undefined };
  }  
 
  userLoaded(user) {
    if (user)
      this.setState({ "user": user });
  } 
  
  userUnLoaded() {
    this.setState({ "user": undefined });
  } 
 
  NotAuthenticated() {
    return <div>You are not authenticated, please click here to authenticate.</div>;
  }

  // @NOTE This function is optional. If you not pass it will looks for "#id_token" in the URL
  checkAuthentication() {
    return window.location.href.includes("my_token_hash"); 
  }
 
  render() {
      return (
        <Authenticate         
          OidcSettings={OidcSettings} 
          checkAuthentication={checkAuthentication}
          userLoaded={this.userLoaded} 
          userunLoaded={this.userUnLoaded} 
          renderNotAuthenticated={this.NotAuthenticated}
        >
            <div>If you see this you are authenticated.</div>
        </Authenticate>
      )
  }
}

export default App;

2 - Create a oidcsettings.js file in the same map as you app.js and provide the Oidc settings. You should retrieve these settings from you identity provider. Getting these settings right is normally the most frustrating part.

OidcSettings provides the following properties.

  • authority (string): The URL of the OIDC/OAuth2 provider.
  • client_id (string): Your client application’s identifier as registered with the OIDC/OAuth2 provider.
  • redirect_uri (string): The redirect URI of your client application to receive a response from the OIDC/OAuth2 provider.
  • scope (string): The scope being requested from the OIDC/OAuth2 provider (default: ‘openid’).
  • response_type: 'id_token token'.
  • post_logout_redirect_uri: (string): The redirect URI of your client after logout.

Example:

var OidcSettings = {    
    authority: 'https://****/identity',
    client_id: 'myclientid',
    redirect_uri: 'https://localhost:9090/',    
    response_type: 'id_token token',
    scope: 'openid profile roles',
    post_logout_redirect_uri: 'https://localhost:9090/'      
};

3 - You need to start your React app using the same url as in redirect_uri. The way to do this is to change the start script inside your package.json to.

windows
"start": "set PORT=9090&&set HTTPS=true&&react-scripts start" 

other
"start": "set PORT=9090 set HTTPS=true react-scripts start" (other)

NOTE: when authenticating against an identity provider, a redirect is used to provide the required token via the querystring. The <Authenticate> needs to pick-up this token so be sure the component is rendered when the redirect-url is called.

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].