Skip to content

Commit

Permalink
feat: update to .NET 8 with latest Duende.IdentityServer preview
Browse files Browse the repository at this point in the history
  • Loading branch information
alsami committed Nov 30, 2023
1 parent bc679c9 commit e5e8d7d
Show file tree
Hide file tree
Showing 29 changed files with 1,115 additions and 1,171 deletions.
5 changes: 3 additions & 2 deletions Directory.Build.props
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
<Project>
<PropertyGroup>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
<LangVersion>latest</LangVersion>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<NoWarn>S3267</NoWarn>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="SonarAnalyzer.CSharp" Version="8.51.0.59060">
<PackageReference Include="SonarAnalyzer.CSharp" Version="9.14.0.81108">
<PrivateAssets>all</PrivateAssets>
</PackageReference>
</ItemGroup>
Expand Down
7 changes: 2 additions & 5 deletions global.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
{
"sdk": {
"version": "7.0.102",
"version": "8.0.100",
"rollForward": "latestFeature"
},
"additionalSdks": [
"6.0.403"
]
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,9 @@ protected void Validate()
{
foreach (var scopeName in apiResource.Scopes)
{
if (!this.internalApiScopes.Any(s => s.Name == scopeName))
#pragma warning disable S6603
if (this.internalApiScopes.All(s => s.Name != scopeName))
#pragma warning restore S6603
{
throw new InvalidOperationException(
$"Resource {apiResource.Name} contains scope {scopeName} not found in ApiScopes");
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public void AddEvent(Event @event)

public Event? GetById(int id)
{
return this.events.FirstOrDefault(e => e.Id == id);
return this.events.Find(e => e.Id == id);
}

public IEnumerable<Event> GetEvents()
Expand All @@ -30,7 +30,7 @@ public IEnumerable<Event> GetEvents()

public bool ContainsEventType(EventTypes eventType)
{
var @event = this.events.FirstOrDefault(e => e.EventType == eventType);
var @event = this.events.Find(e => e.EventType == eventType);
return @event != null;
}

Expand All @@ -47,7 +47,7 @@ public bool ContainsMessageStartsWith(string value,
{
if (string.IsNullOrWhiteSpace(value)) throw new ArgumentNullException(nameof(value));

var matchingEvents = this.events.Where(e => e.Message.StartsWith(value, comparison));
var matchingEvents = this.events.Where(e => e.Message is not null && e.Message.StartsWith(value, comparison));
return matchingEvents.Any();
}
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>net6.0;net7.0</TargetFrameworks>
<TargetFramework>net8.0</TargetFramework>
<IsPackable>true</IsPackable>
<Copyright>2023©Sami Al Khatib</Copyright>
<Authors>Sami Al Khatib</Authors>
Expand All @@ -13,28 +13,21 @@
<PackageReleaseNotes>https://github.com/alsami/alsami.Duende.IdentityServer.AspNetCore.Testing/blob/master/changelog.md</PackageReleaseNotes>
<RepositoryType>git</RepositoryType>
<RepositoryUrl>git://github.com/alsami/alsami.Duende.IdentityServer.AspNetCore.Testing</RepositoryUrl>
<Version>6.2.1</Version>
<FileVersion>6.2.1</FileVersion>
<Version>7.0.0-alpha.0</Version>
<FileVersion>7.0.0</FileVersion>
<EmbedAllSources>true</EmbedAllSources>
<NoWarn>S3881</NoWarn>
<NoWarn>$(NoWarn);S3881</NoWarn>
</PropertyGroup>

<ItemGroup>
<None Include="../../icon.png" Pack="true" PackagePath="\" />
</ItemGroup>

<ItemGroup Condition="$(TargetFramework) == 'net7.0'">
<PackageReference Include="Microsoft.AspNetCore.TestHost" Version="7.0.2" />
</ItemGroup>

<ItemGroup Condition="$(TargetFramework) == 'net6.0'">
<PackageReference Include="Microsoft.AspNetCore.TestHost" Version="6.0.0" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.TestHost" Version="8.0.0" />
<FrameworkReference Include="Microsoft.AspNetCore.App" />
<PackageReference Include="Duende.IdentityServer" Version="6.2.0" />
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.1.1">
<PackageReference Include="Duende.IdentityServer" Version="6.3.6" />
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="8.0.0">
<PrivateAssets>all</PrivateAssets>
</PackageReference>
</ItemGroup>
Expand Down
23 changes: 11 additions & 12 deletions test/Duende.IdentityServer.Api/AuthController.cs
Original file line number Diff line number Diff line change
@@ -1,20 +1,19 @@
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;

namespace Duende.IdentityServer.Api
namespace Duende.IdentityServer.Api;

[Authorize]
[ApiController]
[Route("api/[controller]")]
public class AuthController : ControllerBase
{
[Authorize]
[ApiController]
[Route("api/[controller]")]
public class AuthController : ControllerBase
[HttpGet]
public IActionResult TestAuth()
{
[HttpGet]
public IActionResult TestAuth()
return new OkObjectResult(new
{
return new OkObjectResult(new
{
Message = "This endpoint would not be reachable, if the authentication was not working"
});
}
Message = "This endpoint would not be reachable, if the authentication was not working"
});
}
}
10 changes: 3 additions & 7 deletions test/Duende.IdentityServer.Api/Duende.IdentityServer.Api.csproj
Original file line number Diff line number Diff line change
@@ -1,16 +1,12 @@
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFrameworks>net6.0;net7.0</TargetFrameworks>
<ImplicitUsings>enable</ImplicitUsings>
<TargetFramework>net8.0</TargetFramework>
</PropertyGroup>

<ItemGroup Condition="$(TargetFramework) == 'net6.0'">
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="6.0.0" />
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="8.0.0" />
</ItemGroup>

<ItemGroup Condition="$(TargetFramework) == 'net7.0'">
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="7.0.2" />
</ItemGroup>

</Project>
9 changes: 4 additions & 5 deletions test/Duende.IdentityServer.Api/Program.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
namespace Duende.IdentityServer.Api
namespace Duende.IdentityServer.Api;

public static class Program
{
public static class Program
public static void Main(string[] args)
{
public static void Main(string[] args)
{
throw new NotImplementedException("This application is not meant to be run manually!");
}
}
}
21 changes: 10 additions & 11 deletions test/Duende.IdentityServer.Api/Startup.cs
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
using Microsoft.AspNetCore.Authentication.JwtBearer;

namespace Duende.IdentityServer.Api
namespace Duende.IdentityServer.Api;

public class Startup
{
public class Startup
{
private readonly HttpMessageHandler identityServerMessageHandler;
private readonly HttpMessageHandler identityServerMessageHandler;

public Startup(HttpMessageHandler identityServerMessageHandler)
{
public Startup(HttpMessageHandler identityServerMessageHandler)
{
this.identityServerMessageHandler = identityServerMessageHandler;
}

public void ConfigureServices(IServiceCollection services)
{
public void ConfigureServices(IServiceCollection services)
{
services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme)
.AddJwtBearer(options =>
{
Expand All @@ -24,12 +24,11 @@ public void ConfigureServices(IServiceCollection services)
services.AddMvc(options => options.EnableEndpointRouting = false);
}

public void Configure(IApplicationBuilder app)
{
public void Configure(IApplicationBuilder app)
{
app.UseRouting();
app.UseAuthentication();
app.UseAuthorization();
app.UseEndpoints(builder => builder.MapControllers().RequireAuthorization());
}
}
}
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFrameworks>net6.0;net7.0</TargetFrameworks>
<TargetFramework>net8.0</TargetFramework>
<NoWarn>$(NoWarn);CS0618</NoWarn>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Duende.IdentityServer" Version="6.2.1" />
<PackageReference Include="Serilog.AspNetCore" Version="6.1.0" />
<PackageReference Include="Serilog.Sinks.Console" Version="4.1.0" />
<PackageReference Include="Duende.IdentityServer" Version="6.3.6" />
<PackageReference Include="Serilog.AspNetCore" Version="8.0.0" />
<PackageReference Include="Serilog.Sinks.Console" Version="5.0.1" />
<PackageReference Include="Serilog.Sinks.RollingFile" Version="3.3.0" />
</ItemGroup>

Expand Down
17 changes: 8 additions & 9 deletions test/Duende.IdentityServer.Server/Models/ApiResources.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
using Duende.IdentityServer.Models;

namespace Duende.IdentityServer.Server.Models
namespace Duende.IdentityServer.Server.Models;

public static class ApiResources
{
public static class ApiResources
{
public static IEnumerable<ApiResource> GetApiResources
=> new List<ApiResource>
{
new("api1", "api1")
};
}
public static IEnumerable<ApiResource> GetApiResources
=> new List<ApiResource>
{
new("api1", "api1")
};
}
57 changes: 28 additions & 29 deletions test/Duende.IdentityServer.Server/Models/Clients.cs
Original file line number Diff line number Diff line change
@@ -1,36 +1,35 @@
using Duende.IdentityServer.Models;

namespace Duende.IdentityServer.Server.Models
namespace Duende.IdentityServer.Server.Models;

public static class Clients
{
public static class Clients
{
public const string Id = "sampleclient";
public const string Secret = "samplesecret";
public const string Id = "sampleclient";
public const string Secret = "samplesecret";

public static IEnumerable<Client> GetClients
=> new List<Client>
public static IEnumerable<Client> GetClients
=> new List<Client>
{
new()
{
new()
ClientId = Id,
ClientSecrets = new List<Secret>
{
new(Secret.Sha256())
},
AllowedScopes = new List<string>
{
"api1", IdentityServerConstants.StandardScopes.OpenId,
IdentityServerConstants.StandardScopes.Profile
},
AllowedGrantTypes = new List<string>
{
ClientId = Id,
ClientSecrets = new List<Secret>
{
new(Secret.Sha256())
},
AllowedScopes = new List<string>
{
"api1", IdentityServerConstants.StandardScopes.OpenId,
IdentityServerConstants.StandardScopes.Profile
},
AllowedGrantTypes = new List<string>
{
GrantType.ResourceOwnerPassword
},
AllowOfflineAccess = true,
AccessTokenLifetime = 60 * 60,
RefreshTokenUsage = TokenUsage.OneTimeOnly,
RefreshTokenExpiration = TokenExpiration.Absolute
}
};
}
GrantType.ResourceOwnerPassword
},
AllowOfflineAccess = true,
AccessTokenLifetime = 60 * 60,
RefreshTokenUsage = TokenUsage.OneTimeOnly,
RefreshTokenExpiration = TokenExpiration.Absolute
}
};
}
19 changes: 9 additions & 10 deletions test/Duende.IdentityServer.Server/Models/IdentityResources.cs
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
using Duende.IdentityServer.Models;

namespace Duende.IdentityServer.Server.Models
namespace Duende.IdentityServer.Server.Models;

public static class ApiIdentityResources
{
public static class ApiIdentityResources
{
public static IEnumerable<IdentityResource> GetIdentityResources
=> new List<IdentityResource>
{
new IdentityResources.OpenId(),
new IdentityResources.Profile()
};
}
public static IEnumerable<IdentityResource> GetIdentityResources
=> new List<IdentityResource>
{
new IdentityResources.OpenId(),
new IdentityResources.Profile()
};
}
Loading

0 comments on commit e5e8d7d

Please sign in to comment.