Deprecating asymmetric keys #86

Merged
kdeng00 merged 3 commits from deprecate_asymmetric_keys into master 2022-12-16 14:09:42 -05:00
5 changed files with 12 additions and 24 deletions
+9 -10
View File
@@ -29,10 +29,10 @@ namespace Icarus.Controllers.Managers
#region Fields #region Fields
private string _clientId; private string _clientId;
private string _clientSecret; private string _clientSecret;
private string _privateKeyPath; private string _privateKeyPath = string.Empty;
private string _privateKey; private string _privateKey = string.Empty;
private string _publicKeyPath; private string _publicKeyPath = string.Empty;
private string _publicKey; private string _publicKey = string.Empty;
private string _audience; private string _audience;
private string _grantType; private string _grantType;
private string _url; private string _url;
@@ -88,6 +88,7 @@ namespace Icarus.Controllers.Managers
} }
[Obsolete("Asymmetric key signing for tokens have been deprecated")]
public LoginResult LogIn(User user) public LoginResult LogIn(User user)
{ {
var tokenResult = new TokenTierOne(); var tokenResult = new TokenTierOne();
@@ -152,6 +153,7 @@ namespace Icarus.Controllers.Managers
}; };
} }
[Obsolete("Asymmetric key signing for tokens have been deprecated")]
public bool IsTokenValid(string scope, string accessToken) public bool IsTokenValid(string scope, string accessToken)
{ {
var result = false; var result = false;
@@ -172,6 +174,7 @@ namespace Icarus.Controllers.Managers
return result; return result;
} }
[Obsolete("Asymmetric key signing for tokens have been deprecated")]
public Token DecodeToken(string accessToken) public Token DecodeToken(string accessToken)
{ {
var rsaParams = GetRSAPublic(_publicKey); var rsaParams = GetRSAPublic(_publicKey);
@@ -264,6 +267,7 @@ namespace Icarus.Controllers.Managers
return claim; return claim;
} }
[Obsolete("Asymmetric key signing for tokens have been deprecated")]
private string CreateToken(List<Claim> claims, string privateKey) private string CreateToken(List<Claim> claims, string privateKey)
{ {
var token = string.Empty; var token = string.Empty;
@@ -323,6 +327,7 @@ namespace Icarus.Controllers.Managers
return token; return token;
} }
[Obsolete("Asymmetric key signing for tokens have been deprecated")]
private RSAParameters GetRSAPublic(string publicKey) private RSAParameters GetRSAPublic(string publicKey)
{ {
using (var tr = new System.IO.StringReader(publicKey)) using (var tr = new System.IO.StringReader(publicKey))
@@ -362,12 +367,6 @@ namespace Icarus.Controllers.Managers
_audience = _config["Auth0:ApiIdentifier"]; _audience = _config["Auth0:ApiIdentifier"];
_grantType = "client_credentials"; _grantType = "client_credentials";
_url = $"https://{_config["Auth0:Domain"]}"; _url = $"https://{_config["Auth0:Domain"]}";
_privateKeyPath = _config["RSAKeys:PrivateKeyPath"];
_publicKeyPath = _config["RSAKeys:PublicKeyPath"];
_privateKey = System.IO.File.ReadAllText(_privateKeyPath);
_publicKey = System.IO.File.ReadAllText(_publicKeyPath);
PrintCredentials();
} }
#region Testing Methods #region Testing Methods
-5
View File
@@ -53,11 +53,6 @@ namespace Icarus.Controllers.V1
[HttpGet("{id}")] [HttpGet("{id}")]
public IActionResult GetArtist(int id) public IActionResult GetArtist(int id)
{ {
if (!IsTokenValid("read:artists"))
{
return StatusCode(401, "Not allowed");
}
Artist artist = new Artist Artist artist = new Artist
{ {
ArtistID = id ArtistID = id
+3 -1
View File
@@ -18,6 +18,7 @@ namespace Icarus.Controllers.V1
#region Methods #region Methods
[ApiExplorerSettings(IgnoreApi = true)] [ApiExplorerSettings(IgnoreApi = true)]
[Obsolete("Asymmetric key signing for tokens have been deprecated")]
protected string ParseBearerTokenFromHeader() protected string ParseBearerTokenFromHeader()
{ {
var token = string.Empty; var token = string.Empty;
@@ -39,6 +40,7 @@ namespace Icarus.Controllers.V1
} }
[ApiExplorerSettings(IgnoreApi = true)] [ApiExplorerSettings(IgnoreApi = true)]
[Obsolete("Asymmetric key signing for tokens have been deprecated")]
protected bool IsTokenValid(string scope) protected bool IsTokenValid(string scope)
{ {
var token = ParseBearerTokenFromHeader(); var token = ParseBearerTokenFromHeader();
@@ -48,4 +50,4 @@ namespace Icarus.Controllers.V1
} }
#endregion #endregion
} }
} }
-4
View File
@@ -12,10 +12,6 @@
"ClientId": "", "ClientId": "",
"ClientSecret": "" "ClientSecret": ""
}, },
"RSAKeys": {
"PrivateKeyPath": "",
"PublicKeyPath": ""
},
"JWT": { "JWT": {
"Issuer": "", "Issuer": "",
"Audience": "", "Audience": "",
-4
View File
@@ -12,10 +12,6 @@
"ClientId": "", "ClientId": "",
"ClientSecret": "" "ClientSecret": ""
}, },
"RSAKeys": {
"PrivateKeyPath": "",
"PublicKeyPath": ""
},
"JWT": { "JWT": {
"Issuer": "", "Issuer": "",
"Audience": "", "Audience": "",