mnadeem / react-sso-app

Source code for the blog

Home Page:https://reachmnadeem.wordpress.com/2020/02/05/authentication-sso-with-oauth2-and-jwt-in-react-application-with-nodejs-back-end-and-keycloak-iam/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Introduction

Demonstrates how multi IDP Single sign-on SSO (Authentication & Authorization) can be implemented in React Based front end application with NodeJS base back end application.

Common code which support all IDPs agnostically at React Side. Various strategies have been implemented to support various IDPS, currently implementation have been provided for FusionAuth, Keycloak, Okta, PingFederate. Support for other IDPs can be similarly and easily implemented.

  • Implement OAuthStrategy, look for implementations in package auth.strategy
  • Add an entry in OAuthStrategies

Configure IDPs

Start the keycloak server and configure it as described from here

Configure OKTA and FusionAuth as described here

Configure API

Update environment variables for keycloak, OKTA and FusionAuth

Start API

react-sso-app\api> npm run dev

Start UI

react-sso-app> npm start

Access the Application

Docker

e:\practices\node\react-sso-app>docker-compose up --build 

Output

Starting react-sso-app_api_1 ... done
Starting react-sso-app_ui_1  ... done
Attaching to react-sso-app_api_1, react-sso-app_ui_1
api_1  | App is listening for requests on port 5555
ui_1   | http://api:5555
ui_1   | [HPM] Proxy created: /api  ->  http://api:5555

If you access http://localhost:3000/?idp=okta

api_1  | User mnadeem@gmail.com successfully logged in.
E:\practices\node\react-sso-app>docker-compose ps
       Name                      Command               State           Ports
-------------------------------------------------------------------------------------
react-sso-app_api_1   /bin/sh -c node ./dist/ser ...   Up      0.0.0.0:5555->5555/tcp
react-sso-app_ui_1    docker-entrypoint.sh /bin/ ...   Up      0.0.0.0:3000->3000/tcp

E:\practices\node\react-sso-app>
E:\practices\node\react-sso-app>docker-compose logs -f
Attaching to react-sso-app_ui_1, react-sso-app_api_1
ui_1   | http://api:5555
ui_1   | [HPM] Proxy created: /api  ->  http://api:5555
ui_1   | http://api:5555
ui_1   | [HPM] Proxy created: /api  ->  http://api:5555
api_1  | App is listening for requests on port 5555
api_1  | App is listening for requests on port 5555
api_1  | App is listening for requests on port 5555
api_1  | App is listening for requests on port 5555
api_1  | User mnadeem@gmail.com successfully logged in.
api_1  | App is listening for requests on port 5555
api_1  | User mnadeem@gmail.com successfully logged in.

About

Source code for the blog

https://reachmnadeem.wordpress.com/2020/02/05/authentication-sso-with-oauth2-and-jwt-in-react-application-with-nodejs-back-end-and-keycloak-iam/


Languages

Language:JavaScript 85.3%Language:HTML 5.7%Language:Shell 3.9%Language:CSS 3.1%Language:Dockerfile 2.0%