Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 34ab71a

Browse filesBrowse files
committed
Update Samples to .NET 8 and Razor pages
1 parent 9560601 commit 34ab71a
Copy full SHA for 34ab71a

File tree

Expand file treeCollapse file tree

274 files changed

+196086
-41928
lines changed
Filter options

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
Dismiss banner
Expand file treeCollapse file tree

274 files changed

+196086
-41928
lines changed

‎Quickstarts/Core/Controllers/HomeController.cs

Copy file name to clipboardExpand all lines: Quickstarts/Core/Controllers/HomeController.cs
-76Lines changed: 0 additions & 76 deletions
This file was deleted.

‎Quickstarts/Core/Core.csproj

Copy file name to clipboard
+10-8Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
1-
<Project Sdk="Microsoft.NET.Sdk.Web">
1+
<Project Sdk="Microsoft.NET.Sdk.Web">
22

3-
<PropertyGroup>
4-
<TargetFramework>netcoreapp3.1</TargetFramework>
5-
<AspNetCoreHostingModel>InProcess</AspNetCoreHostingModel>
6-
</PropertyGroup>
3+
<PropertyGroup>
4+
<TargetFramework>net8.0</TargetFramework>
5+
<Nullable>enable</Nullable>
6+
<ImplicitUsings>enable</ImplicitUsings>
7+
</PropertyGroup>
78

9+
<ItemGroup>
10+
<PackageReference Include="Rsk.AspNetCore.Fido.EntityFramework" Version="3.0.0" />
11+
</ItemGroup>
812

9-
<ItemGroup>
10-
<PackageReference Include="Rsk.AspNetCore.Fido" Version="1.3.0" />
11-
</ItemGroup>
13+
1214

1315
</Project>

‎Quickstarts/Core/Models/LoginModel.cs

Copy file name to clipboardExpand all lines: Quickstarts/Core/Models/LoginModel.cs
-7Lines changed: 0 additions & 7 deletions
This file was deleted.

‎Quickstarts/Core/Models/RegistrationModel.cs

Copy file name to clipboardExpand all lines: Quickstarts/Core/Models/RegistrationModel.cs
-8Lines changed: 0 additions & 8 deletions
This file was deleted.

‎Quickstarts/Core/Pages/Error.cshtml

Copy file name to clipboard
+26Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
@page
2+
@model ErrorModel
3+
@{
4+
ViewData["Title"] = "Error";
5+
}
6+
7+
<h1 class="text-danger">Error.</h1>
8+
<h2 class="text-danger">An error occurred while processing your request.</h2>
9+
10+
@if (Model.ShowRequestId)
11+
{
12+
<p>
13+
<strong>Request ID:</strong> <code>@Model.RequestId</code>
14+
</p>
15+
}
16+
17+
<h3>Development Mode</h3>
18+
<p>
19+
Swapping to the <strong>Development</strong> environment displays detailed information about the error that occurred.
20+
</p>
21+
<p>
22+
<strong>The Development environment shouldn't be enabled for deployed applications.</strong>
23+
It can result in displaying sensitive information from exceptions to end users.
24+
For local debugging, enable the <strong>Development</strong> environment by setting the <strong>ASPNETCORE_ENVIRONMENT</strong> environment variable to <strong>Development</strong>
25+
and restarting the app.
26+
</p>
+26Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
using System.Diagnostics;
2+
using Microsoft.AspNetCore.Mvc;
3+
using Microsoft.AspNetCore.Mvc.RazorPages;
4+
5+
namespace Core.Pages;
6+
7+
[ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
8+
[IgnoreAntiforgeryToken]
9+
public class ErrorModel : PageModel
10+
{
11+
public string? RequestId { get; set; }
12+
13+
public bool ShowRequestId => !string.IsNullOrEmpty(RequestId);
14+
15+
private readonly ILogger<ErrorModel> _logger;
16+
17+
public ErrorModel(ILogger<ErrorModel> logger)
18+
{
19+
_logger = logger;
20+
}
21+
22+
public void OnGet()
23+
{
24+
RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier;
25+
}
26+
}

‎Quickstarts/Core/Views/Home/Index.cshtml renamed to ‎Quickstarts/Core/Pages/Index.cshtml

Copy file name to clipboardExpand all lines: Quickstarts/Core/Pages/Index.cshtml
+2-1Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
@using System.Security.Claims
1+
@page
2+
@using System.Security.Claims
23
@{
34
ViewData["Title"] = "Home Page";
45
}
+16Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
using Microsoft.AspNetCore.Mvc;
2+
using Microsoft.AspNetCore.Mvc.RazorPages;
3+
4+
namespace Core.Pages;
5+
6+
public class IndexModel : PageModel
7+
{
8+
private readonly ILogger<IndexModel> _logger;
9+
10+
public IndexModel(ILogger<IndexModel> logger)
11+
{
12+
_logger = logger;
13+
}
14+
15+
public IActionResult OnGet() => Page();
16+
}

‎Quickstarts/Core/Views/Home/StartLogin.cshtml renamed to ‎Quickstarts/Core/Pages/Login/Index.cshtml

Copy file name to clipboardExpand all lines: Quickstarts/Core/Pages/Login/Index.cshtml
+3-2Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
@model Core.Models.LoginModel
1+
@page
2+
@model Core.Pages.Login.IndexModel
23

34
<h2>Login</h2>
4-
<form asp-action="Login">
5+
<form method="post">
56
<div class="form-group">
67
<label asp-for="UserId"></label>
78
<input asp-for="UserId" class="form-control" />
+47Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
using Microsoft.AspNetCore.Mvc;
2+
using Microsoft.AspNetCore.Mvc.RazorPages;
3+
using Rsk.AspNetCore.Fido;
4+
using Rsk.AspNetCore.Fido.Dtos;
5+
6+
namespace Core.Pages.Login;
7+
8+
public class IndexModel : PageModel
9+
{
10+
private readonly IFidoAuthentication _fidoAuthentication;
11+
12+
[BindProperty]
13+
public string UserId { get; set; }
14+
15+
public IndexModel(IFidoAuthentication fidoAuthentication)
16+
{
17+
_fidoAuthentication = fidoAuthentication;
18+
}
19+
public IActionResult OnGet()
20+
{
21+
return Page();
22+
}
23+
24+
public async Task<IActionResult> OnPost()
25+
{
26+
try
27+
{
28+
var challenge = await _fidoAuthentication.InitiateAuthentication(UserId);
29+
30+
var dto = challenge.ToBase64Dto();
31+
32+
return RedirectToPage("Login", new
33+
{
34+
dto.UserId,
35+
dto.Base64Challenge,
36+
dto.RelyingPartyId,
37+
dto.Base64KeyIds,
38+
39+
});
40+
}
41+
catch(PublicKeyCredentialException exception)
42+
{
43+
return BadRequest(exception.Message);
44+
}
45+
46+
}
47+
}

‎Quickstarts/EntityFramework/Views/Home/Login.cshtml renamed to ‎Quickstarts/Core/Pages/Login/Login.cshtml

Copy file name to clipboardExpand all lines: Quickstarts/Core/Pages/Login/Login.cshtml
+15-7Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,26 @@
1-
@using Newtonsoft.Json
2-
@model Rsk.AspNetCore.Fido.Dtos.Base64FidoAuthenticationChallenge
1+
@page
2+
@using Newtonsoft.Json
3+
@model Core.Pages.Login.LoginModel
4+
@Html.AntiForgeryToken()
35

46
<h2>Please use your authenticator</h2>
57

68
<script>
9+
//Authentication Configuration
10+
//https://www.identityserver.com/documentation/fido2/webauthn/authentication/
11+
712
// Challenge
8-
let challengeBytesAsString = atob("@Html.Raw(Model.Base64Challenge)");
13+
let challengeBytesAsString = atob("@Html.Raw(Model.Challenge.Base64Challenge)");
914
let challenge = new Uint8Array(challengeBytesAsString.length);
1015
for (let i = 0; i < challengeBytesAsString.length; i++) {
1116
challenge[i] = challengeBytesAsString.charCodeAt(i);
1217
}
1318
14-
// RP ID
15-
let rpId = "@Model.RelyingPartyId";
19+
// Relying Party ID
20+
let rpId = "@Model.Challenge.RelyingPartyId";
1621
1722
// Allowed credentials
18-
let keys = JSON.parse('@Html.Raw(JsonConvert.SerializeObject(Model.Base64KeyIds))');
23+
let keys = JSON.parse('@Html.Raw(JsonConvert.SerializeObject(Model.Challenge.Base64KeyIds))');
1924
let allowCredentials = [];
2025
2126
for (let i = 0; i < keys.length; i++) {
@@ -31,6 +36,8 @@
3136
id: key
3237
});
3338
}
39+
40+
3441
3542
navigator.credentials.get({ publicKey: { challenge, rpId, allowCredentials } })
3643
.then((result) => {
@@ -54,10 +61,11 @@
5461
5562
// post to login callback endpoint and redirect to homepage
5663
$.ajax({
57-
url: '/Home/CompleteLogin',
64+
url: '/Login/Login',
5865
type: 'POST',
5966
contentType: 'application/json',
6067
data: JSON.stringify(encodedResult),
68+
beforeSend: function (xhr) { xhr.setRequestHeader("XSRF-TOKEN", $('input:hidden[name="__RequestVerificationToken"]').val()); },
6169
success:function() {
6270
window.location.href = "/";
6371
}
+44Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
using System.Security.Claims;
2+
using Microsoft.AspNetCore.Authentication;
3+
using Microsoft.AspNetCore.Http.HttpResults;
4+
using Microsoft.AspNetCore.Mvc;
5+
using Microsoft.AspNetCore.Mvc.RazorPages;
6+
using Rsk.AspNetCore.Fido;
7+
using Rsk.AspNetCore.Fido.Dtos;
8+
9+
namespace Core.Pages.Login;
10+
11+
public class LoginModel : PageModel
12+
{
13+
private readonly IFidoAuthentication _fidoAuthentication;
14+
15+
[BindProperty(SupportsGet = true)]
16+
public Base64FidoAuthenticationChallenge Challenge { get; set; }
17+
18+
public LoginModel(IFidoAuthentication fidoAuthentication)
19+
{
20+
_fidoAuthentication = fidoAuthentication;
21+
}
22+
23+
public IActionResult OnGet()
24+
{
25+
return Page();
26+
}
27+
28+
public async Task<IActionResult> OnPost([FromBody] Base64FidoAuthenticationResponse authenticationResponse)
29+
{
30+
var result = await _fidoAuthentication.CompleteAuthentication(authenticationResponse.ToFidoResponse());
31+
32+
if (result.IsSuccess)
33+
{
34+
await HttpContext.SignInAsync("cookie", new ClaimsPrincipal(new ClaimsIdentity(new List<Claim>
35+
{
36+
new Claim("sub", result.UserId)
37+
}, "cookie")));
38+
}
39+
40+
if (result.IsError) return BadRequest(result.ErrorDescription);
41+
42+
return RedirectToPage("/Index");
43+
}
44+
}

‎Quickstarts/Core/Pages/Privacy.cshtml

Copy file name to clipboard
+8Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
@page
2+
@model PrivacyModel
3+
@{
4+
ViewData["Title"] = "Privacy Policy";
5+
}
6+
<h1>@ViewData["Title"]</h1>
7+
8+
<p>Use this page to detail your site's privacy policy.</p>
+18Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
using Microsoft.AspNetCore.Mvc;
2+
using Microsoft.AspNetCore.Mvc.RazorPages;
3+
4+
namespace Core.Pages;
5+
6+
public class PrivacyModel : PageModel
7+
{
8+
private readonly ILogger<PrivacyModel> _logger;
9+
10+
public PrivacyModel(ILogger<PrivacyModel> logger)
11+
{
12+
_logger = logger;
13+
}
14+
15+
public void OnGet()
16+
{
17+
}
18+
}

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.