Skip to content

Commit

Permalink
Upgrade to .NET SDK 8.0.400
Browse files Browse the repository at this point in the history
  • Loading branch information
VahidN committed Sep 14, 2024
1 parent b485493 commit 953cf68
Show file tree
Hide file tree
Showing 38 changed files with 586 additions and 542 deletions.
2 changes: 1 addition & 1 deletion .config/dotnet-tools.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"isRoot": true,
"tools": {
"dotnet-ef": {
"version": "7.0.3",
"version": "8.0.8",
"commands": [
"dotnet-ef"
]
Expand Down
1 change: 1 addition & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ dotnet_diagnostic.SCS0008.severity = suggestion

# SCS0009: The cookie is missing 'HttpOnly' flag.
dotnet_diagnostic.SCS0009.severity = suggestion
dotnet_diagnostic.S6968.severity = suggestion

# For improved performance, use the LoggerMessage delegates instead of calling 'LoggerExtensions.LogError(ILogger, Exception?, string?, params object?[])'
dotnet_diagnostic.CA1848.severity = suggestion
Expand Down
2 changes: 1 addition & 1 deletion .github/FUNDING.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ community_bridge: # Replace with a single Community Bridge project-name e.g., cl
liberapay: # Replace with a single Liberapay username
issuehunt: # Replace with a single IssueHunt username
otechie: # Replace with a single Otechie username
custom: ['https://coffeebede.ir/%D9%88%D8%AD%D9%8A%D8%AF%D9%86%D8%B5%D9%8A%D8%B1%D9%8A', 'https://www.buymeacoffee.com/vahidn']
custom: ['https://www.coffeete.ir/vnasiri', 'https://www.buymeacoffee.com/vahidn']
6 changes: 3 additions & 3 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ jobs:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v1
- uses: actions/checkout@v4
- name: Setup .NET Core
uses: actions/setup-dotnet@v1
uses: actions/setup-dotnet@v3
with:
dotnet-version: 7.0.202
dotnet-version: 8.0.x
- name: Build ASPNETCore2JwtAuthentication
run: dotnet build ./src/ASPNETCore2JwtAuthentication.WebApp/ASPNETCore2JwtAuthentication.WebApp.csproj --configuration Release
86 changes: 86 additions & 0 deletions .github/workflows/codeql.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
# For most projects, this workflow file will not need changing; you simply need
# to commit it to your repository.
#
# You may wish to alter this file to override the set of languages analyzed,
# or to provide custom queries or build logic.
#
# ******** NOTE ********
# We have attempted to detect the languages in your repository. Please check
# the `language` matrix defined below to confirm you have the correct set of
# supported CodeQL languages.
#
name: "CodeQL"

on:
push:
branches: [ "master" ]
pull_request:
# The branches below must be a subset of the branches above
branches: [ "master" ]

jobs:
analyze:
name: Analyze
# Runner size impacts CodeQL analysis time. To learn more, please see:
# - https://gh.io/recommended-hardware-resources-for-running-codeql
# - https://gh.io/supported-runners-and-hardware-resources
# - https://gh.io/using-larger-runners
# Consider using larger runners for possible analysis time improvements.
runs-on: windows-2019
permissions:
actions: read
contents: read
security-events: write

strategy:
fail-fast: false
matrix:
language: [ 'csharp' ]
# CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python', 'ruby', 'swift' ]
# Use only 'java' to analyze code written in Java, Kotlin or both
# Use only 'javascript' to analyze code written in JavaScript, TypeScript or both
# Learn more about CodeQL language support at https://aka.ms/codeql-docs/language-support

steps:
- name: Checkout repository
uses: actions/checkout@v4

# Initializes the CodeQL tools for scanning.
- name: Initialize CodeQL
uses: github/codeql-action/init@v2
with:
languages: ${{ matrix.language }}
config-file: ./.github/workflows/codeql/codeql-config.yml
# If you wish to specify custom queries, you can do so here or in a config file.
# 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.

# For more details on CodeQL's query packs, refer to: https://docs.github.com/en/code-security/code-scanning/automatically-scanning-your-code-for-vulnerabilities-and-errors/configuring-code-scanning#using-queries-in-ql-packs
# queries: security-extended,security-and-quality


# Autobuild attempts to build any compiled languages (C/C++, C#, Go, Java, or Swift).
# If this step fails, then you should remove it and run the build manually (see below)
# - name: Autobuild
# uses: github/codeql-action/autobuild@v2
- name: Setup .NET
uses: actions/setup-dotnet@v3
with:
dotnet-version: 8.0.x
- name: Build
run: dotnet build --configuration Release

# ℹ️ Command-line programs to run using the OS shell.
# 📚 See https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstepsrun

# If the Autobuild fails above, remove it and uncomment the following three lines.
# modify them (or add more) to build your code if your project, please refer to the EXAMPLE below for guidance.

# - run: |
# echo "Run, Build Application using script"
# ./location_of_script_within_repo/buildscript.sh

- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v2
with:
category: "/language:${{matrix.language}}"
10 changes: 10 additions & 0 deletions .github/workflows/codeql/codeql-config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
name: "Security and Quality"

queries:
- uses: security-and-quality

query-filters:
- exclude:
id: cs/useless-if-statement
- exclude:
id: cs/empty-block
46 changes: 0 additions & 46 deletions .vscode/launch.json

This file was deleted.

16 changes: 0 additions & 16 deletions .vscode/tasks.json

This file was deleted.

44 changes: 22 additions & 22 deletions Directory.Packages.props
Original file line number Diff line number Diff line change
@@ -1,31 +1,31 @@
<Project>
<ItemGroup>
<PackageVersion Include="Meziantou.Analyzer" Version="2.0.19" />
<PackageVersion Include="Microsoft.VisualStudio.Threading.Analyzers" Version="17.5.22" />
<PackageVersion Include="Meziantou.Analyzer" Version="2.0.163" />
<PackageVersion Include="Microsoft.VisualStudio.Threading.Analyzers" Version="17.11.20" />
<PackageVersion Include="Microsoft.CodeAnalysis.BannedApiAnalyzers" Version="3.3.4" />
<PackageVersion Include="AsyncFixer" Version="1.6.0" />
<PackageVersion Include="Asyncify" Version="0.9.7" />
<PackageVersion Include="SonarAnalyzer.CSharp" Version="8.53.0.62665" />
<PackageVersion Include="SonarAnalyzer.CSharp" Version="9.32.0.97167" />
<PackageVersion Include="SecurityCodeScan.VS2019" Version="5.6.7" />
<PackageVersion Include="Roslynator.Analyzers" Version="4.2.0" />
<PackageVersion Include="Microsoft.EntityFrameworkCore.Analyzers" Version="7.0.3" />
<PackageVersion Include="Microsoft.EntityFrameworkCore.Design" Version="7.0.3" />
<PackageVersion Include="Microsoft.EntityFrameworkCore.Tools" Version="7.0.3" />
<PackageVersion Include="Microsoft.AspNet.WebApi.Client" Version="5.2.9" />
<PackageVersion Include="Newtonsoft.Json" Version="13.0.2" />
<PackageVersion Include="Microsoft.EntityFrameworkCore" Version="7.0.3" />
<PackageVersion Include="Microsoft.EntityFrameworkCore.SqlServer" Version="7.0.3" />
<PackageVersion Include="Microsoft.Extensions.Configuration" Version="7.0.0" />
<PackageVersion Include="Microsoft.Extensions.Configuration.Abstractions" Version="7.0.0" />
<PackageVersion Include="Microsoft.Extensions.Configuration.Json" Version="7.0.0" />
<PackageVersion Include="Microsoft.Extensions.Configuration.Binder" Version="7.0.3" />
<PackageVersion Include="fluentassertions" Version="6.10.0" />
<PackageVersion Include="Microsoft.AspNetCore.Mvc.Testing" Version="7.0.3" />
<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="17.5.0" />
<PackageVersion Include="MSTest.TestAdapter" Version="3.0.2" />
<PackageVersion Include="MSTest.TestFramework" Version="3.0.2" />
<PackageVersion Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="7.0.3" />
<PackageVersion Include="Swashbuckle.AspNetCore" Version="6.5.0" />
<PackageVersion Include="Roslynator.Analyzers" Version="4.12.5" />
<PackageVersion Include="Microsoft.EntityFrameworkCore.Analyzers" Version="8.0.8" />
<PackageVersion Include="Microsoft.EntityFrameworkCore.Design" Version="8.0.8" />
<PackageVersion Include="Microsoft.EntityFrameworkCore.Tools" Version="8.0.8" />
<PackageVersion Include="Microsoft.AspNet.WebApi.Client" Version="6.0.0" />
<PackageVersion Include="Newtonsoft.Json" Version="13.0.3" />
<PackageVersion Include="Microsoft.EntityFrameworkCore" Version="8.0.8" />
<PackageVersion Include="Microsoft.EntityFrameworkCore.SqlServer" Version="8.0.8" />
<PackageVersion Include="Microsoft.Extensions.Configuration" Version="8.0.0" />
<PackageVersion Include="Microsoft.Extensions.Configuration.Abstractions" Version="8.0.0" />
<PackageVersion Include="Microsoft.Extensions.Configuration.Json" Version="8.0.0" />
<PackageVersion Include="Microsoft.Extensions.Configuration.Binder" Version="8.0.2" />
<PackageVersion Include="fluentassertions" Version="6.12.1" />
<PackageVersion Include="Microsoft.AspNetCore.Mvc.Testing" Version="8.0.8" />
<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="17.11.1" />
<PackageVersion Include="MSTest.TestAdapter" Version="3.6.0" />
<PackageVersion Include="MSTest.TestFramework" Version="3.6.0" />
<PackageVersion Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="8.0.8" />
<PackageVersion Include="Swashbuckle.AspNetCore" Version="6.7.3" />
<PackageVersion Include="Microsoft.Web.LibraryManager.Build" Version="2.1.175" />
<PackageVersion Include="UAParser" Version="3.1.47" />
</ItemGroup>
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Jwt Authentication without ASP.NET Core Identity 7x
Jwt Authentication without ASP.NET Core Identity 8x
===========

<p>
Expand All @@ -10,11 +10,11 @@ Jwt Authentication without ASP.NET Core Identity 7x

![jwtauth](/src/ASPNETCore2JwtAuthentication.WebApp/wwwroot/images/jwtauth.png)

A Jwt based authentication sample for ASP.NET Core 7x without using the Identity system. It includes:
A Jwt based authentication sample for ASP.NET Core 8x without using the Identity system. It includes:

- Users and Roles tables with a many-to-may relationship.
- A separated EF Core data layer with enabled migrations.
- An EF Core 7x based service layer.
- An EF Core 8x based service layer.
- A Db initializer to seed the default database values.
- An account controller with Jwt and DB based login, custom logout and refresh tokens capabilities.
- 2 sample API controllers to show how user-roles can be applied and used.
Expand Down
2 changes: 1 addition & 1 deletion global.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"sdk": {
"version": "7.0.202"
"version": "8.0.400"
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
</PropertyGroup>
</Project>
19 changes: 10 additions & 9 deletions src/ASPNETCore2JwtAuthentication.Common/ServerPath.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,35 +4,36 @@ public static class ServerPath
{
public static string GetProjectPath(Assembly startupAssembly)
{
if (startupAssembly == null)
{
throw new ArgumentNullException(nameof(startupAssembly));
}
ArgumentNullException.ThrowIfNull(startupAssembly);

var projectName = startupAssembly.GetName().Name;

if (string.IsNullOrWhiteSpace(projectName))
{
throw new InvalidOperationException("Couldn't find the assembly name.");
throw new InvalidOperationException(message: "Couldn't find the assembly name.");
}

var applicationBasePath = AppContext.BaseDirectory;
var directoryInfo = new DirectoryInfo(applicationBasePath);

do
{
directoryInfo = directoryInfo.Parent;

if (directoryInfo is null)
{
break;
}

var projectDirectoryInfo = new DirectoryInfo(Path.Combine(directoryInfo.FullName));
if (projectDirectoryInfo.Exists
&& new FileInfo(Path.Combine(projectDirectoryInfo.FullName, projectName, $"{projectName}.csproj"))
.Exists)

if (projectDirectoryInfo.Exists &&
new FileInfo(Path.Combine(projectDirectoryInfo.FullName, projectName, $"{projectName}.csproj")).Exists)
{
return Path.Combine(projectDirectoryInfo.FullName, projectName);
}
} while (directoryInfo.Parent != null);
}
while (directoryInfo.Parent != null);

throw new InvalidOperationException(
$"Project root could not be located using the application root {applicationBasePath}.");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net7.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<NoWarn>RCS1090</NoWarn>
</PropertyGroup>
<ItemGroup>
Expand Down
6 changes: 4 additions & 2 deletions src/ASPNETCore2JwtAuthentication.ConsoleClient/Token.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ namespace ASPNETCore2JwtAuthentication.ConsoleClient;

public class Token
{
[JsonProperty("access_token")] public string AccessToken { get; set; }
[JsonProperty(propertyName: "access_token")]
public string? AccessToken { get; set; }

[JsonProperty("refresh_token")] public string RefreshToken { get; set; }
[JsonProperty(propertyName: "refresh_token")]
public string? RefreshToken { get; set; }
}
5 changes: 3 additions & 2 deletions src/ASPNETCore2JwtAuthentication.ConsoleClient/User.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

public class User
{
public string Username { get; set; }
public string Password { get; set; }
public required string Username { get; set; }

public required string Password { get; set; }
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\ASPNETCore2JwtAuthentication.DomainClasses\ASPNETCore2JwtAuthentication.DomainClasses.csproj" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,7 @@ public ApplicationDbContext(DbContextOptions options) : base(options)

protected override void OnModelCreating(ModelBuilder modelBuilder)
{
if (modelBuilder == null)
{
throw new ArgumentNullException(nameof(modelBuilder));
}
ArgumentNullException.ThrowIfNull(modelBuilder);

// it should be placed here, otherwise it will rewrite the following settings!
base.OnModelCreating(modelBuilder);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ dotnet tool restore
dotnet build
For /f "tokens=2-4 delims=/ " %%a in ('date /t') do (set mydate=%%c_%%a_%%b)
For /f "tokens=1-2 delims=/:" %%a in ("%TIME: =0%") do (set mytime=%%a%%b)
dotnet ef migrations --startup-project ../ASPNETCore2JwtAuthentication.WebApp/ add V%mydate%_%mytime%
dotnet ef --verbose migrations --startup-project ../ASPNETCore2JwtAuthentication.WebApp/ add V%mydate%_%mytime%
pause
Loading

0 comments on commit 953cf68

Please sign in to comment.