Skip to content

Commit 8658dd3

Browse files
authored
Merge pull request #87 from kdeng00/update_namespace
Migrating to modern c# namespace
2 parents 37cfda8 + c17c9cd commit 8658dd3

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+2982
-3034
lines changed

Authorization/Handlers/HasScopeHandler.cs

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -6,26 +6,25 @@
66

77
using Icarus.Authorization;
88

9-
namespace Icarus.Authorization.Handlers
9+
namespace Icarus.Authorization.Handlers;
10+
11+
public class HasScopeHandler : AuthorizationHandler<HasScopeRequirement>
1012
{
11-
public class HasScopeHandler : AuthorizationHandler<HasScopeRequirement>
13+
protected override Task HandleRequirementAsync(AuthorizationHandlerContext context, HasScopeRequirement requirement)
1214
{
13-
protected override Task HandleRequirementAsync(AuthorizationHandlerContext context, HasScopeRequirement requirement)
15+
if (!context.User.HasClaim(c => c.Type == "scope" && c.Issuer == requirement.Issuer))
1416
{
15-
if (!context.User.HasClaim(c => c.Type == "scope" && c.Issuer == requirement.Issuer))
16-
{
17-
return Task.CompletedTask;
18-
}
19-
20-
var scopes = context.User.FindFirst(c =>
21-
c.Type == "scope" && c.Issuer == requirement.Issuer).Value.Split(' ');
17+
return Task.CompletedTask;
18+
}
2219

23-
if (scopes.Any(s => s == requirement.Scope))
24-
{
25-
context.Succeed(requirement);
26-
}
20+
var scopes = context.User.FindFirst(c =>
21+
c.Type == "scope" && c.Issuer == requirement.Issuer).Value.Split(' ');
2722

28-
return Task.CompletedTask;
23+
if (scopes.Any(s => s == requirement.Scope))
24+
{
25+
context.Succeed(requirement);
2926
}
27+
28+
return Task.CompletedTask;
3029
}
3130
}

Authorization/HasScopeRequirement.cs

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,17 @@
22

33
using Microsoft.AspNetCore.Authorization;
44

5-
namespace Icarus.Authorization
5+
namespace Icarus.Authorization;
6+
7+
public class HasScopeRequirement : IAuthorizationRequirement
68
{
7-
public class HasScopeRequirement : IAuthorizationRequirement
8-
{
9-
public string Issuer { get; }
10-
public string Scope { get; }
9+
public string Issuer { get; }
10+
public string Scope { get; }
1111

1212

13-
public HasScopeRequirement(string scope, string issuer)
14-
{
15-
Scope = scope ?? throw new ArgumentNullException(nameof(scope));
16-
Issuer = issuer ?? throw new ArgumentNullException(nameof(issuer));
17-
}
13+
public HasScopeRequirement(string scope, string issuer)
14+
{
15+
Scope = scope ?? throw new ArgumentNullException(nameof(scope));
16+
Issuer = issuer ?? throw new ArgumentNullException(nameof(issuer));
1817
}
1918
}

Certs/Signing.cs

Lines changed: 53 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -6,75 +6,74 @@
66
using Org.BouncyCastle.OpenSsl;
77

88

9-
namespace Icarus.Certs
9+
namespace Icarus.Certs;
10+
11+
public class SigningIssuerCertificate : IDisposable
1012
{
11-
public class SigningIssuerCertificate : IDisposable
13+
private readonly RSACryptoServiceProvider _rsa;
14+
15+
public SigningIssuerCertificate()
1216
{
13-
private readonly RSACryptoServiceProvider _rsa;
17+
_rsa = new RSACryptoServiceProvider();
18+
}
1419

15-
public SigningIssuerCertificate()
16-
{
17-
_rsa = new RSACryptoServiceProvider();
18-
}
20+
public RsaSecurityKey GetIssuerSigningKey(string publicKeyPath)
21+
{
22+
var file = publicKeyPath;
23+
var publicKey = System.IO.File.ReadAllText(file);
1924

20-
public RsaSecurityKey GetIssuerSigningKey(string publicKeyPath)
25+
using (var reader = System.IO.File.OpenText(file))
2126
{
22-
var file = publicKeyPath;
23-
var publicKey = System.IO.File.ReadAllText(file);
24-
25-
using (var reader = System.IO.File.OpenText(file))
26-
{
27-
var pem = new PemReader(reader);
28-
var o = (RsaKeyParameters)pem.ReadObject();
29-
var parameters = new RSAParameters();
30-
parameters.Modulus = o.Modulus.ToByteArray();
31-
parameters.Exponent = o.Exponent.ToByteArray();
32-
_rsa.ImportParameters(parameters);
33-
}
34-
35-
return new RsaSecurityKey(_rsa);
27+
var pem = new PemReader(reader);
28+
var o = (RsaKeyParameters)pem.ReadObject();
29+
var parameters = new RSAParameters();
30+
parameters.Modulus = o.Modulus.ToByteArray();
31+
parameters.Exponent = o.Exponent.ToByteArray();
32+
_rsa.ImportParameters(parameters);
3633
}
3734

35+
return new RsaSecurityKey(_rsa);
36+
}
3837

39-
public void Dispose()
40-
{
41-
_rsa?.Dispose();
42-
}
38+
39+
public void Dispose()
40+
{
41+
_rsa?.Dispose();
4342
}
43+
}
4444

4545

46-
public class SigningAudienceCertificate : IDisposable
46+
public class SigningAudienceCertificate : IDisposable
47+
{
48+
private readonly RSACryptoServiceProvider _rsa;
49+
50+
public SigningAudienceCertificate()
4751
{
48-
private readonly RSACryptoServiceProvider _rsa;
52+
_rsa = new RSACryptoServiceProvider();
53+
}
4954

50-
public SigningAudienceCertificate()
51-
{
52-
_rsa = new RSACryptoServiceProvider();
53-
}
55+
public SigningCredentials GetAudienceSigningKey(string keyPath)
56+
{
57+
var file = keyPath;
58+
var publicKey = System.IO.File.ReadAllText(file);
5459

55-
public SigningCredentials GetAudienceSigningKey(string keyPath)
60+
using (var reader = System.IO.File.OpenText(file))
5661
{
57-
var file = keyPath;
58-
var publicKey = System.IO.File.ReadAllText(file);
59-
60-
using (var reader = System.IO.File.OpenText(file))
61-
{
62-
var pem = new PemReader(reader);
63-
var o = (RsaKeyParameters)pem.ReadObject();
64-
var parameters = new RSAParameters();
65-
parameters.Modulus = o.Modulus.ToByteArray();
66-
parameters.Exponent = o.Exponent.ToByteArray();
67-
_rsa.ImportParameters(parameters);
68-
}
69-
70-
return new SigningCredentials(
71-
key: new RsaSecurityKey(_rsa),
72-
algorithm: SecurityAlgorithms.RsaSha256);
62+
var pem = new PemReader(reader);
63+
var o = (RsaKeyParameters)pem.ReadObject();
64+
var parameters = new RSAParameters();
65+
parameters.Modulus = o.Modulus.ToByteArray();
66+
parameters.Exponent = o.Exponent.ToByteArray();
67+
_rsa.ImportParameters(parameters);
7368
}
7469

75-
public void Dispose()
76-
{
77-
_rsa?.Dispose();
78-
}
70+
return new SigningCredentials(
71+
key: new RsaSecurityKey(_rsa),
72+
algorithm: SecurityAlgorithms.RsaSha256);
73+
}
74+
75+
public void Dispose()
76+
{
77+
_rsa?.Dispose();
7978
}
80-
}
79+
}

Constants/DirectoryPaths.cs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
using System;
22
using System.IO;
33

4-
namespace Icarus.Constants
4+
namespace Icarus.Constants;
5+
6+
public class DirectoryPaths
57
{
6-
public class DirectoryPaths
7-
{
8-
public static string CoverArtPath =>
9-
Directory.GetCurrentDirectory() + "/Images/Stock/CoverArt.png";
10-
}
8+
public static string CoverArtPath =>
9+
Directory.GetCurrentDirectory() + "/Images/Stock/CoverArt.png";
1110
}

0 commit comments

Comments
 (0)