Skip to content

Commit 0c51986

Browse files
committed
Added 1209
1 parent 4401359 commit 0c51986

File tree

140 files changed

+92930
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

140 files changed

+92930
-0
lines changed
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
{
2+
"version": "0.2.0",
3+
"configurations": [
4+
{
5+
// Use IntelliSense to find out which attributes exist for C# debugging
6+
// Use hover for the description of the existing attributes
7+
// For further information visit https://github.com/OmniSharp/omnisharp-vscode/blob/master/debugger-launchjson.md
8+
"name": ".NET Core Launch (web)",
9+
"type": "coreclr",
10+
"request": "launch",
11+
"preLaunchTask": "build",
12+
// If you have changed target frameworks, make sure to update the program path.
13+
"program": "${workspaceFolder}/src/bin/Debug/net6.0/MyCollectionSite.dll",
14+
"args": [],
15+
"cwd": "${workspaceFolder}/src",
16+
"stopAtEntry": false,
17+
// Enable launching a web browser when ASP.NET Core starts. For more information: https://aka.ms/VSCode-CS-LaunchJson-WebBrowser
18+
"serverReadyAction": {
19+
"action": "openExternally",
20+
"pattern": "\\bNow listening on:\\s+(https?://\\S+)"
21+
},
22+
"env": {
23+
"ASPNETCORE_ENVIRONMENT": "Development"
24+
},
25+
"sourceFileMap": {
26+
"/Views": "${workspaceFolder}/Views"
27+
}
28+
},
29+
{
30+
"name": ".NET Core Attach",
31+
"type": "coreclr",
32+
"request": "attach"
33+
}
34+
]
35+
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
{
2+
"version": "2.0.0",
3+
"tasks": [
4+
{
5+
"label": "build",
6+
"command": "dotnet",
7+
"type": "process",
8+
"args": [
9+
"build",
10+
"${workspaceFolder}/src/MyCollectionSite.csproj",
11+
"/property:GenerateFullPaths=true",
12+
"/consoleloggerparameters:NoSummary"
13+
],
14+
"problemMatcher": "$msCompile"
15+
},
16+
{
17+
"label": "publish",
18+
"command": "dotnet",
19+
"type": "process",
20+
"args": [
21+
"publish",
22+
"${workspaceFolder}/src/MyCollectionSite.csproj",
23+
"/property:GenerateFullPaths=true",
24+
"/consoleloggerparameters:NoSummary"
25+
],
26+
"problemMatcher": "$msCompile"
27+
},
28+
{
29+
"label": "watch",
30+
"command": "dotnet",
31+
"type": "process",
32+
"args": [
33+
"watch",
34+
"run",
35+
"--project",
36+
"${workspaceFolder}/src/MyCollectionSite.csproj"
37+
],
38+
"problemMatcher": "$msCompile"
39+
}
40+
]
41+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio Version 16
4+
VisualStudioVersion = 16.0.30114.105
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MyCollectionSite", "src\MyCollectionSite.csproj", "{5E91B40C-D360-44F0-9DAC-397CEFB24D97}"
7+
EndProject
8+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "test", "test\test.csproj", "{4E71A210-6F3A-4DA9-B20B-3F3541FF83B6}"
9+
EndProject
10+
Global
11+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
12+
Debug|Any CPU = Debug|Any CPU
13+
Release|Any CPU = Release|Any CPU
14+
EndGlobalSection
15+
GlobalSection(SolutionProperties) = preSolution
16+
HideSolutionNode = FALSE
17+
EndGlobalSection
18+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
19+
{5E91B40C-D360-44F0-9DAC-397CEFB24D97}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
20+
{5E91B40C-D360-44F0-9DAC-397CEFB24D97}.Debug|Any CPU.Build.0 = Debug|Any CPU
21+
{5E91B40C-D360-44F0-9DAC-397CEFB24D97}.Release|Any CPU.ActiveCfg = Release|Any CPU
22+
{5E91B40C-D360-44F0-9DAC-397CEFB24D97}.Release|Any CPU.Build.0 = Release|Any CPU
23+
{4E71A210-6F3A-4DA9-B20B-3F3541FF83B6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
24+
{4E71A210-6F3A-4DA9-B20B-3F3541FF83B6}.Debug|Any CPU.Build.0 = Debug|Any CPU
25+
{4E71A210-6F3A-4DA9-B20B-3F3541FF83B6}.Release|Any CPU.ActiveCfg = Release|Any CPU
26+
{4E71A210-6F3A-4DA9-B20B-3F3541FF83B6}.Release|Any CPU.Build.0 = Release|Any CPU
27+
EndGlobalSection
28+
EndGlobal
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Session 1209: Authentication and Authorization
2+
3+
The website is interesting, but it's not very useful if you can't log in. We'll introduce a login mechanism using Identity and then introduce authorization using Identity and the `Authorize` attribute.
4+
5+
## Agenda
6+
7+
1. Let's add the [Identity components](https://learn.microsoft.com/aspnet/core/security/authentication/scaffold-identity) to our project.
8+
9+
1. We'll update our Entity Framework context to also be the context for our authentication database. This will allow us to use the same database for both our application and our authentication.
10+
11+
1. The `dotnet` command line tool will create a new migration for the identity provider. We'll apply that migration to our database.
12+
13+
1. Users will need to be able to login to our website. Let's add the _LoginPartial to our navigation and update our routing to include a call to MapRazorPages.
14+
15+
1. Let's require a user to be logged in to access the _Create_ and _Edit_ pages. We'll use the `Authorize` attribute to do this.
16+
17+
1. We'll add a check if a user is authorized to edit an item. If they are not, we'll hide the _Edit_ and _Delete_ links. This uses the [IAuthorizationService](https://learn.microsoft.com/aspnet/core/security/authorization/views?view=aspnetcore-6.0) in our views
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
{
2+
"version": "0.2.0",
3+
"configurations": [
4+
{
5+
// Use IntelliSense to find out which attributes exist for C# debugging
6+
// Use hover for the description of the existing attributes
7+
// For further information visit https://github.com/OmniSharp/omnisharp-vscode/blob/master/debugger-launchjson.md
8+
"name": ".NET Core Launch (web)",
9+
"type": "coreclr",
10+
"request": "launch",
11+
"preLaunchTask": "build",
12+
// If you have changed target frameworks, make sure to update the program path.
13+
"program": "${workspaceFolder}/bin/Debug/net6.0/MyCollectionSite.dll",
14+
"args": [],
15+
"cwd": "${workspaceFolder}",
16+
"stopAtEntry": false,
17+
// Enable launching a web browser when ASP.NET Core starts. For more information: https://aka.ms/VSCode-CS-LaunchJson-WebBrowser
18+
"serverReadyAction": {
19+
"action": "openExternally",
20+
"pattern": "\\bNow listening on:\\s+(https?://\\S+)"
21+
},
22+
"env": {
23+
"ASPNETCORE_ENVIRONMENT": "Development"
24+
},
25+
"sourceFileMap": {
26+
"/Views": "${workspaceFolder}/Views"
27+
}
28+
},
29+
{
30+
"name": ".NET Core Attach",
31+
"type": "coreclr",
32+
"request": "attach"
33+
}
34+
]
35+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"sqltools.connections": [
3+
{
4+
"previewLimit": 50,
5+
"driver": "SQLite",
6+
"name": "collection-db",
7+
"database": "${workspaceFolder:src}/collection.db"
8+
}
9+
]
10+
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
{
2+
"version": "2.0.0",
3+
"tasks": [
4+
{
5+
"label": "build",
6+
"command": "dotnet",
7+
"type": "process",
8+
"args": [
9+
"build",
10+
"${workspaceFolder}/MyCollectionSite.csproj",
11+
"/property:GenerateFullPaths=true",
12+
"/consoleloggerparameters:NoSummary"
13+
],
14+
"problemMatcher": "$msCompile"
15+
},
16+
{
17+
"label": "publish",
18+
"command": "dotnet",
19+
"type": "process",
20+
"args": [
21+
"publish",
22+
"${workspaceFolder}/MyCollectionSite.csproj",
23+
"/property:GenerateFullPaths=true",
24+
"/consoleloggerparameters:NoSummary"
25+
],
26+
"problemMatcher": "$msCompile"
27+
},
28+
{
29+
"label": "watch",
30+
"command": "dotnet",
31+
"type": "process",
32+
"args": [
33+
"watch",
34+
"run",
35+
"--project",
36+
"${workspaceFolder}/MyCollectionSite.csproj"
37+
],
38+
"problemMatcher": "$msCompile"
39+
}
40+
]
41+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
using Microsoft.AspNetCore.Identity;
2+
using Microsoft.AspNetCore.Identity.EntityFrameworkCore;
3+
using Microsoft.EntityFrameworkCore;
4+
5+
namespace WebApp1.Data;
6+
7+
public class ApplicationDbContext : IdentityDbContext<IdentityUser>
8+
{
9+
public ApplicationDbContext(DbContextOptions<ApplicationDbContext> options)
10+
: base(options)
11+
{
12+
}
13+
14+
protected override void OnModelCreating(ModelBuilder builder)
15+
{
16+
base.OnModelCreating(builder);
17+
// Customize the ASP.NET Identity model and override the defaults if needed.
18+
// For example, you can rename the ASP.NET Identity table names and more.
19+
// Add your customizations after calling base.OnModelCreating(builder);
20+
}
21+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
@page
2+
@model AccessDeniedModel
3+
@{
4+
ViewData["Title"] = "Access denied";
5+
}
6+
7+
<header>
8+
<h1 class="text-danger">@ViewData["Title"]</h1>
9+
<p class="text-danger">You do not have access to this resource.</p>
10+
</header>
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
#nullable disable
4+
5+
using Microsoft.AspNetCore.Mvc.RazorPages;
6+
7+
namespace MyCollectionSite.Areas.Identity.Pages.Account
8+
{
9+
/// <summary>
10+
/// This API supports the ASP.NET Core Identity default UI infrastructure and is not intended to be used
11+
/// directly from your code. This API may change or be removed in future releases.
12+
/// </summary>
13+
public class AccessDeniedModel : PageModel
14+
{
15+
/// <summary>
16+
/// This API supports the ASP.NET Core Identity default UI infrastructure and is not intended to be used
17+
/// directly from your code. This API may change or be removed in future releases.
18+
/// </summary>
19+
public void OnGet()
20+
{
21+
}
22+
}
23+
}

0 commit comments

Comments
 (0)