Skip to content

Commit

Permalink
Update nonce
Browse files Browse the repository at this point in the history
  • Loading branch information
damienbod committed Jun 23, 2023
1 parent a6b38f8 commit 027f877
Show file tree
Hide file tree
Showing 8 changed files with 67 additions and 65 deletions.
29 changes: 14 additions & 15 deletions IssuerDrivingLicense/Pages/Admin.cshtml.cs
Original file line number Diff line number Diff line change
@@ -1,23 +1,22 @@
using Microsoft.AspNetCore.Mvc.RazorPages;
using Microsoft.AspNetCore.Mvc.RazorPages;
using Microsoft.EntityFrameworkCore;
using IssuerDrivingLicense.Persistence;

namespace IssuerDrivingLicense
namespace IssuerDrivingLicense;

public class AdminModel : PageModel
{
public class AdminModel : PageModel
{
private readonly DrivingLicenseDbContext _context;
private readonly DrivingLicenseDbContext _context;

public AdminModel(DrivingLicenseDbContext context)
{
_context = context;
}
public AdminModel(DrivingLicenseDbContext context)
{
_context = context;
}

public List<DriverLicense> DriverLicenses { get; set; } = new List<DriverLicense>();
public List<DriverLicense> DriverLicenses { get; set; } = new List<DriverLicense>();

public async Task OnGetAsync()
{
DriverLicenses = await _context.DriverLicenses.ToListAsync();
}
public async Task OnGetAsync()
{
DriverLicenses = await _context.DriverLicenses.ToListAsync();
}
}
}
4 changes: 2 additions & 2 deletions IssuerDrivingLicense/Pages/DriverLicenseCredentials.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,6 @@
}

@section scripts {
<script src="qrcode.min.js"></script>
<script src="DriverLicenseCredentials.js"></script>
<script src="qrcode.min.js" nonce="@nonce"></script>
<script src="DriverLicenseCredentials.js" nonce="@nonce"></script>
}
41 changes: 20 additions & 21 deletions IssuerDrivingLicense/Pages/DriverLicenseCredentials.cshtml.cs
Original file line number Diff line number Diff line change
@@ -1,33 +1,32 @@
using IssuerDrivingLicense.Persistence;
using Microsoft.AspNetCore.Mvc.RazorPages;

namespace IssuerDrivingLicense.Pages
namespace IssuerDrivingLicense.Pages;

public class DriverLicenseCredentialsModel : PageModel
{
public class DriverLicenseCredentialsModel : PageModel
{
private readonly DriverLicenseService _driverLicenseService;
private readonly DriverLicenseService _driverLicenseService;

public string DriverLicenseMessage { get; set; } = "Loading credentials";
public bool HasDriverLicense { get; set; }
public DriverLicense? DriverLicense { get; set; }
public string DriverLicenseMessage { get; set; } = "Loading credentials";
public bool HasDriverLicense { get; set; }
public DriverLicense? DriverLicense { get; set; }

public DriverLicenseCredentialsModel(DriverLicenseService driverLicenseService)
public DriverLicenseCredentialsModel(DriverLicenseService driverLicenseService)
{
_driverLicenseService = driverLicenseService;
}
public async Task OnGetAsync()
{
DriverLicense = await _driverLicenseService.GetDriverLicense(HttpContext.User?.Identity?.Name);

if (DriverLicense != null)
{
_driverLicenseService = driverLicenseService;
DriverLicenseMessage = "Add your driver license credentials to your wallet";
HasDriverLicense = true;
}
public async Task OnGetAsync()
else
{
DriverLicense = await _driverLicenseService.GetDriverLicense(HttpContext.User?.Identity?.Name);

if (DriverLicense != null)
{
DriverLicenseMessage = "Add your driver license credentials to your wallet";
HasDriverLicense = true;
}
else
{
DriverLicenseMessage = "You have no valid driver license";
}
DriverLicenseMessage = "You have no valid driver license";
}
}
}
23 changes: 11 additions & 12 deletions IssuerDrivingLicense/Pages/Error.cshtml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,18 @@
using Microsoft.AspNetCore.Mvc.RazorPages;
using System.Diagnostics;

namespace IssuerDrivingLicense.Pages
namespace IssuerDrivingLicense.Pages;

[ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
[IgnoreAntiforgeryToken]
public class ErrorModel : PageModel
{
[ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
[IgnoreAntiforgeryToken]
public class ErrorModel : PageModel
{
public string? RequestId { get; set; }
public string? RequestId { get; set; }

public bool ShowRequestId => !string.IsNullOrEmpty(RequestId);
public bool ShowRequestId => !string.IsNullOrEmpty(RequestId);

public void OnGet()
{
RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier;
}
public void OnGet()
{
RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier;
}
}
}
13 changes: 6 additions & 7 deletions IssuerDrivingLicense/Pages/Index.cshtml.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
using Microsoft.AspNetCore.Mvc.RazorPages;
using Microsoft.AspNetCore.Mvc.RazorPages;

namespace IssuerDrivingLicense.Pages
namespace IssuerDrivingLicense.Pages;

public class IndexModel : PageModel
{
public class IndexModel : PageModel
public void OnGet()
{
public void OnGet()
{

}
}
}
}
13 changes: 8 additions & 5 deletions IssuerDrivingLicense/Pages/Shared/_Layout.cshtml
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
<!DOCTYPE html>
@{
var nonce = this.Context.GetNonce();
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
Expand Down Expand Up @@ -52,10 +55,10 @@
</div>
</footer>

<script src="~/lib/jquery/dist/jquery.min.js"></script>
<script src="~/lib/bootstrap/dist/js/bootstrap.bundle.min.js"></script>
<script src="~/js/site.js" asp-append-version="true"></script>
<script src="~/lib/jquery/dist/jquery.min.js" nonce="@nonce"></script>
<script src="~/lib/bootstrap/dist/js/bootstrap.bundle.min.js" nonce="@nonce"></script>
<script src="~/js/site.js" asp-append-version="true" nonce="@nonce"></script>

@await RenderSectionAsync("Scripts", required: false)
</body>
</html>
</html>
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
<script src="~/lib/jquery-validation/dist/jquery.validate.min.js"></script>
<script src="~/lib/jquery-validation-unobtrusive/jquery.validate.unobtrusive.min.js"></script>
@{
var nonce = this.Context.GetNonce();
}
<script src="~/lib/jquery-validation/dist/jquery.validate.min.js" nonce="@nonce"></script>
<script src="~/lib/jquery-validation-unobtrusive/jquery.validate.unobtrusive.min.js" nonce="@nonce"></script>
2 changes: 1 addition & 1 deletion IssuerDrivingLicense/SecurityHeadersDefinitions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public static HeaderPolicyCollection GetHeaderPolicyCollection(bool isDev)
builder.AddFontSrc().Self();
builder.AddStyleSrc().Self().UnsafeInline();
builder.AddBaseUri().Self();
builder.AddScriptSrc().Self().UnsafeInline();
builder.AddScriptSrc().Self().UnsafeInline().WithNonce();
builder.AddFrameAncestors().None();
//builder.AddCustomDirective("require-trusted-types-for", "'script'");
})
Expand Down

0 comments on commit 027f877

Please sign in to comment.