SlideShare a Scribd company logo
www.webstackacademy.com
Authentication and Authorization
Angular
www.webstackacademy.comwww.webstackacademy.com
Introduction
(Security Foundations)
www.webstackacademy.com
Introduction
• Authentication is the process of validating a user on the credentials (username and password)
and provide access to the web application(ex: Email)
• Authorization helps you to control access rights by granting or denying specific permissions
to an authenticated user (Ex: User / Manager / Admin).
• Authorization is applied after the user is authenticated. Typically users are assigned with rights /
permissions based on which appropriate section(s) are loaded in the web application
• The user interacts with the server on Authorized sections of the application which results in data
exchange. In order to protect security and integrity of data other security components (ex:
Encryption) comes into picture
www.webstackacademy.com
Introduction
• Security is an inherent and critical feature of a web application. With rich data available
in the web server, any compromise results in bigger issues in socio / political ecosystem
• There are many algorithms, standards and tools in security which is quite vast in nature
• Our idea is to understand security from Angular Authentication and Authorization perspective
by practically implementing them in front-end web applications
• We will enhance our understanding of Routes (previous chapter) and display / hide certain
components based on the user authorization
www.webstackacademy.com
JSON Web Tokens (JWT)
• JSON Web Token (JWT) is an open standard defined in RFC 7519.
• It is a compact and self-contained way for securely transmitting information between parties (ex:
Web client and server) as a JSON object.
• This information can be verified and trusted because it is digitally signed.
• JWTs are signed using a secret (ex: HMAC algorithm) which is only known to client & server
• The signed token ensures the data integrity and security
www.webstackacademy.com
JSON Web Tokens (JWT) – In Action..
www.webstackacademy.com
JSON Web Tokens (JWT) – Usage
• JWTs are used in web based authorization once the user is successfully
authenticated with valid username & password.
• Each transaction between the client after authorization are done in a secure
manner as the data is encrypted.
www.webstackacademy.com
JSON Web Tokens (JWT) – Structure
• JWT has three parts that are separated by a (.) character
• Header, Payload and Signature (ex: xxxx.yyyy.zzzz)
• Each of them have a unique meaning and significance
• An example JWT will look as follows
www.webstackacademy.com
JWT - Structure
• Part-I (Header): Typically consists of two parts:
• Type of the token (ex: jwt)
• Hashing algorithm used (ex: HMAC SHA256)
• Part-II (Payload): It contains claims. Claims are statements about an entity (typically, the
user) and additional data.
• Both Header & Payload are encoded using base64 encoding and made as a first and second
part of the JWT
{
"alg": "HS256",
"typ": "JWT"
}
{
"sub": "1234567890",
"name": "WSA",
"admin": true
}
www.webstackacademy.com
JWT - Structure
• Part-III (Signature): The signature is nothing but a hash algorithm applied on header and
payload
• To create the signature part you have to take the encoded header, the encoded payload,
a secret, the algorithm specified in the header, and sign that.
• For example if you want to use the HMAC SHA256 algorithm, the signature will be created
in the following way:
HMACSHA256 (base64(header) + "." + base64(payload), secret)
• The output is three Base64 encoded strings separated by dots that can be easily passed in
HTML and HTTP environments
www.webstackacademy.com
What is base64 Encoding? – A brief
• Base64 converts a string of bytes into a string of
ASCII characters so that they can be
safely transmitted within HTTP.
• When encoding, Base64 will divide the string of
bytes into groups of 6 bits and each
group will map to one of 64 characters.
• In case the input is not clearly divisible in 6 bits,
additional zeros are added for padding
• Similar to ASCII table a mapping table is
maintained
www.webstackacademy.com
What is HMAC SHA? – A brief
• HMAC (Hash Message Authentication Code) - SHA
(Secure Hash Algorithm) is a specific type
of message authentication code (MAC)
• It involves a cryptographic hash function and a
secret cryptographic key. The key size can vary (ex:
SHA 256)
• The secret key is known only to the sender and the
receiver
• By applying hashing it generates what is known as
signature of the given plain text. It can be used for
validating the integrity of the message.
www.webstackacademy.com
Exercise
• JWT Debugger tool:
• It is used to generate JWT, let us do some hands-on
• Goto https://jwt.io/#debugger and try out by generating some JWT
• Base64 Encoding tool:
• It is used to check base64 encoding, let us do some hands-on
• Goto: https://www.base64decode.org and try out some encoding
www.webstackacademy.comwww.webstackacademy.com
Local Storage
(Storing user data in the browser)
www.webstackacademy.com
What is Local Storage?
• The Local storage allow to save key/value pairs
in a web browser.
• The Local storage data will persist after the
browser window is closed.
• The local storage property is read-only.
• Previously, cookies were used for storing such
key value pairs.
• Local storage has a significantly higher storage
limit (5MB vs 4KB), better for storing client
specific information
www.webstackacademy.com
Local storage methods
Local storage supports a set of methods for dealing with the data
Method Description
setItem() Add key and value to local storage
getItem() Retrieve a value by the key
removeItem() Remove an item by key
clear() Clear all storage
www.webstackacademy.com
Local storage methods usage
localStorage.setItem('key', 'value');
localStorage.getItem('key');
localStorage.removeItem('key');
localStorage.clear();
www.webstackacademy.comwww.webstackacademy.com
Starter Code
(A Brief about given code to get started with A & A)
www.webstackacademy.com
WebStack Academy
#83, Farah Towers,
1st Floor, MG Road,
Bangalore – 560001
M: +91-809 555 7332
E: training@webstackacademy.com
WSA in Social Media:

More Related Content

PPTX
Introduction to Node.js
Vikash Singh
 
PPTX
Ajax ppt - 32 slides
Smithss25
 
PDF
Angular
Lilia Sfaxi
 
PPTX
Java script
Sadeek Mohammed
 
PDF
Express node js
Yashprit Singh
 
PPTX
Angular Directives
Malla Reddy University
 
Introduction to Node.js
Vikash Singh
 
Ajax ppt - 32 slides
Smithss25
 
Angular
Lilia Sfaxi
 
Java script
Sadeek Mohammed
 
Express node js
Yashprit Singh
 
Angular Directives
Malla Reddy University
 

What's hot (20)

PPTX
Angular
khoado2002
 
PPTX
Express js
Manav Prasad
 
PPTX
Advance Java Topics (J2EE)
slire
 
ODP
Routing & Navigating Pages in Angular 2
Knoldus Inc.
 
PDF
Angular Directives
iFour Technolab Pvt. Ltd.
 
PPTX
Creating custom Validators on Reactive Forms using Angular 6
AIMDek Technologies
 
PPTX
New Elements & Features in HTML5
Jamshid Hashimi
 
PPT
Php Ppt
vsnmurthy
 
PDF
Angular - Chapter 3 - Components
WebStackAcademy
 
PDF
TypeScript - An Introduction
NexThoughts Technologies
 
PDF
Nodejs presentation
Arvind Devaraj
 
PDF
Angular - Chapter 1 - Introduction
WebStackAcademy
 
PPTX
PHP Cookies and Sessions
Nisa Soomro
 
PDF
React js
Rajesh Kolla
 
PDF
jQuery Tutorial For Beginners | Developing User Interface (UI) Using jQuery |...
Edureka!
 
PPTX
Intro to React
Justin Reock
 
PPT
android activity
Deepa Rani
 
PPTX
Web development tool
Deep Bhavsar
 
PPTX
Lab #2: Introduction to Javascript
Walid Ashraf
 
Angular
khoado2002
 
Express js
Manav Prasad
 
Advance Java Topics (J2EE)
slire
 
Routing & Navigating Pages in Angular 2
Knoldus Inc.
 
Angular Directives
iFour Technolab Pvt. Ltd.
 
Creating custom Validators on Reactive Forms using Angular 6
AIMDek Technologies
 
New Elements & Features in HTML5
Jamshid Hashimi
 
Php Ppt
vsnmurthy
 
Angular - Chapter 3 - Components
WebStackAcademy
 
TypeScript - An Introduction
NexThoughts Technologies
 
Nodejs presentation
Arvind Devaraj
 
Angular - Chapter 1 - Introduction
WebStackAcademy
 
PHP Cookies and Sessions
Nisa Soomro
 
React js
Rajesh Kolla
 
jQuery Tutorial For Beginners | Developing User Interface (UI) Using jQuery |...
Edureka!
 
Intro to React
Justin Reock
 
android activity
Deepa Rani
 
Web development tool
Deep Bhavsar
 
Lab #2: Introduction to Javascript
Walid Ashraf
 
Ad

Similar to Angular - Chapter 9 - Authentication and Authorization (20)

PDF
446-FUNDAMENTALS OF WEB FOR NON DEVELOPERS (Useful-Knowledge)
nrvalluri
 
PDF
Fundamentals of Web for Non-Developers
Lemi Orhan Ergin
 
PDF
Securing Web Applications with Token Authentication
Stormpath
 
PDF
blockchain class 3.pdf
GopalSB
 
PDF
Angular - Chapter 7 - HTTP Services
WebStackAcademy
 
PPTX
Blockchain on AWS
AWS Riyadh User Group
 
PPTX
cookie attributes and tokens,jwt tokens1.ppt
ShivakumarBejjenki1
 
PPTX
Securing Single Page Applications with Token Based Authentication
Stefan Achtsnit
 
PPTX
Evolution Of The Web Platform & Browser Security
Sanjeev Verma, PhD
 
PPTX
Training Webinar: Enterprise application performance with server push technol...
OutSystems
 
PPTX
Basics of the Web Platform
Sanjeev Verma, PhD
 
PDF
Technical considerations for Blockchain networks with AWS
atSistemas
 
PDF
The History and Status of Web Crypto API (2012)
Channy Yun
 
PDF
Web architecturesWeb architecturesWeb architectures
ShafeequeAhmed19
 
PPTX
Www architecture,cgi, client server security, protection
Austina Francis
 
PPTX
Building Secure User Interfaces With JWTs (JSON Web Tokens)
Stormpath
 
PPT
526_topic08.ppt
sajeedmalagi
 
PPTX
chapter4.pptxwgdyjshcbnbhvegwydvquhcjdvqigufwk
NiveditaSingh839848
 
PPTX
Building Secure User Interfaces With JWTs
robertjd
 
PPTX
Chapter-5.pptx about The Internet and The World Wide Web
mammadovadil07
 
446-FUNDAMENTALS OF WEB FOR NON DEVELOPERS (Useful-Knowledge)
nrvalluri
 
Fundamentals of Web for Non-Developers
Lemi Orhan Ergin
 
Securing Web Applications with Token Authentication
Stormpath
 
blockchain class 3.pdf
GopalSB
 
Angular - Chapter 7 - HTTP Services
WebStackAcademy
 
Blockchain on AWS
AWS Riyadh User Group
 
cookie attributes and tokens,jwt tokens1.ppt
ShivakumarBejjenki1
 
Securing Single Page Applications with Token Based Authentication
Stefan Achtsnit
 
Evolution Of The Web Platform & Browser Security
Sanjeev Verma, PhD
 
Training Webinar: Enterprise application performance with server push technol...
OutSystems
 
Basics of the Web Platform
Sanjeev Verma, PhD
 
Technical considerations for Blockchain networks with AWS
atSistemas
 
The History and Status of Web Crypto API (2012)
Channy Yun
 
Web architecturesWeb architecturesWeb architectures
ShafeequeAhmed19
 
Www architecture,cgi, client server security, protection
Austina Francis
 
Building Secure User Interfaces With JWTs (JSON Web Tokens)
Stormpath
 
526_topic08.ppt
sajeedmalagi
 
chapter4.pptxwgdyjshcbnbhvegwydvquhcjdvqigufwk
NiveditaSingh839848
 
Building Secure User Interfaces With JWTs
robertjd
 
Chapter-5.pptx about The Internet and The World Wide Web
mammadovadil07
 
Ad

More from WebStackAcademy (20)

PDF
Webstack Academy - Course Demo Webinar and Placement Journey
WebStackAcademy
 
PDF
WSA: Scaling Web Service to Handle Millions of Requests per Second
WebStackAcademy
 
PDF
WSA: Course Demo Webinar - Full Stack Developer Course
WebStackAcademy
 
PDF
Career Building in AI - Technologies, Trends and Opportunities
WebStackAcademy
 
PDF
Webstack Academy - Internship Kick Off
WebStackAcademy
 
PDF
Building Your Online Portfolio
WebStackAcademy
 
PDF
Front-End Developer's Career Roadmap
WebStackAcademy
 
PDF
Angular - Chapter 6 - Firebase Integration
WebStackAcademy
 
PDF
Angular - Chapter 5 - Directives
WebStackAcademy
 
PDF
Angular - Chapter 4 - Data and Event Handling
WebStackAcademy
 
PDF
Angular - Chapter 2 - TypeScript Programming
WebStackAcademy
 
PDF
JavaScript - Chapter 10 - Strings and Arrays
WebStackAcademy
 
PDF
JavaScript - Chapter 15 - Debugging Techniques
WebStackAcademy
 
PDF
JavaScript - Chapter 14 - Form Handling
WebStackAcademy
 
PDF
JavaScript - Chapter 13 - Browser Object Model(BOM)
WebStackAcademy
 
PDF
JavaScript - Chapter 12 - Document Object Model
WebStackAcademy
 
PDF
JavaScript - Chapter 11 - Events
WebStackAcademy
 
PDF
JavaScript - Chapter 9 - TypeConversion and Regular Expressions
WebStackAcademy
 
PDF
JavaScript - Chapter 8 - Objects
WebStackAcademy
 
PDF
JavaScript - Chapter 7 - Advanced Functions
WebStackAcademy
 
Webstack Academy - Course Demo Webinar and Placement Journey
WebStackAcademy
 
WSA: Scaling Web Service to Handle Millions of Requests per Second
WebStackAcademy
 
WSA: Course Demo Webinar - Full Stack Developer Course
WebStackAcademy
 
Career Building in AI - Technologies, Trends and Opportunities
WebStackAcademy
 
Webstack Academy - Internship Kick Off
WebStackAcademy
 
Building Your Online Portfolio
WebStackAcademy
 
Front-End Developer's Career Roadmap
WebStackAcademy
 
Angular - Chapter 6 - Firebase Integration
WebStackAcademy
 
Angular - Chapter 5 - Directives
WebStackAcademy
 
Angular - Chapter 4 - Data and Event Handling
WebStackAcademy
 
Angular - Chapter 2 - TypeScript Programming
WebStackAcademy
 
JavaScript - Chapter 10 - Strings and Arrays
WebStackAcademy
 
JavaScript - Chapter 15 - Debugging Techniques
WebStackAcademy
 
JavaScript - Chapter 14 - Form Handling
WebStackAcademy
 
JavaScript - Chapter 13 - Browser Object Model(BOM)
WebStackAcademy
 
JavaScript - Chapter 12 - Document Object Model
WebStackAcademy
 
JavaScript - Chapter 11 - Events
WebStackAcademy
 
JavaScript - Chapter 9 - TypeConversion and Regular Expressions
WebStackAcademy
 
JavaScript - Chapter 8 - Objects
WebStackAcademy
 
JavaScript - Chapter 7 - Advanced Functions
WebStackAcademy
 

Recently uploaded (20)

PDF
Make GenAI investments go further with the Dell AI Factory - Infographic
Principled Technologies
 
PDF
Event Presentation Google Cloud Next Extended 2025
minhtrietgect
 
PDF
CIFDAQ's Teaching Thursday: Moving Averages Made Simple
CIFDAQ
 
PPTX
The-Ethical-Hackers-Imperative-Safeguarding-the-Digital-Frontier.pptx
sujalchauhan1305
 
PDF
Google’s NotebookLM Unveils Video Overviews
SOFTTECHHUB
 
PPT
L2 Rules of Netiquette in Empowerment technology
Archibal2
 
DOCX
Top AI API Alternatives to OpenAI: A Side-by-Side Breakdown
vilush
 
PDF
Google I/O Extended 2025 Baku - all ppts
HusseinMalikMammadli
 
PDF
Chapter 2 Digital Image Fundamentals.pdf
Getnet Tigabie Askale -(GM)
 
PDF
How Onsite IT Support Drives Business Efficiency, Security, and Growth.pdf
Captain IT
 
PDF
madgavkar20181017ppt McKinsey Presentation.pdf
georgschmitzdoerner
 
PDF
CIFDAQ'S Market Insight: BTC to ETH money in motion
CIFDAQ
 
PDF
Why Your AI & Cybersecurity Hiring Still Misses the Mark in 2025
Virtual Employee Pvt. Ltd.
 
PDF
Unlocking the Future- AI Agents Meet Oracle Database 23ai - AIOUG Yatra 2025.pdf
Sandesh Rao
 
PDF
Oracle AI Vector Search- Getting Started and what's new in 2025- AIOUG Yatra ...
Sandesh Rao
 
PDF
GYTPOL If You Give a Hacker a Host
linda296484
 
PDF
Doc9.....................................
SofiaCollazos
 
PDF
The Evolution of KM Roles (Presented at Knowledge Summit Dublin 2025)
Enterprise Knowledge
 
PDF
BLW VOCATIONAL TRAINING SUMMER INTERNSHIP REPORT
codernjn73
 
PDF
Security features in Dell, HP, and Lenovo PC systems: A research-based compar...
Principled Technologies
 
Make GenAI investments go further with the Dell AI Factory - Infographic
Principled Technologies
 
Event Presentation Google Cloud Next Extended 2025
minhtrietgect
 
CIFDAQ's Teaching Thursday: Moving Averages Made Simple
CIFDAQ
 
The-Ethical-Hackers-Imperative-Safeguarding-the-Digital-Frontier.pptx
sujalchauhan1305
 
Google’s NotebookLM Unveils Video Overviews
SOFTTECHHUB
 
L2 Rules of Netiquette in Empowerment technology
Archibal2
 
Top AI API Alternatives to OpenAI: A Side-by-Side Breakdown
vilush
 
Google I/O Extended 2025 Baku - all ppts
HusseinMalikMammadli
 
Chapter 2 Digital Image Fundamentals.pdf
Getnet Tigabie Askale -(GM)
 
How Onsite IT Support Drives Business Efficiency, Security, and Growth.pdf
Captain IT
 
madgavkar20181017ppt McKinsey Presentation.pdf
georgschmitzdoerner
 
CIFDAQ'S Market Insight: BTC to ETH money in motion
CIFDAQ
 
Why Your AI & Cybersecurity Hiring Still Misses the Mark in 2025
Virtual Employee Pvt. Ltd.
 
Unlocking the Future- AI Agents Meet Oracle Database 23ai - AIOUG Yatra 2025.pdf
Sandesh Rao
 
Oracle AI Vector Search- Getting Started and what's new in 2025- AIOUG Yatra ...
Sandesh Rao
 
GYTPOL If You Give a Hacker a Host
linda296484
 
Doc9.....................................
SofiaCollazos
 
The Evolution of KM Roles (Presented at Knowledge Summit Dublin 2025)
Enterprise Knowledge
 
BLW VOCATIONAL TRAINING SUMMER INTERNSHIP REPORT
codernjn73
 
Security features in Dell, HP, and Lenovo PC systems: A research-based compar...
Principled Technologies
 

Angular - Chapter 9 - Authentication and Authorization

  • 3. www.webstackacademy.com Introduction • Authentication is the process of validating a user on the credentials (username and password) and provide access to the web application(ex: Email) • Authorization helps you to control access rights by granting or denying specific permissions to an authenticated user (Ex: User / Manager / Admin). • Authorization is applied after the user is authenticated. Typically users are assigned with rights / permissions based on which appropriate section(s) are loaded in the web application • The user interacts with the server on Authorized sections of the application which results in data exchange. In order to protect security and integrity of data other security components (ex: Encryption) comes into picture
  • 4. www.webstackacademy.com Introduction • Security is an inherent and critical feature of a web application. With rich data available in the web server, any compromise results in bigger issues in socio / political ecosystem • There are many algorithms, standards and tools in security which is quite vast in nature • Our idea is to understand security from Angular Authentication and Authorization perspective by practically implementing them in front-end web applications • We will enhance our understanding of Routes (previous chapter) and display / hide certain components based on the user authorization
  • 5. www.webstackacademy.com JSON Web Tokens (JWT) • JSON Web Token (JWT) is an open standard defined in RFC 7519. • It is a compact and self-contained way for securely transmitting information between parties (ex: Web client and server) as a JSON object. • This information can be verified and trusted because it is digitally signed. • JWTs are signed using a secret (ex: HMAC algorithm) which is only known to client & server • The signed token ensures the data integrity and security
  • 7. www.webstackacademy.com JSON Web Tokens (JWT) – Usage • JWTs are used in web based authorization once the user is successfully authenticated with valid username & password. • Each transaction between the client after authorization are done in a secure manner as the data is encrypted.
  • 8. www.webstackacademy.com JSON Web Tokens (JWT) – Structure • JWT has three parts that are separated by a (.) character • Header, Payload and Signature (ex: xxxx.yyyy.zzzz) • Each of them have a unique meaning and significance • An example JWT will look as follows
  • 9. www.webstackacademy.com JWT - Structure • Part-I (Header): Typically consists of two parts: • Type of the token (ex: jwt) • Hashing algorithm used (ex: HMAC SHA256) • Part-II (Payload): It contains claims. Claims are statements about an entity (typically, the user) and additional data. • Both Header & Payload are encoded using base64 encoding and made as a first and second part of the JWT { "alg": "HS256", "typ": "JWT" } { "sub": "1234567890", "name": "WSA", "admin": true }
  • 10. www.webstackacademy.com JWT - Structure • Part-III (Signature): The signature is nothing but a hash algorithm applied on header and payload • To create the signature part you have to take the encoded header, the encoded payload, a secret, the algorithm specified in the header, and sign that. • For example if you want to use the HMAC SHA256 algorithm, the signature will be created in the following way: HMACSHA256 (base64(header) + "." + base64(payload), secret) • The output is three Base64 encoded strings separated by dots that can be easily passed in HTML and HTTP environments
  • 11. www.webstackacademy.com What is base64 Encoding? – A brief • Base64 converts a string of bytes into a string of ASCII characters so that they can be safely transmitted within HTTP. • When encoding, Base64 will divide the string of bytes into groups of 6 bits and each group will map to one of 64 characters. • In case the input is not clearly divisible in 6 bits, additional zeros are added for padding • Similar to ASCII table a mapping table is maintained
  • 12. www.webstackacademy.com What is HMAC SHA? – A brief • HMAC (Hash Message Authentication Code) - SHA (Secure Hash Algorithm) is a specific type of message authentication code (MAC) • It involves a cryptographic hash function and a secret cryptographic key. The key size can vary (ex: SHA 256) • The secret key is known only to the sender and the receiver • By applying hashing it generates what is known as signature of the given plain text. It can be used for validating the integrity of the message.
  • 13. www.webstackacademy.com Exercise • JWT Debugger tool: • It is used to generate JWT, let us do some hands-on • Goto https://jwt.io/#debugger and try out by generating some JWT • Base64 Encoding tool: • It is used to check base64 encoding, let us do some hands-on • Goto: https://www.base64decode.org and try out some encoding
  • 15. www.webstackacademy.com What is Local Storage? • The Local storage allow to save key/value pairs in a web browser. • The Local storage data will persist after the browser window is closed. • The local storage property is read-only. • Previously, cookies were used for storing such key value pairs. • Local storage has a significantly higher storage limit (5MB vs 4KB), better for storing client specific information
  • 16. www.webstackacademy.com Local storage methods Local storage supports a set of methods for dealing with the data Method Description setItem() Add key and value to local storage getItem() Retrieve a value by the key removeItem() Remove an item by key clear() Clear all storage
  • 17. www.webstackacademy.com Local storage methods usage localStorage.setItem('key', 'value'); localStorage.getItem('key'); localStorage.removeItem('key'); localStorage.clear();
  • 18. www.webstackacademy.comwww.webstackacademy.com Starter Code (A Brief about given code to get started with A & A)
  • 19. www.webstackacademy.com WebStack Academy #83, Farah Towers, 1st Floor, MG Road, Bangalore – 560001 M: +91-809 555 7332 E: [email protected] WSA in Social Media: