Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use user-provided values as Utf8 #2492

Draft
wants to merge 12 commits into
base: dev
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

using System;
using System.Collections.Generic;
using System.Text;
using System.Text.Json;
using Microsoft.IdentityModel.Logging;
using Microsoft.IdentityModel.Tokens;
Expand Down Expand Up @@ -73,8 +74,15 @@ internal JsonClaimSet CreatePayloadClaimSet(byte[] bytes, int length)
}
else if (reader.ValueTextEquals(JwtPayloadUtf8Bytes.Iss))
{
_iss = JsonSerializerPrimitives.ReadString(ref reader, JwtRegisteredClaimNames.Iss, ClassName, true);
claims[JwtRegisteredClaimNames.Iss] = _iss;
IssuerUtf8 = Encoding.UTF8.GetBytes(JsonSerializerPrimitives.ReadString(ref reader, JwtRegisteredClaimNames.Iss, ClassName, true));
pmaytak marked this conversation as resolved.
Show resolved Hide resolved

//if (!reader.ValueTextEquals(tokenValidationParameters.ValidIssuerUtf8))
//{
// throw new InvalidOperationException();
//}

// Validate
// await Validators.ValidateIssuerAsync
}
else if (reader.ValueTextEquals(JwtPayloadUtf8Bytes.Jti))
{
Expand Down
4 changes: 3 additions & 1 deletion src/Microsoft.IdentityModel.JsonWebTokens/JsonWebToken.cs
Original file line number Diff line number Diff line change
Expand Up @@ -972,11 +972,13 @@ public override string Issuer
{
get
{
_iss ??= Payload.GetStringValue(JwtRegisteredClaimNames.Iss);
_iss ??= IssuerUtf8.ToString();
return _iss;
}
}

internal ReadOnlySpan<byte> IssuerUtf8 { get; set; }

/// <summary>
/// Gets the 'value' of the 'jti' claim from the payload.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using System.Collections.Generic;
using System.ComponentModel;
using System.Security.Claims;
using System.Text;
using System.Threading.Tasks;
using Microsoft.IdentityModel.Abstractions;
using Microsoft.IdentityModel.Logging;
Expand Down Expand Up @@ -893,11 +894,23 @@
/// </summary>
public IEnumerable<string> ValidAudiences { get; set; }

private string _validIssuer;

/// <summary>
/// Gets or sets a <see cref="string"/> that represents a valid issuer that will be used to check against the token's issuer.
/// The default is <c>null</c>.
/// </summary>
public string ValidIssuer { get; set; }
public string ValidIssuer
pmaytak marked this conversation as resolved.
Show resolved Hide resolved
{
get => _validIssuer;
set
{
_validIssuer = value;
ValidIssuerUtf8 = value != null ? Encoding.UTF8.GetBytes(value) : null;
}
}

internal ReadOnlySpan<byte> ValidIssuerUtf8 { get; set; }

Check failure on line 913 in src/Microsoft.IdentityModel.Tokens/TokenValidationParameters.cs

View workflow job for this annotation

GitHub Actions / Wilson GitHub Action Test

Field or auto-implemented property cannot be of type 'ReadOnlySpan<byte>' unless it is an instance member of a ref struct.

Check failure on line 913 in src/Microsoft.IdentityModel.Tokens/TokenValidationParameters.cs

View workflow job for this annotation

GitHub Actions / Wilson GitHub Action Test

Field or auto-implemented property cannot be of type 'ReadOnlySpan<byte>' unless it is an instance member of a ref struct.

Check failure on line 913 in src/Microsoft.IdentityModel.Tokens/TokenValidationParameters.cs

View workflow job for this annotation

GitHub Actions / Wilson GitHub Action Test

Field or auto-implemented property cannot be of type 'ReadOnlySpan<byte>' unless it is an instance member of a ref struct.

Check failure on line 913 in src/Microsoft.IdentityModel.Tokens/TokenValidationParameters.cs

View workflow job for this annotation

GitHub Actions / Wilson GitHub Action Test

Field or auto-implemented property cannot be of type 'ReadOnlySpan<byte>' unless it is an instance member of a ref struct.

Check failure on line 913 in src/Microsoft.IdentityModel.Tokens/TokenValidationParameters.cs

View workflow job for this annotation

GitHub Actions / Wilson GitHub Action Test

Field or auto-implemented property cannot be of type 'ReadOnlySpan<byte>' unless it is an instance member of a ref struct.

Check failure on line 913 in src/Microsoft.IdentityModel.Tokens/TokenValidationParameters.cs

View workflow job for this annotation

GitHub Actions / Wilson GitHub Action Test

Field or auto-implemented property cannot be of type 'ReadOnlySpan<byte>' unless it is an instance member of a ref struct.
pmaytak marked this conversation as resolved.
Show resolved Hide resolved

/// <summary>
/// Gets or sets the <see cref="IEnumerable{String}"/> that contains valid issuers that will be used to check against the token's issuer.
Expand Down
Loading