From dbcf82814d85ed4bd1ec099468cc464233e0541e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20K=C3=BCtbach?= Date: Mon, 16 Sep 2024 11:07:48 +0200 Subject: [PATCH 1/8] Upgrade .NET 8 https://github.com/d-velop/dvelop-sdk-cs/issues/36 --- dvelop-sdk-all/DvelopSdk.csproj | 5 ++-- dvelop-sdk-base/BaseDtos/BaseDtos.csproj | 3 ++- .../BaseInterfaces/BaseInterfaces.csproj | 3 ++- .../CloudCenterDtos/CloudCenterDtos.csproj | 1 + .../ConfigDtos/ConfigDtos.csproj | 3 ++- .../DashboardDtos/DashboardDtos.csproj | 3 ++- dvelop-sdk-home/HomeDtos/HomeDtos.csproj | 23 +++++++++-------- .../HttpClientExtensions.csproj | 25 ++++++++++--------- .../IdentityProviderClient.csproj | 3 ++- ...IdentityProviderMiddleware.UnitTest.csproj | 1 + .../IdentityProviderMiddleware.csproj | 3 ++- .../Logging.Abstractions.csproj | 4 +-- .../Logging.OtelJsonConsole.csproj | 4 +-- .../SigningAlgorithms.UnitTest.csproj | 1 + .../SigningAlgorithms.csproj | 6 ++--- .../TenantMiddleware.UnitTest.csproj | 1 + .../TenantMiddleware/TenantMiddleware.csproj | 2 +- .../WebApiExtensions.UnitTest.csproj | 2 ++ .../WebApiExtensions/WebApiExtensions.csproj | 4 +-- 19 files changed, 56 insertions(+), 41 deletions(-) diff --git a/dvelop-sdk-all/DvelopSdk.csproj b/dvelop-sdk-all/DvelopSdk.csproj index eb6a721..c4db996 100644 --- a/dvelop-sdk-all/DvelopSdk.csproj +++ b/dvelop-sdk-all/DvelopSdk.csproj @@ -3,7 +3,7 @@ Dvelop.Sdk - netstandard2.0 + net8.0 Dvelop.Sdk Dvelop.Sdk Copyright (c) 2019 @@ -12,7 +12,7 @@ true false false - + https://github.com/d-velop/dvelop-sdk-cs https://github.com/d-velop/dvelop-sdk-cs @@ -21,6 +21,7 @@ true true snupkg + latestmajor diff --git a/dvelop-sdk-base/BaseDtos/BaseDtos.csproj b/dvelop-sdk-base/BaseDtos/BaseDtos.csproj index a30bb9f..8b647c2 100644 --- a/dvelop-sdk-base/BaseDtos/BaseDtos.csproj +++ b/dvelop-sdk-base/BaseDtos/BaseDtos.csproj @@ -1,12 +1,13 @@  - netstandard2.0 + net8.0 Dvelop.Sdk.Base.Dto Dvelop.Sdk.Base.Dto true true snupkg + latestmajor diff --git a/dvelop-sdk-base/BaseInterfaces/BaseInterfaces.csproj b/dvelop-sdk-base/BaseInterfaces/BaseInterfaces.csproj index 2d8aa2f..8ddeb74 100644 --- a/dvelop-sdk-base/BaseInterfaces/BaseInterfaces.csproj +++ b/dvelop-sdk-base/BaseInterfaces/BaseInterfaces.csproj @@ -1,9 +1,10 @@ - netstandard2.0 + net8.0 Dvelop.Sdk.BaseInterfaces Dvelop.Sdk.BaseInterfaces + latestmajor diff --git a/dvelop-sdk-cloudcenter/CloudCenterDtos/CloudCenterDtos.csproj b/dvelop-sdk-cloudcenter/CloudCenterDtos/CloudCenterDtos.csproj index 3cb7693..eb743f1 100644 --- a/dvelop-sdk-cloudcenter/CloudCenterDtos/CloudCenterDtos.csproj +++ b/dvelop-sdk-cloudcenter/CloudCenterDtos/CloudCenterDtos.csproj @@ -8,6 +8,7 @@ true true snupkg + latestmajor diff --git a/dvelop-sdk-config/ConfigDtos/ConfigDtos.csproj b/dvelop-sdk-config/ConfigDtos/ConfigDtos.csproj index 71ae132..72f8e8e 100644 --- a/dvelop-sdk-config/ConfigDtos/ConfigDtos.csproj +++ b/dvelop-sdk-config/ConfigDtos/ConfigDtos.csproj @@ -1,12 +1,13 @@  - netstandard2.0 + net8.0 Dvelop.Sdk.Config.Dto Dvelop.Sdk.Config.Dto true true snupkg + latestmajor diff --git a/dvelop-sdk-dash/DashboardDtos/DashboardDtos.csproj b/dvelop-sdk-dash/DashboardDtos/DashboardDtos.csproj index 3ce032a..9a86d5d 100644 --- a/dvelop-sdk-dash/DashboardDtos/DashboardDtos.csproj +++ b/dvelop-sdk-dash/DashboardDtos/DashboardDtos.csproj @@ -1,12 +1,13 @@  - netstandard2.0 + net8.0 Dvelop.Sdk.Dashboard.Dto Dvelop.Sdk.Dashboard.Dto true true snupkg + diff --git a/dvelop-sdk-home/HomeDtos/HomeDtos.csproj b/dvelop-sdk-home/HomeDtos/HomeDtos.csproj index 1964a97..2a7f13c 100644 --- a/dvelop-sdk-home/HomeDtos/HomeDtos.csproj +++ b/dvelop-sdk-home/HomeDtos/HomeDtos.csproj @@ -1,17 +1,18 @@  - - netstandard2.0 - Dvelop.Sdk.Home.Dto - Dvelop.Sdk.Home.Dto - true - true - snupkg - + + net8.0 + Dvelop.Sdk.Home.Dto + Dvelop.Sdk.Home.Dto + true + true + snupkg + latestmajor + - - - + + + diff --git a/dvelop-sdk-httpclientextensions/HttpClientExtensions/HttpClientExtensions.csproj b/dvelop-sdk-httpclientextensions/HttpClientExtensions/HttpClientExtensions.csproj index e9fc8e3..8a3542c 100644 --- a/dvelop-sdk-httpclientextensions/HttpClientExtensions/HttpClientExtensions.csproj +++ b/dvelop-sdk-httpclientextensions/HttpClientExtensions/HttpClientExtensions.csproj @@ -1,25 +1,26 @@ - netstandard2.0 + net8.0 true Dvelop.Sdk.HttpClientExtensions Dvelop.Sdk.HttpClientExtensions Library - - true - true - snupkg - + latestmajor - - - + true + true + snupkg + - - - + + + + + + + diff --git a/dvelop-sdk-identityprovider/IdentityProviderClient/IdentityProviderClient.csproj b/dvelop-sdk-identityprovider/IdentityProviderClient/IdentityProviderClient.csproj index 95bbd99..91e81fa 100644 --- a/dvelop-sdk-identityprovider/IdentityProviderClient/IdentityProviderClient.csproj +++ b/dvelop-sdk-identityprovider/IdentityProviderClient/IdentityProviderClient.csproj @@ -1,13 +1,14 @@  - netstandard2.0 + net8.0 Dvelop.Sdk.IdentityProvider.Client Dvelop.Sdk.IdentityProvider.Client true true true snupkg + latestmajor diff --git a/dvelop-sdk-identityprovider/IdentityProviderMiddleware.UnitTest/IdentityProviderMiddleware.UnitTest.csproj b/dvelop-sdk-identityprovider/IdentityProviderMiddleware.UnitTest/IdentityProviderMiddleware.UnitTest.csproj index c4a2959..c71aec4 100644 --- a/dvelop-sdk-identityprovider/IdentityProviderMiddleware.UnitTest/IdentityProviderMiddleware.UnitTest.csproj +++ b/dvelop-sdk-identityprovider/IdentityProviderMiddleware.UnitTest/IdentityProviderMiddleware.UnitTest.csproj @@ -6,6 +6,7 @@ Dvelop.Sdk.IdentityProviderMiddleware.UnitTest Dvelop.Sdk.IdentityProviderMiddleware.UnitTest Library + latestmajor diff --git a/dvelop-sdk-identityprovider/IdentityProviderMiddleware/IdentityProviderMiddleware.csproj b/dvelop-sdk-identityprovider/IdentityProviderMiddleware/IdentityProviderMiddleware.csproj index 1c98df5..197921f 100644 --- a/dvelop-sdk-identityprovider/IdentityProviderMiddleware/IdentityProviderMiddleware.csproj +++ b/dvelop-sdk-identityprovider/IdentityProviderMiddleware/IdentityProviderMiddleware.csproj @@ -1,13 +1,14 @@ - netstandard2.0 + net8.0 Dvelop.Sdk.IdentityProvider.Middleware Dvelop.Sdk.IdentityProvider.Middleware true true true snupkg + latestmajor diff --git a/dvelop-sdk-logging/Logging.Abstractions/Logging.Abstractions.csproj b/dvelop-sdk-logging/Logging.Abstractions/Logging.Abstractions.csproj index d99a155..63a4857 100644 --- a/dvelop-sdk-logging/Logging.Abstractions/Logging.Abstractions.csproj +++ b/dvelop-sdk-logging/Logging.Abstractions/Logging.Abstractions.csproj @@ -1,10 +1,10 @@  - netstandard2.0 + net8.0 Dvelop.Sdk.Logging.Abstractions Dvelop.Sdk.Logging.Abstractions - 8 + latestmajor true true diff --git a/dvelop-sdk-logging/Logging.OtelJsonConsole/Logging.OtelJsonConsole.csproj b/dvelop-sdk-logging/Logging.OtelJsonConsole/Logging.OtelJsonConsole.csproj index 2d9fb65..ab33fa0 100644 --- a/dvelop-sdk-logging/Logging.OtelJsonConsole/Logging.OtelJsonConsole.csproj +++ b/dvelop-sdk-logging/Logging.OtelJsonConsole/Logging.OtelJsonConsole.csproj @@ -1,10 +1,10 @@ - netstandard2.1 + net8.0 Dvelop.Sdk.Logging.OtelJsonConsole Dvelop.Sdk.Logging.OtelJsonConsole - 8 + latestmajor true true diff --git a/dvelop-sdk-signing/SigningAlgorithms.UnitTest/SigningAlgorithms.UnitTest.csproj b/dvelop-sdk-signing/SigningAlgorithms.UnitTest/SigningAlgorithms.UnitTest.csproj index f9e719d..b995bac 100644 --- a/dvelop-sdk-signing/SigningAlgorithms.UnitTest/SigningAlgorithms.UnitTest.csproj +++ b/dvelop-sdk-signing/SigningAlgorithms.UnitTest/SigningAlgorithms.UnitTest.csproj @@ -6,6 +6,7 @@ Dvelop.Sdk.SigningAlgorithms.UnitTest Dvelop.Sdk.SigningAlgorithms.UnitTest Library + latestmajor diff --git a/dvelop-sdk-signing/SigningAlgorithms/SigningAlgorithms.csproj b/dvelop-sdk-signing/SigningAlgorithms/SigningAlgorithms.csproj index 3fa121f..9c07709 100644 --- a/dvelop-sdk-signing/SigningAlgorithms/SigningAlgorithms.csproj +++ b/dvelop-sdk-signing/SigningAlgorithms/SigningAlgorithms.csproj @@ -2,11 +2,11 @@ true - netstandard2.0 + net8.0 Dvelop.Sdk.SigningAlgorithms Dvelop.Sdk.SigningAlgorithms - - true + latestmajor + true true snupkg diff --git a/dvelop-sdk-tenant/TenantMiddleware.UnitTest/TenantMiddleware.UnitTest.csproj b/dvelop-sdk-tenant/TenantMiddleware.UnitTest/TenantMiddleware.UnitTest.csproj index 7ae5a03..f30fa9f 100644 --- a/dvelop-sdk-tenant/TenantMiddleware.UnitTest/TenantMiddleware.UnitTest.csproj +++ b/dvelop-sdk-tenant/TenantMiddleware.UnitTest/TenantMiddleware.UnitTest.csproj @@ -6,6 +6,7 @@ Dvelop.Sdk.TenantMiddleware.UnitTest Dvelop.Sdk.TenantMiddleware.UnitTest Library + latestmajor diff --git a/dvelop-sdk-tenant/TenantMiddleware/TenantMiddleware.csproj b/dvelop-sdk-tenant/TenantMiddleware/TenantMiddleware.csproj index a12af6e..ce5a4d2 100644 --- a/dvelop-sdk-tenant/TenantMiddleware/TenantMiddleware.csproj +++ b/dvelop-sdk-tenant/TenantMiddleware/TenantMiddleware.csproj @@ -2,7 +2,7 @@ Dvelop.Sdk.TenantMiddleware - netstandard2.0 + net8.0 Dvelop.Sdk.TenantMiddleware Dvelop.Sdk.TenantMiddleware Copyright (c) 2019 diff --git a/dvelop-sdk-webapi/WebApiExtensions.UnitTest/WebApiExtensions.UnitTest.csproj b/dvelop-sdk-webapi/WebApiExtensions.UnitTest/WebApiExtensions.UnitTest.csproj index 84d7a36..75cb50d 100644 --- a/dvelop-sdk-webapi/WebApiExtensions.UnitTest/WebApiExtensions.UnitTest.csproj +++ b/dvelop-sdk-webapi/WebApiExtensions.UnitTest/WebApiExtensions.UnitTest.csproj @@ -10,6 +10,8 @@ Dvelop.Sdk.WebApiExtensions.UnitTest Library + + latestmajor diff --git a/dvelop-sdk-webapi/WebApiExtensions/WebApiExtensions.csproj b/dvelop-sdk-webapi/WebApiExtensions/WebApiExtensions.csproj index a10d70f..ab2d4c9 100644 --- a/dvelop-sdk-webapi/WebApiExtensions/WebApiExtensions.csproj +++ b/dvelop-sdk-webapi/WebApiExtensions/WebApiExtensions.csproj @@ -1,10 +1,10 @@ - netstandard2.0 + net8.0 Dvelop.Sdk.WebApiExtensions Dvelop.Sdk.WebApiExtensions - 8 + latestmajor true true From cc98da4fc4df21c515a9774db0a5cbfcec10b58c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20K=C3=BCtbach?= Date: Mon, 16 Sep 2024 11:07:48 +0200 Subject: [PATCH 2/8] #36 Upgrade .NET 8 Modified for .NET 8 compatibility https://github.com/d-velop/dvelop-sdk-cs/issues/36 --- dvelop-sdk-all/DvelopSdk.csproj | 5 ++-- dvelop-sdk-base/BaseDtos/BaseDtos.csproj | 3 ++- .../BaseInterfaces/BaseInterfaces.csproj | 3 ++- .../CloudCenterDtos/CloudCenterDtos.csproj | 1 + .../ConfigDtos/ConfigDtos.csproj | 3 ++- .../DashboardDtos/DashboardDtos.csproj | 3 ++- dvelop-sdk-home/HomeDtos/HomeDtos.csproj | 23 +++++++++-------- .../HttpClientExtensions.csproj | 25 ++++++++++--------- .../IdentityProviderClient.csproj | 3 ++- ...IdentityProviderMiddleware.UnitTest.csproj | 1 + .../IdentityProviderMiddleware.csproj | 3 ++- .../Logging.Abstractions.csproj | 4 +-- .../Logging.OtelJsonConsole.csproj | 4 +-- .../SigningAlgorithms.UnitTest.csproj | 1 + .../SigningAlgorithms.csproj | 6 ++--- .../TenantMiddleware.UnitTest.csproj | 1 + .../TenantMiddleware/TenantMiddleware.csproj | 2 +- .../WebApiExtensions.UnitTest.csproj | 2 ++ .../WebApiExtensions/WebApiExtensions.csproj | 4 +-- 19 files changed, 56 insertions(+), 41 deletions(-) diff --git a/dvelop-sdk-all/DvelopSdk.csproj b/dvelop-sdk-all/DvelopSdk.csproj index eb6a721..c4db996 100644 --- a/dvelop-sdk-all/DvelopSdk.csproj +++ b/dvelop-sdk-all/DvelopSdk.csproj @@ -3,7 +3,7 @@ Dvelop.Sdk - netstandard2.0 + net8.0 Dvelop.Sdk Dvelop.Sdk Copyright (c) 2019 @@ -12,7 +12,7 @@ true false false - + https://github.com/d-velop/dvelop-sdk-cs https://github.com/d-velop/dvelop-sdk-cs @@ -21,6 +21,7 @@ true true snupkg + latestmajor diff --git a/dvelop-sdk-base/BaseDtos/BaseDtos.csproj b/dvelop-sdk-base/BaseDtos/BaseDtos.csproj index a30bb9f..8b647c2 100644 --- a/dvelop-sdk-base/BaseDtos/BaseDtos.csproj +++ b/dvelop-sdk-base/BaseDtos/BaseDtos.csproj @@ -1,12 +1,13 @@  - netstandard2.0 + net8.0 Dvelop.Sdk.Base.Dto Dvelop.Sdk.Base.Dto true true snupkg + latestmajor diff --git a/dvelop-sdk-base/BaseInterfaces/BaseInterfaces.csproj b/dvelop-sdk-base/BaseInterfaces/BaseInterfaces.csproj index 2d8aa2f..8ddeb74 100644 --- a/dvelop-sdk-base/BaseInterfaces/BaseInterfaces.csproj +++ b/dvelop-sdk-base/BaseInterfaces/BaseInterfaces.csproj @@ -1,9 +1,10 @@ - netstandard2.0 + net8.0 Dvelop.Sdk.BaseInterfaces Dvelop.Sdk.BaseInterfaces + latestmajor diff --git a/dvelop-sdk-cloudcenter/CloudCenterDtos/CloudCenterDtos.csproj b/dvelop-sdk-cloudcenter/CloudCenterDtos/CloudCenterDtos.csproj index 3cb7693..eb743f1 100644 --- a/dvelop-sdk-cloudcenter/CloudCenterDtos/CloudCenterDtos.csproj +++ b/dvelop-sdk-cloudcenter/CloudCenterDtos/CloudCenterDtos.csproj @@ -8,6 +8,7 @@ true true snupkg + latestmajor diff --git a/dvelop-sdk-config/ConfigDtos/ConfigDtos.csproj b/dvelop-sdk-config/ConfigDtos/ConfigDtos.csproj index 71ae132..72f8e8e 100644 --- a/dvelop-sdk-config/ConfigDtos/ConfigDtos.csproj +++ b/dvelop-sdk-config/ConfigDtos/ConfigDtos.csproj @@ -1,12 +1,13 @@  - netstandard2.0 + net8.0 Dvelop.Sdk.Config.Dto Dvelop.Sdk.Config.Dto true true snupkg + latestmajor diff --git a/dvelop-sdk-dash/DashboardDtos/DashboardDtos.csproj b/dvelop-sdk-dash/DashboardDtos/DashboardDtos.csproj index 3ce032a..9a86d5d 100644 --- a/dvelop-sdk-dash/DashboardDtos/DashboardDtos.csproj +++ b/dvelop-sdk-dash/DashboardDtos/DashboardDtos.csproj @@ -1,12 +1,13 @@  - netstandard2.0 + net8.0 Dvelop.Sdk.Dashboard.Dto Dvelop.Sdk.Dashboard.Dto true true snupkg + diff --git a/dvelop-sdk-home/HomeDtos/HomeDtos.csproj b/dvelop-sdk-home/HomeDtos/HomeDtos.csproj index 1964a97..2a7f13c 100644 --- a/dvelop-sdk-home/HomeDtos/HomeDtos.csproj +++ b/dvelop-sdk-home/HomeDtos/HomeDtos.csproj @@ -1,17 +1,18 @@  - - netstandard2.0 - Dvelop.Sdk.Home.Dto - Dvelop.Sdk.Home.Dto - true - true - snupkg - + + net8.0 + Dvelop.Sdk.Home.Dto + Dvelop.Sdk.Home.Dto + true + true + snupkg + latestmajor + - - - + + + diff --git a/dvelop-sdk-httpclientextensions/HttpClientExtensions/HttpClientExtensions.csproj b/dvelop-sdk-httpclientextensions/HttpClientExtensions/HttpClientExtensions.csproj index e9fc8e3..8a3542c 100644 --- a/dvelop-sdk-httpclientextensions/HttpClientExtensions/HttpClientExtensions.csproj +++ b/dvelop-sdk-httpclientextensions/HttpClientExtensions/HttpClientExtensions.csproj @@ -1,25 +1,26 @@ - netstandard2.0 + net8.0 true Dvelop.Sdk.HttpClientExtensions Dvelop.Sdk.HttpClientExtensions Library - - true - true - snupkg - + latestmajor - - - + true + true + snupkg + - - - + + + + + + + diff --git a/dvelop-sdk-identityprovider/IdentityProviderClient/IdentityProviderClient.csproj b/dvelop-sdk-identityprovider/IdentityProviderClient/IdentityProviderClient.csproj index 95bbd99..91e81fa 100644 --- a/dvelop-sdk-identityprovider/IdentityProviderClient/IdentityProviderClient.csproj +++ b/dvelop-sdk-identityprovider/IdentityProviderClient/IdentityProviderClient.csproj @@ -1,13 +1,14 @@  - netstandard2.0 + net8.0 Dvelop.Sdk.IdentityProvider.Client Dvelop.Sdk.IdentityProvider.Client true true true snupkg + latestmajor diff --git a/dvelop-sdk-identityprovider/IdentityProviderMiddleware.UnitTest/IdentityProviderMiddleware.UnitTest.csproj b/dvelop-sdk-identityprovider/IdentityProviderMiddleware.UnitTest/IdentityProviderMiddleware.UnitTest.csproj index c4a2959..c71aec4 100644 --- a/dvelop-sdk-identityprovider/IdentityProviderMiddleware.UnitTest/IdentityProviderMiddleware.UnitTest.csproj +++ b/dvelop-sdk-identityprovider/IdentityProviderMiddleware.UnitTest/IdentityProviderMiddleware.UnitTest.csproj @@ -6,6 +6,7 @@ Dvelop.Sdk.IdentityProviderMiddleware.UnitTest Dvelop.Sdk.IdentityProviderMiddleware.UnitTest Library + latestmajor diff --git a/dvelop-sdk-identityprovider/IdentityProviderMiddleware/IdentityProviderMiddleware.csproj b/dvelop-sdk-identityprovider/IdentityProviderMiddleware/IdentityProviderMiddleware.csproj index 1c98df5..197921f 100644 --- a/dvelop-sdk-identityprovider/IdentityProviderMiddleware/IdentityProviderMiddleware.csproj +++ b/dvelop-sdk-identityprovider/IdentityProviderMiddleware/IdentityProviderMiddleware.csproj @@ -1,13 +1,14 @@ - netstandard2.0 + net8.0 Dvelop.Sdk.IdentityProvider.Middleware Dvelop.Sdk.IdentityProvider.Middleware true true true snupkg + latestmajor diff --git a/dvelop-sdk-logging/Logging.Abstractions/Logging.Abstractions.csproj b/dvelop-sdk-logging/Logging.Abstractions/Logging.Abstractions.csproj index d99a155..63a4857 100644 --- a/dvelop-sdk-logging/Logging.Abstractions/Logging.Abstractions.csproj +++ b/dvelop-sdk-logging/Logging.Abstractions/Logging.Abstractions.csproj @@ -1,10 +1,10 @@  - netstandard2.0 + net8.0 Dvelop.Sdk.Logging.Abstractions Dvelop.Sdk.Logging.Abstractions - 8 + latestmajor true true diff --git a/dvelop-sdk-logging/Logging.OtelJsonConsole/Logging.OtelJsonConsole.csproj b/dvelop-sdk-logging/Logging.OtelJsonConsole/Logging.OtelJsonConsole.csproj index 2d9fb65..ab33fa0 100644 --- a/dvelop-sdk-logging/Logging.OtelJsonConsole/Logging.OtelJsonConsole.csproj +++ b/dvelop-sdk-logging/Logging.OtelJsonConsole/Logging.OtelJsonConsole.csproj @@ -1,10 +1,10 @@ - netstandard2.1 + net8.0 Dvelop.Sdk.Logging.OtelJsonConsole Dvelop.Sdk.Logging.OtelJsonConsole - 8 + latestmajor true true diff --git a/dvelop-sdk-signing/SigningAlgorithms.UnitTest/SigningAlgorithms.UnitTest.csproj b/dvelop-sdk-signing/SigningAlgorithms.UnitTest/SigningAlgorithms.UnitTest.csproj index f9e719d..b995bac 100644 --- a/dvelop-sdk-signing/SigningAlgorithms.UnitTest/SigningAlgorithms.UnitTest.csproj +++ b/dvelop-sdk-signing/SigningAlgorithms.UnitTest/SigningAlgorithms.UnitTest.csproj @@ -6,6 +6,7 @@ Dvelop.Sdk.SigningAlgorithms.UnitTest Dvelop.Sdk.SigningAlgorithms.UnitTest Library + latestmajor diff --git a/dvelop-sdk-signing/SigningAlgorithms/SigningAlgorithms.csproj b/dvelop-sdk-signing/SigningAlgorithms/SigningAlgorithms.csproj index 3fa121f..9c07709 100644 --- a/dvelop-sdk-signing/SigningAlgorithms/SigningAlgorithms.csproj +++ b/dvelop-sdk-signing/SigningAlgorithms/SigningAlgorithms.csproj @@ -2,11 +2,11 @@ true - netstandard2.0 + net8.0 Dvelop.Sdk.SigningAlgorithms Dvelop.Sdk.SigningAlgorithms - - true + latestmajor + true true snupkg diff --git a/dvelop-sdk-tenant/TenantMiddleware.UnitTest/TenantMiddleware.UnitTest.csproj b/dvelop-sdk-tenant/TenantMiddleware.UnitTest/TenantMiddleware.UnitTest.csproj index 7ae5a03..f30fa9f 100644 --- a/dvelop-sdk-tenant/TenantMiddleware.UnitTest/TenantMiddleware.UnitTest.csproj +++ b/dvelop-sdk-tenant/TenantMiddleware.UnitTest/TenantMiddleware.UnitTest.csproj @@ -6,6 +6,7 @@ Dvelop.Sdk.TenantMiddleware.UnitTest Dvelop.Sdk.TenantMiddleware.UnitTest Library + latestmajor diff --git a/dvelop-sdk-tenant/TenantMiddleware/TenantMiddleware.csproj b/dvelop-sdk-tenant/TenantMiddleware/TenantMiddleware.csproj index a12af6e..ce5a4d2 100644 --- a/dvelop-sdk-tenant/TenantMiddleware/TenantMiddleware.csproj +++ b/dvelop-sdk-tenant/TenantMiddleware/TenantMiddleware.csproj @@ -2,7 +2,7 @@ Dvelop.Sdk.TenantMiddleware - netstandard2.0 + net8.0 Dvelop.Sdk.TenantMiddleware Dvelop.Sdk.TenantMiddleware Copyright (c) 2019 diff --git a/dvelop-sdk-webapi/WebApiExtensions.UnitTest/WebApiExtensions.UnitTest.csproj b/dvelop-sdk-webapi/WebApiExtensions.UnitTest/WebApiExtensions.UnitTest.csproj index 84d7a36..75cb50d 100644 --- a/dvelop-sdk-webapi/WebApiExtensions.UnitTest/WebApiExtensions.UnitTest.csproj +++ b/dvelop-sdk-webapi/WebApiExtensions.UnitTest/WebApiExtensions.UnitTest.csproj @@ -10,6 +10,8 @@ Dvelop.Sdk.WebApiExtensions.UnitTest Library + + latestmajor diff --git a/dvelop-sdk-webapi/WebApiExtensions/WebApiExtensions.csproj b/dvelop-sdk-webapi/WebApiExtensions/WebApiExtensions.csproj index a10d70f..ab2d4c9 100644 --- a/dvelop-sdk-webapi/WebApiExtensions/WebApiExtensions.csproj +++ b/dvelop-sdk-webapi/WebApiExtensions/WebApiExtensions.csproj @@ -1,10 +1,10 @@ - netstandard2.0 + net8.0 Dvelop.Sdk.WebApiExtensions Dvelop.Sdk.WebApiExtensions - 8 + latestmajor true true From 495fe933ac0d984a29953a1a3dbe5aa9c0dd6844 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20K=C3=BCtbach?= Date: Mon, 16 Sep 2024 12:58:32 +0200 Subject: [PATCH 3/8] #36 Upgrade .NET 8 Modified for .NET 8 compatibility https://github.com/d-velop/dvelop-sdk-cs/issues/36 --- dvelop-sdk-all/DvelopSdk.csproj | 2 +- dvelop-sdk-base/BaseDtos/BaseDtos.csproj | 2 +- .../CloudCenterDtos/CloudCenterDtos.csproj | 2 +- .../ConfigDtos/ConfigDtos.csproj | 4 +-- .../DashboardDtos/DashboardDtos.csproj | 4 +-- dvelop-sdk-home/HomeDtos/HomeDtos.csproj | 2 +- .../HttpClientExtensions.UnitTest.csproj | 8 ++--- .../HttpClientExtensions.csproj | 2 +- .../IdentityProviderClient.csproj | 4 +-- .../IdentityProviderSessionStore.cs | 10 +++--- .../IdentityProviderDtos.csproj | 2 +- ...IdentityProviderMiddleware.UnitTest.csproj | 10 +++--- .../IdentityProviderMiddlewareTest.cs | 2 +- .../IdentityProviderSessionStoreTest.cs | 8 ++--- .../CustomAuthenticationExtension.cs | 2 +- .../CustomAuthenticationHandler.cs | 28 --------------- .../IdentityProviderMiddleware.cs | 34 +++++++++++-------- .../IdentityProviderMiddleware.csproj | 7 ++-- .../IdpAuthenticationHandler.cs | 26 ++++++++++++++ .../Logging.Abstractions.csproj | 4 +-- .../Logging.OtelJsonConsole.csproj | 6 ++-- .../SigningAlgorithms.UnitTest.csproj | 8 ++--- .../SigningAlgorithms.csproj | 6 ++-- .../TenantMiddleware.UnitTest.csproj | 10 +++--- .../TenantMiddleware/TenantMiddleware.csproj | 2 +- .../WebApiExtensions.UnitTest.csproj | 8 ++--- .../WebApiExtensions/WebApiExtensions.csproj | 4 +-- 27 files changed, 106 insertions(+), 101 deletions(-) delete mode 100644 dvelop-sdk-identityprovider/IdentityProviderMiddleware/CustomAuthenticationHandler.cs create mode 100644 dvelop-sdk-identityprovider/IdentityProviderMiddleware/IdpAuthenticationHandler.cs diff --git a/dvelop-sdk-all/DvelopSdk.csproj b/dvelop-sdk-all/DvelopSdk.csproj index c4db996..80870a4 100644 --- a/dvelop-sdk-all/DvelopSdk.csproj +++ b/dvelop-sdk-all/DvelopSdk.csproj @@ -25,7 +25,7 @@ - + diff --git a/dvelop-sdk-base/BaseDtos/BaseDtos.csproj b/dvelop-sdk-base/BaseDtos/BaseDtos.csproj index 8b647c2..69e4751 100644 --- a/dvelop-sdk-base/BaseDtos/BaseDtos.csproj +++ b/dvelop-sdk-base/BaseDtos/BaseDtos.csproj @@ -11,7 +11,7 @@ - + diff --git a/dvelop-sdk-cloudcenter/CloudCenterDtos/CloudCenterDtos.csproj b/dvelop-sdk-cloudcenter/CloudCenterDtos/CloudCenterDtos.csproj index eb743f1..16839af 100644 --- a/dvelop-sdk-cloudcenter/CloudCenterDtos/CloudCenterDtos.csproj +++ b/dvelop-sdk-cloudcenter/CloudCenterDtos/CloudCenterDtos.csproj @@ -12,7 +12,7 @@ - + diff --git a/dvelop-sdk-config/ConfigDtos/ConfigDtos.csproj b/dvelop-sdk-config/ConfigDtos/ConfigDtos.csproj index 72f8e8e..9a971db 100644 --- a/dvelop-sdk-config/ConfigDtos/ConfigDtos.csproj +++ b/dvelop-sdk-config/ConfigDtos/ConfigDtos.csproj @@ -11,8 +11,8 @@ - - + + diff --git a/dvelop-sdk-dash/DashboardDtos/DashboardDtos.csproj b/dvelop-sdk-dash/DashboardDtos/DashboardDtos.csproj index 9a86d5d..cd407ec 100644 --- a/dvelop-sdk-dash/DashboardDtos/DashboardDtos.csproj +++ b/dvelop-sdk-dash/DashboardDtos/DashboardDtos.csproj @@ -11,8 +11,8 @@ - - + + diff --git a/dvelop-sdk-home/HomeDtos/HomeDtos.csproj b/dvelop-sdk-home/HomeDtos/HomeDtos.csproj index 2a7f13c..e04de88 100644 --- a/dvelop-sdk-home/HomeDtos/HomeDtos.csproj +++ b/dvelop-sdk-home/HomeDtos/HomeDtos.csproj @@ -11,7 +11,7 @@ - + diff --git a/dvelop-sdk-httpclientextensions/HttpClientExtensions.UnitTest/HttpClientExtensions.UnitTest.csproj b/dvelop-sdk-httpclientextensions/HttpClientExtensions.UnitTest/HttpClientExtensions.UnitTest.csproj index 2f405dd..da8b72d 100644 --- a/dvelop-sdk-httpclientextensions/HttpClientExtensions.UnitTest/HttpClientExtensions.UnitTest.csproj +++ b/dvelop-sdk-httpclientextensions/HttpClientExtensions.UnitTest/HttpClientExtensions.UnitTest.csproj @@ -9,10 +9,10 @@ - - - - + + + + all runtime; build; native; contentfiles; analyzers; buildtransitive diff --git a/dvelop-sdk-httpclientextensions/HttpClientExtensions/HttpClientExtensions.csproj b/dvelop-sdk-httpclientextensions/HttpClientExtensions/HttpClientExtensions.csproj index 8a3542c..c3a371c 100644 --- a/dvelop-sdk-httpclientextensions/HttpClientExtensions/HttpClientExtensions.csproj +++ b/dvelop-sdk-httpclientextensions/HttpClientExtensions/HttpClientExtensions.csproj @@ -14,7 +14,7 @@ - + diff --git a/dvelop-sdk-identityprovider/IdentityProviderClient/IdentityProviderClient.csproj b/dvelop-sdk-identityprovider/IdentityProviderClient/IdentityProviderClient.csproj index 91e81fa..dab77d0 100644 --- a/dvelop-sdk-identityprovider/IdentityProviderClient/IdentityProviderClient.csproj +++ b/dvelop-sdk-identityprovider/IdentityProviderClient/IdentityProviderClient.csproj @@ -12,13 +12,13 @@ - + - + diff --git a/dvelop-sdk-identityprovider/IdentityProviderClient/IdentityProviderSessionStore.cs b/dvelop-sdk-identityprovider/IdentityProviderClient/IdentityProviderSessionStore.cs index 54fbfac..4a90a42 100644 --- a/dvelop-sdk-identityprovider/IdentityProviderClient/IdentityProviderSessionStore.cs +++ b/dvelop-sdk-identityprovider/IdentityProviderClient/IdentityProviderSessionStore.cs @@ -8,7 +8,7 @@ namespace Dvelop.Sdk.IdentityProvider.Client { public class IdentityProviderSessionStore { - private readonly ISystemClock _clock; + private readonly TimeProvider _clock; private readonly int _cleanupThreshold; private readonly ConcurrentDictionary _sessionCache = @@ -17,13 +17,13 @@ public class IdentityProviderSessionStore private int _cleanupCounter; private readonly object _cleanupLock=new object(); - public IdentityProviderSessionStore(ISystemClock clock, int cleanupThreshold) + public IdentityProviderSessionStore(TimeProvider clock, int cleanupThreshold) { _clock = clock; _cleanupThreshold = cleanupThreshold; } - public IdentityProviderSessionStore():this(new SystemClock(), 20) + public IdentityProviderSessionStore():this(TimeProvider.System, 20) { } @@ -34,7 +34,7 @@ public ClaimsPrincipal GetPrincipal(string cookie) //CleanUp(); var id = IdFromCookie(cookie); if (!_sessionCache.TryGetValue(id, out var sessionItem)) return null; - if (sessionItem.Expire.CompareTo(_clock.UtcNow) < 0) + if (sessionItem.Expire.CompareTo(_clock.GetUtcNow()) < 0) { _sessionCache.TryRemove(id,out _); return null; @@ -68,7 +68,7 @@ private void CleanUp() foreach (var key in _sessionCache.Keys) { if (!_sessionCache.TryGetValue(key, out var sessionItem)) continue; - if (sessionItem.Expire.CompareTo(_clock.UtcNow) < 0) + if (sessionItem.Expire.CompareTo(_clock.GetUtcNow()) < 0) { _sessionCache.TryRemove(key, out _); } diff --git a/dvelop-sdk-identityprovider/IdentityProviderDtos/IdentityProviderDtos.csproj b/dvelop-sdk-identityprovider/IdentityProviderDtos/IdentityProviderDtos.csproj index 6218754..ee4dcd1 100644 --- a/dvelop-sdk-identityprovider/IdentityProviderDtos/IdentityProviderDtos.csproj +++ b/dvelop-sdk-identityprovider/IdentityProviderDtos/IdentityProviderDtos.csproj @@ -10,7 +10,7 @@ - + diff --git a/dvelop-sdk-identityprovider/IdentityProviderMiddleware.UnitTest/IdentityProviderMiddleware.UnitTest.csproj b/dvelop-sdk-identityprovider/IdentityProviderMiddleware.UnitTest/IdentityProviderMiddleware.UnitTest.csproj index c71aec4..36a1b41 100644 --- a/dvelop-sdk-identityprovider/IdentityProviderMiddleware.UnitTest/IdentityProviderMiddleware.UnitTest.csproj +++ b/dvelop-sdk-identityprovider/IdentityProviderMiddleware.UnitTest/IdentityProviderMiddleware.UnitTest.csproj @@ -10,11 +10,11 @@ - - - - - + + + + + diff --git a/dvelop-sdk-identityprovider/IdentityProviderMiddleware.UnitTest/IdentityProviderMiddlewareTest.cs b/dvelop-sdk-identityprovider/IdentityProviderMiddleware.UnitTest/IdentityProviderMiddlewareTest.cs index cfa9821..d9e7e11 100644 --- a/dvelop-sdk-identityprovider/IdentityProviderMiddleware.UnitTest/IdentityProviderMiddlewareTest.cs +++ b/dvelop-sdk-identityprovider/IdentityProviderMiddleware.UnitTest/IdentityProviderMiddlewareTest.cs @@ -169,7 +169,7 @@ private async Task TestMiddleWare(string requestMethod, Dictionary mh.Send(It.IsAny())).Returns(new HttpResponseMessage() diff --git a/dvelop-sdk-identityprovider/IdentityProviderMiddleware.UnitTest/IdentityProviderSessionStoreTest.cs b/dvelop-sdk-identityprovider/IdentityProviderMiddleware.UnitTest/IdentityProviderSessionStoreTest.cs index 47b1f83..728957d 100644 --- a/dvelop-sdk-identityprovider/IdentityProviderMiddleware.UnitTest/IdentityProviderSessionStoreTest.cs +++ b/dvelop-sdk-identityprovider/IdentityProviderMiddleware.UnitTest/IdentityProviderSessionStoreTest.cs @@ -11,12 +11,12 @@ namespace Dvelop.Sdk.IdentityProviderMiddleware.UnitTest public class IdentityProviderSessionStoreTest { private IdentityProviderSessionStore _unit; - private Mock _clock; + private Mock _clock; [TestInitialize] public void Setup() { - _clock = new Mock {CallBase = true}; + _clock = new Mock {CallBase = true}; _unit = new IdentityProviderSessionStore(_clock.Object, 2); } @@ -63,7 +63,7 @@ public void GetSecondSessionUserCookieShouldReturnPrincipal() public void GetExpiredItemShouldReturnNull() { var now = DateTimeOffset.UtcNow; - _clock.SetupSequence(c => c.UtcNow) + _clock.SetupSequence(c => c.GetUtcNow()) .Returns(now) .Returns(now.AddMinutes(61)); @@ -82,7 +82,7 @@ public void GetExpiredItemShouldReturnNull() public void GetNonExpiredItemShouldReturn() { var now = DateTimeOffset.UtcNow; - _clock.SetupSequence(c => c.UtcNow) + _clock.SetupSequence(c => c.GetUtcNow()) .Returns(now).Returns(now) // SET .Returns(now.AddMinutes(61)) // GET a&1 .Returns(now.AddMinutes(61)); // GET b&1 diff --git a/dvelop-sdk-identityprovider/IdentityProviderMiddleware/CustomAuthenticationExtension.cs b/dvelop-sdk-identityprovider/IdentityProviderMiddleware/CustomAuthenticationExtension.cs index 8270a23..1f29db8 100644 --- a/dvelop-sdk-identityprovider/IdentityProviderMiddleware/CustomAuthenticationExtension.cs +++ b/dvelop-sdk-identityprovider/IdentityProviderMiddleware/CustomAuthenticationExtension.cs @@ -7,7 +7,7 @@ public static class CustomAuthenticationExtensions { public static AuthenticationBuilder AddIdentityProviderAuthentication(this AuthenticationBuilder builder, string authenticationScheme, string displayName, Action configureOptions) { - return builder.AddScheme(authenticationScheme, displayName, configureOptions); + return builder.AddScheme(authenticationScheme, displayName, configureOptions); } } diff --git a/dvelop-sdk-identityprovider/IdentityProviderMiddleware/CustomAuthenticationHandler.cs b/dvelop-sdk-identityprovider/IdentityProviderMiddleware/CustomAuthenticationHandler.cs deleted file mode 100644 index 3bf3d67..0000000 --- a/dvelop-sdk-identityprovider/IdentityProviderMiddleware/CustomAuthenticationHandler.cs +++ /dev/null @@ -1,28 +0,0 @@ -using System.Security.Claims; -using System.Text.Encodings.Web; -using System.Threading.Tasks; -using Microsoft.AspNetCore.Authentication; -using Microsoft.Extensions.Logging; -using Microsoft.Extensions.Options; - -namespace Dvelop.Sdk.IdentityProvider.Middleware -{ - public class CustomAuthenticationHandler : AuthenticationHandler - { - public CustomAuthenticationHandler(IOptionsMonitor options, ILoggerFactory logger, - UrlEncoder encoder, ISystemClock clock) - : base(options, logger, encoder, clock) - { - } - - protected override Task HandleAuthenticateAsync() - { - return Task.FromResult( - AuthenticateResult.Success( - new AuthenticationTicket( - new ClaimsPrincipal(Options.Identity), - new AuthenticationProperties(), - Scheme.Name))); - } - } -} \ No newline at end of file diff --git a/dvelop-sdk-identityprovider/IdentityProviderMiddleware/IdentityProviderMiddleware.cs b/dvelop-sdk-identityprovider/IdentityProviderMiddleware/IdentityProviderMiddleware.cs index a1e04af..b0c5463 100644 --- a/dvelop-sdk-identityprovider/IdentityProviderMiddleware/IdentityProviderMiddleware.cs +++ b/dvelop-sdk-identityprovider/IdentityProviderMiddleware/IdentityProviderMiddleware.cs @@ -5,6 +5,7 @@ using System.Net.Http.Headers; using System.Threading.Tasks; using Dvelop.Sdk.IdentityProvider.Client; +using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Http.Extensions; @@ -43,23 +44,26 @@ public async Task Invoke(HttpContext context) { context.User = await _identityProviderClient.GetClaimsPrincipalAsync(sessionId).ConfigureAwait(false); } - context.Response.OnStarting(state => + + var endpoint = context.GetEndpoint(); + var anon = endpoint?.Metadata.GetMetadata(); + if (anon == null) { - if (context.Response.StatusCode != (int) HttpStatusCode.Unauthorized) - { - return Task.FromResult(false); - } - return Task.FromResult(RequestRedirectedToLogin(context, bearerTokenReceived)); - }, context.Response); + await _next.Invoke(context).ConfigureAwait(false); + return; + } + + context.Response.OnStarting(_ => Task.FromResult(context.Response.StatusCode == (int)HttpStatusCode.Unauthorized && + RequestRedirectedToLogin(context)), context.Response); await _next.Invoke(context).ConfigureAwait(false); } - private bool RequestRedirectedToLogin(HttpContext context, bool bearerTokenReceived) + private bool RequestRedirectedToLogin(HttpContext context) { - if(context == null) { throw new ArgumentNullException(nameof(context));} - - if (!string.IsNullOrWhiteSpace(context.User?.Identity?.Name)) + ArgumentNullException.ThrowIfNull(context); + + if (!string.IsNullOrWhiteSpace(context.User.Identity?.Name)) { return false; } @@ -78,7 +82,7 @@ private bool RequestRedirectedToLogin(HttpContext context, bool bearerTokenRecei private static bool HandleUnauthorizedRequest(HttpContext context) { - if(context== null) { throw new ArgumentNullException(nameof(context));} + ArgumentNullException.ThrowIfNull(context); var accept = context.Request.Headers["accept"]; var mediaTypeWithQualityHeaderValue = GetMediaTypes(accept)?.FirstOrDefault(); @@ -89,14 +93,14 @@ private static bool HandleUnauthorizedRequest(HttpContext context) mediaTypeWithQualityHeaderValue.MediaType != "*/*" && mediaTypeWithQualityHeaderValue.MediaType != "") { - context.Response.Headers?.Add("WWW-Authenticate", "Bearer"); + context.Response.Headers["WWW-Authenticate"] = "Bearer"; context.Response.StatusCode = (int) HttpStatusCode.Unauthorized; return true; } } if (context.Request.Method == "GET" || context.Request.Method == "HEAD") return false; - context.Response.Headers?.Add("WWW-Authenticate", "Bearer"); + context.Response.Headers["WWW-Authenticate"] = "Bearer"; context.Response.StatusCode = (int) HttpStatusCode.Unauthorized; return true; @@ -119,7 +123,7 @@ private static IEnumerable GetMediaTypes(string : new MediaTypeWithQualityHeaderValue("application/octed-stream"); return x; }) - .Where(h => h?.Quality.GetValueOrDefault(1) > 0) + .Where(h => h.Quality.GetValueOrDefault(1) > 0) .OrderByDescending(mt => mt.Quality.GetValueOrDefault(1)); } } diff --git a/dvelop-sdk-identityprovider/IdentityProviderMiddleware/IdentityProviderMiddleware.csproj b/dvelop-sdk-identityprovider/IdentityProviderMiddleware/IdentityProviderMiddleware.csproj index 197921f..ed5f7ac 100644 --- a/dvelop-sdk-identityprovider/IdentityProviderMiddleware/IdentityProviderMiddleware.csproj +++ b/dvelop-sdk-identityprovider/IdentityProviderMiddleware/IdentityProviderMiddleware.csproj @@ -1,4 +1,4 @@ - + net8.0 @@ -9,10 +9,13 @@ true snupkg latestmajor + Library + true - + + diff --git a/dvelop-sdk-identityprovider/IdentityProviderMiddleware/IdpAuthenticationHandler.cs b/dvelop-sdk-identityprovider/IdentityProviderMiddleware/IdpAuthenticationHandler.cs new file mode 100644 index 0000000..5eb540f --- /dev/null +++ b/dvelop-sdk-identityprovider/IdentityProviderMiddleware/IdpAuthenticationHandler.cs @@ -0,0 +1,26 @@ +using System; +using System.Security.Claims; +using System.Text.Encodings.Web; +using System.Threading.Tasks; +using Microsoft.AspNetCore.Authentication; +using Microsoft.Extensions.Logging; +using Microsoft.Extensions.Options; + +namespace Dvelop.Sdk.IdentityProvider.Middleware +{ + public class IdpAuthenticationHandler( + IOptionsMonitor options, + ILoggerFactory logger, + UrlEncoder encoder) + : AuthenticationHandler(options, logger, encoder) + { + + protected override Task HandleAuthenticateAsync() + { + var isIdpAuthenticated = Context.User.Identity?.AuthenticationType?.Equals("d.velop.IdentityProvider") ?? false; + return Task.FromResult(isIdpAuthenticated + ? AuthenticateResult.Success(new AuthenticationTicket(Context.User, new AuthenticationProperties(), Scheme.Name)) + : AuthenticateResult.NoResult()); + } + } +} \ No newline at end of file diff --git a/dvelop-sdk-logging/Logging.Abstractions/Logging.Abstractions.csproj b/dvelop-sdk-logging/Logging.Abstractions/Logging.Abstractions.csproj index 63a4857..2517020 100644 --- a/dvelop-sdk-logging/Logging.Abstractions/Logging.Abstractions.csproj +++ b/dvelop-sdk-logging/Logging.Abstractions/Logging.Abstractions.csproj @@ -12,11 +12,11 @@ - + - + diff --git a/dvelop-sdk-logging/Logging.OtelJsonConsole/Logging.OtelJsonConsole.csproj b/dvelop-sdk-logging/Logging.OtelJsonConsole/Logging.OtelJsonConsole.csproj index ab33fa0..0ad5190 100644 --- a/dvelop-sdk-logging/Logging.OtelJsonConsole/Logging.OtelJsonConsole.csproj +++ b/dvelop-sdk-logging/Logging.OtelJsonConsole/Logging.OtelJsonConsole.csproj @@ -12,12 +12,12 @@ - + - - + + diff --git a/dvelop-sdk-signing/SigningAlgorithms.UnitTest/SigningAlgorithms.UnitTest.csproj b/dvelop-sdk-signing/SigningAlgorithms.UnitTest/SigningAlgorithms.UnitTest.csproj index b995bac..ceab483 100644 --- a/dvelop-sdk-signing/SigningAlgorithms.UnitTest/SigningAlgorithms.UnitTest.csproj +++ b/dvelop-sdk-signing/SigningAlgorithms.UnitTest/SigningAlgorithms.UnitTest.csproj @@ -11,10 +11,10 @@ - - - - + + + + all runtime; build; native; contentfiles; analyzers; buildtransitive diff --git a/dvelop-sdk-signing/SigningAlgorithms/SigningAlgorithms.csproj b/dvelop-sdk-signing/SigningAlgorithms/SigningAlgorithms.csproj index 9c07709..df26703 100644 --- a/dvelop-sdk-signing/SigningAlgorithms/SigningAlgorithms.csproj +++ b/dvelop-sdk-signing/SigningAlgorithms/SigningAlgorithms.csproj @@ -12,15 +12,15 @@ - + - - + + diff --git a/dvelop-sdk-tenant/TenantMiddleware.UnitTest/TenantMiddleware.UnitTest.csproj b/dvelop-sdk-tenant/TenantMiddleware.UnitTest/TenantMiddleware.UnitTest.csproj index f30fa9f..8780652 100644 --- a/dvelop-sdk-tenant/TenantMiddleware.UnitTest/TenantMiddleware.UnitTest.csproj +++ b/dvelop-sdk-tenant/TenantMiddleware.UnitTest/TenantMiddleware.UnitTest.csproj @@ -10,12 +10,12 @@ - + - - - - + + + + diff --git a/dvelop-sdk-tenant/TenantMiddleware/TenantMiddleware.csproj b/dvelop-sdk-tenant/TenantMiddleware/TenantMiddleware.csproj index ce5a4d2..150c64e 100644 --- a/dvelop-sdk-tenant/TenantMiddleware/TenantMiddleware.csproj +++ b/dvelop-sdk-tenant/TenantMiddleware/TenantMiddleware.csproj @@ -19,7 +19,7 @@ - + diff --git a/dvelop-sdk-webapi/WebApiExtensions.UnitTest/WebApiExtensions.UnitTest.csproj b/dvelop-sdk-webapi/WebApiExtensions.UnitTest/WebApiExtensions.UnitTest.csproj index 75cb50d..ced8cf6 100644 --- a/dvelop-sdk-webapi/WebApiExtensions.UnitTest/WebApiExtensions.UnitTest.csproj +++ b/dvelop-sdk-webapi/WebApiExtensions.UnitTest/WebApiExtensions.UnitTest.csproj @@ -16,10 +16,10 @@ - - - - + + + + all runtime; build; native; contentfiles; analyzers; buildtransitive diff --git a/dvelop-sdk-webapi/WebApiExtensions/WebApiExtensions.csproj b/dvelop-sdk-webapi/WebApiExtensions/WebApiExtensions.csproj index ab2d4c9..8324a90 100644 --- a/dvelop-sdk-webapi/WebApiExtensions/WebApiExtensions.csproj +++ b/dvelop-sdk-webapi/WebApiExtensions/WebApiExtensions.csproj @@ -12,8 +12,8 @@ - - + + From 9ee80223010a976145a9d7ec92210c0478e66ba5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20K=C3=BCtbach?= Date: Mon, 16 Sep 2024 14:07:50 +0200 Subject: [PATCH 4/8] #36 Upgrade .NET 8 Bumped Minor Version (Is a breaking change, but SemVer v0 means not Stable at all) Modified for .NET 8 compatibility https://github.com/d-velop/dvelop-sdk-cs/issues/36 --- Directory.Build.props | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Directory.Build.props b/Directory.Build.props index 8978ebf..62e53f2 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -4,6 +4,6 @@ d.velop AG Copyright (c) 2024 https://github.com/d-velop/dvelop-sdk-cs - 0.0.10 + 0.1.0 From 1d13db969a0efca7080c9aea7afb4bb2aa5b0d96 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20K=C3=BCtbach?= Date: Mon, 16 Sep 2024 14:52:15 +0200 Subject: [PATCH 5/8] #5 Resources with [AllowAnonymous] may trigger request to the IDP --- .../IdentityProviderMiddlewareTest.cs | 97 +++++++++++-------- .../IdentityProviderMiddleware.cs | 16 +-- 2 files changed, 65 insertions(+), 48 deletions(-) diff --git a/dvelop-sdk-identityprovider/IdentityProviderMiddleware.UnitTest/IdentityProviderMiddlewareTest.cs b/dvelop-sdk-identityprovider/IdentityProviderMiddleware.UnitTest/IdentityProviderMiddlewareTest.cs index d9e7e11..6675882 100644 --- a/dvelop-sdk-identityprovider/IdentityProviderMiddleware.UnitTest/IdentityProviderMiddlewareTest.cs +++ b/dvelop-sdk-identityprovider/IdentityProviderMiddleware.UnitTest/IdentityProviderMiddlewareTest.cs @@ -10,8 +10,11 @@ using Dvelop.Sdk.IdentityProvider.Client; using Dvelop.Sdk.IdentityProvider.Middleware; using FluentAssertions; +using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Http.Features; +using Microsoft.AspNetCore.Routing; +using Microsoft.AspNetCore.Routing.Patterns; using Microsoft.VisualStudio.TestTools.UnitTesting; using Moq; @@ -115,24 +118,27 @@ public async Task TestInvalidAuthSessionId(string testName, string requestMethod private static IEnumerable GetTestNoAuthSessionIdAndGetRequestAndAcceptHeaderIsData() { - yield return new object[]{"", true}; - yield return new object[]{"text/", false}; - yield return new object[]{"text/*", true}; - yield return new object[]{"*/*", true}; - yield return new object[]{"application/json; q=1.0, */*; q=0.8", false}; // GO middleware says true - yield return new object[]{"text/html", true}; - yield return new object[]{"something/else", false}; - yield return new object[]{"text/html; q=1", true}; - yield return new object[]{"text/html; q=1.0", true}; - yield return new object[]{"text/html; q=0.9", true}; - yield return new object[]{"text/html; q=0", true}; // GO middleware says false - yield return new object[]{"text/html; q=0.0", true}; // GO middleware says false - yield return new object[]{"application/json", false}; - yield return new object[]{"application/json; q=1.0, text/html; q=0.9", false}; // GO middleware says true - yield return new object[]{"application/json; q=1.0, text/html; q=0", false}; - yield return new object[]{"application/json; q=0.9, text/html; q=1.0", true}; - yield return new object[]{"application/json; q=1.0, text/html; q=0.", false}; - yield return new object[]{"text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3", true}; + yield return ["", true]; + yield return ["text/", false]; + yield return ["text/*", true]; + yield return ["*/*", true]; + yield return ["application/json; q=1.0, */*; q=0.8", false]; // GO middleware says true + yield return ["text/html", true]; + yield return ["something/else", false]; + yield return ["text/html; q=1", true]; + yield return ["text/html; q=1.0", true]; + yield return ["text/html; q=0.9", true]; + yield return ["text/html; q=0", true]; // GO middleware says false + yield return ["text/html; q=0.0", true]; // GO middleware says false + yield return ["application/json", false]; + yield return ["application/json; q=1.0, text/html; q=0.9", false]; // GO middleware says true + yield return ["application/json; q=1.0, text/html; q=0", false]; + yield return ["application/json; q=0.9, text/html; q=1.0", true]; + yield return ["application/json; q=1.0, text/html; q=0.", false]; + yield return + [ + "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3", true + ]; } [DynamicData(nameof(GetTestNoAuthSessionIdAndGetRequestAndAcceptHeaderIsData), DynamicDataSourceType.Method, DynamicDataDisplayName = "DisplayName")] @@ -154,9 +160,15 @@ private async Task TestMiddleWare(string requestMethod, Dictionary mh.Send(It.IsAny())).Returns(new HttpResponseMessage() { StatusCode = HttpStatusCode.OK, - Content = new StringContent("") + Content = new StringContent(""), }); var client = new HttpClient(_fakeMessageHandler.Object); @@ -183,6 +195,14 @@ private async Task TestMiddleWare(string requestMethod, Dictionary(feature); + var endpointFeatureMock = new Mock(); + endpointFeatureMock.SetupGet(endpointFeature => endpointFeature.Endpoint) + .Returns(new RouteEndpoint(_ => Task.CompletedTask, + RoutePatternFactory.Parse("/"), 0, + new EndpointMetadataCollection(new AllowAnonymousAttribute()), "Dummy")); + + context.Features.Set(endpointFeatureMock.Object); + async Task Next(HttpContext ctx) { Console.WriteLine(ctx.Response.Headers.Count); @@ -217,37 +237,34 @@ public static string DisplayName(MethodInfo methodInfo, object[] data) return string.IsNullOrWhiteSpace(displayName) ? "-" : displayName; } - private class MiddlewareMock + [Authorize] + private class MiddlewareMock(RequestDelegate next) { - private readonly RequestDelegate _next; public bool HasBeenInvoked { get; private set; } - - public MiddlewareMock(RequestDelegate next) - { - _next = next; - } public async Task InvokeAsync(HttpContext context) { - HasBeenInvoked = true; - context.Response.Body = new MemoryStream(); - context.Response.StatusCode = 401; - - await _next(context).ConfigureAwait(false); + try + { + HasBeenInvoked = true; + context.Response.Body = new MemoryStream(); + context.Response.StatusCode = 401; + + await next(context).ConfigureAwait(false); + } catch (Exception e) + { + Console.WriteLine(e); + throw; + } } } private class MockResponseFeature : IHttpResponseFeature { - public MockResponseFeature() - { - Headers = new HeaderDictionary(); - } - public Stream Body { get; set; } public bool HasStarted { get; private set; } - public IHeaderDictionary Headers { get; set; } + public IHeaderDictionary Headers { get; set; } = new HeaderDictionary(); public string ReasonPhrase { get; set; } diff --git a/dvelop-sdk-identityprovider/IdentityProviderMiddleware/IdentityProviderMiddleware.cs b/dvelop-sdk-identityprovider/IdentityProviderMiddleware/IdentityProviderMiddleware.cs index b0c5463..505db3c 100644 --- a/dvelop-sdk-identityprovider/IdentityProviderMiddleware/IdentityProviderMiddleware.cs +++ b/dvelop-sdk-identityprovider/IdentityProviderMiddleware/IdentityProviderMiddleware.cs @@ -45,13 +45,6 @@ public async Task Invoke(HttpContext context) context.User = await _identityProviderClient.GetClaimsPrincipalAsync(sessionId).ConfigureAwait(false); } - var endpoint = context.GetEndpoint(); - var anon = endpoint?.Metadata.GetMetadata(); - if (anon == null) - { - await _next.Invoke(context).ConfigureAwait(false); - return; - } context.Response.OnStarting(_ => Task.FromResult(context.Response.StatusCode == (int)HttpStatusCode.Unauthorized && RequestRedirectedToLogin(context)), context.Response); @@ -73,9 +66,16 @@ private bool RequestRedirectedToLogin(HttpContext context) return true; } + var endpoint = context.GetEndpoint(); + var anon = endpoint?.Metadata?.GetMetadata(); + + if (anon == null) + { + return true; + } + var encodedUrl = context.Request.GetEncodedPathAndQuery(); context.Response.Redirect(_identityProviderClient.GetLoginUri(encodedUrl).ToString()); - return true; } From dc9a66f576f05d8c824d51068eade7b7078381a4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20K=C3=BCtbach?= Date: Mon, 16 Sep 2024 16:30:25 +0200 Subject: [PATCH 6/8] #5 Resources with [AllowAnonymous] may trigger request to the IDP --- .../IdentityProviderMiddleware.cs | 43 +++++++++---------- 1 file changed, 21 insertions(+), 22 deletions(-) diff --git a/dvelop-sdk-identityprovider/IdentityProviderMiddleware/IdentityProviderMiddleware.cs b/dvelop-sdk-identityprovider/IdentityProviderMiddleware/IdentityProviderMiddleware.cs index 505db3c..d93b1bb 100644 --- a/dvelop-sdk-identityprovider/IdentityProviderMiddleware/IdentityProviderMiddleware.cs +++ b/dvelop-sdk-identityprovider/IdentityProviderMiddleware/IdentityProviderMiddleware.cs @@ -11,7 +11,7 @@ namespace Dvelop.Sdk.IdentityProvider.Middleware { - public class IdentityProviderMiddleware + public class IdentityProviderMiddleware { private readonly IdentityProviderClient _identityProviderClient; private readonly RequestDelegate _next; @@ -31,10 +31,10 @@ public IdentityProviderMiddleware(RequestDelegate next, IdentityProviderOptions TenantInformationCallback = clientOptions.TenantInformationCallback, UseMinimizedOnlyIdValidateDetailLevel = clientOptions.UseMinimizedOnlyIdValidateDetailLevel }; - - _identityProviderClient = new IdentityProviderClient( co ); + + _identityProviderClient = new IdentityProviderClient(co); } - + public async Task Invoke(HttpContext context) { var sessionId = context.GetAuthSessionId(); @@ -44,14 +44,15 @@ public async Task Invoke(HttpContext context) { context.User = await _identityProviderClient.GetClaimsPrincipalAsync(sessionId).ConfigureAwait(false); } - - - context.Response.OnStarting(_ => Task.FromResult(context.Response.StatusCode == (int)HttpStatusCode.Unauthorized && - RequestRedirectedToLogin(context)), context.Response); - + + + context.Response.OnStarting( + _ => Task.FromResult(context.Response.StatusCode == (int)HttpStatusCode.Unauthorized && + RequestRedirectedToLogin(context)), context.Response); + await _next.Invoke(context).ConfigureAwait(false); } - + private bool RequestRedirectedToLogin(HttpContext context) { ArgumentNullException.ThrowIfNull(context); @@ -60,23 +61,23 @@ private bool RequestRedirectedToLogin(HttpContext context) { return false; } - + if (HandleUnauthorizedRequest(context)) { return true; } - + var endpoint = context.GetEndpoint(); var anon = endpoint?.Metadata?.GetMetadata(); - - if (anon == null) + + if (anon != null) { return true; } - + var encodedUrl = context.Request.GetEncodedPathAndQuery(); context.Response.Redirect(_identityProviderClient.GetLoginUri(encodedUrl).ToString()); - + return true; } @@ -94,27 +95,25 @@ private static bool HandleUnauthorizedRequest(HttpContext context) mediaTypeWithQualityHeaderValue.MediaType != "") { context.Response.Headers["WWW-Authenticate"] = "Bearer"; - context.Response.StatusCode = (int) HttpStatusCode.Unauthorized; + context.Response.StatusCode = (int)HttpStatusCode.Unauthorized; return true; } } if (context.Request.Method == "GET" || context.Request.Method == "HEAD") return false; context.Response.Headers["WWW-Authenticate"] = "Bearer"; - context.Response.StatusCode = (int) HttpStatusCode.Unauthorized; + context.Response.StatusCode = (int)HttpStatusCode.Unauthorized; return true; - } - - + private static IEnumerable GetMediaTypes(string headerValues) { if (string.IsNullOrEmpty(headerValues)) { return new List(); } - + return headerValues.Split(',') .Select(headerValue => { From 16e5ece7472b0e2c232f6642b3f91d3ab37d5ca2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20K=C3=BCtbach?= Date: Mon, 16 Sep 2024 17:13:41 +0200 Subject: [PATCH 7/8] #5 Resources with [AllowAnonymous] may trigger request to the IDP Added some more tests --- .../IdentityProviderMiddlewareTest.cs | 208 ++++++++++++------ .../IdentityProviderMiddleware.cs | 14 +- 2 files changed, 150 insertions(+), 72 deletions(-) diff --git a/dvelop-sdk-identityprovider/IdentityProviderMiddleware.UnitTest/IdentityProviderMiddlewareTest.cs b/dvelop-sdk-identityprovider/IdentityProviderMiddleware.UnitTest/IdentityProviderMiddlewareTest.cs index 6675882..3a3160f 100644 --- a/dvelop-sdk-identityprovider/IdentityProviderMiddleware.UnitTest/IdentityProviderMiddlewareTest.cs +++ b/dvelop-sdk-identityprovider/IdentityProviderMiddleware.UnitTest/IdentityProviderMiddlewareTest.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using System.Diagnostics.CodeAnalysis; using System.IO; +using System.Linq; using System.Net; using System.Net.Http; using System.Reflection; @@ -45,34 +46,64 @@ public void Setup() private static IEnumerable GetTestNoAuthSessionIdData() { - yield return new object[] { "IDP-1740_path", + yield return + [ + "IDP-1740_path", "GET", new Dictionary{{"Accept","text/html"}}, "/hüme", 302, new Dictionary { {"Location","/identityprovider/login?redirect=%2fh%25C3%25BCme"} - }, false}; + }, false + ]; - yield return new object[] { "IDP-1740_query", + yield return + [ + "IDP-1740_query", "GET", new Dictionary{{"Accept","text/html"}}, "/bla?path=%2Fh%C3%BCme", 302, new Dictionary { {"Location","/identityprovider/login?redirect=%2Fbla%3Fpath%3D%252Fh%25C3%25BCme"} - }, false}; + }, false + ]; - yield return new object[] { "GetRequestAndHtmlAccepted_Should_RedirectToIdp", - "GET", new Dictionary{{"Accept","text/html"}}, "/a/b?q1=x&q2=1", 302, new Dictionary{{"Location","/identityprovider/login?redirect=%2Fa%2Fb%3Fq1%3Dx%26q2%3D1"}}, false}; - yield return new object[] { "AndHeadRequestAndHtmlAccepted_Should_RedirectToIdp", - "HEAD", new Dictionary{{"Accept","text/html"}}, "/a/b?q1=x&q2=1", 302, new Dictionary{{"Location","/identityprovider/login?redirect=%2Fa%2Fb%3Fq1%3Dx%26q2%3D1" }}, false}; - yield return new object[] { "BasicAuthorizationAndGetRequestAndHtmlAccepted_Should_RedirectsToIdp", - "GET", new Dictionary{{"Accept","text/html"},{"Authorization", "Basic adabdk"}}, "/a/b?q1=x&q2=1", 302, new Dictionary{{"Location","/identityprovider/login?redirect=%2Fa%2Fb%3Fq1%3Dx%26q2%3D1"}}, false}; - yield return new object[] { "OtherCookieAndGetRequestAndHtmlAccepted_Should_RedirectsToIdp", - "GET", new Dictionary{{"Cookie","AnyCookie=adabdk"},{"Accept","text/html"}}, "/a/b?q1=x&q2=1", 302, new Dictionary{{"Location","/identityprovider/login?redirect=%2Fa%2Fb%3Fq1%3Dx%26q2%3D1"}}, false}; - yield return new object[] { "PostRequestAndHtmlAccepted_ReturnsStatus401AndWWW-AuthenticateBearerHeader", - "POST", new Dictionary{{"Accept","text/html"}}, "/a/b?q1=x&q2=1", 401, new Dictionary{{"WWW-Authenticate","Bearer" }}, false}; - yield return new object[] { "PutRequestAndHtmlAccepted_ReturnsStatus401AndWWW-AuthenticateBearerHeader", - "PUT", new Dictionary{{"Accept","text/html"}}, "/a/b?q1=x&q2=1", 401, new Dictionary{{"WWW-Authenticate","Bearer" }}, false}; - yield return new object[] { "DeleteRequestAndHtmlAccepted_ReturnsStatus401AndWWW-AuthenticateBearerHeader", - "DELETE", new Dictionary{{"Accept","text/html"}}, "/a/b?q1=x&q2=1", 401, new Dictionary{{"WWW-Authenticate","Bearer" }}, false}; - yield return new object[] { "PatchRequestAndHtmlAccepted_ReturnsStatus401AndWWW-AuthenticateBearerHeader", - "PATCH", new Dictionary{{"Accept","text/html"}}, "/a/b?q1=x&q2=1", 401, new Dictionary{{"WWW-Authenticate","Bearer" }}, false}; + yield return + [ + "GetRequestAndHtmlAccepted_Should_RedirectToIdp", + "GET", new Dictionary{{"Accept","text/html"}}, "/a/b?q1=x&q2=1", 302, new Dictionary{{"Location","/identityprovider/login?redirect=%2Fa%2Fb%3Fq1%3Dx%26q2%3D1"}}, false + ]; + yield return + [ + "AndHeadRequestAndHtmlAccepted_Should_RedirectToIdp", + "HEAD", new Dictionary{{"Accept","text/html"}}, "/a/b?q1=x&q2=1", 302, new Dictionary{{"Location","/identityprovider/login?redirect=%2Fa%2Fb%3Fq1%3Dx%26q2%3D1" }}, false + ]; + yield return + [ + "BasicAuthorizationAndGetRequestAndHtmlAccepted_Should_RedirectsToIdp", + "GET", new Dictionary{{"Accept","text/html"},{"Authorization", "Basic adabdk"}}, "/a/b?q1=x&q2=1", 302, new Dictionary{{"Location","/identityprovider/login?redirect=%2Fa%2Fb%3Fq1%3Dx%26q2%3D1"}}, false + ]; + yield return + [ + "OtherCookieAndGetRequestAndHtmlAccepted_Should_RedirectsToIdp", + "GET", new Dictionary{{"Cookie","AnyCookie=adabdk"},{"Accept","text/html"}}, "/a/b?q1=x&q2=1", 302, new Dictionary{{"Location","/identityprovider/login?redirect=%2Fa%2Fb%3Fq1%3Dx%26q2%3D1"}}, false + ]; + yield return + [ + "PostRequestAndHtmlAccepted_ReturnsStatus401AndWWW-AuthenticateBearerHeader", + "POST", new Dictionary{{"Accept","text/html"}}, "/a/b?q1=x&q2=1", 401, new Dictionary{{"WWW-Authenticate","Bearer" }}, false + ]; + yield return + [ + "PutRequestAndHtmlAccepted_ReturnsStatus401AndWWW-AuthenticateBearerHeader", + "PUT", new Dictionary{{"Accept","text/html"}}, "/a/b?q1=x&q2=1", 401, new Dictionary{{"WWW-Authenticate","Bearer" }}, false + ]; + yield return + [ + "DeleteRequestAndHtmlAccepted_ReturnsStatus401AndWWW-AuthenticateBearerHeader", + "DELETE", new Dictionary{{"Accept","text/html"}}, "/a/b?q1=x&q2=1", 401, new Dictionary{{"WWW-Authenticate","Bearer" }}, false + ]; + yield return + [ + "PatchRequestAndHtmlAccepted_ReturnsStatus401AndWWW-AuthenticateBearerHeader", + "PATCH", new Dictionary{{"Accept","text/html"}}, "/a/b?q1=x&q2=1", 401, new Dictionary{{"WWW-Authenticate","Bearer" }}, false + ]; } @@ -81,29 +112,53 @@ private static IEnumerable GetTestNoAuthSessionIdData() public async Task TestNoAuthSessionId(string testName, string requestMethod, Dictionary requestHeader, string requestUri, int expectedStatus, Dictionary expectedResponseHeader,bool allowExternalValidation) { Console.WriteLine(testName); - await TestMiddleWare(requestMethod,requestHeader,requestUri,expectedStatus,expectedResponseHeader,allowExternalValidation).ConfigureAwait(false); + await TestMiddleWare(requestMethod,requestHeader,requestUri,false,expectedStatus,expectedResponseHeader,allowExternalValidation).ConfigureAwait(false); } private static IEnumerable GetTestInvalidAuthSessionIdData() { const string invalidToken = "200e7388-1834-434b-be79-3745181e1457"; - yield return new object[] { "GetRequestAndHtmlAccepted_Middleware_RedirectsToIdp", - "GET", new Dictionary{{"Accept", "text/html"}, {"Authorization", "Bearer " + invalidToken}}, "/a/b?q1=x&q2=1", 302, new Dictionary{{"Location","/identityprovider/login?redirect=%2Fa%2Fb%3Fq1%3Dx%26q2%3D1"}}, false}; - yield return new object[] { "HeadRequestAndHtmlAccepted_Middleware_RedirectsToIdp", - "HEAD", new Dictionary{{"Accept", "text/html"}, {"Authorization", "Bearer " + invalidToken}}, "/a/b?q1=x&q2=1", 302,new Dictionary{{"Location","/identityprovider/login?redirect=%2Fa%2Fb%3Fq1%3Dx%26q2%3D1"}}, false}; - yield return new object[] { "GetRequestAndHtmlNotAccepted_Middleware_ReturnsStatus401AndWWW-AuthenticateBearerHeader", - "GET", new Dictionary{{"Accept", "application/json"}, {"Authorization", "Bearer " + invalidToken}}, "/a/b?q1=x&q2=1", 401, new Dictionary{{"Www-Authenticate","Bearer" }}, false}; - yield return new object[] { "PostRequestAndHtmlAccepted_Middleware_ReturnsStatus401AndWWW-AuthenticateBearerHeader", - "POST", new Dictionary{{"Accept", "text/html"}, {"Authorization", "Bearer " + invalidToken}}, "/a/b?q1=x&q2=1", 401, new Dictionary{{"Www-Authenticate","Bearer" }}, false}; - yield return new object[] { "PutRequestAndHtmlAccepted_Middleware_ReturnsStatus401AndWWW-AuthenticateBearerHeader", - "PUT", new Dictionary{{"Accept", "text/html"}, {"Authorization", "Bearer " + invalidToken}}, "/a/b?q1=x&q2=1", 401, new Dictionary{{"Www-Authenticate","Bearer" }}, false}; - yield return new object[] { "DeleteRequestAndHtmlAccepted_Middleware_ReturnsStatus401AndWWW-AuthenticateBearerHeader", - "DELETE", new Dictionary{{"Accept","text/html"}, {"Authorization", "Bearer " + invalidToken}}, "/a/b?q1=x&q2=1", 401,new Dictionary{{"Www-Authenticate","Bearer" }}, false}; - yield return new object[] { "PatchRequestAndHtmlAccepted_Middleware_ReturnsStatus401AndWWW-AuthenticateBearerHeader", - "PATCH", new Dictionary{{"Accept","text/html"}, {"Authorization", "Bearer " + invalidToken}}, "/a/b?q1=x&q2=1",401, new Dictionary{{"Www-Authenticate","Bearer" }}, false}; - yield return new object[] { "GetRequestAndHtmlAcceptedAndExternalValidation_Middleware_RedirectsToIdp", - "GET", new Dictionary{{"Accept","text/html"}, {"Authorization", "Bearer " + invalidToken}}, "/a/b?q1=x&q2=1", 302, new Dictionary{{"Location","/identityprovider/login?redirect=%2Fa%2Fb%3Fq1%3Dx%26q2%3D1"}}, true}; + yield return + [ + "GetRequestAndHtmlAccepted_Middleware_RedirectsToIdp", + "GET", new Dictionary{{"Accept", "text/html"}, {"Authorization", "Bearer " + invalidToken}}, "/a/b?q1=x&q2=1", 302, new Dictionary{{"Location","/identityprovider/login?redirect=%2Fa%2Fb%3Fq1%3Dx%26q2%3D1"}}, false + ]; + yield return + [ + "HeadRequestAndHtmlAccepted_Middleware_RedirectsToIdp", + "HEAD", new Dictionary{{"Accept", "text/html"}, {"Authorization", "Bearer " + invalidToken}}, "/a/b?q1=x&q2=1", 302,new Dictionary{{"Location","/identityprovider/login?redirect=%2Fa%2Fb%3Fq1%3Dx%26q2%3D1"}}, false + ]; + yield return + [ + "GetRequestAndHtmlNotAccepted_Middleware_ReturnsStatus401AndWWW-AuthenticateBearerHeader", + "GET", new Dictionary{{"Accept", "application/json"}, {"Authorization", "Bearer " + invalidToken}}, "/a/b?q1=x&q2=1", 401, new Dictionary{{"Www-Authenticate","Bearer" }}, false + ]; + yield return + [ + "PostRequestAndHtmlAccepted_Middleware_ReturnsStatus401AndWWW-AuthenticateBearerHeader", + "POST", new Dictionary{{"Accept", "text/html"}, {"Authorization", "Bearer " + invalidToken}}, "/a/b?q1=x&q2=1", 401, new Dictionary{{"Www-Authenticate","Bearer" }}, false + ]; + yield return + [ + "PutRequestAndHtmlAccepted_Middleware_ReturnsStatus401AndWWW-AuthenticateBearerHeader", + "PUT", new Dictionary{{"Accept", "text/html"}, {"Authorization", "Bearer " + invalidToken}}, "/a/b?q1=x&q2=1", 401, new Dictionary{{"Www-Authenticate","Bearer" }}, false + ]; + yield return + [ + "DeleteRequestAndHtmlAccepted_Middleware_ReturnsStatus401AndWWW-AuthenticateBearerHeader", + "DELETE", new Dictionary{{"Accept","text/html"}, {"Authorization", "Bearer " + invalidToken}}, "/a/b?q1=x&q2=1", 401,new Dictionary{{"Www-Authenticate","Bearer" }}, false + ]; + yield return + [ + "PatchRequestAndHtmlAccepted_Middleware_ReturnsStatus401AndWWW-AuthenticateBearerHeader", + "PATCH", new Dictionary{{"Accept","text/html"}, {"Authorization", "Bearer " + invalidToken}}, "/a/b?q1=x&q2=1",401, new Dictionary{{"Www-Authenticate","Bearer" }}, false + ]; + yield return + [ + "GetRequestAndHtmlAcceptedAndExternalValidation_Middleware_RedirectsToIdp", + "GET", new Dictionary{{"Accept","text/html"}, {"Authorization", "Bearer " + invalidToken}}, "/a/b?q1=x&q2=1", 302, new Dictionary{{"Location","/identityprovider/login?redirect=%2Fa%2Fb%3Fq1%3Dx%26q2%3D1"}}, true + ]; } [DynamicData(nameof(GetTestInvalidAuthSessionIdData), DynamicDataSourceType.Method, DynamicDataDisplayName = "DisplayName")] @@ -113,45 +168,69 @@ public async Task TestInvalidAuthSessionId(string testName, string requestMethod Dictionary expectedResponseHeader, bool allowExternalValidation) { Console.WriteLine(testName); - await TestMiddleWare(requestMethod,requestHeader,requestUri,expectedStatus,expectedResponseHeader,allowExternalValidation).ConfigureAwait(false); + await TestMiddleWare(requestMethod,requestHeader,requestUri,false,expectedStatus,expectedResponseHeader,allowExternalValidation).ConfigureAwait(false); } private static IEnumerable GetTestNoAuthSessionIdAndGetRequestAndAcceptHeaderIsData() { - yield return ["", true]; - yield return ["text/", false]; - yield return ["text/*", true]; - yield return ["*/*", true]; - yield return ["application/json; q=1.0, */*; q=0.8", false]; // GO middleware says true - yield return ["text/html", true]; - yield return ["something/else", false]; - yield return ["text/html; q=1", true]; - yield return ["text/html; q=1.0", true]; - yield return ["text/html; q=0.9", true]; - yield return ["text/html; q=0", true]; // GO middleware says false - yield return ["text/html; q=0.0", true]; // GO middleware says false - yield return ["application/json", false]; - yield return ["application/json; q=1.0, text/html; q=0.9", false]; // GO middleware says true - yield return ["application/json; q=1.0, text/html; q=0", false]; - yield return ["application/json; q=0.9, text/html; q=1.0", true]; - yield return ["application/json; q=1.0, text/html; q=0.", false]; - yield return - [ - "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3", true - ]; + yield return ["", true, true]; + yield return ["text/", true, false]; + yield return ["text/*",true, true]; + yield return ["*/*", true, true]; + yield return ["application/json; q=1.0, */*; q=0.8",true, false]; // GO middleware says true + yield return ["text/html", true, true]; + yield return ["something/else", true, false]; + yield return ["text/html; q=1", true, true]; + yield return ["text/html; q=1.0",true, true]; + yield return ["text/html; q=0.9",true, true]; + yield return ["text/html; q=0",true, true]; // GO middleware says false + yield return ["text/html; q=0.0",true, true]; // GO middleware says false + yield return ["application/json", true, false]; + yield return ["application/json; q=1.0, text/html; q=0.9",true, false]; // GO middleware says true + yield return ["application/json; q=1.0, text/html; q=0", true, false]; + yield return ["application/json; q=0.9, text/html; q=1.0", true, true]; + yield return ["application/json; q=1.0, text/html; q=0.",true, false]; + yield return ["text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3", true, true]; + + + yield return ["", false, true]; + yield return ["text/", false, false]; + yield return ["text/*", false, true]; + yield return ["*/*", false, true]; + yield return ["application/json; q=1.0, */*; q=0.8", false, false]; // GO middleware says true + yield return ["text/html", false, true]; + yield return ["something/else", false, false]; + yield return ["text/html; q=1", false, true]; + yield return ["text/html; q=1.0", false, true]; + yield return ["text/html; q=0.9", false, true]; + yield return ["text/html; q=0", false, true]; // GO middleware says false + yield return ["text/html; q=0.0", false, true]; // GO middleware says false + yield return ["application/json", false, false]; + yield return ["application/json; q=1.0, text/html; q=0.9", false, false]; // GO middleware says true + yield return ["application/json; q=1.0, text/html; q=0", false, false]; + yield return ["application/json; q=0.9, text/html; q=1.0", false, true]; + yield return ["application/json; q=1.0, text/html; q=0.", false, false]; + yield return ["text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3", false, true]; } [DynamicData(nameof(GetTestNoAuthSessionIdAndGetRequestAndAcceptHeaderIsData), DynamicDataSourceType.Method, DynamicDataDisplayName = "DisplayName")] [DataTestMethod] - public async Task GetTestNoAuthSessionIdAndGetRequestAndAcceptHeaderIs(string acceptHeader, bool redirectExpected) + public async Task GetTestNoAuthSessionIdAndGetRequestAndAcceptHeaderIs(string acceptHeader,bool anonymousAllowed, bool redirectExpected) { + Console.WriteLine(acceptHeader); var requestHeader = new Dictionary{{"Accept", acceptHeader}}; - await TestMiddleWare("GET",requestHeader,"/a/b?q1=x&q2=1",redirectExpected?302:401,new Dictionary(),false ).ConfigureAwait(false); + await TestMiddleWare("GET", + requestHeader, + "/a/b?q1=x&q2=1", + anonymousAllowed, + redirectExpected?302:401, + new Dictionary(), + false ).ConfigureAwait(false); } - private async Task TestMiddleWare(string requestMethod, Dictionary requestHeader, string requestUri, int expectedStatus, Dictionary expectedResponseHeader,bool allowExternalValidation) + private async Task TestMiddleWare(string requestMethod, Dictionary requestHeader, string requestUri, bool allowAnonymous, int expectedStatus, Dictionary expectedResponseHeader,bool allowExternalValidation) { var uri = new Uri(requestUri, UriKind.RelativeOrAbsolute); if (!uri.IsAbsoluteUri) @@ -196,10 +275,11 @@ private async Task TestMiddleWare(string requestMethod, Dictionary(feature); var endpointFeatureMock = new Mock(); + endpointFeatureMock.SetupGet(endpointFeature => endpointFeature.Endpoint) .Returns(new RouteEndpoint(_ => Task.CompletedTask, RoutePatternFactory.Parse("/"), 0, - new EndpointMetadataCollection(new AllowAnonymousAttribute()), "Dummy")); + new EndpointMetadataCollection(allowAnonymous?new AllowAnonymousAttribute():new AuthorizeAttribute()), "Dummy")); context.Features.Set(endpointFeatureMock.Object); @@ -233,7 +313,7 @@ async Task Next(HttpContext ctx) //Used by Tests to create a readable TestName public static string DisplayName(MethodInfo methodInfo, object[] data) { - var displayName = $"{data[0]}"; + var displayName = $"{data[0]} ({string.Join( ", ", data.Skip(1) )})"; return string.IsNullOrWhiteSpace(displayName) ? "-" : displayName; } diff --git a/dvelop-sdk-identityprovider/IdentityProviderMiddleware/IdentityProviderMiddleware.cs b/dvelop-sdk-identityprovider/IdentityProviderMiddleware/IdentityProviderMiddleware.cs index d93b1bb..3fa58f8 100644 --- a/dvelop-sdk-identityprovider/IdentityProviderMiddleware/IdentityProviderMiddleware.cs +++ b/dvelop-sdk-identityprovider/IdentityProviderMiddleware/IdentityProviderMiddleware.cs @@ -45,6 +45,12 @@ public async Task Invoke(HttpContext context) context.User = await _identityProviderClient.GetClaimsPrincipalAsync(sessionId).ConfigureAwait(false); } + var endpoint = context.GetEndpoint(); + var anon = endpoint?.Metadata?.GetMetadata(); + if (anon != null && context.Response.StatusCode == 0) + { + context.Response.StatusCode = (int)HttpStatusCode.OK; + } context.Response.OnStarting( _ => Task.FromResult(context.Response.StatusCode == (int)HttpStatusCode.Unauthorized && @@ -67,14 +73,6 @@ private bool RequestRedirectedToLogin(HttpContext context) return true; } - var endpoint = context.GetEndpoint(); - var anon = endpoint?.Metadata?.GetMetadata(); - - if (anon != null) - { - return true; - } - var encodedUrl = context.Request.GetEncodedPathAndQuery(); context.Response.Redirect(_identityProviderClient.GetLoginUri(encodedUrl).ToString()); From a41567c7f588164518b536fc4681e42823c80c32 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20K=C3=BCtbach?= Date: Tue, 17 Sep 2024 12:44:07 +0200 Subject: [PATCH 8/8] #5 Resources with [AllowAnonymous] may trigger request to the IDP Added Readme to project --- Directory.Build.props | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/Directory.Build.props b/Directory.Build.props index 62e53f2..bcb8e35 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -5,5 +5,10 @@ Copyright (c) 2024 https://github.com/d-velop/dvelop-sdk-cs 0.1.0 + README.md + + + +