Skip to content

Commit

Permalink
Merge pull request #49 from DuendeSoftware/brock/7.0-update
Browse files Browse the repository at this point in the history
updates for .NET 8 and IdentityServer 7.0
  • Loading branch information
brockallen authored Jan 25, 2024
2 parents 1ea8f9b + 8e1ad09 commit 30c4f1c
Show file tree
Hide file tree
Showing 184 changed files with 2,798 additions and 1,157 deletions.
10 changes: 6 additions & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,14 @@ jobs:
name: ${{ matrix.runs-on }}
runs-on: ${{ matrix.runs-on }}
steps:
- uses: actions/[email protected]
- uses: actions/checkout@v3
with:
fetch-depth: 0

- name: Setup dotnet
uses: actions/setup-dotnet@v1
- name: Setup dotnet (main)
uses: actions/setup-dotnet@v4
with:
dotnet-version: '6.0.x'
dotnet-version: '8.0.x'

- run: dotnet --info

Expand Down
11 changes: 6 additions & 5 deletions .github/workflows/codeql-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,20 +35,21 @@ jobs:

steps:
- name: Checkout repository
uses: actions/checkout@v2.4.0
uses: actions/checkout@v3

- name: Setup dotnet
uses: actions/setup-dotnet@v1
uses: actions/setup-dotnet@v4
with:
dotnet-version: '6.0.x'
dotnet-version: '8.0.x'

- run: dotnet --info

# Initializes the CodeQL tools for scanning.
- name: Initialize CodeQL
uses: github/codeql-action/init@v1
uses: github/codeql-action/init@v3
with:
languages: ${{ matrix.language }}
tools: latest
# 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.
Expand All @@ -57,4 +58,4 @@ jobs:
- run: dotnet run --project build -- build

- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v1
uses: github/codeql-action/analyze@v3
2 changes: 1 addition & 1 deletion build/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ namespace build
{
internal static class Program
{
private const string NugetPackageVersion = "6.3.1";
private const string NugetPackageVersion = "7.0.0";

private const string packOutput = "./artifacts";
private const string envVarMissing = " environment variable is missing. Aborting.";
Expand Down
2 changes: 1 addition & 1 deletion build/build.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net6.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
</PropertyGroup>

<ItemGroup>
Expand Down
2 changes: 1 addition & 1 deletion global.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"sdk": {
"version": "6.0.100",
"version": "8.0.100",
"rollForward": "latestMajor",
"allowPrerelease": false
}
Expand Down
8 changes: 4 additions & 4 deletions src/BffLocalApi/BffLocalApi.csproj
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Duende.BFF.Yarp" Version="2.1.0" />
<PackageReference Include="Serilog.AspNetCore" Version="6.0.0" />
<PackageReference Include="Duende.BFF.Yarp" Version="2.2.0" />
<PackageReference Include="Serilog.AspNetCore" Version="8.0.0" />

<PackageReference Include="Microsoft.AspNetCore.Authentication.OpenIdConnect" Version="6.0.0" />
<PackageReference Include="Microsoft.AspNetCore.Authentication.OpenIdConnect" Version="8.0.0" />
</ItemGroup>

</Project>
4 changes: 2 additions & 2 deletions src/BffRemoteApi/BffRemoteApi.csproj
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Duende.BFF.Yarp" Version="2.1.0" />
<PackageReference Include="Duende.BFF.Yarp" Version="2.2.0" />
</ItemGroup>


Expand Down

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

Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@

namespace IdentityServerAspNetIdentity.Data.Migrations
{
/// <inheritdoc />
public partial class Users : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.CreateTable(
Expand Down Expand Up @@ -192,6 +194,7 @@ protected override void Up(MigrationBuilder migrationBuilder)
unique: true);
}

/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ partial class ApplicationDbContextModelSnapshot : ModelSnapshot
protected override void BuildModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder.HasAnnotation("ProductVersion", "6.0.0");
modelBuilder.HasAnnotation("ProductVersion", "8.0.0");

modelBuilder.Entity("IdentityServerHost.Models.ApplicationUser", b =>
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,21 @@
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Duende.IdentityServer.AspNetIdentity" Version="6.3.2" />
<PackageReference Include="Duende.IdentityServer.AspNetIdentity" Version="7.0.0" />

<PackageReference Include="Microsoft.AspNetCore.Authentication.Google" Version="6.0.0" />
<PackageReference Include="Serilog.AspNetCore" Version="6.0.0" />
<PackageReference Include="Microsoft.AspNetCore.Authentication.Google" Version="8.0.0" />
<PackageReference Include="Serilog.AspNetCore" Version="8.0.0" />

<PackageReference Include="Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore" Version="6.0.0" />
<PackageReference Include="Microsoft.AspNetCore.Identity.EntityFrameworkCore" Version="6.0.0" />
<PackageReference Include="Microsoft.AspNetCore.Identity.UI" Version="6.0.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="6.0.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="6.0.0" />
<PackageReference Include="Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore" Version="8.0.0" />
<PackageReference Include="Microsoft.AspNetCore.Identity.EntityFrameworkCore" Version="8.0.0" />
<PackageReference Include="Microsoft.AspNetCore.Identity.UI" Version="8.0.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="8.0.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="8.0.0" />
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// Copyright (c) Duende Software. All rights reserved.
// See LICENSE in the project root for license information.

using Microsoft.AspNetCore.Mvc.RazorPages;

namespace IdentityServerHost.Pages.Account;
Expand All @@ -7,4 +10,4 @@ public class AccessDeniedModel : PageModel
public void OnGet()
{
}
}
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
// Copyright (c) Duende Software. All rights reserved.
// See LICENSE in the project root for license information.

using Duende.IdentityServer;
using Duende.IdentityServer.Events;
using Duende.IdentityServer.Models;
using Duende.IdentityServer.Services;
Expand All @@ -22,10 +26,10 @@ public class Index : PageModel
private readonly IAuthenticationSchemeProvider _schemeProvider;
private readonly IIdentityProviderStore _identityProviderStore;

public ViewModel View { get; set; }
public ViewModel View { get; set; } = default!;

[BindProperty]
public InputModel Input { get; set; }
public InputModel Input { get; set; } = default!;

public Index(
IIdentityServerInteractionService interaction,
Expand All @@ -42,8 +46,8 @@ public Index(
_identityProviderStore = identityProviderStore;
_events = events;
}
public async Task<IActionResult> OnGet(string returnUrl)

public async Task<IActionResult> OnGet(string? returnUrl)
{
await BuildModelAsync(returnUrl);

Expand All @@ -66,6 +70,9 @@ public async Task<IActionResult> OnPost()
{
if (context != null)
{
// This "can't happen", because if the ReturnUrl was null, then the context would be null
ArgumentNullException.ThrowIfNull(Input.ReturnUrl, nameof(Input.ReturnUrl));

// if the user cancels, send a result back into IdentityServer as if they
// denied the consent (even if this client does not require consent).
// this will send back an access denied OIDC error response to the client.
Expand All @@ -79,7 +86,7 @@ public async Task<IActionResult> OnPost()
return this.LoadingPage(Input.ReturnUrl);
}

return Redirect(Input.ReturnUrl);
return Redirect(Input.ReturnUrl ?? "~/");
}
else
{
Expand All @@ -90,14 +97,18 @@ public async Task<IActionResult> OnPost()

if (ModelState.IsValid)
{
var result = await _signInManager.PasswordSignInAsync(Input.Username, Input.Password, Input.RememberLogin, lockoutOnFailure: true);
var result = await _signInManager.PasswordSignInAsync(Input.Username!, Input.Password!, Input.RememberLogin, lockoutOnFailure: true);
if (result.Succeeded)
{
var user = await _userManager.FindByNameAsync(Input.Username);
await _events.RaiseAsync(new UserLoginSuccessEvent(user.UserName, user.Id, user.UserName, clientId: context?.Client.ClientId));
var user = await _userManager.FindByNameAsync(Input.Username!);
await _events.RaiseAsync(new UserLoginSuccessEvent(user!.UserName, user.Id, user.UserName, clientId: context?.Client.ClientId));
Telemetry.Metrics.UserLogin(context?.Client.ClientId, IdentityServerConstants.LocalIdentityProvider);

if (context != null)
{
// This "can't happen", because if the ReturnUrl was null, then the context would be null
ArgumentNullException.ThrowIfNull(Input.ReturnUrl, nameof(Input.ReturnUrl));

if (context.IsNativeClient())
{
// The client is native, so this change in how to
Expand All @@ -106,7 +117,7 @@ public async Task<IActionResult> OnPost()
}

// we can trust model.ReturnUrl since GetAuthorizationContextAsync returned non-null
return Redirect(Input.ReturnUrl);
return Redirect(Input.ReturnUrl ?? "~/");
}

// request for a local page
Expand All @@ -121,20 +132,22 @@ public async Task<IActionResult> OnPost()
else
{
// user might have clicked on a malicious link - should be logged
throw new Exception("invalid return URL");
throw new ArgumentException("invalid return URL");
}
}

await _events.RaiseAsync(new UserLoginFailureEvent(Input.Username, "invalid credentials", clientId:context?.Client.ClientId));
const string error = "invalid credentials";
await _events.RaiseAsync(new UserLoginFailureEvent(Input.Username, error, clientId:context?.Client.ClientId));
Telemetry.Metrics.UserLoginFailure(context?.Client.ClientId, IdentityServerConstants.LocalIdentityProvider, error);
ModelState.AddModelError(string.Empty, LoginOptions.InvalidCredentialsErrorMessage);
}

// something went wrong, show form with error
await BuildModelAsync(Input.ReturnUrl);
return Page();
}
private async Task BuildModelAsync(string returnUrl)

private async Task BuildModelAsync(string? returnUrl)
{
Input = new InputModel
{
Expand All @@ -152,11 +165,11 @@ private async Task BuildModelAsync(string returnUrl)
EnableLocalLogin = local,
};

Input.Username = context?.LoginHint;
Input.Username = context.LoginHint;

if (!local)
{
View.ExternalProviders = new[] { new ViewModel.ExternalProvider { AuthenticationScheme = context.IdP } };
View.ExternalProviders = new[] { new ViewModel.ExternalProvider ( authenticationScheme: context.IdP ) };
}

return;
Expand All @@ -167,27 +180,27 @@ private async Task BuildModelAsync(string returnUrl)
var providers = schemes
.Where(x => x.DisplayName != null)
.Select(x => new ViewModel.ExternalProvider
{
DisplayName = x.DisplayName ?? x.Name,
AuthenticationScheme = x.Name
}).ToList();
(
authenticationScheme: x.Name,
displayName: x.DisplayName ?? x.Name
)).ToList();

var dyanmicSchemes = (await _identityProviderStore.GetAllSchemeNamesAsync())
var dynamicSchemes = (await _identityProviderStore.GetAllSchemeNamesAsync())
.Where(x => x.Enabled)
.Select(x => new ViewModel.ExternalProvider
{
AuthenticationScheme = x.Scheme,
DisplayName = x.DisplayName
});
providers.AddRange(dyanmicSchemes);
(
authenticationScheme: x.Scheme,
displayName: x.DisplayName ?? x.Scheme
));
providers.AddRange(dynamicSchemes);


var allowLocal = true;
var client = context?.Client;
if (client != null)
{
allowLocal = client.EnableLocalLogin;
if (client.IdentityProviderRestrictions != null && client.IdentityProviderRestrictions.Any())
if (client.IdentityProviderRestrictions != null && client.IdentityProviderRestrictions.Count != 0)
{
providers = providers.Where(provider => client.IdentityProviderRestrictions.Contains(provider.AuthenticationScheme)).ToList();
}
Expand All @@ -200,4 +213,4 @@ private async Task BuildModelAsync(string returnUrl)
ExternalProviders = providers.ToArray()
};
}
}
}
Loading

0 comments on commit 30c4f1c

Please sign in to comment.