SlideShare una empresa de Scribd logo
1 de 49
Descargar para leer sin conexión
.NET Core + ASP.NET Core Training Course
Session 19
.NET Core
What we learned?
Session 6 ~ 18 Overview
• ASP.NET Core Basics
• Middleware, Controllers, Action Filters and Routing
• Models
• Views
• Entity Framework Core
• New Features in 1.1
.NET Core
What we’ll learn today?
Session 19 Agenda
• ASP.NET Identity
.NET Core
What is Identity?
Introduction to Identity
ASP.NET Core Identity is a membership system which allows you to add login
functionality to your application. Users can create an account and login with a user
name and password or they can use an external login providers such as Facebook,
Google, Microsoft Account, Twitter and more.+
You can configure ASP.NET Core Identity to use a SQL Server database to store user
names, passwords, and profile data. Alternatively, you can use your own persistent
store to store data in another persistent storage, such as Azure Table Storage.
.NET Core
Overview
Introduction to Identity
Microsoft.AspNetCore.Identity.EntityFrameworkCore package, will persist the identity
data and schema to SQL Server using Entity Framework Core.
ConfigureServices method in the Startup class:
Identity is enabled for the application by calling UseIdentity in the Configure method
of the Startup class. This adds cookie-based authentication to the request pipeline.
.NET Core
Overview
Introduction to Identity
.NET Core
User Registration
Introduction to Identity
When the user clicks the
Register link, the UserManager
and SignInManager services are
injected into the Controller:
.NET Core
UserRegistration
Introduction to Identity
.NET Core
User Sign-in
Introduction to Identity
User can log in by the SignInAsync method, also contained in the Register action. By
signing in, the SignInAsync method stores a cookie with the user's claims.
If needed, you can access the user's identity details inside a controller action. For
instance, by setting a breakpoint inside the HomeController.Index action method, you
can view the User.claims details. By having the user signed-in, you can make
authorization decisions.
.NET Core
DB Schema
Introduction to Identity
.NET Core
Dependencies
Introduction to Identity
These dependencies are needed to use the identity system in ASP.NET Core applications:
• EntityFramework.SqlServer - Entity Framework is Microsoft's recommended data
access technology for relational databases.
• Microsoft.AspNetCore.Authentication.Cookies - Middleware that enables an
application to use cookie based authentication, similar to ASP.NET's Forms
Authentication.
• Microsoft.AspNetCore.Cryptography.KeyDerivation - Utilities for key derivation.
• Microsoft.AspNetCore.Hosting.Abstractions - Hosting abstractions.
.NET Core
An Introduction to OAuth 2
Introduction OAuth
OAuth 2 is an authorization framework that enables applications to obtain limited
access to user accounts on an HTTP service, such as Facebook, GitHub, and
DigitalOcean. It works by delegating user authentication to the service that hosts the
user account, and authorizing third-party applications to access the user account.
OAuth 2 provides authorization flows for web and desktop applications, and mobile
devices.
.NET Core
OAuth Roles
Introduction OAuth
• Resource Owner: User
The resource owner is the user who authorizes an application to access their
account. The application's access to the user's account is limited to the
"scope" of the authorization granted (e.g. read or write access).
.NET Core
OAuth Roles
Introduction OAuth
• Resource / Authorization Server: API
The resource server hosts the protected user accounts, and the authorization
server verifies the identity of the user then issues access tokens to the
application.
From an application developer's point of view, a service's API fulfills both the
resource and authorization server roles. We will refer to both of these roles
combined, as the Service or API role.
.NET Core
OAuth Roles
Introduction OAuth
• Client: Application
The client is the application that wants to access the user's account. Before it
may do so, it must be authorized by the user, and the authorization must be
validated by the API.
.NET Core
OAuth Roles
Introduction OAuth
OAuth2 defines 4 roles :
• Resource Owner: generally yourself.
• Resource Server: server hosting protected data (for example Google hosting your
profile and personal information).
• Client: application requesting access to a resource server (it can be your PHP website, a
Javascript application or a mobile application).
• Authorization Server: server issuing access token to the client. This token will be used
for the client to request the resource server. This server can be the same as the
authorization server (same physical server and same application), and it is often the
case.
.NET Core
Tokens
Introduction OAuth
Tokens are random strings generated by the authorization server and are issued
when the client requests them. There are 2 types of token:
• Access Token: this is the most important because it allows the user data from
being accessed by a third-party application. This token is sent by the client as a
parameter or as a header in the request to the resource server. It has a limited
lifetime, which is defined by the authorization server. It must be kept
confidential as soon as possible but we will see that this is not always possible,
especially when the client is a web browser that sends requests to the resource
server via Javascript.
.NET Core
Tokens
Introduction OAuth
• Refresh Token: this token is issued with the access token but unlike the latter, it
is not sent in each request from the client to the resource server. It merely
serves to be sent to the authorization server for renewing the access token
when it has expired. For security reasons, it is not always possible to obtain this
token.
.NET Core
Tokens - Access token scope
Introduction OAuth
The scope is a parameter used to limit the rights of the access token. This is
the authorization server that defines the list of the available scopes. The client
must then send the scopes he wants to use for his application during the
request to the authorization server. More the scope is reduced, the greater the
chance that the resource owner authorizes access.
.NET Core
Tokens - HTTPS
Introduction OAuth
OAuth2 requires the use of HTTPS for communication between the client and
the authorization server because of sensitive data passing between the two
(tokens and possibly resource owner credentials). In fact you are not forced to
do so if you implement your own authorization server but you must know that
you are opening a big security hole by doing this.
.NET Core
Register as a client
Introduction OAuth
Since you want to retrieve data from a resource server using OAuth2, you have to
register as a client of the authorization server.
Each provider is free to allow this by the method of his choice. The protocol only
defines the parameters that must be specified by the client and those to be returned
by the authorization server. Here are the parameters (they may differ depending of the providers):
• Application Name: the application name
• Redirect URLs: URLs of the client for receiving authorization code and access token
• Grant Type(s): authorization types that will be used by the client
• Javascript Origin (optional): the hostname that will be allowed to request the resource
server via XMLHttpRequest
.NET Core
Register as a client
Introduction OAuth
Authorization server response
• Client Id: unique random string
• Client Secret: secret key that must be kept confidential
.NET Core
Client ID and Client Secret
Introduction OAuth
Once your application is registered, the service will issue "client credentials" in the form
of a client identifier and a client secret.
The Client ID is a publicly exposed string that is used by the service API to identify the
application, and is also used to build authorization URLs that are presented to users.
The Client Secret is used to authenticate the identity of the application to the service
API when the application requests to access a user's account, and must be kept private
between the application and the API.
.NET Core
Register as a client
Introduction OAuth
Authorization server response
• Client Id: unique random string
• Client Secret: secret key that must be kept confidential
.NET Core
Abstract Protocol Flow
Introduction OAuth
1. The application requests authorization to access
service resources from the user
2. If the user authorized the request, the application
receives an authorization grant
3. The application requests an access token from the
authorization server (API) by presenting authentication
of its own identity, and the authorization grant
4. If the application identity is authenticated and the
authorization grant is valid, the authorization server
(API) issues an access token to the application.
Authorization is complete.
5. The application requests the resource from the
resource server (API) and presents the access token for
authentication
6. If the access token is valid, the resource server (API)
serves the resource to the application
.NET Core
Authorization grant types
Introduction OAuth
OAuth2 defines 4 grant types depending on the location and the nature of the client
involved in obtaining an access token.
1. Authorization Code Grant
When it should be used?
It should be used as soon as the client is a web server. It allows you to obtain a
long-lived access token since it can be renewed with a refresh token (if the
authorization server enables it).
.NET Core
Authorization grant types - Authorization Code Grant
Introduction OAuth
Example:
Resource Owner: you
Resource Server: a Google server
Client: any website
Authorization Server: a Google server
Scenario:
1. A website wants to obtain information about your Google profile.
2. You are redirected by the client (the website) to the authorization server (Google).
3. If you authorize access, the authorization server sends an authorization code to the client (the website) in the
callback response.
4. Then, this code is exchanged against an access token between the client and the authorization server.
5. The website is now able to use this access token to query the resource server (Google again) and retrieve your
profile data.
.NET Core
Authorization grant types - Authorization Code Grant
Introduction OAuth
You never see the access token, it will be stored by the website (in session for
example). Google also sends other information with the access token, such as the
token lifetime and eventually a refresh token.
This is the ideal scenario and the safer one because the access token is not passed on
the client side (web browser in our example).
.NET Core
Authorization grant types - Authorization Code Grant
Introduction OAuth
.NET Core
Authorization grant types
Introduction OAuth
2. Implicit Grant
When it should be used?
It is typically used when the client is running in a browser using a scripting
language such as Javascript. This grant type does not allow the issuance of a
refresh token.
Example:
Resource Owner: you
Resource Server: a Facebook server
Client: a website using AngularJS for example
Authorization Server: a Facebook server
.NET Core
Authorization grant types - Implicit Grant
Introduction OAuth
Scenario:
1. The client (AngularJS) wants to obtain information about your Facebook profile.
2. You are redirected by the browser to the authorization server (Facebook).
3. If you authorize access, the authorization server redirects you to the website with the access token in the
URI fragment (not sent to the web server). Example of callback:
http://example.com/oauthcallback#access_token=MzJmNDc3M2VjMmQzN.
4. This access token can now be retrieved and used by the client (AngularJS) to query the resource server
(Facebook). Example of query: https://graph.facebook.com/me?access_token=MzJmNDc3M2VjMmQzN.
5. Maybe you wonder how the client can make a call to the Facebook API with Javascript without being
blocked because of the Same Origin Policy? Well, this cross-domain request is possible because Facebook
authorizes it thanks to a header called Access-Control-Allow-Origin present in the response.
.NET Core
Authorization grant types - Implicit Grant
Introduction OAuth
.NET Core
Authorization grant types
Introduction OAuth
3. Resource Owner Password Credentials Grant
When it should be used?
With this type of authorization, the credentials (and thus the password) are sent to the client and
then to the authorization server. It is therefore imperative that there is absolute trust between
these two entities. It is mainly used when the client has been developed by the same authority as
the authorization server. For example, we could imagine a website named example.com seeking
access to protected resources of its own subdomain api.example.com. The user would not be
surprised to type his login/password on the site example.com since his account was created on it.
.NET Core
Authorization grant types - Resource Owner Password Credentials Grant
Introduction OAuth
Example:
• Resource Owner: you having an account on acme.com website of the Acme company
• Resource Server: Acme company exposing its API at api.acme.com
• Client: acme.com website from Acme company
• Authorization Server: an Acme server
.NET Core
Authorization grant types - Resource Owner Password Credentials Grant
Introduction OAuth
Scenario:
1. Acme company, doing things well, thought to make available a RESTful API to third-party
applications.
2. This company thinks it would be convenient to use its own API to avoid reinventing the wheel.
3. Company needs an access token to call the methods of its own API.
4. For this, company asks you to enter your login credentials via a standard HTML form as you
normally would.
5. The server-side application (website acme.com) will exchange your credentials against an
access token from the authorization server (if your credentials are valid, of course).
6. This application can now use the access token to query its own resource server
(api.acme.com).
.NET Core
Authorization grant types - Resource Owner Password Credentials Grant
Introduction OAuth
.NET Core
Authorization grant types
Introduction OAuth
4. Client Credentials Grant
When it should be used?
This type of authorization is used when the client is himself the resource owner. There is no
authorization to obtain from the end-user.
Example:
Resource Owner: any website
Resource Server: Google Cloud Storage
Client: the resource owner
Authorization Server: a Google server
.NET Core
Authorization grant types - Client Credentials Grant
Introduction OAuth
Scenario:
1. A website stores its files of any kind on Google Cloud Storage.
2. The website must go through the Google API to retrieve or modify files and must authenticate
with the authorization server.
3. Once authenticated, the website obtains an access token that can now be used for querying
the resource server (Google Cloud Storage).
.NET Core
Authorization grant types - Client Credentials Grant
Introduction OAuth
.NET Core
Access token usage
Introduction OAuth
The access token can be sent in several ways to the resource server.
Request parameter (GET or POST)
Example using GET: https://api.example.com/profile?access_token=MzJmNDc3M2VjMmQzN
This is not ideal because the token can be found in the access logs of the web server.
Authorization header
GET /profile HTTP/1.1
Host: api.example.com
Authorization: Bearer MzJmNDc3M2VjMmQzN
It is elegant but all resource servers do not allow this.
.NET Core
Security
Introduction OAuth
OAuth2 is sometimes criticized for its permeability, but it is often due to bad
implementations of the protocol. There are big mistakes to avoid when using it, here
are some examples.
Vulnerability in Authorization Code Grant
There is a vulnerability in this flow that allows an attacker to steal a user’s account under
certain conditions. This hole is often encountered and also in many known websites (such as
Pinterest, SoundCloud, Digg, …) that have not properly implemented the flow.
.NET Core
Security - Example:
Introduction OAuth
• Your victim has a valid account on a website called A.
• The A website allows a user to login or register with Facebook and is previously registered as a client in
Facebook OAuth2 authorization server.
• You click on the Facebook Connect button of website A but do not follow the redirection thanks to Firefox
NoRedirect addon or by using Burp for example (callback looks like this: http://site-internet-
a.com/facebook/login?code=OGI2NmY2NjYxN2Y4YzE3).
• You get the url (containing the authorization code) to which you would be redirected (visible in Firebug).
• Now you have to force your victim to visit this url via a hidden iframe on a website or an image in an email for
example.
• If the victim is logged in website A, jackpot! Now you have access to the victim’s account in website A with your
Facebook account. You just have to click on the Facebook Connect button and you will be connected with the
victim’s account.
.NET Core
Security - Workaround:
Introduction OAuth
There is a way to prevent this by adding a “state” parameter. The latter is only recommended and not
required in the specifications. If the client sends this parameter when requesting an authorization code,
it will be returned unchanged by the authorization server in the response and will be compared by the
client before the exchange of the authorization code against the access token. This parameter
generally matches to a unique hash of a random number that is stored in the user session. For example
in PHP: sha1(uniqid(mt_rand(), true)).
In our example, if the website A was using the parameter “state”, he would have realized in the callback
that the hash does not match the one stored in the session of the victim and would therefore
prevented the theft of victim’s account.
.NET Core
Security - Vulnerability in Implicit Grant:
Introduction OAuth
This type of authorization is the least secure of all because it exposes the access
token to client-side (Javascript most of the time). There is a widespread hole that
stems from the fact that the client does not know if the access token was generated
for him or not (Confused Deputy Problem). This allows an attacker to steal a user
account.
.NET Core
Security - Vulnerability in Implicit Grant - Example:
Introduction OAuth
• An attacker aims to steal a victim’s account on a website A. This website allows you
to connect via your Facebook account and uses implicit authorization.
• The attacker creates a website B allowing login via Facebook too.
• The victim logs in to the website B with his Facebook account and therefore
implicitly authorized the generation of an access token for this.
• The attacker gets the access token via his website B and uses it on website A by
modifying the access token in the URI fragment. If website A is not protected
against this attack, the victim’s account is compromised and the attacker has now
access to it.
.NET Core
Security - Vulnerability in Implicit Grant - Workaround:
Introduction OAuth
To avoid this, the authorization server must provide in its API a way to retrieve access
token information. Thus, website A would be able to compare the client_id of the
access token of the attacker against its own client_id. As the stolen access token was
generated for the website B, client_id would have been different from client_id of
website A and the connection would have been refused.
.NET Core
Security - Clickjacking:
Introduction OAuth
This technique allows the attacker to cheat by hiding the authorization page in a
transparent iframe and getting the victim to click a link that is visually over the
“Allow” button of the authorization page.
Example:
.NET Core
Security – Clickjacking - Workaround:
Introduction OAuth
To avoid this, it is necessary that the authorization server returns a header named X-
Frame-Options on the authorization page with the value DENY or SAMEORIGIN. This
prevents the authorization page to be displayed in an iframe (DENY) or requires
consistency between the domain name of the main page and the domain name
specified in the iframe “src” attribute (SAMEORIGIN).
This header is not standard but is supported in the following browsers: IE8+,
Firefox3.6.9+, Opera10.5+, Safari4+, Chrome 4.1.249.1042+.
.NET Core
Demo
Demo

Más contenido relacionado

La actualidad más candente

.NET Core, ASP.NET Core Course, Session 10
.NET Core, ASP.NET Core Course, Session 10.NET Core, ASP.NET Core Course, Session 10
.NET Core, ASP.NET Core Course, Session 10aminmesbahi
 
.NET Core, ASP.NET Core Course, Session 16
.NET Core, ASP.NET Core Course, Session 16.NET Core, ASP.NET Core Course, Session 16
.NET Core, ASP.NET Core Course, Session 16aminmesbahi
 
.NET Core, ASP.NET Core Course, Session 11
.NET Core, ASP.NET Core Course, Session 11.NET Core, ASP.NET Core Course, Session 11
.NET Core, ASP.NET Core Course, Session 11aminmesbahi
 
.NET Core, ASP.NET Core Course, Session 3
.NET Core, ASP.NET Core Course, Session 3.NET Core, ASP.NET Core Course, Session 3
.NET Core, ASP.NET Core Course, Session 3aminmesbahi
 
.NET Core, ASP.NET Core Course, Session 15
.NET Core, ASP.NET Core Course, Session 15.NET Core, ASP.NET Core Course, Session 15
.NET Core, ASP.NET Core Course, Session 15aminmesbahi
 
.NET Core, ASP.NET Core Course, Session 1
.NET Core, ASP.NET Core Course, Session 1.NET Core, ASP.NET Core Course, Session 1
.NET Core, ASP.NET Core Course, Session 1aminmesbahi
 
.NET Core, ASP.NET Core Course, Session 2
.NET Core, ASP.NET Core Course, Session 2.NET Core, ASP.NET Core Course, Session 2
.NET Core, ASP.NET Core Course, Session 2aminmesbahi
 
Servletarchitecture,lifecycle,get,post
Servletarchitecture,lifecycle,get,postServletarchitecture,lifecycle,get,post
Servletarchitecture,lifecycle,get,postvamsi krishna
 
SFDC Inbound Integrations
SFDC Inbound IntegrationsSFDC Inbound Integrations
SFDC Inbound IntegrationsSujit Kumar
 
Bt0083 server side programing
Bt0083 server side programing Bt0083 server side programing
Bt0083 server side programing Techglyphs
 
Java Servlets
Java ServletsJava Servlets
Java ServletsNitin Pai
 
Knowledge Sharing : Java Servlet
Knowledge Sharing : Java ServletKnowledge Sharing : Java Servlet
Knowledge Sharing : Java ServletFahmi Jafar
 
ASP.NET MVC 4 Request Pipeline Internals
ASP.NET MVC 4 Request Pipeline InternalsASP.NET MVC 4 Request Pipeline Internals
ASP.NET MVC 4 Request Pipeline InternalsLukasz Lysik
 
Core web application development
Core web application developmentCore web application development
Core web application developmentBahaa Farouk
 

La actualidad más candente (20)

.NET Core, ASP.NET Core Course, Session 10
.NET Core, ASP.NET Core Course, Session 10.NET Core, ASP.NET Core Course, Session 10
.NET Core, ASP.NET Core Course, Session 10
 
.NET Core, ASP.NET Core Course, Session 16
.NET Core, ASP.NET Core Course, Session 16.NET Core, ASP.NET Core Course, Session 16
.NET Core, ASP.NET Core Course, Session 16
 
.NET Core, ASP.NET Core Course, Session 11
.NET Core, ASP.NET Core Course, Session 11.NET Core, ASP.NET Core Course, Session 11
.NET Core, ASP.NET Core Course, Session 11
 
.NET Core, ASP.NET Core Course, Session 3
.NET Core, ASP.NET Core Course, Session 3.NET Core, ASP.NET Core Course, Session 3
.NET Core, ASP.NET Core Course, Session 3
 
.NET Core, ASP.NET Core Course, Session 15
.NET Core, ASP.NET Core Course, Session 15.NET Core, ASP.NET Core Course, Session 15
.NET Core, ASP.NET Core Course, Session 15
 
.NET Core, ASP.NET Core Course, Session 1
.NET Core, ASP.NET Core Course, Session 1.NET Core, ASP.NET Core Course, Session 1
.NET Core, ASP.NET Core Course, Session 1
 
.NET Core, ASP.NET Core Course, Session 2
.NET Core, ASP.NET Core Course, Session 2.NET Core, ASP.NET Core Course, Session 2
.NET Core, ASP.NET Core Course, Session 2
 
Servletarchitecture,lifecycle,get,post
Servletarchitecture,lifecycle,get,postServletarchitecture,lifecycle,get,post
Servletarchitecture,lifecycle,get,post
 
Servlets
ServletsServlets
Servlets
 
SFDC Inbound Integrations
SFDC Inbound IntegrationsSFDC Inbound Integrations
SFDC Inbound Integrations
 
Java Servlets
Java ServletsJava Servlets
Java Servlets
 
Bt0083 server side programing
Bt0083 server side programing Bt0083 server side programing
Bt0083 server side programing
 
Servlets
ServletsServlets
Servlets
 
Jspprogramming
JspprogrammingJspprogramming
Jspprogramming
 
Java Servlets
Java ServletsJava Servlets
Java Servlets
 
Knowledge Sharing : Java Servlet
Knowledge Sharing : Java ServletKnowledge Sharing : Java Servlet
Knowledge Sharing : Java Servlet
 
Java Servlet
Java Servlet Java Servlet
Java Servlet
 
Servlet by Rj
Servlet by RjServlet by Rj
Servlet by Rj
 
ASP.NET MVC 4 Request Pipeline Internals
ASP.NET MVC 4 Request Pipeline InternalsASP.NET MVC 4 Request Pipeline Internals
ASP.NET MVC 4 Request Pipeline Internals
 
Core web application development
Core web application developmentCore web application development
Core web application development
 

Similar a ASP.NET Core Identity and OAuth 2.0 Training

Oauth2 and OWSM OAuth2 support
Oauth2 and OWSM OAuth2 supportOauth2 and OWSM OAuth2 support
Oauth2 and OWSM OAuth2 supportGaurav Sharma
 
OAuth 2.0 - The fundamentals, the good , the bad, technical primer and commo...
OAuth 2.0  - The fundamentals, the good , the bad, technical primer and commo...OAuth 2.0  - The fundamentals, the good , the bad, technical primer and commo...
OAuth 2.0 - The fundamentals, the good , the bad, technical primer and commo...Good Dog Labs, Inc.
 
Microservice security with spring security 5.1,Oauth 2.0 and open id connect
Microservice security with spring security 5.1,Oauth 2.0 and open id connect Microservice security with spring security 5.1,Oauth 2.0 and open id connect
Microservice security with spring security 5.1,Oauth 2.0 and open id connect Nilanjan Roy
 
Protecting your APIs with OAuth 2.0
Protecting your APIs with OAuth 2.0Protecting your APIs with OAuth 2.0
Protecting your APIs with OAuth 2.0Ubisecure
 
Deep Dive into OAuth for Connected Apps
Deep Dive into OAuth for Connected AppsDeep Dive into OAuth for Connected Apps
Deep Dive into OAuth for Connected AppsSalesforce Developers
 
GSoC Mideterm-OAuth2 Module
GSoC Mideterm-OAuth2 ModuleGSoC Mideterm-OAuth2 Module
GSoC Mideterm-OAuth2 ModuleMayank Sharma
 
OAuth with AngularJS and WebAPI - SoCal Code Camp 2015
OAuth with AngularJS and WebAPI - SoCal Code Camp 2015OAuth with AngularJS and WebAPI - SoCal Code Camp 2015
OAuth with AngularJS and WebAPI - SoCal Code Camp 2015Stuart
 
Protecting your APIs with Doorkeeper and OAuth 2.0
Protecting your APIs with Doorkeeper and OAuth 2.0Protecting your APIs with Doorkeeper and OAuth 2.0
Protecting your APIs with Doorkeeper and OAuth 2.0Mads Toustrup-Lønne
 
Stateless Auth using OAUTH2 & JWT
Stateless Auth using OAUTH2 & JWTStateless Auth using OAUTH2 & JWT
Stateless Auth using OAUTH2 & JWTMobiliya
 
Intro to OAuth2 and OpenID Connect
Intro to OAuth2 and OpenID ConnectIntro to OAuth2 and OpenID Connect
Intro to OAuth2 and OpenID ConnectLiamWadman
 
APIs_ An Introduction.pptx
APIs_ An Introduction.pptxAPIs_ An Introduction.pptx
APIs_ An Introduction.pptxAkashThorat25
 
e-SUAP - Security - Windows azure access control list (english version)
e-SUAP - Security - Windows azure access control list (english version)e-SUAP - Security - Windows azure access control list (english version)
e-SUAP - Security - Windows azure access control list (english version)Sabino Labarile
 
Rest WebAPI with OData
Rest WebAPI with ODataRest WebAPI with OData
Rest WebAPI with ODataMahek Merchant
 
Stateless Auth using OAuth2 & JWT
Stateless Auth using OAuth2 & JWTStateless Auth using OAuth2 & JWT
Stateless Auth using OAuth2 & JWTGaurav Roy
 

Similar a ASP.NET Core Identity and OAuth 2.0 Training (20)

Oauth2 and OWSM OAuth2 support
Oauth2 and OWSM OAuth2 supportOauth2 and OWSM OAuth2 support
Oauth2 and OWSM OAuth2 support
 
OAuth 2.0 - The fundamentals, the good , the bad, technical primer and commo...
OAuth 2.0  - The fundamentals, the good , the bad, technical primer and commo...OAuth 2.0  - The fundamentals, the good , the bad, technical primer and commo...
OAuth 2.0 - The fundamentals, the good , the bad, technical primer and commo...
 
Microservice security with spring security 5.1,Oauth 2.0 and open id connect
Microservice security with spring security 5.1,Oauth 2.0 and open id connect Microservice security with spring security 5.1,Oauth 2.0 and open id connect
Microservice security with spring security 5.1,Oauth 2.0 and open id connect
 
Protecting your APIs with OAuth 2.0
Protecting your APIs with OAuth 2.0Protecting your APIs with OAuth 2.0
Protecting your APIs with OAuth 2.0
 
Deep Dive into OAuth for Connected Apps
Deep Dive into OAuth for Connected AppsDeep Dive into OAuth for Connected Apps
Deep Dive into OAuth for Connected Apps
 
GSoC Mideterm-OAuth2 Module
GSoC Mideterm-OAuth2 ModuleGSoC Mideterm-OAuth2 Module
GSoC Mideterm-OAuth2 Module
 
API Security with OAuth2.0.
API Security with OAuth2.0.API Security with OAuth2.0.
API Security with OAuth2.0.
 
OAuth with AngularJS and WebAPI - SoCal Code Camp 2015
OAuth with AngularJS and WebAPI - SoCal Code Camp 2015OAuth with AngularJS and WebAPI - SoCal Code Camp 2015
OAuth with AngularJS and WebAPI - SoCal Code Camp 2015
 
Protecting your APIs with Doorkeeper and OAuth 2.0
Protecting your APIs with Doorkeeper and OAuth 2.0Protecting your APIs with Doorkeeper and OAuth 2.0
Protecting your APIs with Doorkeeper and OAuth 2.0
 
Stateless Auth using OAUTH2 & JWT
Stateless Auth using OAUTH2 & JWTStateless Auth using OAUTH2 & JWT
Stateless Auth using OAUTH2 & JWT
 
Intro to OAuth2 and OpenID Connect
Intro to OAuth2 and OpenID ConnectIntro to OAuth2 and OpenID Connect
Intro to OAuth2 and OpenID Connect
 
APIs_ An Introduction.pptx
APIs_ An Introduction.pptxAPIs_ An Introduction.pptx
APIs_ An Introduction.pptx
 
OAuth
OAuthOAuth
OAuth
 
O auth 2
O auth 2O auth 2
O auth 2
 
e-SUAP - Security - Windows azure access control list (english version)
e-SUAP - Security - Windows azure access control list (english version)e-SUAP - Security - Windows azure access control list (english version)
e-SUAP - Security - Windows azure access control list (english version)
 
Rest WebAPI with OData
Rest WebAPI with ODataRest WebAPI with OData
Rest WebAPI with OData
 
OAuth2
OAuth2OAuth2
OAuth2
 
Stateless Auth using OAuth2 & JWT
Stateless Auth using OAuth2 & JWTStateless Auth using OAuth2 & JWT
Stateless Auth using OAuth2 & JWT
 
O auth2.0 guide
O auth2.0 guideO auth2.0 guide
O auth2.0 guide
 
OAuth
OAuthOAuth
OAuth
 

Más de aminmesbahi

How to choose appropriate technology for product development - Persian Version
How to choose appropriate technology for product development - Persian VersionHow to choose appropriate technology for product development - Persian Version
How to choose appropriate technology for product development - Persian Versionaminmesbahi
 
How to choose appropriate technology for product development
How to choose appropriate technology for product developmentHow to choose appropriate technology for product development
How to choose appropriate technology for product developmentaminmesbahi
 
Python + Machine Learning Course, Session 2
Python + Machine Learning Course, Session 2Python + Machine Learning Course, Session 2
Python + Machine Learning Course, Session 2aminmesbahi
 
Python + Machine Learning Course, Session 1
Python + Machine Learning Course, Session 1Python + Machine Learning Course, Session 1
Python + Machine Learning Course, Session 1aminmesbahi
 
.NET Core, ASP.NET Core Course, Session 9
.NET Core, ASP.NET Core Course, Session 9.NET Core, ASP.NET Core Course, Session 9
.NET Core, ASP.NET Core Course, Session 9aminmesbahi
 
.NET Core, ASP.NET Core Course, Session 5
.NET Core, ASP.NET Core Course, Session 5.NET Core, ASP.NET Core Course, Session 5
.NET Core, ASP.NET Core Course, Session 5aminmesbahi
 
.NET Core, ASP.NET Core Course, Session 4
.NET Core, ASP.NET Core Course, Session 4.NET Core, ASP.NET Core Course, Session 4
.NET Core, ASP.NET Core Course, Session 4aminmesbahi
 
A comparative study of process templates in team
A comparative study of process templates in teamA comparative study of process templates in team
A comparative study of process templates in teamaminmesbahi
 
SQL server 2016 New Features
SQL server 2016 New FeaturesSQL server 2016 New Features
SQL server 2016 New Featuresaminmesbahi
 

Más de aminmesbahi (9)

How to choose appropriate technology for product development - Persian Version
How to choose appropriate technology for product development - Persian VersionHow to choose appropriate technology for product development - Persian Version
How to choose appropriate technology for product development - Persian Version
 
How to choose appropriate technology for product development
How to choose appropriate technology for product developmentHow to choose appropriate technology for product development
How to choose appropriate technology for product development
 
Python + Machine Learning Course, Session 2
Python + Machine Learning Course, Session 2Python + Machine Learning Course, Session 2
Python + Machine Learning Course, Session 2
 
Python + Machine Learning Course, Session 1
Python + Machine Learning Course, Session 1Python + Machine Learning Course, Session 1
Python + Machine Learning Course, Session 1
 
.NET Core, ASP.NET Core Course, Session 9
.NET Core, ASP.NET Core Course, Session 9.NET Core, ASP.NET Core Course, Session 9
.NET Core, ASP.NET Core Course, Session 9
 
.NET Core, ASP.NET Core Course, Session 5
.NET Core, ASP.NET Core Course, Session 5.NET Core, ASP.NET Core Course, Session 5
.NET Core, ASP.NET Core Course, Session 5
 
.NET Core, ASP.NET Core Course, Session 4
.NET Core, ASP.NET Core Course, Session 4.NET Core, ASP.NET Core Course, Session 4
.NET Core, ASP.NET Core Course, Session 4
 
A comparative study of process templates in team
A comparative study of process templates in teamA comparative study of process templates in team
A comparative study of process templates in team
 
SQL server 2016 New Features
SQL server 2016 New FeaturesSQL server 2016 New Features
SQL server 2016 New Features
 

Último

TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providermohitmore19
 
Clustering techniques data mining book ....
Clustering techniques data mining book ....Clustering techniques data mining book ....
Clustering techniques data mining book ....ShaimaaMohamedGalal
 
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...MyIntelliSource, Inc.
 
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AISyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AIABDERRAOUF MEHENNI
 
Hand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxHand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxbodapatigopi8531
 
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...MyIntelliSource, Inc.
 
Salesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantSalesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantAxelRicardoTrocheRiq
 
Test Automation Strategy for Frontend and Backend
Test Automation Strategy for Frontend and BackendTest Automation Strategy for Frontend and Backend
Test Automation Strategy for Frontend and BackendArshad QA
 
Unlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language ModelsUnlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language Modelsaagamshah0812
 
HR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comHR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comFatema Valibhai
 
Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsArshad QA
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️Delhi Call girls
 
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️anilsa9823
 
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...OnePlan Solutions
 
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfLearn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfkalichargn70th171
 
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected WorkerHow To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected WorkerThousandEyes
 

Último (20)

TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service provider
 
Clustering techniques data mining book ....
Clustering techniques data mining book ....Clustering techniques data mining book ....
Clustering techniques data mining book ....
 
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
 
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICECHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
 
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS LiveVip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
 
Call Girls In Mukherjee Nagar 📱 9999965857 🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...
Call Girls In Mukherjee Nagar 📱  9999965857  🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...Call Girls In Mukherjee Nagar 📱  9999965857  🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...
Call Girls In Mukherjee Nagar 📱 9999965857 🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...
 
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AISyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
 
Hand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxHand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptx
 
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
 
Salesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantSalesforce Certified Field Service Consultant
Salesforce Certified Field Service Consultant
 
Test Automation Strategy for Frontend and Backend
Test Automation Strategy for Frontend and BackendTest Automation Strategy for Frontend and Backend
Test Automation Strategy for Frontend and Backend
 
Unlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language ModelsUnlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language Models
 
HR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comHR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.com
 
Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview Questions
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
 
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️
 
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
 
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfLearn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
 
Microsoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdfMicrosoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdf
 
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected WorkerHow To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
 

ASP.NET Core Identity and OAuth 2.0 Training

  • 1. .NET Core + ASP.NET Core Training Course Session 19
  • 2. .NET Core What we learned? Session 6 ~ 18 Overview • ASP.NET Core Basics • Middleware, Controllers, Action Filters and Routing • Models • Views • Entity Framework Core • New Features in 1.1
  • 3. .NET Core What we’ll learn today? Session 19 Agenda • ASP.NET Identity
  • 4. .NET Core What is Identity? Introduction to Identity ASP.NET Core Identity is a membership system which allows you to add login functionality to your application. Users can create an account and login with a user name and password or they can use an external login providers such as Facebook, Google, Microsoft Account, Twitter and more.+ You can configure ASP.NET Core Identity to use a SQL Server database to store user names, passwords, and profile data. Alternatively, you can use your own persistent store to store data in another persistent storage, such as Azure Table Storage.
  • 5. .NET Core Overview Introduction to Identity Microsoft.AspNetCore.Identity.EntityFrameworkCore package, will persist the identity data and schema to SQL Server using Entity Framework Core. ConfigureServices method in the Startup class: Identity is enabled for the application by calling UseIdentity in the Configure method of the Startup class. This adds cookie-based authentication to the request pipeline.
  • 7. .NET Core User Registration Introduction to Identity When the user clicks the Register link, the UserManager and SignInManager services are injected into the Controller:
  • 9. .NET Core User Sign-in Introduction to Identity User can log in by the SignInAsync method, also contained in the Register action. By signing in, the SignInAsync method stores a cookie with the user's claims. If needed, you can access the user's identity details inside a controller action. For instance, by setting a breakpoint inside the HomeController.Index action method, you can view the User.claims details. By having the user signed-in, you can make authorization decisions.
  • 11. .NET Core Dependencies Introduction to Identity These dependencies are needed to use the identity system in ASP.NET Core applications: • EntityFramework.SqlServer - Entity Framework is Microsoft's recommended data access technology for relational databases. • Microsoft.AspNetCore.Authentication.Cookies - Middleware that enables an application to use cookie based authentication, similar to ASP.NET's Forms Authentication. • Microsoft.AspNetCore.Cryptography.KeyDerivation - Utilities for key derivation. • Microsoft.AspNetCore.Hosting.Abstractions - Hosting abstractions.
  • 12. .NET Core An Introduction to OAuth 2 Introduction OAuth OAuth 2 is an authorization framework that enables applications to obtain limited access to user accounts on an HTTP service, such as Facebook, GitHub, and DigitalOcean. It works by delegating user authentication to the service that hosts the user account, and authorizing third-party applications to access the user account. OAuth 2 provides authorization flows for web and desktop applications, and mobile devices.
  • 13. .NET Core OAuth Roles Introduction OAuth • Resource Owner: User The resource owner is the user who authorizes an application to access their account. The application's access to the user's account is limited to the "scope" of the authorization granted (e.g. read or write access).
  • 14. .NET Core OAuth Roles Introduction OAuth • Resource / Authorization Server: API The resource server hosts the protected user accounts, and the authorization server verifies the identity of the user then issues access tokens to the application. From an application developer's point of view, a service's API fulfills both the resource and authorization server roles. We will refer to both of these roles combined, as the Service or API role.
  • 15. .NET Core OAuth Roles Introduction OAuth • Client: Application The client is the application that wants to access the user's account. Before it may do so, it must be authorized by the user, and the authorization must be validated by the API.
  • 16. .NET Core OAuth Roles Introduction OAuth OAuth2 defines 4 roles : • Resource Owner: generally yourself. • Resource Server: server hosting protected data (for example Google hosting your profile and personal information). • Client: application requesting access to a resource server (it can be your PHP website, a Javascript application or a mobile application). • Authorization Server: server issuing access token to the client. This token will be used for the client to request the resource server. This server can be the same as the authorization server (same physical server and same application), and it is often the case.
  • 17. .NET Core Tokens Introduction OAuth Tokens are random strings generated by the authorization server and are issued when the client requests them. There are 2 types of token: • Access Token: this is the most important because it allows the user data from being accessed by a third-party application. This token is sent by the client as a parameter or as a header in the request to the resource server. It has a limited lifetime, which is defined by the authorization server. It must be kept confidential as soon as possible but we will see that this is not always possible, especially when the client is a web browser that sends requests to the resource server via Javascript.
  • 18. .NET Core Tokens Introduction OAuth • Refresh Token: this token is issued with the access token but unlike the latter, it is not sent in each request from the client to the resource server. It merely serves to be sent to the authorization server for renewing the access token when it has expired. For security reasons, it is not always possible to obtain this token.
  • 19. .NET Core Tokens - Access token scope Introduction OAuth The scope is a parameter used to limit the rights of the access token. This is the authorization server that defines the list of the available scopes. The client must then send the scopes he wants to use for his application during the request to the authorization server. More the scope is reduced, the greater the chance that the resource owner authorizes access.
  • 20. .NET Core Tokens - HTTPS Introduction OAuth OAuth2 requires the use of HTTPS for communication between the client and the authorization server because of sensitive data passing between the two (tokens and possibly resource owner credentials). In fact you are not forced to do so if you implement your own authorization server but you must know that you are opening a big security hole by doing this.
  • 21. .NET Core Register as a client Introduction OAuth Since you want to retrieve data from a resource server using OAuth2, you have to register as a client of the authorization server. Each provider is free to allow this by the method of his choice. The protocol only defines the parameters that must be specified by the client and those to be returned by the authorization server. Here are the parameters (they may differ depending of the providers): • Application Name: the application name • Redirect URLs: URLs of the client for receiving authorization code and access token • Grant Type(s): authorization types that will be used by the client • Javascript Origin (optional): the hostname that will be allowed to request the resource server via XMLHttpRequest
  • 22. .NET Core Register as a client Introduction OAuth Authorization server response • Client Id: unique random string • Client Secret: secret key that must be kept confidential
  • 23. .NET Core Client ID and Client Secret Introduction OAuth Once your application is registered, the service will issue "client credentials" in the form of a client identifier and a client secret. The Client ID is a publicly exposed string that is used by the service API to identify the application, and is also used to build authorization URLs that are presented to users. The Client Secret is used to authenticate the identity of the application to the service API when the application requests to access a user's account, and must be kept private between the application and the API.
  • 24. .NET Core Register as a client Introduction OAuth Authorization server response • Client Id: unique random string • Client Secret: secret key that must be kept confidential
  • 25. .NET Core Abstract Protocol Flow Introduction OAuth 1. The application requests authorization to access service resources from the user 2. If the user authorized the request, the application receives an authorization grant 3. The application requests an access token from the authorization server (API) by presenting authentication of its own identity, and the authorization grant 4. If the application identity is authenticated and the authorization grant is valid, the authorization server (API) issues an access token to the application. Authorization is complete. 5. The application requests the resource from the resource server (API) and presents the access token for authentication 6. If the access token is valid, the resource server (API) serves the resource to the application
  • 26. .NET Core Authorization grant types Introduction OAuth OAuth2 defines 4 grant types depending on the location and the nature of the client involved in obtaining an access token. 1. Authorization Code Grant When it should be used? It should be used as soon as the client is a web server. It allows you to obtain a long-lived access token since it can be renewed with a refresh token (if the authorization server enables it).
  • 27. .NET Core Authorization grant types - Authorization Code Grant Introduction OAuth Example: Resource Owner: you Resource Server: a Google server Client: any website Authorization Server: a Google server Scenario: 1. A website wants to obtain information about your Google profile. 2. You are redirected by the client (the website) to the authorization server (Google). 3. If you authorize access, the authorization server sends an authorization code to the client (the website) in the callback response. 4. Then, this code is exchanged against an access token between the client and the authorization server. 5. The website is now able to use this access token to query the resource server (Google again) and retrieve your profile data.
  • 28. .NET Core Authorization grant types - Authorization Code Grant Introduction OAuth You never see the access token, it will be stored by the website (in session for example). Google also sends other information with the access token, such as the token lifetime and eventually a refresh token. This is the ideal scenario and the safer one because the access token is not passed on the client side (web browser in our example).
  • 29. .NET Core Authorization grant types - Authorization Code Grant Introduction OAuth
  • 30. .NET Core Authorization grant types Introduction OAuth 2. Implicit Grant When it should be used? It is typically used when the client is running in a browser using a scripting language such as Javascript. This grant type does not allow the issuance of a refresh token. Example: Resource Owner: you Resource Server: a Facebook server Client: a website using AngularJS for example Authorization Server: a Facebook server
  • 31. .NET Core Authorization grant types - Implicit Grant Introduction OAuth Scenario: 1. The client (AngularJS) wants to obtain information about your Facebook profile. 2. You are redirected by the browser to the authorization server (Facebook). 3. If you authorize access, the authorization server redirects you to the website with the access token in the URI fragment (not sent to the web server). Example of callback: http://example.com/oauthcallback#access_token=MzJmNDc3M2VjMmQzN. 4. This access token can now be retrieved and used by the client (AngularJS) to query the resource server (Facebook). Example of query: https://graph.facebook.com/me?access_token=MzJmNDc3M2VjMmQzN. 5. Maybe you wonder how the client can make a call to the Facebook API with Javascript without being blocked because of the Same Origin Policy? Well, this cross-domain request is possible because Facebook authorizes it thanks to a header called Access-Control-Allow-Origin present in the response.
  • 32. .NET Core Authorization grant types - Implicit Grant Introduction OAuth
  • 33. .NET Core Authorization grant types Introduction OAuth 3. Resource Owner Password Credentials Grant When it should be used? With this type of authorization, the credentials (and thus the password) are sent to the client and then to the authorization server. It is therefore imperative that there is absolute trust between these two entities. It is mainly used when the client has been developed by the same authority as the authorization server. For example, we could imagine a website named example.com seeking access to protected resources of its own subdomain api.example.com. The user would not be surprised to type his login/password on the site example.com since his account was created on it.
  • 34. .NET Core Authorization grant types - Resource Owner Password Credentials Grant Introduction OAuth Example: • Resource Owner: you having an account on acme.com website of the Acme company • Resource Server: Acme company exposing its API at api.acme.com • Client: acme.com website from Acme company • Authorization Server: an Acme server
  • 35. .NET Core Authorization grant types - Resource Owner Password Credentials Grant Introduction OAuth Scenario: 1. Acme company, doing things well, thought to make available a RESTful API to third-party applications. 2. This company thinks it would be convenient to use its own API to avoid reinventing the wheel. 3. Company needs an access token to call the methods of its own API. 4. For this, company asks you to enter your login credentials via a standard HTML form as you normally would. 5. The server-side application (website acme.com) will exchange your credentials against an access token from the authorization server (if your credentials are valid, of course). 6. This application can now use the access token to query its own resource server (api.acme.com).
  • 36. .NET Core Authorization grant types - Resource Owner Password Credentials Grant Introduction OAuth
  • 37. .NET Core Authorization grant types Introduction OAuth 4. Client Credentials Grant When it should be used? This type of authorization is used when the client is himself the resource owner. There is no authorization to obtain from the end-user. Example: Resource Owner: any website Resource Server: Google Cloud Storage Client: the resource owner Authorization Server: a Google server
  • 38. .NET Core Authorization grant types - Client Credentials Grant Introduction OAuth Scenario: 1. A website stores its files of any kind on Google Cloud Storage. 2. The website must go through the Google API to retrieve or modify files and must authenticate with the authorization server. 3. Once authenticated, the website obtains an access token that can now be used for querying the resource server (Google Cloud Storage).
  • 39. .NET Core Authorization grant types - Client Credentials Grant Introduction OAuth
  • 40. .NET Core Access token usage Introduction OAuth The access token can be sent in several ways to the resource server. Request parameter (GET or POST) Example using GET: https://api.example.com/profile?access_token=MzJmNDc3M2VjMmQzN This is not ideal because the token can be found in the access logs of the web server. Authorization header GET /profile HTTP/1.1 Host: api.example.com Authorization: Bearer MzJmNDc3M2VjMmQzN It is elegant but all resource servers do not allow this.
  • 41. .NET Core Security Introduction OAuth OAuth2 is sometimes criticized for its permeability, but it is often due to bad implementations of the protocol. There are big mistakes to avoid when using it, here are some examples. Vulnerability in Authorization Code Grant There is a vulnerability in this flow that allows an attacker to steal a user’s account under certain conditions. This hole is often encountered and also in many known websites (such as Pinterest, SoundCloud, Digg, …) that have not properly implemented the flow.
  • 42. .NET Core Security - Example: Introduction OAuth • Your victim has a valid account on a website called A. • The A website allows a user to login or register with Facebook and is previously registered as a client in Facebook OAuth2 authorization server. • You click on the Facebook Connect button of website A but do not follow the redirection thanks to Firefox NoRedirect addon or by using Burp for example (callback looks like this: http://site-internet- a.com/facebook/login?code=OGI2NmY2NjYxN2Y4YzE3). • You get the url (containing the authorization code) to which you would be redirected (visible in Firebug). • Now you have to force your victim to visit this url via a hidden iframe on a website or an image in an email for example. • If the victim is logged in website A, jackpot! Now you have access to the victim’s account in website A with your Facebook account. You just have to click on the Facebook Connect button and you will be connected with the victim’s account.
  • 43. .NET Core Security - Workaround: Introduction OAuth There is a way to prevent this by adding a “state” parameter. The latter is only recommended and not required in the specifications. If the client sends this parameter when requesting an authorization code, it will be returned unchanged by the authorization server in the response and will be compared by the client before the exchange of the authorization code against the access token. This parameter generally matches to a unique hash of a random number that is stored in the user session. For example in PHP: sha1(uniqid(mt_rand(), true)). In our example, if the website A was using the parameter “state”, he would have realized in the callback that the hash does not match the one stored in the session of the victim and would therefore prevented the theft of victim’s account.
  • 44. .NET Core Security - Vulnerability in Implicit Grant: Introduction OAuth This type of authorization is the least secure of all because it exposes the access token to client-side (Javascript most of the time). There is a widespread hole that stems from the fact that the client does not know if the access token was generated for him or not (Confused Deputy Problem). This allows an attacker to steal a user account.
  • 45. .NET Core Security - Vulnerability in Implicit Grant - Example: Introduction OAuth • An attacker aims to steal a victim’s account on a website A. This website allows you to connect via your Facebook account and uses implicit authorization. • The attacker creates a website B allowing login via Facebook too. • The victim logs in to the website B with his Facebook account and therefore implicitly authorized the generation of an access token for this. • The attacker gets the access token via his website B and uses it on website A by modifying the access token in the URI fragment. If website A is not protected against this attack, the victim’s account is compromised and the attacker has now access to it.
  • 46. .NET Core Security - Vulnerability in Implicit Grant - Workaround: Introduction OAuth To avoid this, the authorization server must provide in its API a way to retrieve access token information. Thus, website A would be able to compare the client_id of the access token of the attacker against its own client_id. As the stolen access token was generated for the website B, client_id would have been different from client_id of website A and the connection would have been refused.
  • 47. .NET Core Security - Clickjacking: Introduction OAuth This technique allows the attacker to cheat by hiding the authorization page in a transparent iframe and getting the victim to click a link that is visually over the “Allow” button of the authorization page. Example:
  • 48. .NET Core Security – Clickjacking - Workaround: Introduction OAuth To avoid this, it is necessary that the authorization server returns a header named X- Frame-Options on the authorization page with the value DENY or SAMEORIGIN. This prevents the authorization page to be displayed in an iframe (DENY) or requires consistency between the domain name of the main page and the domain name specified in the iframe “src” attribute (SAMEORIGIN). This header is not standard but is supported in the following browsers: IE8+, Firefox3.6.9+, Opera10.5+, Safari4+, Chrome 4.1.249.1042+.