Skip to content

Commit 0051109

Browse files
authored
Sample commit (#71)
* Sample commit * Updated from stream
1 parent c481807 commit 0051109

File tree

93 files changed

+42780
-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.

93 files changed

+42780
-0
lines changed
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
{
2+
// Use IntelliSense to find out which attributes exist for C# debugging
3+
// Use hover for the description of the existing attributes
4+
// For further information visit https://github.com/OmniSharp/omnisharp-vscode/blob/master/debugger-launchjson.md
5+
"version": "0.2.0",
6+
"configurations": [
7+
{
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/WebApp1/bin/Debug/net5.0/WebApp1.dll",
14+
"args": [],
15+
"cwd": "${workspaceFolder}/src/WebApp1",
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+
"processId": "${command:pickProcess}"
34+
}
35+
]
36+
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
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/WebApp1/WebApp1.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/WebApp1/WebApp1.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+
"${workspaceFolder}/src/WebApp1/WebApp1.csproj",
36+
"/property:GenerateFullPaths=true",
37+
"/consoleloggerparameters:NoSummary"
38+
],
39+
"problemMatcher": "$msCompile"
40+
}
41+
]
42+
}
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
# Session 7 - Authentication and Authorization
2+
3+
Official get started tutorial: https://docs.microsoft.com/aspnet/core/security/authentication/identity?view=aspnetcore-5.0
4+
5+
Scaffold Identity https://docs.microsoft.com/aspnet/core/security/authentication/scaffold-identity?view=aspnetcore-5.0
6+
7+
Add Custom User fields
8+
9+
Update UI
10+
11+
Generate migrations, update database
12+
13+
https://github.com/aspnet-contrib/AspNet.Security.OAuth.Providers
14+
15+
16+
## Authorization
17+
18+
Add Roles
19+
20+
https://docs.microsoft.com/en-us/aspnet/core/security/authorization/razor-pages-authorization?view=aspnetcore-5.0
21+
22+
AllowAnonymous attribute
23+
24+
Authorize attribute
25+
26+
[Authorize(Roles = "Administrator")]
27+
28+
On Razor Pages:
29+
services.AddRazorPages(options =>
30+
{
31+
options.Conventions.AuthorizePage("/Contact");
32+
options.Conventions.AuthorizeFolder("/Private");
33+
options.Conventions.AllowAnonymousToPage("/Private/PublicPage");
34+
options.Conventions.AllowAnonymousToFolder("/Private/PublicPages");
35+
});
36+
37+
38+
Policies with roles
39+
services.AddAuthorization(options =>
40+
{
41+
options.AddPolicy("RequireAdministratorRole",
42+
policy => policy.RequireRole("Administrator"));
43+
});
44+
45+
46+
47+
48+
49+
@foreach (var claim in User.Claims)
50+
{
51+
<p><b>@claim.Type</b> @claim.Value</p>
52+
}
53+
54+
55+
### View based Auth
56+
57+
https://docs.microsoft.com/aspnet/core/security/authorization/views?view=aspnetcore-5.0
58+
59+
@using Microsoft.AspNetCore.Authorization
60+
@inject IAuthorizationService AuthorizationService
61+
62+
@if ((await AuthorizationService.AuthorizeAsync(User, "PolicyName")).Succeeded)
63+
{
64+
<p>This paragraph is displayed because you fulfilled PolicyName.</p>
65+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
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/net5.0/WebApp1.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+
"processId": "${command:pickProcess}"
34+
}
35+
]
36+
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
{
2+
"version": "2.0.0",
3+
"tasks": [
4+
{
5+
"label": "build",
6+
"command": "dotnet",
7+
"type": "process",
8+
"args": [
9+
"build",
10+
"${workspaceFolder}/WebApp1.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}/WebApp1.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+
"${workspaceFolder}/WebApp1.csproj",
36+
"/property:GenerateFullPaths=true",
37+
"/consoleloggerparameters:NoSummary"
38+
],
39+
"problemMatcher": "$msCompile"
40+
}
41+
]
42+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Threading.Tasks;
5+
using Microsoft.AspNetCore.Identity;
6+
7+
namespace WebApp1.Areas.Identity.Data
8+
{
9+
// Add profile data for application users by adding properties to the WebApp1User class
10+
public class WebApp1User : IdentityUser
11+
{
12+
13+
[PersonalData]
14+
public string Name { get; set; }
15+
16+
[PersonalData]
17+
public DateTime DOB { get; set; }
18+
19+
}
20+
}
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
@page
2+
@model LoginModel
3+
4+
@{
5+
ViewData["Title"] = "Log in";
6+
}
7+
8+
<h1>@ViewData["Title"]</h1>
9+
<div class="row">
10+
<div class="col-md-4">
11+
<section>
12+
<form id="account" method="post">
13+
<h4>Use a local account to log in.</h4>
14+
<hr />
15+
<div asp-validation-summary="All" class="text-danger"></div>
16+
<div class="form-group">
17+
<label asp-for="Input.Email"></label>
18+
<input asp-for="Input.Email" class="form-control" />
19+
<span asp-validation-for="Input.Email" class="text-danger"></span>
20+
</div>
21+
<div class="form-group">
22+
<label asp-for="Input.Password"></label>
23+
<input asp-for="Input.Password" class="form-control" />
24+
<span asp-validation-for="Input.Password" class="text-danger"></span>
25+
</div>
26+
<div class="form-group">
27+
<div class="checkbox">
28+
<label asp-for="Input.RememberMe">
29+
<input asp-for="Input.RememberMe" />
30+
@Html.DisplayNameFor(m => m.Input.RememberMe)
31+
</label>
32+
</div>
33+
</div>
34+
<div class="form-group">
35+
<button type="submit" class="btn btn-primary">Log in</button>
36+
</div>
37+
<div class="form-group">
38+
<p>
39+
<a id="forgot-password" asp-page="./ForgotPassword">Forgot your password?</a>
40+
</p>
41+
<p>
42+
<a asp-page="./Register" asp-route-returnUrl="@Model.ReturnUrl">Register as a new user</a>
43+
</p>
44+
<p>
45+
<a id="resend-confirmation" asp-page="./ResendEmailConfirmation">Resend email confirmation</a>
46+
</p>
47+
</div>
48+
</form>
49+
</section>
50+
</div>
51+
<div class="col-md-6 col-md-offset-2">
52+
<section>
53+
<h4>Use another service to log in.</h4>
54+
<hr />
55+
@{
56+
if ((Model.ExternalLogins?.Count ?? 0) == 0)
57+
{
58+
<div>
59+
<p>
60+
There are no external authentication services configured. See <a href="https://go.microsoft.com/fwlink/?LinkID=532715">this article</a>
61+
for details on setting up this ASP.NET application to support logging in via external services.
62+
</p>
63+
</div>
64+
}
65+
else
66+
{
67+
<form id="external-account" asp-page="./ExternalLogin" asp-route-returnUrl="@Model.ReturnUrl" method="post" class="form-horizontal">
68+
<div>
69+
<p>
70+
@foreach (var provider in Model.ExternalLogins)
71+
{
72+
<button type="submit" class="btn btn-primary" name="provider" value="@provider.Name" title="Log in using your @provider.DisplayName account">@provider.DisplayName</button>
73+
}
74+
</p>
75+
</div>
76+
</form>
77+
}
78+
}
79+
</section>
80+
</div>
81+
</div>
82+
83+
@section Scripts {
84+
<partial name="_ValidationScriptsPartial" />
85+
}

0 commit comments

Comments
 (0)