ASP.Net Security
natankrasney@gmail.com
1
โ€ซืืชืจโ€ฌ โ€ซืื‘ื˜ื—ืชโ€ฌ
: โ€ซื”ื‘ืื™ืโ€ฌ โ€ซื”ืžืืคื™ื™ื ื™ืโ€ฌ โ€ซืืชโ€ฌ โ€ซื›ื•ืœืœืชโ€ฌ โ€ซืืชืจโ€ฌ โ€ซืื‘ื˜ื—ืชโ€ฌ
Authentication
Authorization
Confidentiality
natankrasney@gmail.com
2
Authentication
.โ€ซื•ืกืกืžื”โ€ฌ โ€ซืžืฉืชืžืฉโ€ฌ โ€ซืฉืโ€ฌ โ€ซื‘ืืžืฆืขื•ืชโ€ฌ โ€ซืœื“ื•ื’ืžืโ€ฌ โ€ซื”ืžืฉืชืžืฉโ€ฌ โ€ซื–ื”ื•ืชโ€ฌ โ€ซืืชโ€ฌ โ€ซืžื•ื•ื“ืื™ืโ€ฌ โ€ซื‘ื•โ€ฌ โ€ซืชื”ืœื™ืšโ€ฌ โ€ซื–ื”ื•โ€ฌ
: โ€ซืขื‘ื•ืจโ€ฌ โ€ซืœื“ื•ื’ืžืโ€ฌ โ€ซื—ืฉื•ื‘โ€ฌ โ€ซื”ืชื”ืœื™ืšโ€ฌ
โ—โ€ซืฉืœื”โ€ฌ โ€ซื‘ืืชืจโ€ฌ โ€ซืจืฉื•ืžื™ืโ€ฌ โ€ซืฉื ื”ื™ื”โ€ฌ โ€ซื‘ืœื™โ€ฌ โ€ซื‘ื”โ€ฌ โ€ซืœืงื ื•ืชโ€ฌ โ€ซื ื™ืชืŸโ€ฌ โ€ซืฉืœืโ€ฌ amazon โ€ซืœื“ื•ื’ืžืโ€ฌ โ€ซืื™ื ื˜ืจื ื˜ื™ืชโ€ฌ โ€ซื—ื ื•ืชโ€ฌ
โ—facebookโ€ซื‘โ€ฌ โ€ซื—ืฉื‘ื•ืŸโ€ฌ โ€ซืœืคืชื•ื—โ€ฌ โ€ซืžื ืชโ€ฌ โ€ซืขืœโ€ฌ
โ—gmailโ€ซื‘โ€ฌ โ€ซืžื™ื™ืœโ€ฌ โ€ซื—ืฉื‘ื•ืŸโ€ฌ โ€ซืœืงื‘ืœโ€ฌ โ€ซืžื ืชโ€ฌ โ€ซืขืœโ€ฌ
โ—โ€ซื•ืขื•ื“โ€ฌ
ASP.Net โ€ซื‘โ€ฌ โ€ซืœื”ืฉืชืžืฉโ€ฌ โ€ซื•ืืคืฉืจโ€ฌ authenticationโ€ซื‘โ€ฌ โ€ซืœืชืžื™ื›ื”โ€ฌ โ€ซืขืฆืžืื™ืชโ€ฌ โ€ซืžืขืจื›ืชโ€ฌ โ€ซืœืžืžืฉโ€ฌ โ€ซืืคืฉืจโ€ฌ
โ€ซื›ืืŸโ€ฌ โ€ซืœื“ื•ื’ืžืโ€ฌ โ€ซืจืื•โ€ฌ Identity
natankrasney@gmail.com
3
ASP.Net Identity โ€ซืขืโ€ฌ โ€ซืคืจื•ื™ืงื˜โ€ฌ โ€ซื™ืฆื™ืจืชโ€ฌ
Individual User Accounts โ€ซืžืกื•ื’โ€ฌ Authentication โ€ซื•ื‘ื—ื™ืจืชโ€ฌ (empty โ€ซ)ืœืโ€ฌ MVC โ€ซืคืจื•ื™ืงื˜โ€ฌ โ€ซืคืชื™ื—ืชโ€ฌ
.โ€ซื’ื•ื’ืœโ€ฌ , โ€ซืคื™ื™ืกื‘ื•ืงโ€ฌ โ€ซื‘ืืžืฆืขื•ืชโ€ฌ โ€ซืœื“ื•ื’ืžืโ€ฌ social login โ€ซื•ื’ืโ€ฌ userpassword โ€ซื‘ืขื–ืจืชโ€ฌ โ€ซื’ื™ืฉื”โ€ฌ โ€ซืžืืคืฉืจโ€ฌ โ€ซื•ื–ื”โ€ฌ
.โ€ซืžื”ืžืฉืชืžืฉโ€ฌ โ€ซืงื•ื“โ€ฌ โ€ซืฉืœโ€ฌ โ€ซืฆื•ืจืšโ€ฌ โ€ซืœืœืโ€ฌ login , logout , registerโ€ซืœโ€ฌ โ€ซืืคืฉืจื•ืชโ€ฌ โ€ซื ื•ืชืŸโ€ฌ โ€ซืฉื ื•ืฆืจโ€ฌ โ€ซื”ืคืจื•ื™ืงื˜โ€ฌ
natankrasney@gmail.com
4
ASP.Net Identity โ€ซืฉืœโ€ฌ โ€ซืืจื›ื™ื˜ืงื˜ื•ืจื”โ€ฌ
: โ€ซื”ื—ืฉื•ื‘ื•ืชโ€ฌ โ€ซื”ืžื—ืœืงื•ืชโ€ฌ
natankrasney@gmail.com
5
โ€ซืžืขืœโ€ฌ โ€ซืžืžื•ืžืฉโ€ฌ Storage
โ€ซื‘ืขื–ืจืชโ€ฌ SQL Server
EntityFramework
โ€ซืฉื™ืจื•ืชื™ืโ€ฌ
โ€โ€ซโ€œืฉื—ืงื ื™ืโ€ฌ
IdentityRole
ModelViewController - ASP.Net Identity
: โ€ซืื•ื˜ืžื˜ื™ืชโ€ฌ โ€ซื™ื•ืฆืจโ€ฌ Identity
โ—AccountController , ManageController
โ—View
โ—Model
natankrasney@gmail.com
6
ASP.Net Identity Storage
natankrasney@gmail.com
7
logged in โ€ซืฉืื™ื ื•โ€ฌ โ€ซืœืžืฉืชืžืฉโ€ฌ โ€ซื’ื™ืฉื”โ€ฌ โ€ซื”ื’ื‘ืœืชโ€ฌ
โ€ซื‘ืฉืโ€ฌ attribute โ€ซื‘ืขื–ืจืชโ€ฌ โ€ซื ืขืฉื”โ€ฌ โ€ซื•ื–ื”โ€ฌ Login โ€ซืฉืขืฉื”โ€ฌ โ€ซืœืžืฉืชืžืฉโ€ฌ โ€ซืจืงโ€ฌ (Viewโ€ซืœโ€ฌ โ€ซื’ื™ืฉื”โ€ฌ โ€ซ)ื•ื“ืจื›ื”โ€ฌ actionโ€ซืœโ€ฌ โ€ซื’ื™ืฉื”โ€ฌ โ€ซืœื”ื’ื‘ื™ืœโ€ฌ โ€ซื ื™ืชืŸโ€ฌ
: [Authorize]
โ—actionโ€ซืœโ€ฌ โ€ซื”ื’ื™ืฉื”โ€ฌ โ€ซืชื•ืชืจโ€ฌ โ€ซืื–โ€ฌ logged in โ€ซื›ื‘ืจโ€ฌ โ€ซื•ื”ืžืฉืชืžืฉโ€ฌ โ€ซื‘ืžื™ื“ื”โ€ฌ
โ—action โ€ซื™ื•ื—ื–ืจโ€ฌ โ€ซื”ื•ืโ€ฌ โ€ซืื–โ€ฌ โ€ซืชืงื™ื ื”โ€ฌ โ€ซื‘ืฆื•ืจื”โ€ฌ โ€ซื™ื›ื ืกโ€ฌ โ€ซื”ื•ืโ€ฌ โ€ซืžืฉืโ€ฌ โ€ซืืโ€ฌ .login โ€ซืœืžืกืšโ€ฌ โ€ซื™ื•ืขื‘ืจโ€ฌ โ€ซื”ื•ืโ€ฌ โ€ซืื–โ€ฌ logged in โ€ซืื™ื ื•โ€ฌ โ€ซื•ื”ืžืฉืชืžืฉโ€ฌ โ€ซื‘ืžื™ื“ื”โ€ฌ
โ€ซืœื”ื™ื›ื ืกโ€ฌ โ€ซื ื™ืกื”โ€ฌ โ€ซืืœื™ื”โ€ฌ
: โ€ซืœืžืžืฉโ€ฌ โ€ซืืคืฉืจโ€ฌ
โ—actionโ€ซื”โ€ฌ โ€ซื‘ืจืžืชโ€ฌ
โ—(โ€ซื‘ืžื—ืœืงื”โ€ฌ โ€ซื™ืโ€ฌ - action โ€ซื”โ€ฌ โ€ซืœื›ืœโ€ฌ โ€ซืฉื™ื™ื•ืฉืโ€ฌ โ€ซ)ื›ืšโ€ฌ controllerโ€ซื”โ€ฌ โ€ซื‘ืจืžืชโ€ฌ
โ—โ€ซื”ื•ืกืคืชโ€ฌ โ€ซื‘ืืžืฆืขื•ืชโ€ฌ RegisterGlobalFilters โ€ซื“ืจืšโ€ฌ โ€ซื”ืืคืœื™ืงืฆื™ื”โ€ฌ โ€ซื‘ืจืžืชโ€ฌ
filters.Add(new AuthorizeAttribute());
login โ€ซืขืฉื”โ€ฌ โ€ซืœืโ€ฌ โ€ซืืโ€ฌ โ€ซื’ืโ€ฌ actionโ€ซืœโ€ฌ โ€ซื’ื™ืฉื”โ€ฌ โ€ซืžืืคืฉืจโ€ฌ [AllowAnonymous] โ€ซื‘ืฉืโ€ฌ Attribute
natankrasney@gmail.com
8
โ€ซืขืโ€ฌ โ€ซื‘ื™ืชโ€ฌ โ€ซื‘ื“ืฃโ€ฌ โ€ซืœื“ื•ื’ืžืโ€ฌ โ€ซืœืฉื™ืžื•ืฉโ€ฌ โ€ซื ื•ื—โ€ฌ
โ€ซืจืฉื•ืโ€ฌ โ€ซืžืฉืชืžืฉโ€ฌ โ€ซืฉืจืงโ€ฌ โ€ซืฉืจื•ืฆื™ืโ€ฌ โ€ซืœื™ื ืงโ€ฌ
.โ€ซืืœื™ื•โ€ฌ โ€ซืœื”ื™ื›ื ืกโ€ฌ โ€ซื™ื•ื›ืœโ€ฌ
OAuth
. โ€ซื•ืขื•ื“โ€ฌ google , linkedin, facebook โ€ซืฉืœโ€ฌ โ€ซื‘ืฉืžื•ืฉโ€ฌ authentication โ€ซืคืจื•ื˜ื•ืงื•ืœโ€ฌ โ€ซื”ื•ืโ€ฌ OAuth
login โ€ซืœืขืฉื•ืชโ€ฌ โ€ซืœืžืฉืชืžืฉื™ืโ€ฌ โ€ซืืคืฉืจโ€ฌ OAuth
OAuth - Open Authorization
โ€ซื”ืคืขื•ืœื•ืชโ€ฌ โ€ซืืชโ€ฌ โ€ซืžื—ื™ื™ื‘ืชโ€ฌ โ€ซืฉืœื•โ€ฌ facebookโ€ซื”โ€ฌ โ€ซื—ืฉื‘ื•ืŸโ€ฌ โ€ซื‘ืืžืฆืขื•ืชโ€ฌ โ€ซืฉืœื ื•โ€ฌ โ€ซืœืืชืจโ€ฌ Login โ€ซืœืขืฉื•ืชโ€ฌ โ€ซืœืžืฉืชืžืฉโ€ฌ โ€ซืืคืฉืจื•ืชโ€ฌ โ€ซืžืชืŸโ€ฌ
: โ€ซื›ืžืคืชื—ื™ืโ€ฌ โ€ซืฉืœื ื•โ€ฌ
โ—facebookโ€ซื‘โ€ฌ โ€ซื›ืืคืœื™ืงืฆื™ื”โ€ฌ โ€ซืฉืœื ื•โ€ฌ โ€ซื”ืืชืจโ€ฌ โ€ซืจื™ืฉื•ืโ€ฌ
โ—โ€ซื‘ืขื–ืจืชื•โ€ฌ user name ,password โ€ซืžืขื™ื™ืŸโ€ฌ โ€ซื–ื”โ€ฌ .โ€ซืฉืœื ื•โ€ฌ โ€ซื”ืืชืจโ€ฌ โ€ซืขื‘ื•ืจโ€ฌ โ€ซืžืคื™ื™ืกื‘ื•ืงโ€ฌ secret โ€ซื•โ€ฌ api key โ€ซืงื‘ืœืชโ€ฌ
โ€ซืคื™ื™ืกื‘ื•ืงโ€ฌ โ€ซืžื•ืœโ€ฌ โ€ซื™ืชืงืฉืจโ€ฌ โ€ซืฉืœื ื•โ€ฌ โ€ซื”ืืชืจโ€ฌ
โ—โ€ซื“ืจืšโ€ฌ โ€ซืฉืœื ื•โ€ฌ โ€ซืœืืชืจโ€ฌ login โ€ซืœืขืฉื•ืชโ€ฌ โ€ซื™ืจืฆื”โ€ฌ โ€ซืฉืžืฉืชืžืฉโ€ฌ โ€ซื‘ืจื’ืขโ€ฌ api key , secretโ€ซื”โ€ฌ โ€ซืืชโ€ฌ โ€ซืœืคื™ื™ืกื‘ื•ืงโ€ฌ โ€ซื™ืขื‘ื™ืจโ€ฌ โ€ซื”ืืชืจโ€ฌ
โ€ซืฉืœื ื•โ€ฌ โ€ซื‘ืืชืจโ€ฌ facebook โ€ซื›ืคืชื•ืจโ€ฌ
โ—httpsโ€ซื‘โ€ฌ โ€ซื ืฉืชืžืฉโ€ฌ facebookโ€ซืœโ€ฌ โ€ซืฉืœื ื•โ€ฌ โ€ซื”ืืชืจโ€ฌ โ€ซื‘ื™ืŸโ€ฌ โ€ซื”ืชืงืฉื•ืจืชโ€ฌ โ€ซืขืชโ€ฌ โ€ซืœื”ื’ืŸโ€ฌ โ€ซืžื ืชโ€ฌ โ€ซืขืœโ€ฌ
natankrasney@gmail.com
9
OAuth โ€ซืจืืฉื•ืŸโ€ฌ โ€ซืฉืœื‘โ€ฌ
โ€ซืฉืœื ื•โ€ฌ โ€ซื”ืืชืจโ€ฌ โ€ซื“ืจืšโ€ฌ facebookโ€ซืœโ€ฌ โ€ซื”ืžืฉืชืžืฉโ€ฌ โ€ซืฉืœโ€ฌ login โ€ซืœืื—ืจโ€ฌ facebookโ€ซืœโ€ฌ โ€ซืคื•ื ื”โ€ฌ โ€ซืฉืœื ื•โ€ฌ โ€ซื”ืืชืจโ€ฌ
natankrasney@gmail.com
10
Our Web Site
OAuth โ€ซืฉื ื™โ€ฌ โ€ซืฉืœื‘โ€ฌ
.โ€ซืื•ืžืชื”โ€ฌ โ€ซืฉืœื•โ€ฌ โ€ซืฉื”ื–ื”ื•ืชโ€ฌ โ€ซื›ืšโ€ฌ โ€ซื‘ืคื™ื™ืกื‘ื•ืงโ€ฌ โ€ซื—ืฉื‘ื•ืŸโ€ฌ โ€ซื‘ืืžืชโ€ฌ โ€ซื™ืฉโ€ฌ โ€ซืฉืœืžืฉืชืžืฉโ€ฌ โ€ซืžื•ื›ื™ื—โ€ฌ โ€ซืฉื—ื•ื–ืจโ€ฌ tokenโ€ซื”โ€ฌ
โ€ซืืฆืœื ื•โ€ฌ โ€ซืื•ืชื•โ€ฌ โ€ซืฉื ืจืฉื•ืโ€ฌ โ€ซื›ืšโ€ฌ โ€ซืœืืชืจโ€ฌ โ€ซื”ืžืฉืชืžืฉโ€ฌ โ€ซืืชโ€ฌ โ€ซืžื—ื–ื™ืจื”โ€ฌ facebook
natankrasney@gmail.com
11
Our Web Site
Social Login
โ€ซืœืืชืจโ€ฌ Login โ€ซืœื‘ืฆืขโ€ฌ โ€ซืžื ืชโ€ฌ โ€ซืขืœโ€ฌ โ€ซื’ื•ื’ืœโ€ฌ , โ€ซืœื™ื ืงื“ืื™ืŸโ€ฌ , โ€ซื˜ื•ื•ื™ื˜ืจโ€ฌ , โ€ซืคื™ื™ืกื‘ื•ืงโ€ฌ โ€ซื‘ื—ืฉื‘ื•ื ื•ืชโ€ฌ โ€ซืฉื™ืžื•ืฉโ€ฌ
โ€ซื›ืืŸโ€ฌ โ€ซืจืื•โ€ฌ
โ€ซืžโ€ฌ โ€ซื”ืคืจื•ื™ืงื˜โ€ฌ โ€ซืืชโ€ฌ โ€ซืœืฉื“ืจื’โ€ฌ โ€ซื—ืฉื•ื‘โ€ฌ โ€ซืื‘ืœโ€ฌ โ€ซืžื•ืจื›ื‘โ€ฌ โ€ซืื™ื ื•โ€ฌ โ€ซืœืคื™ื™ืกื‘ื•ืงโ€ฌ Login
Microsoft.Owin.Security.Facebook version 3.0.1
โ€ซื‘ืืžืฆืขื•ืชโ€ฌ
Install-Package Microsoft.Owin.Security.Facebook
โ€ซื“ืจืšโ€ฌ
Tools->NuGet Package Manager->Package Manager Console
natankrasney@gmail.com
12
email confirmation โ€ซื‘ืขื–ืจืชโ€ฌ โ€ซืืชืจโ€ฌ โ€ซืื‘ื˜ื—ืชโ€ฌ โ€ซืฉื™ืคื•ืจโ€ฌ
email confirmation โ€ซืœืขืฉื•ืชโ€ฌ โ€ซืื™ืšโ€ฌ โ€ซืฉืžืกื‘ื™ืจโ€ฌ โ€ซืžืืžืจโ€ฌ โ€ซื›ืืŸโ€ฌ โ€ซืจืื”โ€ฌ
: โ€ซื”ืขืจื”โ€ฌ
โ—: 6.3.4 โ€ซื’ืจืกื”โ€ฌ โ€ซืœืงื—ืชโ€ฌ โ€ซื•ืฆืจื™ืšโ€ฌ โ€ซื ื›ื•ืŸโ€ฌ โ€ซืื™ื ื•โ€ฌ โ€ซื‘ืœื™ื ืงโ€ฌ โ€ซืฉืžื•ืคื™ืขโ€ฌ SendGrid
Install-Package SendGrid -Version 6.3.4
email โ€ซืœื™ื™ืฉืโ€ฌ โ€ซืžื ืชโ€ฌ โ€ซืขืœโ€ฌ .ReadMeโ€ซื”โ€ฌ โ€ซืืชโ€ฌ โ€ซืœืงืจื•ืโ€ฌ โ€ซืฆืจื™ืšโ€ฌ โ€ซืื‘ืœโ€ฌ โ€ซื›ืืŸโ€ฌ โ€ซืขื•ื‘ื“ืชโ€ฌ โ€ซื’ืจืกื”โ€ฌ โ€ซื™ืฉโ€ฌ
โ€ซื”ืฉืงืฃโ€ฌ โ€ซื‘ืจืืฉโ€ฌ โ€ซื‘ืœื™ื ืงโ€ฌ โ€ซืฉืžื•ืฆื’โ€ฌ โ€ซื”ืชื”ืœื™ืšโ€ฌ โ€ซืืชโ€ฌ โ€ซืœื‘ืฆืขโ€ฌ โ€ซืฆืจื™ืšโ€ฌ โ€ซื—ื“ืฉโ€ฌ โ€ซื‘ืคืจื•ื™ืงื˜โ€ฌconfirmation
natankrasney@gmail.com
13
Authorization
.โ€ซื‘ืฆื•ืขืโ€ฌ โ€ซื•ื ืื›ืฃโ€ฌ โ€ซืœืžืฉืชืžืฉื™ืโ€ฌ (Roles) - โ€ซืชืคืงื™ื“ื™ืโ€ฌ โ€ซืžื•ื’ื“ืจื™ืโ€ฌ โ€ซื‘ื•โ€ฌ โ€ซืชื”ืœื™ืšโ€ฌ
โ€ซืžืฉืชืžืฉื™ืโ€ฌ โ€ซืขื‘ื•ืจโ€ฌ โ€ซืชืคืงื™ื“ื™ืโ€ฌ โ€ซืžืกืคืจโ€ฌ โ€ซืœื”ื’ื“ื™ืจโ€ฌ โ€ซืืคืฉืจโ€ฌ โ€ซืื™ื ื˜ืจื ื˜ื™ื•ืชโ€ฌ โ€ซื—ื ื•ื™ื•ืชโ€ฌ โ€ซืจืฉืชโ€ฌ โ€ซืฉืœโ€ฌ โ€ซื‘ืืชืจโ€ฌ โ€ซืœื“ื•ื’ืžืโ€ฌ
: โ€ซืจืฉื•ืžื™ืโ€ฌ
โ—โ€ซื‘ืจืฉื™ืžืชโ€ฌ โ€ซืœืฆืคื•ืชโ€ฌ โ€ซื™ื›ื•ืœโ€ฌ โ€ซืœืโ€ฌ โ€ซืื‘ืœโ€ฌ โ€ซื‘ืขื‘ืจโ€ฌ โ€ซืงื ื”โ€ฌ โ€ซืฉื”ื•ืโ€ฌ โ€ซื‘ืžื•ืฆืจื™ืโ€ฌ โ€ซืœืฆืคื•ืชโ€ฌ โ€ซื™ื›ื•ืœโ€ฌ : โ€ซืคืฉื•ื˜โ€ฌ โ€ซืžืฉืชืžืฉโ€ฌ
โ€ซืžื•ืฆืจื™ืโ€ฌ โ€ซืœื”ื•ืกื™ืฃ/ืœืขืจื•ืš/ืœืžื—ื•ืงโ€ฌ โ€ซื™ื›ื•ืœโ€ฌ โ€ซื•ืœืโ€ฌ โ€ซื”ืžืฉืชืžืฉื™ืโ€ฌ
โ—โ€ซื—ื ื•ืชโ€ฌ โ€ซืžื ื”ืœโ€ฌ โ€ซืœื”ื’ื“ื™ืจโ€ฌ โ€ซื™ื›ื•ืœโ€ฌ โ€ซืœืโ€ฌ โ€ซืื‘ืœโ€ฌ โ€ซืžื•ืฆืจื™ืโ€ฌ โ€ซืœื”ื•ืกื™ืฃ/ืœืขืจื•ืš/ืœืžื—ื•ืงโ€ฌ โ€ซืœื“ื•ื’ืžืโ€ฌ โ€ซื™ื›ื•ืœโ€ฌ - โ€ซื—ื ื•ืชโ€ฌ โ€ซืžื ื”ืœโ€ฌ
โ—โ€ซื—ื ื•ืชโ€ฌ โ€ซืžื ื”ืœโ€ฌ โ€ซืœื”ื’ื“ื™ืจโ€ฌ โ€ซื‘ืคืจื˜โ€ฌ โ€ซื”ื›ืœโ€ฌ โ€ซืœื‘ืฆืขโ€ฌ โ€ซื™ื›ื•ืœโ€ฌ - โ€ซืจืฉืชโ€ฌ โ€ซืžื ื”ืœโ€ฌ
natankrasney@gmail.com
14
Role โ€ซื‘ืืžืฆืขื•ืชโ€ฌ logged in โ€ซืœืžืฉืชืžืฉโ€ฌ โ€ซื’ื™ืฉื”โ€ฌ โ€ซื”ื’ื‘ืœืชโ€ฌ
: โ€ซื”ื‘ืื”โ€ฌ โ€ซื‘ืฆื•ืจื”โ€ฌ โ€ซืœื”ื›ื ื™ืกโ€ฌ โ€ซืืคืฉืจโ€ฌ roleโ€ซื”โ€ฌ โ€ซืืชโ€ฌ
AspNetRoles โ€ซืœื˜ื‘ืœื”โ€ฌ โ€ซื•ืžื›ื ื™ืกื™ืโ€ฌ admin โ€ซืœื“ื•ื’ืžืโ€ฌ role โ€ซืฉืœโ€ฌ โ€ซืฉืโ€ฌ โ€ซืžื’ื“ื™ืจื™ืโ€ฌ โ€ซืงื•ื“ืโ€ฌ
โ€ซืžืฉืชืžืฉโ€ฌ โ€ซืฉืœโ€ฌ id โ€ซืœื‘ื™ืŸโ€ฌ โ€ซื”ื–ื”โ€ฌ role โ€ซืฉืœโ€ฌ id โ€ซื”โ€ฌ โ€ซื‘ื™ืŸโ€ฌ AspNetUserRoles โ€ซื‘ื˜ื‘ืœื”โ€ฌ โ€ซืžืงืฉืจื™ืโ€ฌ โ€ซื›ืšโ€ฌ โ€ซืื—ืจโ€ฌ
AspNetUsers โ€ซื‘ื˜ื‘ืœื”โ€ฌ โ€ซืฉืžื•ืคื™ืขโ€ฌ
โ€ซื“ืจื›ื™ืโ€ฌ โ€ซื‘ืฉืชื™โ€ฌ โ€ซืœื”ืฉืชืžืฉโ€ฌ โ€ซื ื™ืชืŸโ€ฌ โ€ซื‘ืงื•ื“โ€ฌ โ€ซื›ืšโ€ฌ โ€ซืื—ืจโ€ฌ
โ— User.IsInRole(โ€œadminโ€)
โ— [Authorize(Roles=โ€adminโ€)]
natankrasney@gmail.com
15
โ€ซื‘ืงื•ื“โ€ฌ โ€ซืชื ืื™โ€ฌ โ€ซื‘ืชื•ืšโ€ฌ
View โ€ซืื•โ€ฌ controllerโ€ซื‘โ€ฌ
action โ€ซืฉืœโ€ฌ attributeโ€ซื›โ€ฌ
controllerโ€ซื‘โ€ฌ
โ€ซืืชโ€ฌ โ€ซืœืฉื™ืโ€ฌ โ€ซื›ื“ืื™โ€ฌ
โ€ซืงื•ื‘ืฅโ€ฌ โ€ซื‘ืชื•ืšโ€ฌ admin
constants
Confidentiality
โ€ซืœื’ืจื•ืโ€ฌ โ€ซืฉื™ื•ื›ืœโ€ฌ hacker โ€ซืœื“ื•ื’ืžืโ€ฌ โ€ซื–ื“ื•ื ื™ื•ืชโ€ฌ โ€ซืœื™ื“ื™ื™ืโ€ฌ โ€ซื™ื’ื™ืขโ€ฌ โ€ซืฉืœืโ€ฌ โ€ซื›ืšโ€ฌ โ€ซื”ืžื™ื“ืขโ€ฌ โ€ซืขืœโ€ฌ โ€ซืœืฉืžื•ืจโ€ฌ โ€ซื—ืฉื•ื‘โ€ฌ โ€ซื”ื–ื•โ€ฌ โ€ซื‘ืงื˜ื’ื•ืจื™ื”โ€ฌ
.โ€ซื”ืžื™ื“ืขโ€ฌ โ€ซื‘ืขื–ืจืชโ€ฌ โ€ซื ื–ืงโ€ฌ
โ€ซื”ื‘ืื™ืโ€ฌ โ€ซื‘ืืžืฆืขื™ืโ€ฌ โ€ซืœื“ื•ื’ืžืโ€ฌ โ€ซื ื•ืงื˜ื™ืโ€ฌ โ€ซื•ืœื›ืŸโ€ฌ
โ—โ€ซืœื“ื•ื’ืžืโ€ฌ โ€ซืจืื•โ€ฌ http โ€ซื‘ืžืงื•ืโ€ฌ httpsโ€ซื‘โ€ฌ โ€ซืฉื™ืžื•ืฉโ€ฌ - โ€ซืœืฉืจืชโ€ฌ โ€ซื”ืœืงื•ื—โ€ฌ โ€ซื‘ื™ืŸโ€ฌ โ€ซืฉืขื•ื‘ืจโ€ฌ โ€ซื”ืžื™ื“ืขโ€ฌ โ€ซื”ืฆืคื ืชโ€ฌ
โ—โ€ซื”ืกืกืžืโ€ฌ โ€ซืืชโ€ฌ โ€ซืœื”ืกืชื™ืจโ€ฌ โ€ซืžื ืชโ€ฌ โ€ซืขืœโ€ฌ hashingโ€ซื‘โ€ฌ โ€ซืžืฉืชืžืฉโ€ฌ Identity .โ€ซื‘ืฉืจืชโ€ฌ โ€ซื”ืกืกืžืื•ืชโ€ฌ โ€ซืฉืœโ€ฌ โ€ซื”ืฆืคื ื”โ€ฌ
natankrasney@gmail.com
16
โ€ซื‘ืคืจื•ื™ืงื˜โ€ฌ SSLโ€ซื‘โ€ฌ โ€ซืฉื™ืžื•ืฉโ€ฌ
.โ€ซืœืฉืจืชโ€ฌ โ€ซื”ืœืงื•ื—โ€ฌ โ€ซื‘ื™ืŸโ€ฌ โ€ซืฉืขื•ื‘ืจโ€ฌ โ€ซื”ืžื™ื“ืขโ€ฌ โ€ซืืชโ€ฌ โ€ซืžืฆืคื™ืŸโ€ฌ httpโ€ซื‘โ€ฌ โ€ซื•ืœืโ€ฌ httpsโ€ซื‘โ€ฌ โ€ซืฉื™ืžื•ืฉโ€ฌ
(Setting up SSL in the Project โ€ซืขืœโ€ฌ โ€ซืœื—ืœืงโ€ฌ โ€ซ)ื’ืœื•ืœโ€ฌ โ€ซื›ืืŸโ€ฌ โ€ซื‘ืชื™ืขื•ื“โ€ฌ โ€ซืžื•ืคื™ืขโ€ฌ โ€ซื˜ื•ื‘โ€ฌ โ€ซื”ืกื‘ืจโ€ฌ
โ€ซืœืคื•ื ืงืฆื™ื”โ€ฌ โ€ซืœื”ื•ืกื™ืฃโ€ฌ โ€ซื™ืฉโ€ฌ httpsโ€ซื‘โ€ฌ โ€ซืจืงโ€ฌ โ€ซืœืืชืจโ€ฌ โ€ซืœื’ืฉืชโ€ฌ โ€ซืืคืฉืจโ€ฌ โ€ซืฉื™ื”ื™ื”โ€ฌ โ€ซืœื•ื•ื“ืโ€ฌ โ€ซืžื ืชโ€ฌ โ€ซืขืœโ€ฌ
โ€ซื”ื‘ืื”โ€ฌ โ€ซื”ืฉื•ืจื”โ€ฌ โ€ซืืชโ€ฌ RegisterGlobalFilters
filters.Add(new RequireHttpsAttribute());
natankrasney@gmail.com
17

ASP.net Security

  • 1.
  • 2.
    โ€ซืืชืจโ€ฌ โ€ซืื‘ื˜ื—ืชโ€ฌ : โ€ซื”ื‘ืื™ืโ€ฌโ€ซื”ืžืืคื™ื™ื ื™ืโ€ฌ โ€ซืืชโ€ฌ โ€ซื›ื•ืœืœืชโ€ฌ โ€ซืืชืจโ€ฌ โ€ซืื‘ื˜ื—ืชโ€ฌ Authentication Authorization Confidentiality natankrasney@gmail.com 2
  • 3.
    Authentication .โ€ซื•ืกืกืžื”โ€ฌ โ€ซืžืฉืชืžืฉโ€ฌ โ€ซืฉืโ€ฌโ€ซื‘ืืžืฆืขื•ืชโ€ฌ โ€ซืœื“ื•ื’ืžืโ€ฌ โ€ซื”ืžืฉืชืžืฉโ€ฌ โ€ซื–ื”ื•ืชโ€ฌ โ€ซืืชโ€ฌ โ€ซืžื•ื•ื“ืื™ืโ€ฌ โ€ซื‘ื•โ€ฌ โ€ซืชื”ืœื™ืšโ€ฌ โ€ซื–ื”ื•โ€ฌ : โ€ซืขื‘ื•ืจโ€ฌ โ€ซืœื“ื•ื’ืžืโ€ฌ โ€ซื—ืฉื•ื‘โ€ฌ โ€ซื”ืชื”ืœื™ืšโ€ฌ โ—โ€ซืฉืœื”โ€ฌ โ€ซื‘ืืชืจโ€ฌ โ€ซืจืฉื•ืžื™ืโ€ฌ โ€ซืฉื ื”ื™ื”โ€ฌ โ€ซื‘ืœื™โ€ฌ โ€ซื‘ื”โ€ฌ โ€ซืœืงื ื•ืชโ€ฌ โ€ซื ื™ืชืŸโ€ฌ โ€ซืฉืœืโ€ฌ amazon โ€ซืœื“ื•ื’ืžืโ€ฌ โ€ซืื™ื ื˜ืจื ื˜ื™ืชโ€ฌ โ€ซื—ื ื•ืชโ€ฌ โ—facebookโ€ซื‘โ€ฌ โ€ซื—ืฉื‘ื•ืŸโ€ฌ โ€ซืœืคืชื•ื—โ€ฌ โ€ซืžื ืชโ€ฌ โ€ซืขืœโ€ฌ โ—gmailโ€ซื‘โ€ฌ โ€ซืžื™ื™ืœโ€ฌ โ€ซื—ืฉื‘ื•ืŸโ€ฌ โ€ซืœืงื‘ืœโ€ฌ โ€ซืžื ืชโ€ฌ โ€ซืขืœโ€ฌ โ—โ€ซื•ืขื•ื“โ€ฌ ASP.Net โ€ซื‘โ€ฌ โ€ซืœื”ืฉืชืžืฉโ€ฌ โ€ซื•ืืคืฉืจโ€ฌ authenticationโ€ซื‘โ€ฌ โ€ซืœืชืžื™ื›ื”โ€ฌ โ€ซืขืฆืžืื™ืชโ€ฌ โ€ซืžืขืจื›ืชโ€ฌ โ€ซืœืžืžืฉโ€ฌ โ€ซืืคืฉืจโ€ฌ โ€ซื›ืืŸโ€ฌ โ€ซืœื“ื•ื’ืžืโ€ฌ โ€ซืจืื•โ€ฌ Identity natankrasney@gmail.com 3
  • 4.
    ASP.Net Identity โ€ซืขืโ€ฌโ€ซืคืจื•ื™ืงื˜โ€ฌ โ€ซื™ืฆื™ืจืชโ€ฌ Individual User Accounts โ€ซืžืกื•ื’โ€ฌ Authentication โ€ซื•ื‘ื—ื™ืจืชโ€ฌ (empty โ€ซ)ืœืโ€ฌ MVC โ€ซืคืจื•ื™ืงื˜โ€ฌ โ€ซืคืชื™ื—ืชโ€ฌ .โ€ซื’ื•ื’ืœโ€ฌ , โ€ซืคื™ื™ืกื‘ื•ืงโ€ฌ โ€ซื‘ืืžืฆืขื•ืชโ€ฌ โ€ซืœื“ื•ื’ืžืโ€ฌ social login โ€ซื•ื’ืโ€ฌ userpassword โ€ซื‘ืขื–ืจืชโ€ฌ โ€ซื’ื™ืฉื”โ€ฌ โ€ซืžืืคืฉืจโ€ฌ โ€ซื•ื–ื”โ€ฌ .โ€ซืžื”ืžืฉืชืžืฉโ€ฌ โ€ซืงื•ื“โ€ฌ โ€ซืฉืœโ€ฌ โ€ซืฆื•ืจืšโ€ฌ โ€ซืœืœืโ€ฌ login , logout , registerโ€ซืœโ€ฌ โ€ซืืคืฉืจื•ืชโ€ฌ โ€ซื ื•ืชืŸโ€ฌ โ€ซืฉื ื•ืฆืจโ€ฌ โ€ซื”ืคืจื•ื™ืงื˜โ€ฌ natankrasney@gmail.com 4
  • 5.
    ASP.Net Identity โ€ซืฉืœโ€ฌโ€ซืืจื›ื™ื˜ืงื˜ื•ืจื”โ€ฌ : โ€ซื”ื—ืฉื•ื‘ื•ืชโ€ฌ โ€ซื”ืžื—ืœืงื•ืชโ€ฌ natankrasney@gmail.com 5 โ€ซืžืขืœโ€ฌ โ€ซืžืžื•ืžืฉโ€ฌ Storage โ€ซื‘ืขื–ืจืชโ€ฌ SQL Server EntityFramework โ€ซืฉื™ืจื•ืชื™ืโ€ฌ โ€โ€ซโ€œืฉื—ืงื ื™ืโ€ฌ IdentityRole
  • 6.
    ModelViewController - ASP.NetIdentity : โ€ซืื•ื˜ืžื˜ื™ืชโ€ฌ โ€ซื™ื•ืฆืจโ€ฌ Identity โ—AccountController , ManageController โ—View โ—Model natankrasney@gmail.com 6
  • 7.
  • 8.
    logged in โ€ซืฉืื™ื ื•โ€ฌโ€ซืœืžืฉืชืžืฉโ€ฌ โ€ซื’ื™ืฉื”โ€ฌ โ€ซื”ื’ื‘ืœืชโ€ฌ โ€ซื‘ืฉืโ€ฌ attribute โ€ซื‘ืขื–ืจืชโ€ฌ โ€ซื ืขืฉื”โ€ฌ โ€ซื•ื–ื”โ€ฌ Login โ€ซืฉืขืฉื”โ€ฌ โ€ซืœืžืฉืชืžืฉโ€ฌ โ€ซืจืงโ€ฌ (Viewโ€ซืœโ€ฌ โ€ซื’ื™ืฉื”โ€ฌ โ€ซ)ื•ื“ืจื›ื”โ€ฌ actionโ€ซืœโ€ฌ โ€ซื’ื™ืฉื”โ€ฌ โ€ซืœื”ื’ื‘ื™ืœโ€ฌ โ€ซื ื™ืชืŸโ€ฌ : [Authorize] โ—actionโ€ซืœโ€ฌ โ€ซื”ื’ื™ืฉื”โ€ฌ โ€ซืชื•ืชืจโ€ฌ โ€ซืื–โ€ฌ logged in โ€ซื›ื‘ืจโ€ฌ โ€ซื•ื”ืžืฉืชืžืฉโ€ฌ โ€ซื‘ืžื™ื“ื”โ€ฌ โ—action โ€ซื™ื•ื—ื–ืจโ€ฌ โ€ซื”ื•ืโ€ฌ โ€ซืื–โ€ฌ โ€ซืชืงื™ื ื”โ€ฌ โ€ซื‘ืฆื•ืจื”โ€ฌ โ€ซื™ื›ื ืกโ€ฌ โ€ซื”ื•ืโ€ฌ โ€ซืžืฉืโ€ฌ โ€ซืืโ€ฌ .login โ€ซืœืžืกืšโ€ฌ โ€ซื™ื•ืขื‘ืจโ€ฌ โ€ซื”ื•ืโ€ฌ โ€ซืื–โ€ฌ logged in โ€ซืื™ื ื•โ€ฌ โ€ซื•ื”ืžืฉืชืžืฉโ€ฌ โ€ซื‘ืžื™ื“ื”โ€ฌ โ€ซืœื”ื™ื›ื ืกโ€ฌ โ€ซื ื™ืกื”โ€ฌ โ€ซืืœื™ื”โ€ฌ : โ€ซืœืžืžืฉโ€ฌ โ€ซืืคืฉืจโ€ฌ โ—actionโ€ซื”โ€ฌ โ€ซื‘ืจืžืชโ€ฌ โ—(โ€ซื‘ืžื—ืœืงื”โ€ฌ โ€ซื™ืโ€ฌ - action โ€ซื”โ€ฌ โ€ซืœื›ืœโ€ฌ โ€ซืฉื™ื™ื•ืฉืโ€ฌ โ€ซ)ื›ืšโ€ฌ controllerโ€ซื”โ€ฌ โ€ซื‘ืจืžืชโ€ฌ โ—โ€ซื”ื•ืกืคืชโ€ฌ โ€ซื‘ืืžืฆืขื•ืชโ€ฌ RegisterGlobalFilters โ€ซื“ืจืšโ€ฌ โ€ซื”ืืคืœื™ืงืฆื™ื”โ€ฌ โ€ซื‘ืจืžืชโ€ฌ filters.Add(new AuthorizeAttribute()); login โ€ซืขืฉื”โ€ฌ โ€ซืœืโ€ฌ โ€ซืืโ€ฌ โ€ซื’ืโ€ฌ actionโ€ซืœโ€ฌ โ€ซื’ื™ืฉื”โ€ฌ โ€ซืžืืคืฉืจโ€ฌ [AllowAnonymous] โ€ซื‘ืฉืโ€ฌ Attribute natankrasney@gmail.com 8 โ€ซืขืโ€ฌ โ€ซื‘ื™ืชโ€ฌ โ€ซื‘ื“ืฃโ€ฌ โ€ซืœื“ื•ื’ืžืโ€ฌ โ€ซืœืฉื™ืžื•ืฉโ€ฌ โ€ซื ื•ื—โ€ฌ โ€ซืจืฉื•ืโ€ฌ โ€ซืžืฉืชืžืฉโ€ฌ โ€ซืฉืจืงโ€ฌ โ€ซืฉืจื•ืฆื™ืโ€ฌ โ€ซืœื™ื ืงโ€ฌ .โ€ซืืœื™ื•โ€ฌ โ€ซืœื”ื™ื›ื ืกโ€ฌ โ€ซื™ื•ื›ืœโ€ฌ
  • 9.
    OAuth . โ€ซื•ืขื•ื“โ€ฌ google, linkedin, facebook โ€ซืฉืœโ€ฌ โ€ซื‘ืฉืžื•ืฉโ€ฌ authentication โ€ซืคืจื•ื˜ื•ืงื•ืœโ€ฌ โ€ซื”ื•ืโ€ฌ OAuth login โ€ซืœืขืฉื•ืชโ€ฌ โ€ซืœืžืฉืชืžืฉื™ืโ€ฌ โ€ซืืคืฉืจโ€ฌ OAuth OAuth - Open Authorization โ€ซื”ืคืขื•ืœื•ืชโ€ฌ โ€ซืืชโ€ฌ โ€ซืžื—ื™ื™ื‘ืชโ€ฌ โ€ซืฉืœื•โ€ฌ facebookโ€ซื”โ€ฌ โ€ซื—ืฉื‘ื•ืŸโ€ฌ โ€ซื‘ืืžืฆืขื•ืชโ€ฌ โ€ซืฉืœื ื•โ€ฌ โ€ซืœืืชืจโ€ฌ Login โ€ซืœืขืฉื•ืชโ€ฌ โ€ซืœืžืฉืชืžืฉโ€ฌ โ€ซืืคืฉืจื•ืชโ€ฌ โ€ซืžืชืŸโ€ฌ : โ€ซื›ืžืคืชื—ื™ืโ€ฌ โ€ซืฉืœื ื•โ€ฌ โ—facebookโ€ซื‘โ€ฌ โ€ซื›ืืคืœื™ืงืฆื™ื”โ€ฌ โ€ซืฉืœื ื•โ€ฌ โ€ซื”ืืชืจโ€ฌ โ€ซืจื™ืฉื•ืโ€ฌ โ—โ€ซื‘ืขื–ืจืชื•โ€ฌ user name ,password โ€ซืžืขื™ื™ืŸโ€ฌ โ€ซื–ื”โ€ฌ .โ€ซืฉืœื ื•โ€ฌ โ€ซื”ืืชืจโ€ฌ โ€ซืขื‘ื•ืจโ€ฌ โ€ซืžืคื™ื™ืกื‘ื•ืงโ€ฌ secret โ€ซื•โ€ฌ api key โ€ซืงื‘ืœืชโ€ฌ โ€ซืคื™ื™ืกื‘ื•ืงโ€ฌ โ€ซืžื•ืœโ€ฌ โ€ซื™ืชืงืฉืจโ€ฌ โ€ซืฉืœื ื•โ€ฌ โ€ซื”ืืชืจโ€ฌ โ—โ€ซื“ืจืšโ€ฌ โ€ซืฉืœื ื•โ€ฌ โ€ซืœืืชืจโ€ฌ login โ€ซืœืขืฉื•ืชโ€ฌ โ€ซื™ืจืฆื”โ€ฌ โ€ซืฉืžืฉืชืžืฉโ€ฌ โ€ซื‘ืจื’ืขโ€ฌ api key , secretโ€ซื”โ€ฌ โ€ซืืชโ€ฌ โ€ซืœืคื™ื™ืกื‘ื•ืงโ€ฌ โ€ซื™ืขื‘ื™ืจโ€ฌ โ€ซื”ืืชืจโ€ฌ โ€ซืฉืœื ื•โ€ฌ โ€ซื‘ืืชืจโ€ฌ facebook โ€ซื›ืคืชื•ืจโ€ฌ โ—httpsโ€ซื‘โ€ฌ โ€ซื ืฉืชืžืฉโ€ฌ facebookโ€ซืœโ€ฌ โ€ซืฉืœื ื•โ€ฌ โ€ซื”ืืชืจโ€ฌ โ€ซื‘ื™ืŸโ€ฌ โ€ซื”ืชืงืฉื•ืจืชโ€ฌ โ€ซืขืชโ€ฌ โ€ซืœื”ื’ืŸโ€ฌ โ€ซืžื ืชโ€ฌ โ€ซืขืœโ€ฌ natankrasney@gmail.com 9
  • 10.
    OAuth โ€ซืจืืฉื•ืŸโ€ฌ โ€ซืฉืœื‘โ€ฌ โ€ซืฉืœื ื•โ€ฌโ€ซื”ืืชืจโ€ฌ โ€ซื“ืจืšโ€ฌ facebookโ€ซืœโ€ฌ โ€ซื”ืžืฉืชืžืฉโ€ฌ โ€ซืฉืœโ€ฌ login โ€ซืœืื—ืจโ€ฌ facebookโ€ซืœโ€ฌ โ€ซืคื•ื ื”โ€ฌ โ€ซืฉืœื ื•โ€ฌ โ€ซื”ืืชืจโ€ฌ natankrasney@gmail.com 10 Our Web Site
  • 11.
    OAuth โ€ซืฉื ื™โ€ฌ โ€ซืฉืœื‘โ€ฌ .โ€ซืื•ืžืชื”โ€ฌโ€ซืฉืœื•โ€ฌ โ€ซืฉื”ื–ื”ื•ืชโ€ฌ โ€ซื›ืšโ€ฌ โ€ซื‘ืคื™ื™ืกื‘ื•ืงโ€ฌ โ€ซื—ืฉื‘ื•ืŸโ€ฌ โ€ซื‘ืืžืชโ€ฌ โ€ซื™ืฉโ€ฌ โ€ซืฉืœืžืฉืชืžืฉโ€ฌ โ€ซืžื•ื›ื™ื—โ€ฌ โ€ซืฉื—ื•ื–ืจโ€ฌ tokenโ€ซื”โ€ฌ โ€ซืืฆืœื ื•โ€ฌ โ€ซืื•ืชื•โ€ฌ โ€ซืฉื ืจืฉื•ืโ€ฌ โ€ซื›ืšโ€ฌ โ€ซืœืืชืจโ€ฌ โ€ซื”ืžืฉืชืžืฉโ€ฌ โ€ซืืชโ€ฌ โ€ซืžื—ื–ื™ืจื”โ€ฌ facebook natankrasney@gmail.com 11 Our Web Site
  • 12.
    Social Login โ€ซืœืืชืจโ€ฌ Loginโ€ซืœื‘ืฆืขโ€ฌ โ€ซืžื ืชโ€ฌ โ€ซืขืœโ€ฌ โ€ซื’ื•ื’ืœโ€ฌ , โ€ซืœื™ื ืงื“ืื™ืŸโ€ฌ , โ€ซื˜ื•ื•ื™ื˜ืจโ€ฌ , โ€ซืคื™ื™ืกื‘ื•ืงโ€ฌ โ€ซื‘ื—ืฉื‘ื•ื ื•ืชโ€ฌ โ€ซืฉื™ืžื•ืฉโ€ฌ โ€ซื›ืืŸโ€ฌ โ€ซืจืื•โ€ฌ โ€ซืžโ€ฌ โ€ซื”ืคืจื•ื™ืงื˜โ€ฌ โ€ซืืชโ€ฌ โ€ซืœืฉื“ืจื’โ€ฌ โ€ซื—ืฉื•ื‘โ€ฌ โ€ซืื‘ืœโ€ฌ โ€ซืžื•ืจื›ื‘โ€ฌ โ€ซืื™ื ื•โ€ฌ โ€ซืœืคื™ื™ืกื‘ื•ืงโ€ฌ Login Microsoft.Owin.Security.Facebook version 3.0.1 โ€ซื‘ืืžืฆืขื•ืชโ€ฌ Install-Package Microsoft.Owin.Security.Facebook โ€ซื“ืจืšโ€ฌ Tools->NuGet Package Manager->Package Manager Console natankrasney@gmail.com 12
  • 13.
    email confirmation โ€ซื‘ืขื–ืจืชโ€ฌโ€ซืืชืจโ€ฌ โ€ซืื‘ื˜ื—ืชโ€ฌ โ€ซืฉื™ืคื•ืจโ€ฌ email confirmation โ€ซืœืขืฉื•ืชโ€ฌ โ€ซืื™ืšโ€ฌ โ€ซืฉืžืกื‘ื™ืจโ€ฌ โ€ซืžืืžืจโ€ฌ โ€ซื›ืืŸโ€ฌ โ€ซืจืื”โ€ฌ : โ€ซื”ืขืจื”โ€ฌ โ—: 6.3.4 โ€ซื’ืจืกื”โ€ฌ โ€ซืœืงื—ืชโ€ฌ โ€ซื•ืฆืจื™ืšโ€ฌ โ€ซื ื›ื•ืŸโ€ฌ โ€ซืื™ื ื•โ€ฌ โ€ซื‘ืœื™ื ืงโ€ฌ โ€ซืฉืžื•ืคื™ืขโ€ฌ SendGrid Install-Package SendGrid -Version 6.3.4 email โ€ซืœื™ื™ืฉืโ€ฌ โ€ซืžื ืชโ€ฌ โ€ซืขืœโ€ฌ .ReadMeโ€ซื”โ€ฌ โ€ซืืชโ€ฌ โ€ซืœืงืจื•ืโ€ฌ โ€ซืฆืจื™ืšโ€ฌ โ€ซืื‘ืœโ€ฌ โ€ซื›ืืŸโ€ฌ โ€ซืขื•ื‘ื“ืชโ€ฌ โ€ซื’ืจืกื”โ€ฌ โ€ซื™ืฉโ€ฌ โ€ซื”ืฉืงืฃโ€ฌ โ€ซื‘ืจืืฉโ€ฌ โ€ซื‘ืœื™ื ืงโ€ฌ โ€ซืฉืžื•ืฆื’โ€ฌ โ€ซื”ืชื”ืœื™ืšโ€ฌ โ€ซืืชโ€ฌ โ€ซืœื‘ืฆืขโ€ฌ โ€ซืฆืจื™ืšโ€ฌ โ€ซื—ื“ืฉโ€ฌ โ€ซื‘ืคืจื•ื™ืงื˜โ€ฌconfirmation natankrasney@gmail.com 13
  • 14.
    Authorization .โ€ซื‘ืฆื•ืขืโ€ฌ โ€ซื•ื ืื›ืฃโ€ฌ โ€ซืœืžืฉืชืžืฉื™ืโ€ฌ(Roles) - โ€ซืชืคืงื™ื“ื™ืโ€ฌ โ€ซืžื•ื’ื“ืจื™ืโ€ฌ โ€ซื‘ื•โ€ฌ โ€ซืชื”ืœื™ืšโ€ฌ โ€ซืžืฉืชืžืฉื™ืโ€ฌ โ€ซืขื‘ื•ืจโ€ฌ โ€ซืชืคืงื™ื“ื™ืโ€ฌ โ€ซืžืกืคืจโ€ฌ โ€ซืœื”ื’ื“ื™ืจโ€ฌ โ€ซืืคืฉืจโ€ฌ โ€ซืื™ื ื˜ืจื ื˜ื™ื•ืชโ€ฌ โ€ซื—ื ื•ื™ื•ืชโ€ฌ โ€ซืจืฉืชโ€ฌ โ€ซืฉืœโ€ฌ โ€ซื‘ืืชืจโ€ฌ โ€ซืœื“ื•ื’ืžืโ€ฌ : โ€ซืจืฉื•ืžื™ืโ€ฌ โ—โ€ซื‘ืจืฉื™ืžืชโ€ฌ โ€ซืœืฆืคื•ืชโ€ฌ โ€ซื™ื›ื•ืœโ€ฌ โ€ซืœืโ€ฌ โ€ซืื‘ืœโ€ฌ โ€ซื‘ืขื‘ืจโ€ฌ โ€ซืงื ื”โ€ฌ โ€ซืฉื”ื•ืโ€ฌ โ€ซื‘ืžื•ืฆืจื™ืโ€ฌ โ€ซืœืฆืคื•ืชโ€ฌ โ€ซื™ื›ื•ืœโ€ฌ : โ€ซืคืฉื•ื˜โ€ฌ โ€ซืžืฉืชืžืฉโ€ฌ โ€ซืžื•ืฆืจื™ืโ€ฌ โ€ซืœื”ื•ืกื™ืฃ/ืœืขืจื•ืš/ืœืžื—ื•ืงโ€ฌ โ€ซื™ื›ื•ืœโ€ฌ โ€ซื•ืœืโ€ฌ โ€ซื”ืžืฉืชืžืฉื™ืโ€ฌ โ—โ€ซื—ื ื•ืชโ€ฌ โ€ซืžื ื”ืœโ€ฌ โ€ซืœื”ื’ื“ื™ืจโ€ฌ โ€ซื™ื›ื•ืœโ€ฌ โ€ซืœืโ€ฌ โ€ซืื‘ืœโ€ฌ โ€ซืžื•ืฆืจื™ืโ€ฌ โ€ซืœื”ื•ืกื™ืฃ/ืœืขืจื•ืš/ืœืžื—ื•ืงโ€ฌ โ€ซืœื“ื•ื’ืžืโ€ฌ โ€ซื™ื›ื•ืœโ€ฌ - โ€ซื—ื ื•ืชโ€ฌ โ€ซืžื ื”ืœโ€ฌ โ—โ€ซื—ื ื•ืชโ€ฌ โ€ซืžื ื”ืœโ€ฌ โ€ซืœื”ื’ื“ื™ืจโ€ฌ โ€ซื‘ืคืจื˜โ€ฌ โ€ซื”ื›ืœโ€ฌ โ€ซืœื‘ืฆืขโ€ฌ โ€ซื™ื›ื•ืœโ€ฌ - โ€ซืจืฉืชโ€ฌ โ€ซืžื ื”ืœโ€ฌ natankrasney@gmail.com 14
  • 15.
    Role โ€ซื‘ืืžืฆืขื•ืชโ€ฌ loggedin โ€ซืœืžืฉืชืžืฉโ€ฌ โ€ซื’ื™ืฉื”โ€ฌ โ€ซื”ื’ื‘ืœืชโ€ฌ : โ€ซื”ื‘ืื”โ€ฌ โ€ซื‘ืฆื•ืจื”โ€ฌ โ€ซืœื”ื›ื ื™ืกโ€ฌ โ€ซืืคืฉืจโ€ฌ roleโ€ซื”โ€ฌ โ€ซืืชโ€ฌ AspNetRoles โ€ซืœื˜ื‘ืœื”โ€ฌ โ€ซื•ืžื›ื ื™ืกื™ืโ€ฌ admin โ€ซืœื“ื•ื’ืžืโ€ฌ role โ€ซืฉืœโ€ฌ โ€ซืฉืโ€ฌ โ€ซืžื’ื“ื™ืจื™ืโ€ฌ โ€ซืงื•ื“ืโ€ฌ โ€ซืžืฉืชืžืฉโ€ฌ โ€ซืฉืœโ€ฌ id โ€ซืœื‘ื™ืŸโ€ฌ โ€ซื”ื–ื”โ€ฌ role โ€ซืฉืœโ€ฌ id โ€ซื”โ€ฌ โ€ซื‘ื™ืŸโ€ฌ AspNetUserRoles โ€ซื‘ื˜ื‘ืœื”โ€ฌ โ€ซืžืงืฉืจื™ืโ€ฌ โ€ซื›ืšโ€ฌ โ€ซืื—ืจโ€ฌ AspNetUsers โ€ซื‘ื˜ื‘ืœื”โ€ฌ โ€ซืฉืžื•ืคื™ืขโ€ฌ โ€ซื“ืจื›ื™ืโ€ฌ โ€ซื‘ืฉืชื™โ€ฌ โ€ซืœื”ืฉืชืžืฉโ€ฌ โ€ซื ื™ืชืŸโ€ฌ โ€ซื‘ืงื•ื“โ€ฌ โ€ซื›ืšโ€ฌ โ€ซืื—ืจโ€ฌ โ— User.IsInRole(โ€œadminโ€) โ— [Authorize(Roles=โ€adminโ€)] natankrasney@gmail.com 15 โ€ซื‘ืงื•ื“โ€ฌ โ€ซืชื ืื™โ€ฌ โ€ซื‘ืชื•ืšโ€ฌ View โ€ซืื•โ€ฌ controllerโ€ซื‘โ€ฌ action โ€ซืฉืœโ€ฌ attributeโ€ซื›โ€ฌ controllerโ€ซื‘โ€ฌ โ€ซืืชโ€ฌ โ€ซืœืฉื™ืโ€ฌ โ€ซื›ื“ืื™โ€ฌ โ€ซืงื•ื‘ืฅโ€ฌ โ€ซื‘ืชื•ืšโ€ฌ admin constants
  • 16.
    Confidentiality โ€ซืœื’ืจื•ืโ€ฌ โ€ซืฉื™ื•ื›ืœโ€ฌ hackerโ€ซืœื“ื•ื’ืžืโ€ฌ โ€ซื–ื“ื•ื ื™ื•ืชโ€ฌ โ€ซืœื™ื“ื™ื™ืโ€ฌ โ€ซื™ื’ื™ืขโ€ฌ โ€ซืฉืœืโ€ฌ โ€ซื›ืšโ€ฌ โ€ซื”ืžื™ื“ืขโ€ฌ โ€ซืขืœโ€ฌ โ€ซืœืฉืžื•ืจโ€ฌ โ€ซื—ืฉื•ื‘โ€ฌ โ€ซื”ื–ื•โ€ฌ โ€ซื‘ืงื˜ื’ื•ืจื™ื”โ€ฌ .โ€ซื”ืžื™ื“ืขโ€ฌ โ€ซื‘ืขื–ืจืชโ€ฌ โ€ซื ื–ืงโ€ฌ โ€ซื”ื‘ืื™ืโ€ฌ โ€ซื‘ืืžืฆืขื™ืโ€ฌ โ€ซืœื“ื•ื’ืžืโ€ฌ โ€ซื ื•ืงื˜ื™ืโ€ฌ โ€ซื•ืœื›ืŸโ€ฌ โ—โ€ซืœื“ื•ื’ืžืโ€ฌ โ€ซืจืื•โ€ฌ http โ€ซื‘ืžืงื•ืโ€ฌ httpsโ€ซื‘โ€ฌ โ€ซืฉื™ืžื•ืฉโ€ฌ - โ€ซืœืฉืจืชโ€ฌ โ€ซื”ืœืงื•ื—โ€ฌ โ€ซื‘ื™ืŸโ€ฌ โ€ซืฉืขื•ื‘ืจโ€ฌ โ€ซื”ืžื™ื“ืขโ€ฌ โ€ซื”ืฆืคื ืชโ€ฌ โ—โ€ซื”ืกืกืžืโ€ฌ โ€ซืืชโ€ฌ โ€ซืœื”ืกืชื™ืจโ€ฌ โ€ซืžื ืชโ€ฌ โ€ซืขืœโ€ฌ hashingโ€ซื‘โ€ฌ โ€ซืžืฉืชืžืฉโ€ฌ Identity .โ€ซื‘ืฉืจืชโ€ฌ โ€ซื”ืกืกืžืื•ืชโ€ฌ โ€ซืฉืœโ€ฌ โ€ซื”ืฆืคื ื”โ€ฌ natankrasney@gmail.com 16
  • 17.
    โ€ซื‘ืคืจื•ื™ืงื˜โ€ฌ SSLโ€ซื‘โ€ฌ โ€ซืฉื™ืžื•ืฉโ€ฌ .โ€ซืœืฉืจืชโ€ฌโ€ซื”ืœืงื•ื—โ€ฌ โ€ซื‘ื™ืŸโ€ฌ โ€ซืฉืขื•ื‘ืจโ€ฌ โ€ซื”ืžื™ื“ืขโ€ฌ โ€ซืืชโ€ฌ โ€ซืžืฆืคื™ืŸโ€ฌ httpโ€ซื‘โ€ฌ โ€ซื•ืœืโ€ฌ httpsโ€ซื‘โ€ฌ โ€ซืฉื™ืžื•ืฉโ€ฌ (Setting up SSL in the Project โ€ซืขืœโ€ฌ โ€ซืœื—ืœืงโ€ฌ โ€ซ)ื’ืœื•ืœโ€ฌ โ€ซื›ืืŸโ€ฌ โ€ซื‘ืชื™ืขื•ื“โ€ฌ โ€ซืžื•ืคื™ืขโ€ฌ โ€ซื˜ื•ื‘โ€ฌ โ€ซื”ืกื‘ืจโ€ฌ โ€ซืœืคื•ื ืงืฆื™ื”โ€ฌ โ€ซืœื”ื•ืกื™ืฃโ€ฌ โ€ซื™ืฉโ€ฌ httpsโ€ซื‘โ€ฌ โ€ซืจืงโ€ฌ โ€ซืœืืชืจโ€ฌ โ€ซืœื’ืฉืชโ€ฌ โ€ซืืคืฉืจโ€ฌ โ€ซืฉื™ื”ื™ื”โ€ฌ โ€ซืœื•ื•ื“ืโ€ฌ โ€ซืžื ืชโ€ฌ โ€ซืขืœโ€ฌ โ€ซื”ื‘ืื”โ€ฌ โ€ซื”ืฉื•ืจื”โ€ฌ โ€ซืืชโ€ฌ RegisterGlobalFilters filters.Add(new RequireHttpsAttribute()); natankrasney@gmail.com 17