SlideShare a Scribd company logo
Simplify React App
Login
Today’s Lineup
● Challenges in adding login to React
● Managing user accounts
● Asgardeo Javascript SDKs
● Integrate your application with Asgardeo
⦿ Create a React application with Vite
⦿ Implement the two basic components
⦿ Install Asgardeo React SDK
⦿ Integrate your React application with Asgardeo
⦿ Implement login and logout buttons
● Application security best practices
Practical Session
Nipuni Paaris
01
Associate Technical Lead @ WSO2
x
Challenges in Adding Login to
React
Navigating challenges in adding login to React
5
State management
Handling authentication state across different components
Security
Ensuring secure transmission and storage of user credentials
Token management
Managing access tokens and refresh tokens
Token processing
Accessing the session tokens and extracting attributes and roles
Session management
Maintaining user sessions and handling session expiration
1
2
3
4
5
Navigating challenges in adding login to React
6
Redirects and routing
Handling redirects post-login and ensuring secure routes
User experience
Creating a seamless and intuitive login experience
Third-party integrations
Integrating with third-party authentication providers
Role-Based Access Control (RBAC)
Implementing and managing user roles and permissions
Error handling
Properly handling and displaying authentication errors
6
7
8
9
10
Managing user accounts
In-App user management and login
Out-of-the-Box Identity
Providers
Getting started with user management in your
application
Social login
User authorization
Multi factor authentication (MFA)
Application insights
User registration
API Access
User login
Consent management
Single sign-on (SSO)
Password reset Account locking
Focus solely on your
business capabilities!
Integrate your app with an
OOTB Identity Provider
And
Why DIY when you can fly?
● Enhanced security
⦿ Multi-Factor Authentication (MFA)
⦿ Secure token storage
⦿ Continuous updates
⦿ Advanced threat detection
● Reduced development effort
⦿ Speed up implementation
⦿ Focus on core features
⦿ Reduce maintenance burden
● Scalability and compliance
Why DIY when you can fly?
● Streamlined user experience
⦿ Seamless login processes
⦿ Consistent user interface
⦿ Reduced password fatigue
● Support for modern authentication protocols
● Centralized user management and governance
⦿ User provisioning and de-provisioning
⦿ Role-Based Access Control (RBAC)
⦿ Audit and reporting
● Seamless integration with third parties
Asgardeo Javascript SDKs
Why DIY when you can fly?
Why DIY when you can fly?
Asgardeo Javascript SDK
(@asgardeo/auth-js)
Asgardeo SPA SDK
(@asgardeo/auth-spa)
Asgardeo Node SDK
(@asgardeo/auth-node)
Asgardeo React SDK
(@asgardeo/auth-react)
Asgardeo Angular SDK
(@asgardeo/auth-angular)
Asgardeo Express SDK
(@asgardeo/auth-express)
Step 01: Setup the initial React application
# Following command is used to create a new react project usingVite
# You can replace react-sample with your project name
# You can also replace react with react-ts if you need to use
Typescript.
npm create vite@latest react-sample -- --template react
Step 02: Create the first components
// The home page component.
export const HomePage = () => {
return (
<div>
<h1>
Welcome to the HomePage!
</h1>
<p>
This is the content of the
page.
</p>
</div>
);
}
// The landing page component.
export const LandingPage = () => {
return (
<div>
<h1>
Welcome to the LandingPage!
</h1>
<p>
This is the content of the
page.
</p>
</div>
);
}
Step 03: Install the Asgardeo React SDK
# Run the following command to install @asgardeo/auth-react from
the npm registry.
npm install @asgardeo/auth-react --save
Step 04: Integrate your application with Asgardeo
// Import and wrap your root component with the AuthProvider.
// AuthProvider takes a config object as a prop that can be used to initialize the SDK
instance.
const config = {
signInRedirectURL: "http://localhost:5173",
signOutRedirectURL: "http://localhost:5173",
clientID: "YOUR_APP_CLIENT_ID",
baseUrl: "https://api.asgardeo.io/t/{tenant}",
scope: [ "openid", "profile" ]
};
ReactDOM.createRoot(document.getElementById(“root”)).render(
<React.StrictMode>
<AuthProvider config={ config }>
<App />
</AuthProvider>
</React.StrictMode>,
);
Key benefits of Asgardeo Javascript SDKs
● Integrate OAuth 2.0 and OpenID Connect (OIDC)
into JavaScript applications.
● Follows identity and access management best
practices.
● Protection against common vulnerabilities such as
XSS.
● Automatic token refresh and secure storage.
● Integrates well with other vendors.
● Cross-platform compatibility with various
JavaScript frameworks and libraries.
React Security Best Practices
Hacker Victim
Trusted website
Hacker injects the
malicious script
Victim triggers the
malicious script
Victims browser executes the malicious script and
unknowingly send information to the hacker
Cross-site scripting (XSS)
Does React make you immune to
XSS?
YES
BUT…
<div dangerouslySetInnerHTML={{__html:”<script>alert(“XSS!”);</script>”}}/>
// OR
this.myRef.current.innerHTML = ”<script>alert(“XSS!”);</script>”;
Don’t do this
import DOMPurify from "dompurify";
<div dangerouslySetInnerHTML={{__html:DOMPurify.sanitize(data) }} />
Sanitize and render HTML
const maliciousUrl = “javascript:alert(1)”;
<a href={ maliciousUrl }>Click here!</a>
Don’t do this
function validateURL(url) {
const parsed = new URL(url)
return ['https:', 'http:'].includes(parsed.protocol)
}
<a href={validateURL(url) ? url : ''}>Click here!</a>
Validate URL inputs
When an application incorrectly implement access control, logged in users might get
permissions to do operations beyond their designated limits through hacks. Which
mostly happens through access token leaks.
This will lead to:
Broken access control
● Unauthorized information disclosure.
● Data modification or destruction.
OR
Local/Session storage Web worker
Storage mechanisms in Asgardeo React SDK
References and further reading
● Simplify React App login:
https://medium.com/identity-beyond-borders/simplify-react-app-logi
n-3bcaa166ded0
● Asgardeo React SDK:
https://github.com/asgardeo/asgardeo-auth-react-sdk
● OWASP Top 10: https://owasp.org/www-project-top-ten
● Asgardeo official documentation:
https://wso2.com/asgardeo/docs/get-started/try-your-own-app/java
script/
Question Time!
Thank You.

More Related Content

PDF
Simplify React app login with asgardeo-sdk
PDF
Mastering Secure Login Mechanisms for React Apps.pdf
PDF
React security vulnerabilities
PDF
A Detailed Guide to Securing React applications with Keycloak - WalkingTree ...
PDF
React commonest security flaws and remedial measures!
PDF
Shields Up! Securing React Apps
PDF
API Security - OWASP top 10 for APIs + tips for pentesters
PPTX
Secure Coding for NodeJS
Simplify React app login with asgardeo-sdk
Mastering Secure Login Mechanisms for React Apps.pdf
React security vulnerabilities
A Detailed Guide to Securing React applications with Keycloak - WalkingTree ...
React commonest security flaws and remedial measures!
Shields Up! Securing React Apps
API Security - OWASP top 10 for APIs + tips for pentesters
Secure Coding for NodeJS

Similar to Simplify React App Login with Asgardeo React SDK (20)

PPTX
7 Deadly Sins in Azure AD App Development
PPTX
Fragments-Plug the vulnerabilities in your App
PDF
Checkmarx meetup API Security - API Security in depth - Inon Shkedy
PPTX
Using Firebase Authentication in a React App.pptx
PPTX
Rest API Security - A quick understanding of Rest API Security
PPTX
IRREPORT.pptx
PDF
Serverless Security Guy Podjarny Liran Tal
PPTX
Mit 2014 introduction to open id connect and o-auth 2
PPTX
From JSX to Deployment: Mastering the React Workflow for Scalable Front-End D...
PDF
OWASP API Security Top 10 Examples
PPTX
Enterprise Access Control Patterns for Rest and Web APIs
PPTX
A Practical Guide to Securing Modern Web Applications
PDF
DEV117 - Unleash the Power of the AppDev Pack and Node.js in Domino
PDF
React Libraries For Every Purpose Your Business Needs In 2022
PDF
React Best Practices All Developers Should Follow in 2024.pdf
PPTX
Building Secure User Interfaces With JWTs
PDF
OWASP Portland - OWASP Top 10 For JavaScript Developers
PDF
"Auth for React.js APP", Nikita Galkin
PDF
Navigating Identity and Access Management in the Modern Enterprise
PPTX
FINALPPT.pptx
7 Deadly Sins in Azure AD App Development
Fragments-Plug the vulnerabilities in your App
Checkmarx meetup API Security - API Security in depth - Inon Shkedy
Using Firebase Authentication in a React App.pptx
Rest API Security - A quick understanding of Rest API Security
IRREPORT.pptx
Serverless Security Guy Podjarny Liran Tal
Mit 2014 introduction to open id connect and o-auth 2
From JSX to Deployment: Mastering the React Workflow for Scalable Front-End D...
OWASP API Security Top 10 Examples
Enterprise Access Control Patterns for Rest and Web APIs
A Practical Guide to Securing Modern Web Applications
DEV117 - Unleash the Power of the AppDev Pack and Node.js in Domino
React Libraries For Every Purpose Your Business Needs In 2022
React Best Practices All Developers Should Follow in 2024.pdf
Building Secure User Interfaces With JWTs
OWASP Portland - OWASP Top 10 For JavaScript Developers
"Auth for React.js APP", Nikita Galkin
Navigating Identity and Access Management in the Modern Enterprise
FINALPPT.pptx
Ad

Recently uploaded (20)

PDF
PPT on Performance Review to get promotions
PDF
Enhancing Cyber Defense Against Zero-Day Attacks using Ensemble Neural Networks
PPTX
CARTOGRAPHY AND GEOINFORMATION VISUALIZATION chapter1 NPTE (2).pptx
PPT
introduction to datamining and warehousing
PPTX
Artificial Intelligence
PPT
Mechanical Engineering MATERIALS Selection
PPT
Introduction, IoT Design Methodology, Case Study on IoT System for Weather Mo...
PPTX
OOP with Java - Java Introduction (Basics)
PPTX
Geodesy 1.pptx...............................................
PDF
SM_6th-Sem__Cse_Internet-of-Things.pdf IOT
PDF
Digital Logic Computer Design lecture notes
PPTX
M Tech Sem 1 Civil Engineering Environmental Sciences.pptx
PDF
Mitigating Risks through Effective Management for Enhancing Organizational Pe...
PPTX
Lecture Notes Electrical Wiring System Components
PDF
Evaluating the Democratization of the Turkish Armed Forces from a Normative P...
PDF
The CXO Playbook 2025 – Future-Ready Strategies for C-Suite Leaders Cerebrai...
PDF
Embodied AI: Ushering in the Next Era of Intelligent Systems
PDF
BMEC211 - INTRODUCTION TO MECHATRONICS-1.pdf
PDF
Automation-in-Manufacturing-Chapter-Introduction.pdf
PPTX
MET 305 2019 SCHEME MODULE 2 COMPLETE.pptx
PPT on Performance Review to get promotions
Enhancing Cyber Defense Against Zero-Day Attacks using Ensemble Neural Networks
CARTOGRAPHY AND GEOINFORMATION VISUALIZATION chapter1 NPTE (2).pptx
introduction to datamining and warehousing
Artificial Intelligence
Mechanical Engineering MATERIALS Selection
Introduction, IoT Design Methodology, Case Study on IoT System for Weather Mo...
OOP with Java - Java Introduction (Basics)
Geodesy 1.pptx...............................................
SM_6th-Sem__Cse_Internet-of-Things.pdf IOT
Digital Logic Computer Design lecture notes
M Tech Sem 1 Civil Engineering Environmental Sciences.pptx
Mitigating Risks through Effective Management for Enhancing Organizational Pe...
Lecture Notes Electrical Wiring System Components
Evaluating the Democratization of the Turkish Armed Forces from a Normative P...
The CXO Playbook 2025 – Future-Ready Strategies for C-Suite Leaders Cerebrai...
Embodied AI: Ushering in the Next Era of Intelligent Systems
BMEC211 - INTRODUCTION TO MECHATRONICS-1.pdf
Automation-in-Manufacturing-Chapter-Introduction.pdf
MET 305 2019 SCHEME MODULE 2 COMPLETE.pptx
Ad

Simplify React App Login with Asgardeo React SDK

  • 2. Today’s Lineup ● Challenges in adding login to React ● Managing user accounts ● Asgardeo Javascript SDKs ● Integrate your application with Asgardeo ⦿ Create a React application with Vite ⦿ Implement the two basic components ⦿ Install Asgardeo React SDK ⦿ Integrate your React application with Asgardeo ⦿ Implement login and logout buttons ● Application security best practices Practical Session
  • 4. Challenges in Adding Login to React
  • 5. Navigating challenges in adding login to React 5 State management Handling authentication state across different components Security Ensuring secure transmission and storage of user credentials Token management Managing access tokens and refresh tokens Token processing Accessing the session tokens and extracting attributes and roles Session management Maintaining user sessions and handling session expiration 1 2 3 4 5
  • 6. Navigating challenges in adding login to React 6 Redirects and routing Handling redirects post-login and ensuring secure routes User experience Creating a seamless and intuitive login experience Third-party integrations Integrating with third-party authentication providers Role-Based Access Control (RBAC) Implementing and managing user roles and permissions Error handling Properly handling and displaying authentication errors 6 7 8 9 10
  • 8. In-App user management and login Out-of-the-Box Identity Providers Getting started with user management in your application
  • 9. Social login User authorization Multi factor authentication (MFA) Application insights User registration API Access User login Consent management Single sign-on (SSO) Password reset Account locking
  • 10. Focus solely on your business capabilities! Integrate your app with an OOTB Identity Provider And
  • 11. Why DIY when you can fly? ● Enhanced security ⦿ Multi-Factor Authentication (MFA) ⦿ Secure token storage ⦿ Continuous updates ⦿ Advanced threat detection ● Reduced development effort ⦿ Speed up implementation ⦿ Focus on core features ⦿ Reduce maintenance burden ● Scalability and compliance
  • 12. Why DIY when you can fly? ● Streamlined user experience ⦿ Seamless login processes ⦿ Consistent user interface ⦿ Reduced password fatigue ● Support for modern authentication protocols ● Centralized user management and governance ⦿ User provisioning and de-provisioning ⦿ Role-Based Access Control (RBAC) ⦿ Audit and reporting ● Seamless integration with third parties
  • 14. Why DIY when you can fly? Why DIY when you can fly? Asgardeo Javascript SDK (@asgardeo/auth-js) Asgardeo SPA SDK (@asgardeo/auth-spa) Asgardeo Node SDK (@asgardeo/auth-node) Asgardeo React SDK (@asgardeo/auth-react) Asgardeo Angular SDK (@asgardeo/auth-angular) Asgardeo Express SDK (@asgardeo/auth-express)
  • 15. Step 01: Setup the initial React application # Following command is used to create a new react project usingVite # You can replace react-sample with your project name # You can also replace react with react-ts if you need to use Typescript. npm create vite@latest react-sample -- --template react
  • 16. Step 02: Create the first components // The home page component. export const HomePage = () => { return ( <div> <h1> Welcome to the HomePage! </h1> <p> This is the content of the page. </p> </div> ); } // The landing page component. export const LandingPage = () => { return ( <div> <h1> Welcome to the LandingPage! </h1> <p> This is the content of the page. </p> </div> ); }
  • 17. Step 03: Install the Asgardeo React SDK # Run the following command to install @asgardeo/auth-react from the npm registry. npm install @asgardeo/auth-react --save
  • 18. Step 04: Integrate your application with Asgardeo // Import and wrap your root component with the AuthProvider. // AuthProvider takes a config object as a prop that can be used to initialize the SDK instance. const config = { signInRedirectURL: "http://localhost:5173", signOutRedirectURL: "http://localhost:5173", clientID: "YOUR_APP_CLIENT_ID", baseUrl: "https://api.asgardeo.io/t/{tenant}", scope: [ "openid", "profile" ] }; ReactDOM.createRoot(document.getElementById(“root”)).render( <React.StrictMode> <AuthProvider config={ config }> <App /> </AuthProvider> </React.StrictMode>, );
  • 19. Key benefits of Asgardeo Javascript SDKs ● Integrate OAuth 2.0 and OpenID Connect (OIDC) into JavaScript applications. ● Follows identity and access management best practices. ● Protection against common vulnerabilities such as XSS. ● Automatic token refresh and secure storage. ● Integrates well with other vendors. ● Cross-platform compatibility with various JavaScript frameworks and libraries.
  • 20. React Security Best Practices
  • 21. Hacker Victim Trusted website Hacker injects the malicious script Victim triggers the malicious script Victims browser executes the malicious script and unknowingly send information to the hacker Cross-site scripting (XSS)
  • 22. Does React make you immune to XSS? YES
  • 25. import DOMPurify from "dompurify"; <div dangerouslySetInnerHTML={{__html:DOMPurify.sanitize(data) }} /> Sanitize and render HTML
  • 26. const maliciousUrl = “javascript:alert(1)”; <a href={ maliciousUrl }>Click here!</a> Don’t do this
  • 27. function validateURL(url) { const parsed = new URL(url) return ['https:', 'http:'].includes(parsed.protocol) } <a href={validateURL(url) ? url : ''}>Click here!</a> Validate URL inputs
  • 28. When an application incorrectly implement access control, logged in users might get permissions to do operations beyond their designated limits through hacks. Which mostly happens through access token leaks. This will lead to: Broken access control ● Unauthorized information disclosure. ● Data modification or destruction.
  • 29. OR Local/Session storage Web worker Storage mechanisms in Asgardeo React SDK
  • 30. References and further reading ● Simplify React App login: https://medium.com/identity-beyond-borders/simplify-react-app-logi n-3bcaa166ded0 ● Asgardeo React SDK: https://github.com/asgardeo/asgardeo-auth-react-sdk ● OWASP Top 10: https://owasp.org/www-project-top-ten ● Asgardeo official documentation: https://wso2.com/asgardeo/docs/get-started/try-your-own-app/java script/