Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Consent and logo #26

Merged
merged 30 commits into from
Apr 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
8b3af50
Package updates
JosephEShook Apr 5, 2024
0e14e28
Reworked the Postgresql to be snake case and deploy to a specific uda…
JosephEShook Apr 5, 2024
a9b9a57
Misc
JosephEShook Apr 6, 2024
2810d79
Fix-up missing AlwaysIncludeUserClaimsInIdToken
JosephEShook Apr 6, 2024
94c1add
Prove Idp2 can use ServerSettings from appsettings and pass hl7_ident…
JosephEShook Apr 6, 2024
797886a
CSP (content security policy) trusts only UDAP registered logs in int…
JosephEShook Apr 7, 2024
ffacf5f
Bump Udap.Client and Udap.Common
dependabot[bot] Apr 8, 2024
754f57f
Bump Microsoft.IdentityModel.JsonWebTokens from 7.5.0 to 7.5.1
dependabot[bot] Apr 8, 2024
fba08f9
Fixup image ref
JosephEShook Apr 8, 2024
c025f6c
Changing Identities for test users.
JosephEShook Apr 8, 2024
9194b0d
Ensure Logo is written if it is supplied and valid even it it is not …
JosephEShook Apr 8, 2024
e631696
Merge pull request #463 from JoeShook/dependabot/nuget/develop/multi-…
JoeShook Apr 8, 2024
e21e532
Merge pull request #465 from JoeShook/dependabot/nuget/develop/Micros…
JoeShook Apr 8, 2024
35f6239
RequireConsent defaults to true.
JosephEShook Apr 8, 2024
f08ba55
Merge branch 'develop' of https://github.com/JoeShook/udap-dotnet int…
JosephEShook Apr 8, 2024
2aa1b4c
RequireConsent is defaulted to true
JosephEShook Apr 8, 2024
56f3805
Package updates
JosephEShook Apr 8, 2024
c6b27e3
update logo when client updates registration.
JosephEShook Apr 9, 2024
7ccaf50
Bump Udap.Client and Udap.Common
dependabot[bot] Apr 10, 2024
40093b9
Bump dotnet-ef from 8.0.3 to 8.0.4
dependabot[bot] Apr 10, 2024
cb5ce27
Merge pull request #472 from JoeShook/dependabot/nuget/develop/multi-…
JoeShook Apr 10, 2024
7bd97e3
Bump Microsoft.AspNetCore.Mvc.Testing and Microsoft.Extensions.Config…
dependabot[bot] Apr 10, 2024
d0efe79
Bump System.CommandLine from 2.0.0-beta4.24201.1 to 2.0.0-beta4.24209.3
dependabot[bot] Apr 10, 2024
ac50df4
Package updates. Tricky when updating IdenityModel. Notice the Dire…
JosephEShook Apr 10, 2024
71706cb
Merge pull request #469 from JoeShook/dependabot/nuget/develop/System…
JoeShook Apr 10, 2024
7f083e1
Revisit package updates. Ensure only using the newest IdentityModel …
JosephEShook Apr 10, 2024
964c14a
Merge branch 'develop' of https://github.com/JoeShook/udap-dotnet int…
JosephEShook Apr 10, 2024
7b53367
Merge pull request #473 from JoeShook/dependabot/nuget/develop/dotnet…
JoeShook Apr 10, 2024
b370b8d
Merge pull request #475 from JoeShook/dependabot/nuget/develop/multi-…
JoeShook Apr 10, 2024
f688fd4
Merge pull request #477 from JoeShook/develop
JoeShook Apr 11, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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": "8.0.2",
"version": "8.0.4",
"commands": [
"dotnet-ef"
]
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -223,3 +223,4 @@ examples/clients/UdapEd/Client/wwwroot/temp/MudBlazor.min.js
examples/clients/UdapEd/Client/wwwroot/temp/MudBlazor.min.css
.tye/docker_store
/examples/Udap.Proxy.Server/CertStore/issued/fhirLabsApiClientLocalhostCert.pfx
/examples/Udap.Proxy.Server/CertStore/issued/gfhirlabs.healthcare.client.pfx
22 changes: 11 additions & 11 deletions Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,22 @@
<PackageVersion Include="Hl7.Fhir.Specification.R4B" Version="5.3.0" />
<PackageVersion Include="Microsoft.AspNetCore.Authentication.OpenIdConnect" Version="8.0.2" />
<PackageVersion Include="Microsoft.AspNetCore.DataProtection.Abstractions" Version="8.0.2" />
<PackageVersion Include="Microsoft.AspNetCore.DataProtection.EntityFrameworkCore" Version="8.0.3" />
<PackageVersion Include="Microsoft.AspNetCore.DataProtection.EntityFrameworkCore" Version="8.0.4" />
<PackageVersion Include="Microsoft.Extensions.Hosting.Abstractions" Version="8.0.0" />
<PackageVersion Include="Microsoft.Extensions.Logging.Abstractions" Version="8.0.1" />
<PackageVersion Include="Microsoft.IdentityModel.Protocols.OpenIdConnect" Version="7.4.1" />
<PackageVersion Include="Microsoft.IdentityModel.Protocols.OpenIdConnect" Version="7.5.1" />
<PackageVersion Include="Microsoft.IdentityModel.Tokens" Version="7.5.1" />
<PackageVersion Include="MSTest.TestAdapter" Version="3.1.1" />
<PackageVersion Include="MSTest.TestFramework" Version="3.1.1" />
<PackageVersion Include="IdentityModel" Version="6.2.0" />
<PackageVersion Include="System.Text.Json" Version="[6.0.7,7.0.3]" />
<PackageVersion Include="IdentityModel" Version="7.0.0" />
<!-- <PackageVersion Include="System.Text.Json" Version="[6.0.7,8.0.3]" /> -->
<PackageVersion Include="AutoMapper" Version="13.0.1" />
<PackageVersion Include="Duende.IdentityServer" Version="7.0.3" />
<PackageVersion Include="Duende.IdentityServer.AspNetIdentity" Version="7.0.3" />
<PackageVersion Include="Duende.IdentityServer.EntityFramework.Storage" Version="7.0.3" />
<PackageVersion Include="Duende.IdentityServer" Version="7.0.4" />
<PackageVersion Include="Duende.IdentityServer.AspNetIdentity" Version="7.0.4" />
<PackageVersion Include="Duende.IdentityServer.EntityFramework.Storage" Version="7.0.4" />
<PackageVersion Include="IdentityModel.AspNetCore.OAuth2Introspection" Version="6.2.0" />
<PackageVersion Include="Microsoft.AspNetCore.Mvc" Version="2.2.0" />
<PackageVersion Include="Microsoft.EntityFrameworkCore" Version="8.0.3" />
<PackageVersion Include="Microsoft.EntityFrameworkCore" Version="8.0.4" />
<PackageVersion Include="Microsoft.EntityFrameworkCore.Design" Version="[7.0.13,8.0.1]" />
<PackageVersion Include="Microsoft.EntityFrameworkCore.SqlServer" Version="[7.0.13,8.0.0]" />
<PackageVersion Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.19.6" />
Expand All @@ -36,8 +37,7 @@
<PackageVersion Include="Microsoft.Extensions.Configuration.Abstractions" Version="[6.0.0,7.0.1]" />
<PackageVersion Include="Microsoft.Extensions.Options" Version="8.0.2" />
<PackageVersion Include="Microsoft.Extensions.Options.ConfigurationExtensions" Version="8.0.0" />
<PackageVersion Include="Microsoft.IdentityModel.JsonWebTokens" Version="7.5.0" />
<PackageVersion Include="Microsoft.IdentityModel.Tokens" Version="[6.10.0,6.30.0]" />
<PackageVersion Include="Microsoft.IdentityModel.JsonWebTokens" Version="7.5.1" />
<PackageVersion Include="OpenTelemetry" Version="1.7.0" />
<PackageVersion Include="OpenTelemetry.Exporter.Console" Version="1.7.0" />
<PackageVersion Include="OpenTelemetry.Exporter.OpenTelemetryProtocol" Version="1.7.0" />
Expand All @@ -48,7 +48,7 @@
<PackageVersion Include="Serilog.AspNetCore" Version="[6.1.0,7.0.0]" />
<PackageVersion Include="Serilog.Extensions.Logging" Version="[3.1.0,7.0.0]" />
<PackageVersion Include="Portable.BouncyCastle" Version="1.9.0" />
<PackageVersion Include="System.IdentityModel.Tokens.Jwt" Version="7.5.0" />
<PackageVersion Include="System.IdentityModel.Tokens.Jwt" Version="7.5.1" />
<PackageVersion Include="Udap.Metadata.Server" Version="0.3.24" />
<PackageVersion Include="Yarp.ReverseProxy" Version="2.1.0" />
</ItemGroup>
Expand Down
17 changes: 10 additions & 7 deletions Udap.Client/Client/Messages/UdapDiscoveryDocumentResponse.cs
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,10 @@ protected override Task InitializeAsync(object? initializationData = null)
public string? RegistrationEndpoint => TryGetString(UdapConstants.Discovery.RegistrationEndpoint);

// generic
public JsonElement TryGetValue(string name) => Json.TryGetValue(name);
public string? TryGetString(string name) => Json.TryGetString(name);
public bool? TryGetBoolean(string name) => Json.TryGetBoolean(name);
public IEnumerable<string> TryGetStringArray(string name) => Json.TryGetStringArray(name);
public JsonElement? TryGetValue(string name) => Json?.TryGetValue(name);
public string? TryGetString(string name) => Json?.TryGetString(name);
public bool? TryGetBoolean(string name) => Json?.TryGetBoolean(name);
public IEnumerable<string>? TryGetStringArray(string name) => Json?.TryGetStringArray(name);

private string Validate(DiscoveryPolicy policy)
{
Expand All @@ -97,10 +97,13 @@ private string Validate(DiscoveryPolicy policy)
}
}

var error = ValidateEndpoints(Json, policy);
if (error.IsPresent())
if (Json.HasValue)
{
return error;
var error = ValidateEndpoints(Json.Value, policy);
if (error.IsPresent())
{
return error;
}
}

return string.Empty;
Expand Down
2 changes: 1 addition & 1 deletion Udap.Client/Client/UdapClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,7 @@ private async Task<UdapDiscoveryDocumentResponse> InternalValidateResource(

if (disco.HttpStatusCode == HttpStatusCode.OK && !disco.IsError)
{
UdapServerMetaData = disco.Json.Deserialize<UdapMetadata>();
UdapServerMetaData = disco.Json?.Deserialize<UdapMetadata>();
_logger.LogDebug(UdapServerMetaData?.SerializeToJson());

if (!await _clientDiscoveryValidator.ValidateJwtToken(UdapServerMetaData!, baseUrl))
Expand Down
2 changes: 1 addition & 1 deletion Udap.Client/Client/UdapClientMessageHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ protected override async Task<HttpResponseMessage> SendAsync(HttpRequestMessage

if (disco.HttpStatusCode == HttpStatusCode.OK && !disco.IsError)
{
_clientDiscoveryValidator.UdapServerMetaData = disco.Json.Deserialize<UdapMetadata>();
_clientDiscoveryValidator.UdapServerMetaData = disco.Json?.Deserialize<UdapMetadata>();
_logger.LogDebug(_clientDiscoveryValidator.UdapServerMetaData?.SerializeToJson());

if (!await _clientDiscoveryValidator.ValidateJwtToken(_clientDiscoveryValidator.UdapServerMetaData!, baseUrl!))
Expand Down
12 changes: 3 additions & 9 deletions Udap.Client/Udap.Client.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
<PackageIcon>UDAP_Ecosystem_Gears 48X48.jpg</PackageIcon>
<PackageTags>UDAP;FHIR;HL7</PackageTags>
<Description>Package is a part of the UDAP reference implementation for .NET.</Description>

</PropertyGroup>


Expand All @@ -25,19 +26,12 @@
</ItemGroup>



<ItemGroup Condition="'$(TargetFramework)' == 'net6.0'">
<PackageReference Include="IdentityModel" />
<PackageReference Include="Microsoft.IdentityModel.JsonWebTokens" />
</ItemGroup>

<ItemGroup Condition="'$(TargetFramework)' == 'net7.0'">
<ItemGroup >
<PackageReference Include="IdentityModel" />
<PackageReference Include="Microsoft.IdentityModel.JsonWebTokens" />
</ItemGroup>


<!-- <ItemGroup> -->
<!-- <ItemGroup> -->
<!-- <FrameworkReference Include="Microsoft.AspNetCore.App" /> -->
<!-- </ItemGroup> -->

Expand Down
2 changes: 2 additions & 0 deletions Udap.Server/Configuration/ServerSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ public class ServerSettings


public bool AlwaysIncludeUserClaimsInIdToken { get; set; }

public bool RequireConsent { get; set; } = true;
}


Expand Down
125 changes: 125 additions & 0 deletions Udap.Server/DbContexts/UdapDbContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,13 @@
// */
#endregion

using Duende.IdentityServer.EntityFramework.DbContexts;
using Duende.IdentityServer.EntityFramework.Entities;
using Microsoft.AspNetCore.DataProtection.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using System.Reflection.Emit;
using Duende.IdentityServer.EntityFramework.Extensions;
using Udap.Server.Entities;
using Udap.Server.Extensions;
using Udap.Server.Options;
Expand Down Expand Up @@ -136,7 +139,129 @@ protected override void OnModelCreating(ModelBuilder modelBuilder)
modelBuilder.Entity<ClientScope>().ToTable("ClientScopes");
}


base.OnModelCreating(modelBuilder);

if (Database.ProviderName == "Npgsql.EntityFrameworkCore.PostgreSQL")
{
modelBuilder.HasDefaultSchema("udap");

foreach (var entity in modelBuilder.Model.GetEntityTypes())
{
// Replace table names
entity.SetTableName(entity.GetTableName()?.ToSnakeCase());

// Replace column names
foreach (var property in entity.GetProperties())
{
property.SetColumnName(property.GetColumnName().ToSnakeCase());
}

foreach (var key in entity.GetKeys())
{
key.SetName(key.GetName()?.ToSnakeCase());
}

foreach (var key in entity.GetForeignKeys())
{
key.SetConstraintName(key.GetConstraintName()?.ToSnakeCase());
}

foreach (var index in entity.GetIndexes())
{
index.SetDatabaseName(index.GetDatabaseName()?.ToSnakeCase());
}
}
}
}

}

/// <summary>
/// Override naming conventions of the base ConfigurationDbContext during OnModelCreating
/// </summary>
public class NpgsqlConfigurationDbContext : ConfigurationDbContext<NpgsqlConfigurationDbContext>
{
public NpgsqlConfigurationDbContext(DbContextOptions<NpgsqlConfigurationDbContext> options) : base(options)
{
}

protected override void OnModelCreating(ModelBuilder modelBuilder)
{
base.OnModelCreating(modelBuilder);

modelBuilder.HasDefaultSchema("udap");

foreach (var entity in modelBuilder.Model.GetEntityTypes())
{
// Replace table names
entity.SetTableName(entity.GetTableName()?.ToSnakeCase());

// Replace column names
foreach (var property in entity.GetProperties())
{
property.SetColumnName(property.GetColumnName().ToSnakeCase());
}

foreach (var key in entity.GetKeys())
{
key.SetName(key.GetName()?.ToSnakeCase());
}

foreach (var key in entity.GetForeignKeys())
{
key.SetConstraintName(key.GetConstraintName()?.ToSnakeCase());
}

foreach (var index in entity.GetIndexes())
{
index.SetDatabaseName(index.GetDatabaseName()?.ToSnakeCase());
}
}
}
}


/// <summary>
/// Override naming conventions of the base PersistedGrantDbContext during OnModelCreating
/// </summary>
public class NpgsqlPersistedGrantDbContext : PersistedGrantDbContext<NpgsqlPersistedGrantDbContext>
{
public NpgsqlPersistedGrantDbContext(DbContextOptions<NpgsqlPersistedGrantDbContext> options) : base(options)
{
}

protected override void OnModelCreating(ModelBuilder modelBuilder)
{
base.OnModelCreating(modelBuilder);

modelBuilder.HasDefaultSchema("udap");

foreach (var entity in modelBuilder.Model.GetEntityTypes())
{
// Replace table names
entity.SetTableName(entity.GetTableName()?.ToSnakeCase());

// Replace column names
foreach (var property in entity.GetProperties())
{
property.SetColumnName(property.GetColumnName().ToSnakeCase());
}

foreach (var key in entity.GetKeys())
{
key.SetName(key.GetName()?.ToSnakeCase());
}

foreach (var key in entity.GetForeignKeys())
{
key.SetConstraintName(key.GetConstraintName()?.ToSnakeCase());
}

foreach (var index in entity.GetIndexes())
{
index.SetDatabaseName(index.GetDatabaseName()?.ToSnakeCase());
}
}
}
}
11 changes: 11 additions & 0 deletions Udap.Server/Extensions/StringExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#endregion

using System.Diagnostics;
using System.Text.RegularExpressions;

namespace Udap.Server.Extensions;

Expand Down Expand Up @@ -46,4 +47,14 @@ internal static class StringExtensions
// {
// return string.IsNullOrWhiteSpace(value);
// }


public static string ToSnakeCase(this string input)
{
if (string.IsNullOrEmpty(input)) { return input; }

var startUnderscores = Regex.Match(input, @"^_+");
return startUnderscores + Regex.Replace(input, @"([a-z0-9])([A-Z])", "$1_$2").ToLower();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,8 @@ IEnumerable<Anchor> anchors
{
//TODO: Maybe inject a component to generate the clientID so a user can use their own technique.
ClientId = CryptoRandom.CreateUniqueId(),
AlwaysIncludeUserClaimsInIdToken = _serverSettings.AlwaysIncludeUserClaimsInIdToken
AlwaysIncludeUserClaimsInIdToken = _serverSettings.AlwaysIncludeUserClaimsInIdToken,
RequireConsent = _serverSettings.RequireConsent
};

_logger.LogDebug($"Validating chain for ClientId: {client.ClientId}. x5c {jwtHeader.X5c}");
Expand Down Expand Up @@ -380,14 +381,18 @@ IEnumerable<Anchor> anchors
//
if (client.AllowedGrantTypes.Contains(OidcConstants.GrantTypes.AuthorizationCode))
{
var (successFlag, errorResult) = await ValidateLogoUri(document);

if (_serverSettings.LogoRequired)
{
var (successFlag, errorResult) = await ValidateLogoUri(document);
if (!successFlag)
{
return errorResult!;
}
}

if (successFlag)
{
client.LogoUri = document.LogoUri;
}

Expand Down
2 changes: 2 additions & 0 deletions Udap.Server/Stores/UdapClientRegistrationStore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@ public async Task<bool> UpsertClient(Duende.IdentityServer.Models.Client client,
existingClient.AllowedGrantTypes = client.ToEntity().AllowedGrantTypes;
existingClient.AllowOfflineAccess = client.AllowOfflineAccess;
existingClient.RequirePkce = client.RequirePkce;
existingClient.LogoUri = client.LogoUri;

await _dbContext.SaveChangesAsync(token);
_logger.LogInformation("Updated client: {Id}", existingClient.Id);
return true;
Expand Down
Loading
Loading