Skip to content

Commit

Permalink
Migrate to .NET 6.0 (#20)
Browse files Browse the repository at this point in the history
* Migrate project and dependencies to target .NET 6.0 RC1

* Update Program startup code to the new .NET 6 template format

Consolidating Program.cs and Startup.cs in a single file

* Update Github Actions to use .Net Core 6.0 preview

* Update Program startup code to .NET 6 changes

Remove DeveloperExceptionPage middleware as it is now added by the framework automatically
UseEndpoints braces are no longer required and we can map controller routes directly to the app

As per https://devblogs.microsoft.com/aspnet/asp-net-core-updates-in-net-6-rc-1/#developer-exception-page-middleware-change

* Update dotnet-ef to version 6 RC

* Update database migration methods to EF 6 changes

As some have been deprecated

* Update Hashing methods to .NET 6 changes

As some have been deprecated

* Change some helper methods to be static

* Update exception throwing to include the parameter

* Use new C# idioms & features

* Update package references to .NET 6 RC2

* Update dependencies

Update IdentityModel to 5.2.0
Remove unneeded development dependencies

* Update package references to .NET 6.0 (final)

* Update the EntityFramework CLI tool to 6.0 (final)

* Update GitHub Actions to .NET 6 (final)

Note : There is still a workaround in place to enable .NET 6 in the CodeQL GitHub Action.
  • Loading branch information
AmineI authored Nov 10, 2021
1 parent fdd82b3 commit eb55058
Show file tree
Hide file tree
Showing 14 changed files with 297 additions and 334 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build-and-deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ env:
CONNECTIONSTRINGS__DEFAULTCONNECTION: ${{ secrets.database_connection_string }}
CONFIGURATION: Debug
ASPNETCORE_ENVIRONMENT: Development
DOTNET_CORE_VERSION: 5.0.x
DOTNET_CORE_VERSION: 6.0.x
WORKING_DIRECTORY: Source/WebApp-Service-Provider-DotNet/
jobs:
build-and-deploy:
Expand Down
7 changes: 7 additions & 0 deletions .github/workflows/codeql-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,14 @@ jobs:
# By default, queries listed here will override any specified in a config file.
# Prefix the list here with "+" to use these queries and those in the config file.
# queries: ./path/to/local/query, your-org/your-repo/queries@main


# TODO : Remove this entire step when CodeQL supports .NET 6 as the autobuild step is able to do that automatically for non-preview versions
- name: Setup .NET Core SDK
uses: actions/setup-dotnet@v1.8.2
with:
dotnet-version: 6.0.x

# Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
# If this step fails, then you should remove it and run the build manually (see below)
- name: Autobuild
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
]
},
"dotnet-ef": {
"version": "5.0.7",
"version": "6.0.0",
"commands": [
"dotnet-ef"
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ public async Task<IActionResult> ExternalLoginCallback(string returnUrl = null)
ViewData["LoginProvider"] = info.ProviderDisplayName;

DateTime.TryParseExact(info.Principal.FindFirstValue("birthdate"), "yyyy-MM-dd", new CultureInfo("fr-FR"), DateTimeStyles.AssumeUniversal, out DateTime parsedBirthDate);
ExternalLoginConfirmationViewModel model = new ExternalLoginConfirmationViewModel
ExternalLoginConfirmationViewModel model = new()
{
Email = info.Principal.FindFirstValue("email"),
Gender = info.Principal.FindFirstValue("gender"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,15 +101,15 @@ public async Task<IActionResult> GetResourceCallback(string code, string state)

if (string.IsNullOrEmpty(code))
{
throw new ArgumentNullException("Authorization code cannot be null");
throw new ArgumentNullException(code,"Authorization code cannot be null");
}
if (string.IsNullOrEmpty(state))
{
throw new ArgumentNullException("State cannot be null");
throw new ArgumentNullException(state,"State cannot be null");
}
if (state != consentCookie.State)
{
throw new ArgumentException("Invalid state");
throw new ArgumentException("Invalid state", state);
}

var tokenClient = new HttpClient();
Expand Down Expand Up @@ -199,7 +199,7 @@ public async Task<IActionResult> Resource()
{
ViewData["Message"] = "La ressource demandée n'a pas été trouvée.";
if (consentCookie.Provider=="Custom"){
UriBuilder addDataUri = new UriBuilder(GetResourceUrl(consentCookie.Provider))
UriBuilder addDataUri = new(GetResourceUrl(consentCookie.Provider))
{
Path = "/Account/Register"
};
Expand Down Expand Up @@ -228,7 +228,7 @@ private class ConsentCookie

#region Helpers

private BaseResourceViewModel ConvertResource(string json, string scheme)
private static BaseResourceViewModel ConvertResource(string json, string scheme)
{
return scheme switch
{
Expand Down Expand Up @@ -258,13 +258,13 @@ private string GetConsentRedirectUri()
: Request.Scheme + "://" + Request.Host + Url.Action(nameof(GetResourceCallback));
}

private string Base64Encode(string text)
private static string Base64Encode(string text)
{
var bytes = Encoding.UTF8.GetBytes(text);
return Convert.ToBase64String(bytes);
}

private string Base64Decode(string base64EncodedText)
private static string Base64Decode(string base64EncodedText)
{
var bytes = Convert.FromBase64String(base64EncodedText);
return Encoding.UTF8.GetString(bytes);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ private string CreateUri(string action)
return string.Format("{0}://{1}{2}", protocol, Request.Host, Url.Action(action));
}

private string GetClaimValue(IEnumerable<Claim> claims, string claimType)
private static string GetClaimValue(IEnumerable<Claim> claims, string claimType)
{
var claim = claims.FirstOrDefault(c => c.Type == claimType);
if (claim != null)
Expand Down
16 changes: 7 additions & 9 deletions Source/WebApp-Service-Provider-DotNet/Helpers/Hashing.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,15 @@ public static class Hashing
{
public static string HashString(string stringToHash)
{
using (SHA512 sha512 = new SHA512Managed())
using SHA512 sha512 = SHA512.Create();
var hash = sha512.ComputeHash(Encoding.UTF8.GetBytes(stringToHash));

StringBuilder stringHashBuilder = new(hash.Length * 2);
foreach (byte b in hash)
{
var hash = sha512.ComputeHash(Encoding.UTF8.GetBytes(stringToHash));

StringBuilder stringHashBuilder = new StringBuilder(hash.Length * 2);
foreach (byte b in hash)
{
stringHashBuilder.Append(b.ToString("X2").ToLower());
}
return stringHashBuilder.ToString();
stringHashBuilder.Append(b.ToString("X2").ToLower());
}
return stringHashBuilder.ToString();
}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public static bool IsEIdasLevelMet(string acrValues, int minimumEIdasLevel)
{
if (acrValues != null)
{
Regex myRegex = new Regex(@"eidas(\d)");
Regex myRegex = new(@"eidas(\d)");
Match match = myRegex.Match(acrValues);
if (match.Success)
{
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit eb55058

Please sign in to comment.