diff --git a/src/BulwarkToken/DefaultTokenizer.cs b/src/BulwarkToken/DefaultTokenizer.cs deleted file mode 100644 index dac099c..0000000 --- a/src/BulwarkToken/DefaultTokenizer.cs +++ /dev/null @@ -1,114 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Security.Cryptography; -using Bulwark.Repositories; -using JWT.Algorithms; -using JWT.Builder; - -namespace Bulwark.Token -{ - public class DefaultTokenizer : ITokenizer - { - public string Name { get; } - public string Issuer { get; } - public string Audience { get; } - - private Dictionary _certs; - private RSA _privateKey; - private RSA _publicKey; - - public DefaultTokenizer(string issuer, string audience, - RSA privateKey, RSA publicKey) - { - _privateKey = privateKey; - _publicKey = publicKey; - Name = "default"; - Issuer = issuer; - Audience = audience; - } - - public string CreateAccessToken(string userId) - { - var token = JwtBuilder.Create() - .WithAlgorithm(new RS256Algorithm(_publicKey, - _privateKey)) - .AddHeader("use", "access") - .Id(Guid.NewGuid().ToString()) - .Issuer(Issuer) - .Audience(Audience) - .AddClaim("exp", - DateTimeOffset.UtcNow.AddHours(1) - .ToUnixTimeSeconds()) - .AddClaim("sub", userId) - .Encode(); - - return token; - } - - public string CreateIdToken( - Dictionary idClaims, string salt) - { - var token = JwtBuilder.Create() - .WithAlgorithm(new HMACSHA256Algorithm()) - .AddHeader("use", "identity") - .Id(Guid.NewGuid().ToString()) - .WithSecret(salt) - .AddClaim("exp", DateTimeOffset.UtcNow.AddHours(1) - .ToUnixTimeSeconds()) - .AddClaim("iss", Issuer) - .AddClaim("aud", Audience); - - token.AddClaims(idClaims); - return token.Encode(); - } - - public string CreateRefreshToken(string userId, string salt) - { - var token = JwtBuilder.Create() - .WithAlgorithm(new HMACSHA256Algorithm()) - .WithSecret(salt) - .AddHeader("use", "refresh") - .Id(Guid.NewGuid().ToString()) - .Issuer(Issuer) - .Audience(Audience) - .AddClaim("exp", DateTimeOffset.UtcNow.AddHours(1) - .ToUnixTimeSeconds()) - .AddClaim("sub", userId) - .Encode(); - - return token; - } - - public string ValidateAccessToken(string token) - { - var json = JwtBuilder.Create() - .WithAlgorithm(new RS256Algorithm(_publicKey)) - .MustVerifySignature() - .Decode(token); - - return json; - } - - public string ValidateIdToken(string token, string salt) - { - var json = JwtBuilder.Create() - .WithAlgorithm(new HMACSHA256Algorithm()) - .WithSecret(salt) - .MustVerifySignature() - .Decode(token); - - return json; - } - - public string ValidateRefreshToken(string token, string salt) - { - var json = JwtBuilder.Create() - .WithAlgorithm(new HMACSHA256Algorithm()) - .WithSecret(salt) - .MustVerifySignature() - .Decode(token); - - return json; - } - } -} diff --git a/src/BulwarkToken/ITokenizer.cs b/src/BulwarkToken/ITokenizer.cs deleted file mode 100644 index e5c1105..0000000 --- a/src/BulwarkToken/ITokenizer.cs +++ /dev/null @@ -1,19 +0,0 @@ -using System; -using System.Collections.Generic; - -namespace Bulwark.Token -{ - public interface ITokenizer - { - string Issuer { get; } - string Audience { get; } - string Name { get; } - string CreateAccessToken(string userId); - string CreateIdToken( - Dictionary idClaims, string salt); - string CreateRefreshToken(string userId, string salt); - string ValidateAccessToken(string token); - string ValidateIdToken(string token, string salt); - string ValidateRefreshToken(string token, string salt); - } -} diff --git a/src/BulwarkToken/Token.csproj b/src/BulwarkToken/Token.csproj deleted file mode 100644 index 423321e..0000000 --- a/src/BulwarkToken/Token.csproj +++ /dev/null @@ -1,17 +0,0 @@ - - - - netstandard2.1 - Bulwark.Token - - - - - - - - - - - - diff --git a/src/BulwarkToken/TokenStrategyContext.cs b/src/BulwarkToken/TokenStrategyContext.cs deleted file mode 100644 index b42a2eb..0000000 --- a/src/BulwarkToken/TokenStrategyContext.cs +++ /dev/null @@ -1,71 +0,0 @@ -using System; -using System.Collections.Generic; -using Newtonsoft.Json.Linq; - -namespace Bulwark.Token -{ - public class TokenStrategyContext - { - private Dictionary _tokenizers; - - public TokenStrategyContext(List tokenizers) - { - _tokenizers = new Dictionary(); - foreach (var tokenizer in tokenizers) - { - Add(tokenizer); - } - } - - public TokenStrategyContext() - { - _tokenizers = new Dictionary(); - } - - public void Add(ITokenizer tokenizer) - { - _tokenizers.Add(tokenizer.Name, tokenizer); - } - - public string CreateAccessToken(string userId, string name = "default") - { - var tokenizer = _tokenizers[name]; - return tokenizer.CreateAccessToken(userId); - } - - public string CreateIdToken(Dictionary idClaims, - string salt, - string name = "default") - { - var tokenizer = _tokenizers[name]; - return tokenizer.CreateIdToken(idClaims, salt); - } - - public string CreateRefreshToken(string userId, string salt, - string name = "default") - { - var tokenizer = _tokenizers[name]; - return tokenizer.CreateRefreshToken(userId, salt); - } - - public JObject ValidateAccessToken(string token, string name = "default") - { - var json = _tokenizers[name].ValidateAccessToken(token); - return JObject.Parse(json); - } - - public JObject ValidateRefreshToken(string token, string salt, - string name = "default") - { - var json = _tokenizers[name].ValidateRefreshToken(token, salt); - return JObject.Parse(json); - } - - public JObject ValidateIdToken(string token, string salt, - string name = "default") - { - var json = _tokenizers[name].ValidateIdToken(token, salt); - return JObject.Parse(json); - } - } -}