Skip to content

Commit

Permalink
Removed Branca and PASETO libraries
Browse files Browse the repository at this point in the history
  • Loading branch information
scottbrady91 committed Mar 29, 2024
1 parent f51f030 commit 0ba9ba4
Show file tree
Hide file tree
Showing 43 changed files with 21 additions and 4,395 deletions.
14 changes: 0 additions & 14 deletions ScottBrady.IdentityModel.sln
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,6 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ScottBrady.IdentityModel.Sa
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ScottBrady.IdentityModel.AspNetCore", "src\ScottBrady.IdentityModel.AspNetCore\ScottBrady.IdentityModel.AspNetCore.csproj", "{E2F2D4E3-A732-43FE-B082-9FD5ACBEA89B}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ScottBrady.IdentityModel.Tokens.Branca", "src\ScottBrady.IdentityModel.Tokens.Branca\ScottBrady.IdentityModel.Tokens.Branca.csproj", "{E27F8536-728B-4855-A8D5-921297CBD58C}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ScottBrady.IdentityModel.Tokens.Paseto", "src\ScottBrady.IdentityModel.Tokens.Paseto\ScottBrady.IdentityModel.Tokens.Paseto.csproj", "{EA07CA1B-4571-4FD1-9BCE-272A68FB48A6}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand All @@ -43,14 +39,6 @@ Global
{E2F2D4E3-A732-43FE-B082-9FD5ACBEA89B}.Debug|Any CPU.Build.0 = Debug|Any CPU
{E2F2D4E3-A732-43FE-B082-9FD5ACBEA89B}.Release|Any CPU.ActiveCfg = Release|Any CPU
{E2F2D4E3-A732-43FE-B082-9FD5ACBEA89B}.Release|Any CPU.Build.0 = Release|Any CPU
{E27F8536-728B-4855-A8D5-921297CBD58C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{E27F8536-728B-4855-A8D5-921297CBD58C}.Debug|Any CPU.Build.0 = Debug|Any CPU
{E27F8536-728B-4855-A8D5-921297CBD58C}.Release|Any CPU.ActiveCfg = Release|Any CPU
{E27F8536-728B-4855-A8D5-921297CBD58C}.Release|Any CPU.Build.0 = Release|Any CPU
{EA07CA1B-4571-4FD1-9BCE-272A68FB48A6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{EA07CA1B-4571-4FD1-9BCE-272A68FB48A6}.Debug|Any CPU.Build.0 = Debug|Any CPU
{EA07CA1B-4571-4FD1-9BCE-272A68FB48A6}.Release|Any CPU.ActiveCfg = Release|Any CPU
{EA07CA1B-4571-4FD1-9BCE-272A68FB48A6}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand All @@ -60,8 +48,6 @@ Global
{B57DDA53-D240-46ED-8275-F19600491681} = {FA25402D-0A81-48F1-9E83-7CA4801E59F9}
{B7F49824-C721-4BD1-9BAF-6E442AEAB14D} = {0787B459-DE3E-4296-965C-5C891AE23840}
{E2F2D4E3-A732-43FE-B082-9FD5ACBEA89B} = {2CE8E91B-6B6A-4C1F-B6FE-80A1F1199A7A}
{E27F8536-728B-4855-A8D5-921297CBD58C} = {2CE8E91B-6B6A-4C1F-B6FE-80A1F1199A7A}
{EA07CA1B-4571-4FD1-9BCE-272A68FB48A6} = {2CE8E91B-6B6A-4C1F-B6FE-80A1F1199A7A}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {7ACFEAF2-1A47-419B-989B-75A0A686D710}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.Json.Nodes;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Identity;
Expand All @@ -10,9 +10,6 @@
using Microsoft.IdentityModel.Tokens;
using ScottBrady.IdentityModel.Crypto;
using ScottBrady.IdentityModel.Samples.AspNetCore.Models;
using ScottBrady.IdentityModel.Tokens;
using ScottBrady.IdentityModel.Tokens.Branca;
using ScottBrady.IdentityModel.Tokens.Paseto;

namespace ScottBrady.IdentityModel.Samples.AspNetCore.Controllers;

Expand All @@ -31,59 +28,6 @@ public IActionResult Index()
{
return View();
}

[HttpGet]
public IActionResult Branca()
{
var handler = new BrancaTokenHandler();

var token = handler.CreateToken(new SecurityTokenDescriptor
{
Issuer = "me",
Audience = "you",
EncryptingCredentials = options.BrancaEncryptingCredentials
});

var parsedToken = handler.DecryptToken(token, ((SymmetricSecurityKey) options.BrancaEncryptingCredentials.Key).Key);

return View("Index", new TokenModel
{
Type = "Branca",
Token = token,
Payload = Encoding.UTF8.GetString(parsedToken.Payload)
});
}

[HttpGet]
public IActionResult Paseto(string version)
{
var handler = new PasetoTokenHandler();

SigningCredentials signingCredentials;
if (version == PasetoConstants.Versions.V1)
signingCredentials = new SigningCredentials(options.PasetoV1PrivateKey, SecurityAlgorithms.RsaSsaPssSha384);
else if (version == PasetoConstants.Versions.V2)
signingCredentials = new SigningCredentials(options.EdDsaPrivateKey, ExtendedSecurityAlgorithms.EdDsa);
else
throw new NotSupportedException("Unsupported version");

var descriptor = new PasetoSecurityTokenDescriptor(version, PasetoConstants.Purposes.Public)
{
Issuer = "me",
Audience = "you",
SigningCredentials = signingCredentials
};

var token = handler.CreateToken(descriptor);
var payload = descriptor.ToJwtPayload(JwtDateTimeFormat.Iso);

return View("Index", new TokenModel
{
Type = "PASETO",
Token = token,
Payload = payload
});
}

[HttpGet]
public IActionResult EdDsaJwt()
Expand All @@ -98,18 +42,31 @@ public IActionResult EdDsaJwt()
};

var token = handler.CreateToken(descriptor);
var payload = descriptor.ToJwtPayload(JwtDateTimeFormat.Iso);
var payloadClaims = handler.ReadJsonWebToken(token).Claims;

var claimsJson = new JsonObject();
foreach (var claim in payloadClaims)
{
if (claim.ValueType.Contains("integer"))
{
claimsJson.Add(claim.Type, int.Parse(claim.Value));
}
else
{
claimsJson.Add(claim.Type, claim.Value);
}
}

return View("Index", new TokenModel
{
Type = "EdDSA JWT",
Token = token,
Payload = payload
Payload = claimsJson.ToString()
});
}

[HttpGet]
[Authorize(AuthenticationSchemes = "branca-bearer,paseto-bearer-v1,paseto-bearer-v2,eddsa")]
[Authorize(AuthenticationSchemes = "eddsa")]
public IActionResult CallApi()
{
return Ok();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,36 +1,11 @@
using System;
using System.Security.Cryptography;
using Microsoft.IdentityModel.Tokens;
using ScottBrady.IdentityModel.Crypto;
using ScottBrady.IdentityModel.Tokens;

namespace ScottBrady.IdentityModel.Samples.AspNetCore;

public class SampleOptions
{
private EncryptingCredentials encryptingCredentials;

public EncryptingCredentials BrancaEncryptingCredentials
{
get
{
if (encryptingCredentials == null)
{
var key = new byte[32];
RandomNumberGenerator.Create().GetBytes(key);

encryptingCredentials = new EncryptingCredentials(
new SymmetricSecurityKey(key),
ExtendedSecurityAlgorithms.XChaCha20Poly1305);
}

return encryptingCredentials;
}
}

public RsaSecurityKey PasetoV1PrivateKey = new RsaSecurityKey(RSA.Create());
public RsaSecurityKey PasetoV1PublicKey => new RsaSecurityKey(RSA.Create(PasetoV1PrivateKey.Rsa.ExportParameters(false)));

public readonly EdDsaSecurityKey EdDsaPublicKey = new EdDsaSecurityKey(
EdDsa.Create(new EdDsaParameters(ExtendedSecurityAlgorithms.Curves.Ed25519) {X =Convert.FromBase64String("doaS7QILHBdnPULlgs1fX0MWpd1wak14r1yT6ae/b4M=")}));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@

<ItemGroup>
<ProjectReference Include="..\..\src\ScottBrady.IdentityModel.AspNetCore\ScottBrady.IdentityModel.AspNetCore.csproj" />
<ProjectReference Include="..\..\src\ScottBrady.IdentityModel.Tokens.Branca\ScottBrady.IdentityModel.Tokens.Branca.csproj" />
<ProjectReference Include="..\..\src\ScottBrady.IdentityModel.Tokens.Paseto\ScottBrady.IdentityModel.Tokens.Paseto.csproj" />
<ProjectReference Include="..\..\src\ScottBrady.IdentityModel\ScottBrady.IdentityModel.csproj" />
</ItemGroup>

Expand Down
31 changes: 0 additions & 31 deletions samples/ScottBrady.IdentityModel.Samples.AspNetCore/Startup.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
using System.Collections.Generic;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Identity;
using Microsoft.AspNetCore.Identity.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.IdentityModel.Logging;
using ScottBrady.IdentityModel.AspNetCore.Identity;
using ScottBrady.IdentityModel.Tokens.Branca;
using ScottBrady.IdentityModel.Tokens.Paseto;

namespace ScottBrady.IdentityModel.Samples.AspNetCore;

Expand All @@ -24,34 +21,6 @@ public void ConfigureServices(IServiceCollection services)
services.AddSingleton(sampleOptions);

services.AddAuthentication()
.AddJwtBearer("branca-bearer", options =>
{
options.SecurityTokenValidators.Clear();
options.SecurityTokenValidators.Add(new BrancaTokenHandler());
options.TokenValidationParameters.TokenDecryptionKey = sampleOptions.BrancaEncryptingCredentials.Key;
options.TokenValidationParameters.ValidIssuer = "me";
options.TokenValidationParameters.ValidAudience = "you";
})
.AddJwtBearer("paseto-bearer-v1", options =>
{
options.SecurityTokenValidators.Clear();
options.SecurityTokenValidators.Add(new PasetoTokenHandler(
new Dictionary<string, PasetoVersionStrategy> {{PasetoConstants.Versions.V1, new PasetoVersion1()}}));
options.TokenValidationParameters.IssuerSigningKey = sampleOptions.PasetoV1PublicKey;
options.TokenValidationParameters.ValidIssuer = "me";
options.TokenValidationParameters.ValidAudience = "you";
})
.AddJwtBearer("paseto-bearer-v2", options =>
{
options.SecurityTokenValidators.Clear();
options.SecurityTokenValidators.Add(new PasetoTokenHandler(
new Dictionary<string, PasetoVersionStrategy> {{PasetoConstants.Versions.V2, new PasetoVersion2()}}));
options.TokenValidationParameters.IssuerSigningKey = sampleOptions.EdDsaPublicKey;
options.TokenValidationParameters.ValidIssuer = "me";
options.TokenValidationParameters.ValidAudience = "you";
})
.AddJwtBearer("eddsa", options =>
{
options.TokenValidationParameters.IssuerSigningKey = sampleOptions.EdDsaPublicKey;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,6 @@
<div class="px-5">
<h1 class="display-4 text-center">ScottBrady.IdentityModel</h1>
<p class="text-center">Identity & Crypto helpers</p>
<p>
<a asp-action="Branca">Get Branca token</a>
</p>
<p>
<a asp-action="Paseto" asp-route-version="v1">Get PASETO v1.public</a>
</p>
<p>
<a asp-action="Paseto" asp-route-version="v2">Get PASETO v2.public</a>
</p>
<p>
<a asp-action="EdDsaJwt" asp-route-version="v2">Get EdDSA JWT</a>
</p>
Expand Down
23 changes: 0 additions & 23 deletions src/ScottBrady.IdentityModel.Tokens.Branca/BrancaSecurityToken.cs

This file was deleted.

34 changes: 0 additions & 34 deletions src/ScottBrady.IdentityModel.Tokens.Branca/BrancaToken.cs

This file was deleted.

Loading

0 comments on commit 0ba9ba4

Please sign in to comment.