SlideShare une entreprise Scribd logo
1  sur  21
Identity Management
in
ASP.NET Core
ONDREJ BALAS @ONDREJBALAS
WWW.ONDREJBALAS.COM
ONDREJ@ONDREJBALAS.COM
ONDREJ BALAS
Microsoft MVP in Visual Studio
Writer for Visual Studio Magazine
Owner of UseTech Design
Building software that drives business
WWW.ONDREJBALAS.COM
ONDREJ@ONDREJBALAS.COM
@ONDREJBALAS
AspNetCore.Identity
Access Control (Authentication & Authorization)
First released as NuGet packages, compatible with .NET 4.5 and higher
MVC 6 ASP.NET Core MVC 1.0 templates use Identity 3 ASP.NET Core Identity 1.0
Use this when you
ARE NOT
using ASP.NET Core
Use this when you
ARE
using ASP.NET Core
ASP.NET Membership (2005)
Tightly coupled to SQL Server (with a specific schema)
Even other relational databases like MySQL required a complicated custom provider
Roles and passwords were required
Custom user profile fields were a PAIN!
Simple Membership (2012)
Supports a custom database schema
You can choose the ID and username columns
There are extensions for OAuth and OpenID
Supports account reset token by default
Built on top of ASP.NET Membership so there is still a tight coupling to SQL Server
Making changes to persistence means rewriting things like password hashing too
AspNet.Identity
OAuth & OpenID (Facebook, Google, Microsoft Live, LinkedIn, etc..)
Custom Data Stores (even NoSQL!) are easy to implement
Roles, Claims, or Both
Organizational Accounts Too (Active Directory, Azure AD, Office 365)
Happiness
Claims
Additional bits of information
More granular than roles
A KeyValue store that lives with the user
Stored in the user’s (encrypted) cookie
Demonstrating
Authentication under the hood
Bare-bones no-password authentication
Adding the Identity bits
Managers & Stores
Authorization Policies
Not Covering
WebForms
EntityFramework
Request
Response
HTTP 200 (OK)
Request
Request[Authorize]
public IActionResult ProtectedPage()
{
// ...
}
Request
Response
HTTP 302 (redirect)
to login page
Request
Response
HTTP 200 (OK)
user=cat&pw=meow
Response
HTTP 302 (redirect)
to protected page
POST Request
Set-Cookie: login=somelongtoken; path=/
Response
HTTP 200 (OK)
Request
Cookie: login=somelongtoken
Code Samples
All code samples are created in Visual Studio 2015 Update 3.
The project template is the ASP.NET Core Web Application (.NET Framework)
under .NET Framework 4.6.2, and using the MVC template with No
Authentication.
I chose to use No Authentication because the templates including
authentication are coupled with EF, including some implementations sitting in
the Microsoft.AspNetCore.Identity.EntityFrameworkCore namespace. This
muddies the waters and makes it difficult to see the separation between Identity
and the data layer.
Let’s code!
Managers
UserManager
RoleManager
SignInManager
Stores
IUserStore
IUserLoginStore
IUserClaimStore
IUserRoleStore
IRoleStore
IUserPasswordStore
[Authorize(Policy=“MemberSection”)]
SomeRequirement
: IAuthorizationRequirement
services.AddAuthorization(…)
…are used on
controllers and
actions
…and are wired
up in Startup.cs
…have
requirements
and handlers
Authorization Policies…
AnotherHandler
: AuthorizationHandler<SomeRequirement>
Thanks!
ONDREJ BALAS WWW.ONDREJBALAS.COM
ONDREJ@ONDREJBALAS.COM
@ONDREJBALAS
GITHUB.COM/ONDREJBALAS

Contenu connexe

Tendances

Tendances (20)

Implementing security requirements for banking API system using Open Source ...
 Implementing security requirements for banking API system using Open Source ... Implementing security requirements for banking API system using Open Source ...
Implementing security requirements for banking API system using Open Source ...
 
Angular Basics.pptx
Angular Basics.pptxAngular Basics.pptx
Angular Basics.pptx
 
Asp.Net Core MVC with Entity Framework
Asp.Net Core MVC with Entity FrameworkAsp.Net Core MVC with Entity Framework
Asp.Net Core MVC with Entity Framework
 
Web api
Web apiWeb api
Web api
 
Web API 2 Token Based Authentication
Web API 2 Token Based AuthenticationWeb API 2 Token Based Authentication
Web API 2 Token Based Authentication
 
Swagger
SwaggerSwagger
Swagger
 
ASP.NET MVC.
ASP.NET MVC.ASP.NET MVC.
ASP.NET MVC.
 
Angular 2.0 forms
Angular 2.0 formsAngular 2.0 forms
Angular 2.0 forms
 
Routing & Navigating Pages in Angular 2
Routing & Navigating Pages in Angular 2Routing & Navigating Pages in Angular 2
Routing & Navigating Pages in Angular 2
 
Spring Security 5
Spring Security 5Spring Security 5
Spring Security 5
 
Arquitetura Node com NestJS
Arquitetura Node com NestJSArquitetura Node com NestJS
Arquitetura Node com NestJS
 
Token Authentication in ASP.NET Core
Token Authentication in ASP.NET CoreToken Authentication in ASP.NET Core
Token Authentication in ASP.NET Core
 
Model view controller (mvc)
Model view controller (mvc)Model view controller (mvc)
Model view controller (mvc)
 
Angular 10 course_content
Angular 10 course_contentAngular 10 course_content
Angular 10 course_content
 
Node.js Express Tutorial | Node.js Tutorial For Beginners | Node.js + Expres...
Node.js Express Tutorial | Node.js Tutorial For Beginners | Node.js +  Expres...Node.js Express Tutorial | Node.js Tutorial For Beginners | Node.js +  Expres...
Node.js Express Tutorial | Node.js Tutorial For Beginners | Node.js + Expres...
 
ASP.MVC Training
ASP.MVC TrainingASP.MVC Training
ASP.MVC Training
 
Spring mvc
Spring mvcSpring mvc
Spring mvc
 
Front end architecture patterns
Front end architecture patternsFront end architecture patterns
Front end architecture patterns
 
Blazor Full-Stack
Blazor Full-StackBlazor Full-Stack
Blazor Full-Stack
 
.Net Core
.Net Core.Net Core
.Net Core
 

En vedette

Being an ally to trans
Being an ally to transBeing an ally to trans
Being an ally to trans
Pip Nosegroeg
 

En vedette (15)

君はyarn.lockをコミットしているか?
君はyarn.lockをコミットしているか?君はyarn.lockをコミットしているか?
君はyarn.lockをコミットしているか?
 
Creating scalable solutions with aws
Creating scalable solutions with awsCreating scalable solutions with aws
Creating scalable solutions with aws
 
Guide for Executives in Working with Private Equity
Guide for Executives in Working with Private EquityGuide for Executives in Working with Private Equity
Guide for Executives in Working with Private Equity
 
Authentication and Authorization in Asp.Net
Authentication and Authorization in Asp.NetAuthentication and Authorization in Asp.Net
Authentication and Authorization in Asp.Net
 
Driving Member Engagement by Showing #VolunteerLove
Driving Member Engagement by Showing #VolunteerLoveDriving Member Engagement by Showing #VolunteerLove
Driving Member Engagement by Showing #VolunteerLove
 
テキスト1(公開版)
テキスト1(公開版)テキスト1(公開版)
テキスト1(公開版)
 
OER World Map: Adolescence of a Community Platform
OER World Map: Adolescence of a Community PlatformOER World Map: Adolescence of a Community Platform
OER World Map: Adolescence of a Community Platform
 
Oferta agregada y demanda agregada
Oferta agregada y demanda agregadaOferta agregada y demanda agregada
Oferta agregada y demanda agregada
 
The 4 Stages Of Learning
The 4 Stages Of LearningThe 4 Stages Of Learning
The 4 Stages Of Learning
 
Being an ally to trans
Being an ally to transBeing an ally to trans
Being an ally to trans
 
Epidemiology of Preterm Birth
Epidemiology of Preterm BirthEpidemiology of Preterm Birth
Epidemiology of Preterm Birth
 
Deben elegirse a 2 comisionados del Instituto de Acceso a la Información Públ...
Deben elegirse a 2 comisionados del Instituto de Acceso a la Información Públ...Deben elegirse a 2 comisionados del Instituto de Acceso a la Información Públ...
Deben elegirse a 2 comisionados del Instituto de Acceso a la Información Públ...
 
Ley de sustancias controladas y poder de estado
Ley de sustancias controladas y poder de estadoLey de sustancias controladas y poder de estado
Ley de sustancias controladas y poder de estado
 
Legalthings e-book
Legalthings e-bookLegalthings e-book
Legalthings e-book
 
Docencia y Public Engagement
Docencia y Public EngagementDocencia y Public Engagement
Docencia y Public Engagement
 

Similaire à Identity in ASP.NET Core

Microsoft SQL Azure - Building Applications Using SQL Azure Presentation
Microsoft SQL Azure - Building Applications Using SQL Azure PresentationMicrosoft SQL Azure - Building Applications Using SQL Azure Presentation
Microsoft SQL Azure - Building Applications Using SQL Azure Presentation
Microsoft Private Cloud
 
Building & managing wa app wely
Building & managing wa app   welyBuilding & managing wa app   wely
Building & managing wa app wely
Spiffy
 
Building & Managing Windows Azure
Building & Managing Windows AzureBuilding & Managing Windows Azure
Building & Managing Windows Azure
K.Mohamed Faizal
 
Developing and deploying windows azure applications
Developing and deploying windows azure applicationsDeveloping and deploying windows azure applications
Developing and deploying windows azure applications
Manish Corriea
 
SQL Server 2008 Security Overview
SQL Server 2008 Security OverviewSQL Server 2008 Security Overview
SQL Server 2008 Security Overview
ukdpe
 

Similaire à Identity in ASP.NET Core (20)

Extending Oracle SSO
Extending Oracle SSOExtending Oracle SSO
Extending Oracle SSO
 
Microsoft SQL Azure - Building Applications Using SQL Azure Presentation
Microsoft SQL Azure - Building Applications Using SQL Azure PresentationMicrosoft SQL Azure - Building Applications Using SQL Azure Presentation
Microsoft SQL Azure - Building Applications Using SQL Azure Presentation
 
Chris O'Brien - Best bits of Azure for Office 365/SharePoint developers
Chris O'Brien - Best bits of Azure for Office 365/SharePoint developersChris O'Brien - Best bits of Azure for Office 365/SharePoint developers
Chris O'Brien - Best bits of Azure for Office 365/SharePoint developers
 
AspMVC4 start101
AspMVC4 start101AspMVC4 start101
AspMVC4 start101
 
ASP.NET Lecture 5
ASP.NET Lecture 5ASP.NET Lecture 5
ASP.NET Lecture 5
 
Building & managing wa app wely
Building & managing wa app   welyBuilding & managing wa app   wely
Building & managing wa app wely
 
Building & Managing Windows Azure
Building & Managing Windows AzureBuilding & Managing Windows Azure
Building & Managing Windows Azure
 
Hitchhiker's Guide to Azure AD - SPSKC
Hitchhiker's Guide to Azure AD - SPSKCHitchhiker's Guide to Azure AD - SPSKC
Hitchhiker's Guide to Azure AD - SPSKC
 
Entity Framework Code First Migrations
Entity Framework Code First MigrationsEntity Framework Code First Migrations
Entity Framework Code First Migrations
 
Go…Running Kentico CMS on Windows Azure
Go…Running Kentico CMS on Windows AzureGo…Running Kentico CMS on Windows Azure
Go…Running Kentico CMS on Windows Azure
 
Introduction to basic governance in Azure - #GABDK
Introduction to basic governance in Azure - #GABDKIntroduction to basic governance in Azure - #GABDK
Introduction to basic governance in Azure - #GABDK
 
BizSpark Startup Night Windows Azure March 29, 2011
BizSpark Startup Night Windows Azure March 29, 2011BizSpark Startup Night Windows Azure March 29, 2011
BizSpark Startup Night Windows Azure March 29, 2011
 
Continuous Integration and the Data Warehouse - PASS SQL Saturday Slovenia
Continuous Integration and the Data Warehouse - PASS SQL Saturday SloveniaContinuous Integration and the Data Warehouse - PASS SQL Saturday Slovenia
Continuous Integration and the Data Warehouse - PASS SQL Saturday Slovenia
 
Continuous Integration and the Data Warehouse - PASS SQL Saturday Slovenia
Continuous Integration and the Data Warehouse - PASS SQL Saturday SloveniaContinuous Integration and the Data Warehouse - PASS SQL Saturday Slovenia
Continuous Integration and the Data Warehouse - PASS SQL Saturday Slovenia
 
Developing and deploying windows azure applications
Developing and deploying windows azure applicationsDeveloping and deploying windows azure applications
Developing and deploying windows azure applications
 
Office 365 Directory Synchronization
Office 365 Directory SynchronizationOffice 365 Directory Synchronization
Office 365 Directory Synchronization
 
Day2
Day2Day2
Day2
 
Geek Sync | SQL Security Principals and Permissions 101
Geek Sync | SQL Security Principals and Permissions 101Geek Sync | SQL Security Principals and Permissions 101
Geek Sync | SQL Security Principals and Permissions 101
 
SQL Server 2008 Security Overview
SQL Server 2008 Security OverviewSQL Server 2008 Security Overview
SQL Server 2008 Security Overview
 
Spunite exploring identity management options in office 365
Spunite   exploring identity management options in office 365Spunite   exploring identity management options in office 365
Spunite exploring identity management options in office 365
 

Plus de ondrejbalas (6)

Power BI - Data from any Source
Power BI - Data from any SourcePower BI - Data from any Source
Power BI - Data from any Source
 
Open Source Game Development in C#
Open Source Game Development in C#Open Source Game Development in C#
Open Source Game Development in C#
 
Game Jams - Yum!
Game Jams - Yum!Game Jams - Yum!
Game Jams - Yum!
 
Monetize yourself
Monetize yourselfMonetize yourself
Monetize yourself
 
ReSharper: Discover the Secrets
ReSharper: Discover the SecretsReSharper: Discover the Secrets
ReSharper: Discover the Secrets
 
Creating a Plug-In Architecture
Creating a Plug-In ArchitectureCreating a Plug-In Architecture
Creating a Plug-In Architecture
 

Dernier

%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
masabamasaba
 
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
masabamasaba
 
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
masabamasaba
 

Dernier (20)

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 🔝✔️✔️
 
Introducing Microsoft’s new Enterprise Work Management (EWM) Solution
Introducing Microsoft’s new Enterprise Work Management (EWM) SolutionIntroducing Microsoft’s new Enterprise Work Management (EWM) Solution
Introducing Microsoft’s new Enterprise Work Management (EWM) Solution
 
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
 
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 🔝✔️✔️
 
Microsoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdfMicrosoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdf
 
%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrand%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrand
 
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
Direct Style Effect Systems -The Print[A] Example- A Comprehension AidDirect Style Effect Systems -The Print[A] Example- A Comprehension Aid
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
 
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
 
Generic or specific? Making sensible software design decisions
Generic or specific? Making sensible software design decisionsGeneric or specific? Making sensible software design decisions
Generic or specific? Making sensible software design decisions
 
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdf
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdfPayment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdf
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdf
 
SHRMPro HRMS Software Solutions Presentation
SHRMPro HRMS Software Solutions PresentationSHRMPro HRMS Software Solutions Presentation
SHRMPro HRMS Software Solutions Presentation
 
Chinsurah Escorts ☎️8617697112 Starting From 5K to 15K High Profile Escorts ...
Chinsurah Escorts ☎️8617697112  Starting From 5K to 15K High Profile Escorts ...Chinsurah Escorts ☎️8617697112  Starting From 5K to 15K High Profile Escorts ...
Chinsurah Escorts ☎️8617697112 Starting From 5K to 15K High Profile Escorts ...
 
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
 
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
 
VTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learnVTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learn
 
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
 
8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech students8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech students
 
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
 
%+27788225528 love spells in Vancouver Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Vancouver Psychic Readings, Attraction spells,Br...%+27788225528 love spells in Vancouver Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Vancouver Psychic Readings, Attraction spells,Br...
 

Identity in ASP.NET Core

Notes de l'éditeur

  1. The icons use FontAwesome. If they appear to be missing, try installing the font from here: http://fortawesome.github.io/Font-Awesome/ The slides & code for this presentation are available online.
  2. Keep in mind that when ASP.NET Membership shipped, it pre-dated things like MVC which didn’t release until much later. So this was a solution that made sense at the time. Really only worked with SQL server. Other relational databases (even MySQL) required custom providers, and trying to write a custom provider for a non-relational database was very difficult Things like roles and passwords were a requirement of the system. This meant no compatibility with things like OAuth, Claims based authentication, etc. Adding fields to users was difficult. The mechanism was user profiles, but they way they worked was weird. Because of the tight coupling with SQL and a specific database schema, additional fields were all stored in a single column, in a relatively cryptic format. Nothing as neat as JSON or even XML. This made querying or reporting on user data overly complicated. And forget about doing SQL joins to any of that.
  3. It all starts when you go to your browser and type in the url to your favorite website. Behind the scenes, your browser will make a request, and the website will respond with an HTTP 200 (OK). The body of the response will contain the HTML needed to construct the page in your browser.
  4. Let’s say you then click on a link that takes you to a protected part of the website. You can think of this as being an Action with an [Authorize] attribute surrounding it. The server will examine the request and determine if it’s an authenticated request. Using cookie authentication, it is looking for a specific cookie that should contain some kind of token that it can correlate to a user and validate. Since this request has no cookie, authentication fails, and the server responds with a 302 (redirect) to the login page.
  5. Let’s say you then click on a link that takes you to a protected part of the website. You can think of this as being an Action with an [Authorize] attribute surrounding it. The server will examine the request and determine if it’s an authenticated request. Using cookie authentication, it is looking for a specific cookie that should contain some kind of token that it can correlate to a user and validate. Since this request has no cookie, authentication fails, and the server responds with a 302 (redirect) to the login page.
  6. Let’s say you then click on a link that takes you to a protected part of the website. You can think of this as being an Action with an [Authorize] attribute surrounding it. The server will examine the request and determine if it’s an authenticated request. Using cookie authentication, it is looking for a specific cookie that should contain some kind of token that it can correlate to a user and validate. Since this request has no cookie, authentication fails, and the server responds with a 302 (redirect) to the login page.
  7. The 302 has contains no body (content), only a URL of the next page to request. The browser will then make the next request, to the login page, and get the 200 (OK) response back from the server. At the login page, the user will type in their username and password, and then hit the login (or “Meow” in this case) button.
  8. That will trigger the browser to make an HTTP POST request, with the body containing the values you entered. This Is where SSL comes in handy! The server will respond with a 302 back to the protected page, but this time with a “Set-Cookie” header.
  9. At the login page, the user will type in their username and password, and then hit the login (or “Meow” in this case) button. That will trigger the browser to make an HTTP POST request, with the body containing the values you entered. This Is where SSL comes in handy! The server will respond with a 302 back to the protected page, but this time with a “Set-Cookie” header.
  10. You probably noticed the [Authorize] attribute on the About action of the HomeController. In the past, the Authorize attribute was often used in conjunction with roles, only authorizing a user to execute an action if they were in that role. But now we have something called Authorization Policies: a way to use more complex logic than just a simple "are you in this role?"