Skip to content

Commit

Permalink
Add JWT ctor that accepts a span
Browse files Browse the repository at this point in the history
Update YAML to build previews

Add ReadOnlySpan overloads

Add benchmark

Add ValidateAndGetOutputSize for spans

Remove duplication

Update benchmark

Remove duplicates

Update

Add benchmarks

Update

Replace ReadyOnlySpan with ReadOnlyMemory

Update test

Update benchmark naming

Move ArrayPool to JsonWebToken level

Update CreateHeaderClaimSet

Update benchmark for JWE to resolve error

Fix a typo (#2479)

* update comment for azp in jsonwebtoken

* removed extra words

Link to breaking change announcement in IDX10506 (#2478)

When an IDX10506 exception is thrown from JsonWebTokenHandler, there's a
good chance this is due to a breaking change to ASP.NET Core 8.

This adds a link to the breaking change announcement at
https://learn.microsoft.com/en-us/dotnet/core/compatibility/aspnet-core/8.0/securitytoken-events

7.3.1 changelog (#2476)

* 7.3.1 changelog

* two additions

* add space

fix log message dup (#2481)

Reduce duplication

Fix comment

Set _encodedTokenMemory as readonly

Remove unnecessary private method

Use Base64UrlEncoding.Decode with action

Use ValidateAndGetOutputSize(ReadOnlySpan<char> strSpan..) thoughout

Add tests

Revert change

Temporarily allow publishing to NuGet

use just `1` for preview

up version to 7.4.0 for preview

Separate JWS and JWE benchmarks
  • Loading branch information
Sruthi Keerthi Rangavajhula committed Feb 24, 2024
1 parent 131d476 commit 1b2845a
Show file tree
Hide file tree
Showing 19 changed files with 396 additions and 136 deletions.
14 changes: 14 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,19 @@
See the [releases](https://github.com/AzureAD/azure-activedirectory-identitymodel-extensions-for-dotnet/releases) for details on bug fixes and added features.

7.3.1
======
### Bug Fixes:
- Replace propertyName with `MetadataName` constant. See issue [#2471](https://github.com/AzureAD/azure-activedirectory-identitymodel-extensions-for-dotnet/issues/2471) for details.
- Fix 6x to 7x regression where mixed cases OIDC json was not correctly process. See [#2404](https://github.com/AzureAD/azure-activedirectory-identitymodel-extensions-for-dotnet/issues/2402) and [#2402](https://github.com/AzureAD/azure-activedirectory-identitymodel-extensions-for-dotnet/issues/2402) for details.

### Performance Improvements:
- Update the benchmark configuration. See issue [#2468](https://github.com/AzureAD/azure-activedirectory-identitymodel-extensions-for-dotnet/issues/2468).

### Documentation:
- Update comment for `azp` in `JsonWebToken`. See [#2475](https://github.com/AzureAD/azure-activedirectory-identitymodel-extensions-for-dotnet/issues/2475) for details.
- Link to breaking change announcement. See [#2478].
- Fix typo in log message. See [#2479].

7.3.0
======
### New Features:
Expand Down
4 changes: 4 additions & 0 deletions benchmark/Microsoft.IdentityModel.Benchmarks/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ public static void Main(string[] args)
}
private static void DebugThroughTests()
{
ReadJWETokenTests readTokenTests = new ReadJWETokenTests();
readTokenTests.Setup();
readTokenTests.ReadJWE_FromMemory();

AsymmetricAdapterSignatures asymmetricAdapter = new AsymmetricAdapterSignatures();
asymmetricAdapter.Setup();
asymmetricAdapter.SignDotnetCreatingBufferRSA();
Expand Down
47 changes: 47 additions & 0 deletions benchmark/Microsoft.IdentityModel.Benchmarks/ReadJWETokenTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

using System;
using BenchmarkDotNet.Attributes;
using Microsoft.IdentityModel.JsonWebTokens;
using Microsoft.IdentityModel.Tokens;

namespace Microsoft.IdentityModel.Benchmarks
{
// dotnet run -c release -f net8.0 --filter Microsoft.IdentityModel.Benchmarks.ReadTokenTests*

[Config(typeof(BenchmarkConfig))]
[HideColumns("Type", "Job", "WarmupCount", "LaunchCount")]
[MemoryDiagnoser]
public class ReadJWETokenTests
{
string _encryptedJWE;

[GlobalSetup]
public void Setup()
{
var jsonWebTokenHandler = new JsonWebTokenHandler();
var jweTokenDescriptor = new SecurityTokenDescriptor
{
SigningCredentials = BenchmarkUtils.SigningCredentialsRsaSha256,
EncryptingCredentials = BenchmarkUtils.EncryptingCredentialsAes256Sha512,
TokenType = JwtHeaderParameterNames.Jwk,
Claims = BenchmarkUtils.Claims
};

_encryptedJWE = jsonWebTokenHandler.CreateToken(jweTokenDescriptor);
}

[Benchmark]
public JsonWebToken ReadJWE_FromString()
{
return new JsonWebToken(_encryptedJWE);
}

[Benchmark]
public JsonWebToken ReadJWE_FromMemory()
{
return new JsonWebToken(_encryptedJWE.AsMemory());
}
}
}
47 changes: 47 additions & 0 deletions benchmark/Microsoft.IdentityModel.Benchmarks/ReadJWSTokenTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

using System;
using BenchmarkDotNet.Attributes;
using Microsoft.IdentityModel.JsonWebTokens;
using Microsoft.IdentityModel.Tokens;

namespace Microsoft.IdentityModel.Benchmarks
{
// dotnet run -c release -f net8.0 --filter Microsoft.IdentityModel.Benchmarks.ReadJWSTokenTests*

[Config(typeof(BenchmarkConfig))]
[HideColumns("Type", "Job", "WarmupCount", "LaunchCount")]
[MemoryDiagnoser]
[RankColumn]
public class ReadJWSTokenTests
{
string _encodedJWS;

[GlobalSetup]
public void Setup()
{
var jsonWebTokenHandler = new JsonWebTokenHandler();
var jwsTokenDescriptor = new SecurityTokenDescriptor
{
SigningCredentials = BenchmarkUtils.SigningCredentialsRsaSha256,
TokenType = JwtHeaderParameterNames.Jwk,
Claims = BenchmarkUtils.Claims
};

_encodedJWS = jsonWebTokenHandler.CreateToken(jwsTokenDescriptor);
}

[Benchmark]
public JsonWebToken ReadJWS_FromString()
{
return new JsonWebToken(_encodedJWS);
}

[Benchmark]
public JsonWebToken ReadJWS_FromMemory()
{
return new JsonWebToken(_encodedJWS.AsMemory());
}
}
}
10 changes: 9 additions & 1 deletion build/releaseBuild.yml
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ jobs:
inputs:
targetType: filePath
filePath: ./updateAssemblyInfo.ps1
arguments: '-packageType $(BuildConfiguration)'
arguments: '-packageType $(NugetPackageType)'

- task: DotNetCoreCLI@2
displayName: Build
Expand Down Expand Up @@ -195,6 +195,14 @@ jobs:
BuildDropPath: '$(Build.SourcesDirectory)\src'
ManifestDirPath: '$(Build.SourcesDirectory)\artifacts'

- task: NuGetCommand@2
displayName: 'Upload NuGet Package to VSTS NuGet'
inputs:
command: push
packagesToPush: '$(Build.Repository.LocalPath)\artifacts\*.nupkg'
publishVstsFeed: '46419298-b96c-437f-bd4c-12c8df7f868d'
allowPackageConflicts: true

- task: PublishBuildArtifacts@1
displayName: 'Publish NuGet Package Artifact'
inputs:
Expand Down
2 changes: 1 addition & 1 deletion buildConfiguration.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<dotnetArchitecture>x64</dotnetArchitecture>
<nugetVersion>3.5.0-rc-1285</nugetVersion>
<runtimes>net461,netstandard2.0</runtimes>
<assemblyVersion>7.3.1</assemblyVersion>
<assemblyVersion>7.4.0</assemblyVersion>
<nugetSuffix>preview</nugetSuffix>
<projects>
<src>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,17 @@ public partial class JsonWebToken
{
internal JsonClaimSet CreateHeaderClaimSet(byte[] bytes)
{
return CreateHeaderClaimSet(bytes, bytes.Length);
return CreateHeaderClaimSet(bytes.AsSpan());
}

internal JsonClaimSet CreateHeaderClaimSet(byte[] bytes, int length)
{
Utf8JsonReader reader = new(bytes.AsSpan().Slice(0, length));
return CreateHeaderClaimSet(bytes.AsSpan(0, length));
}

internal JsonClaimSet CreateHeaderClaimSet(ReadOnlySpan<byte> byteSpan)
{
Utf8JsonReader reader = new(byteSpan);
if (!JsonSerializerPrimitives.IsReaderAtTokenType(ref reader, JsonTokenType.StartObject, false))
throw LogHelper.LogExceptionMessage(
new JsonException(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,12 @@ public partial class JsonWebToken
{
internal JsonClaimSet CreatePayloadClaimSet(byte[] bytes, int length)
{
Utf8JsonReader reader = new(bytes.AsSpan().Slice(0, length));
return CreatePayloadClaimSet(bytes.AsSpan(0, length));
}

internal JsonClaimSet CreatePayloadClaimSet(ReadOnlySpan<byte> byteSpan)
{
Utf8JsonReader reader = new(byteSpan);
if (!JsonSerializerPrimitives.IsReaderAtTokenType(ref reader, JsonTokenType.StartObject, false))
throw LogHelper.LogExceptionMessage(
new JsonException(
Expand Down
Loading

0 comments on commit 1b2845a

Please sign in to comment.