Skip to content

Commit d5d8d97

Browse files
author
Daniele Giallonardo
committed
Code cleanup
1 parent 3ac699f commit d5d8d97

19 files changed

Lines changed: 164 additions & 158 deletions

File tree

samples/1_SimpleSPWebApp/SPID.AspNetCore.WebApp/SPID.AspNetCore.WebApp.csproj

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,14 @@
66
</PropertyGroup>
77

88
<ItemGroup>
9-
<PackageReference Include="Microsoft.AspNetCore.Mvc.Razor.RuntimeCompilation" Version="8.0.4" />
10-
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
11-
<PackageReference Include="SPID.AspNetCore.Authentication" Version="3.2.0" />
9+
<PackageReference Include="Microsoft.AspNetCore.Mvc.Razor.RuntimeCompilation" Version="8.0.5" />
10+
<PackageReference Include="SPID.AspNetCore.Authentication" Version="3.3.0" />
1211
</ItemGroup>
12+
13+
<!--<ItemGroup>
14+
<Reference Include="SPID.AspNetCore.Authentication">
15+
<HintPath>..\..\..\src\SPID.AspNetCore.Authentication\bin\Debug\net8.0\SPID.AspNetCore.Authentication.dll</HintPath>
16+
</Reference>
17+
</ItemGroup>-->
1318

1419
</Project>

samples/2_IdentityServer/SPID.AspNetCore.IdentityServerSample.IdentityServer/SPID.AspNetCore.IdentityServerSample.IdentityServer.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@
77
<ItemGroup>
88
<PackageReference Include="IdentityServer4" Version="4.1.2" />
99

10-
<PackageReference Include="Microsoft.AspNetCore.Authentication.Google" Version="8.0.4" />
10+
<PackageReference Include="Microsoft.AspNetCore.Authentication.Google" Version="8.0.5" />
1111

12-
<PackageReference Include="SPID.AspNetCore.Authentication" Version="3.2.0" />
12+
<PackageReference Include="SPID.AspNetCore.Authentication" Version="3.3.0" />
1313

1414
</ItemGroup>
1515

samples/2_IdentityServer/SPID.AspNetCore.IdentityServerSample.MvcClient/SPID.AspNetCore.IdentityServerSample.MvcClient.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
</PropertyGroup>
66

77
<ItemGroup>
8-
<PackageReference Include="Microsoft.AspNetCore.Authentication.OpenIdConnect" Version="8.0.4" />
8+
<PackageReference Include="Microsoft.AspNetCore.Authentication.OpenIdConnect" Version="8.0.5" />
99
</ItemGroup>
1010

1111
</Project>

samples/3_RazorPages/SPID.AspNetCore.WebApp.RazorPages/SPID.AspNetCore.WebApp.RazorPages.csproj

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,16 @@
88
</PropertyGroup>
99

1010
<ItemGroup>
11-
<PackageReference Include="Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore" Version="8.0.4" />
12-
<PackageReference Include="Microsoft.AspNetCore.Identity.EntityFrameworkCore" Version="8.0.4" />
13-
<PackageReference Include="Microsoft.AspNetCore.Identity.UI" Version="8.0.4" />
14-
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="8.0.4" />
15-
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="8.0.4">
11+
<PackageReference Include="Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore" Version="8.0.5" />
12+
<PackageReference Include="Microsoft.AspNetCore.Identity.EntityFrameworkCore" Version="8.0.5" />
13+
<PackageReference Include="Microsoft.AspNetCore.Identity.UI" Version="8.0.5" />
14+
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="8.0.5" />
15+
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="8.0.5">
1616
<PrivateAssets>all</PrivateAssets>
1717
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
1818
</PackageReference>
1919
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="8.0.2" />
20-
<PackageReference Include="SPID.AspNetCore.Authentication" Version="3.2.0" />
20+
<PackageReference Include="SPID.AspNetCore.Authentication" Version="3.3.0" />
2121
</ItemGroup>
2222

2323
</Project>

src/SPID.AspNetCore.Authentication/Events/RedirectContext.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ public RedirectContext(
2020
SpidOptions options,
2121
AuthenticationProperties properties,
2222
object signedProtocolMessage)
23-
: base(context, scheme, options, properties)
23+
: base(context, scheme, options, properties)
2424
{
2525
SignedProtocolMessage = signedProtocolMessage;
2626
}

src/SPID.AspNetCore.Authentication/Extensions/LoggingExtensions.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@ namespace SPID.AspNetCore.Authentication
55
{
66
internal static class LoggingExtensions
77
{
8-
private static Action<ILogger, Exception> _exceptionProcessingMessage;
9-
private static Action<ILogger, string, Exception> _malformedRedirectUri;
10-
private static Action<ILogger, Exception> _remoteSignOutHandledResponse;
11-
private static Action<ILogger, Exception> _remoteSignOutFailed;
12-
private static Action<ILogger, Exception> _remoteSignOutSkipped;
13-
private static Action<ILogger, Exception> _remoteSignOut;
8+
private static readonly Action<ILogger, Exception> _exceptionProcessingMessage;
9+
private static readonly Action<ILogger, string, Exception> _malformedRedirectUri;
10+
private static readonly Action<ILogger, Exception> _remoteSignOutHandledResponse;
11+
private static readonly Action<ILogger, Exception> _remoteSignOutFailed;
12+
private static readonly Action<ILogger, Exception> _remoteSignOutSkipped;
13+
private static readonly Action<ILogger, Exception> _remoteSignOut;
1414

1515
static LoggingExtensions()
1616
{

src/SPID.AspNetCore.Authentication/Helpers/BusinessValidation.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,12 @@ namespace SPID.AspNetCore.Authentication.Helpers
77
{
88
internal static class BusinessValidation
99
{
10-
public static void Argument<T>(T input, string error, [CallerArgumentExpression("input")] string inputName = "") where T : class
10+
public static void Argument<T>(T input, string error, [CallerArgumentExpression(nameof(input))] string inputName = "") where T : class
1111
{
1212
if (input is string && string.IsNullOrWhiteSpace(input.ToString()) || input == default(T))
13+
{
1314
throw new SpidException(String.Format(ErrorLocalization.ArgumentNull, inputName), error, SpidErrorCode.ArgumentNull);
15+
}
1416
}
1517

1618
public static void ValidationCondition(Func<bool> condition, SpidException error)
@@ -50,7 +52,8 @@ public static void ValidationNotNullNotWhitespace(string input, SpidException er
5052
}
5153
}
5254

53-
public static T ValidationNotNullNotEmpty<T>(T input, SpidException error) where T : class, new()
55+
public static T ValidationNotNullNotEmpty<T>(T input, SpidException error)
56+
where T : class, new()
5457
{
5558
var instance = new T();
5659
if (input == default(T)) throw error;

src/SPID.AspNetCore.Authentication/Helpers/OptionsHelper.cs

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -11,25 +11,26 @@ internal static class OptionsHelper
1111
internal static SpidConfiguration CreateFromConfiguration(IConfiguration configuration)
1212
{
1313
var section = configuration.GetSection("Spid");
14-
var options = new SpidConfiguration();
15-
16-
options.IsStagingValidatorEnabled = section.GetValue<bool?>("IsStagingValidatorEnabled") ?? false;
17-
options.IsLocalValidatorEnabled = section.GetValue<bool?>("IsLocalValidatorEnabled") ?? false;
18-
options.AllowUnsolicitedLogins = section.GetValue<bool?>("AllowUnsolicitedLogins") ?? false;
19-
options.AssertionConsumerServiceURL = section.GetValue<string>("AssertionConsumerServiceURL");
20-
options.AssertionConsumerServiceIndex = section.GetValue<ushort?>("AssertionConsumerServiceIndex");
21-
options.AttributeConsumingServiceIndex = section.GetValue<ushort?>("AttributeConsumingServiceIndex") ?? 0;
22-
options.CallbackPath = section.GetValue<string>("CallbackPath");
23-
options.IdPRegistryURL = section.GetValue<string>("IdPRegistryURL");
24-
options.EntityId = section.GetValue<string>("EntityId");
25-
options.RemoteSignOutPath = section.GetValue<string>("RemoteSignOutPath");
26-
options.SignOutScheme = section.GetValue<string>("SignOutScheme");
27-
options.UseTokenLifetime = section.GetValue<bool?>("UseTokenLifetime") ?? false;
28-
options.SkipUnrecognizedRequests = section.GetValue<bool?>("SkipUnrecognizedRequests") ?? true;
29-
options.CacheIdpMetadata = section.GetValue<bool?>("CacheIdpMetadata") ?? true;
30-
options.IdpMetadataCacheDurationInMinutes = section.GetValue<int?>("IdpMetadataCacheDurationInMinutes") ?? 1440;
31-
options.RandomIdentityProvidersOrder = section.GetValue<bool?>("RandomIdentityProvidersOrder") ?? false;
32-
options.SecurityLevel = section.GetValue<int?>("SecurityLevel") ?? 2;
14+
var options = new SpidConfiguration
15+
{
16+
IsStagingValidatorEnabled = section.GetValue<bool?>("IsStagingValidatorEnabled") ?? false,
17+
IsLocalValidatorEnabled = section.GetValue<bool?>("IsLocalValidatorEnabled") ?? false,
18+
AllowUnsolicitedLogins = section.GetValue<bool?>("AllowUnsolicitedLogins") ?? false,
19+
AssertionConsumerServiceURL = section.GetValue<string>("AssertionConsumerServiceURL"),
20+
AssertionConsumerServiceIndex = section.GetValue<ushort?>("AssertionConsumerServiceIndex"),
21+
AttributeConsumingServiceIndex = section.GetValue<ushort?>("AttributeConsumingServiceIndex") ?? 0,
22+
CallbackPath = section.GetValue<string>("CallbackPath"),
23+
IdPRegistryURL = section.GetValue<string>("IdPRegistryURL"),
24+
EntityId = section.GetValue<string>("EntityId"),
25+
RemoteSignOutPath = section.GetValue<string>("RemoteSignOutPath"),
26+
SignOutScheme = section.GetValue<string>("SignOutScheme"),
27+
UseTokenLifetime = section.GetValue<bool?>("UseTokenLifetime") ?? false,
28+
SkipUnrecognizedRequests = section.GetValue<bool?>("SkipUnrecognizedRequests") ?? true,
29+
CacheIdpMetadata = section.GetValue<bool?>("CacheIdpMetadata") ?? true,
30+
IdpMetadataCacheDurationInMinutes = section.GetValue<int?>("IdpMetadataCacheDurationInMinutes") ?? 1440,
31+
RandomIdentityProvidersOrder = section.GetValue<bool?>("RandomIdentityProvidersOrder") ?? false,
32+
SecurityLevel = section.GetValue<int?>("SecurityLevel") ?? 2
33+
};
3334
var requestMethodParsed = Enum.TryParse<RequestMethod>(section.GetValue<string?>("RequestMethod"), out var requestMethod);
3435
options.RequestMethod = requestMethodParsed ? requestMethod : RequestMethod.Post;
3536
options.DefaultLanguage = section.GetValue<string?>("DefaultLanguage") ?? "it";

src/SPID.AspNetCore.Authentication/Helpers/X509Helpers.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
using SPID.AspNetCore.Authentication.Exceptions;
22
using SPID.AspNetCore.Authentication.Resources;
33
using System;
4-
using System.IO;
54
using System.Security.Cryptography;
65
using System.Security.Cryptography.X509Certificates;
76
using System.Text;
@@ -83,7 +82,7 @@ public static string CreateSignature(this string payload, X509Certificate2 certi
8382
return Convert.ToBase64String(rsa.SignHash(hash, HashAlgorithmName.SHA256, RSASignaturePadding.Pkcs1), Base64FormattingOptions.None);
8483
}
8584

86-
public static byte[] ExportPublicKey(this X509Certificate2 cert)
85+
public static byte[] ExportPublicKey(this X509Certificate2 cert)
8786
=> cert.Export(X509ContentType.Cert);
8887
}
8988
}

src/SPID.AspNetCore.Authentication/Models/ServiceProviders/DefaultServiceProvidersFactory.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ namespace SPID.AspNetCore.Authentication.Models.ServiceProviders
55
{
66
internal class DefaultServiceProvidersFactory : IServiceProvidersFactory
77
{
8-
public async Task<List<ServiceProvider>> GetServiceProviders()
8+
public async Task<List<ServiceProvider>> GetServiceProviders()
99
=> await Task.FromResult(new List<ServiceProvider>());
1010
}
1111
}

0 commit comments

Comments
 (0)