From d123a83de6333a9ea961d3439df773b7d8736fbf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?K=C3=A9vin=20Chalet?= Date: Wed, 23 Dec 2020 20:55:26 +0100 Subject: [PATCH] Fix the Data Protection formatters to use the same properties format version as ASOS --- src/OpenIddict.Abstractions/OpenIddictResources.resx | 3 +++ .../OpenIddictServerDataProtectionFormatter.cs | 9 +++++---- .../OpenIddictValidationDataProtectionFormatter.cs | 7 ++++--- 3 files changed, 12 insertions(+), 7 deletions(-) diff --git a/src/OpenIddict.Abstractions/OpenIddictResources.resx b/src/OpenIddict.Abstractions/OpenIddictResources.resx index 2222dda2..ed48e9c7 100644 --- a/src/OpenIddict.Abstractions/OpenIddictResources.resx +++ b/src/OpenIddict.Abstractions/OpenIddictResources.resx @@ -1119,6 +1119,9 @@ To register the OpenIddict core services, reference the 'OpenIddict.Core' packag The specified principal doesn't contain a valid claims-based identity. + + The payload of this authentication ticket was serialized using an unsupported formatter version. + The security token is missing. diff --git a/src/OpenIddict.Server.DataProtection/OpenIddictServerDataProtectionFormatter.cs b/src/OpenIddict.Server.DataProtection/OpenIddictServerDataProtectionFormatter.cs index 2f02cb8c..850bb211 100644 --- a/src/OpenIddict.Server.DataProtection/OpenIddictServerDataProtectionFormatter.cs +++ b/src/OpenIddict.Server.DataProtection/OpenIddictServerDataProtectionFormatter.cs @@ -16,6 +16,7 @@ using System.Text.Json; using OpenIddict.Abstractions; using static OpenIddict.Abstractions.OpenIddictConstants; using Properties = OpenIddict.Server.DataProtection.OpenIddictServerDataProtectionConstants.Properties; +using SR = OpenIddict.Abstractions.OpenIddictResources; namespace OpenIddict.Server.DataProtection { @@ -66,7 +67,7 @@ namespace OpenIddict.Server.DataProtection var version = reader.ReadInt32(); if (version != 5) { - return (null, ImmutableDictionary.Create()); + throw new InvalidOperationException(SR.GetResourceString(SR.ID0287)); } // Read the authentication scheme associated to the ticket. @@ -150,9 +151,9 @@ namespace OpenIddict.Server.DataProtection { // Read the version of the format used to serialize the properties. var version = reader.ReadInt32(); - if (version != 5) + if (version != 1) { - return ImmutableDictionary.Create(); + throw new InvalidOperationException(SR.GetResourceString(SR.ID0287)); } var count = reader.ReadInt32(); @@ -363,7 +364,7 @@ namespace OpenIddict.Server.DataProtection static void WriteProperties(BinaryWriter writer, IReadOnlyDictionary properties) { // Write the version of the format used to serialize the properties. - writer.Write(/* version: */ 5); + writer.Write(/* version: */ 1); writer.Write(properties.Count); foreach (var property in properties) diff --git a/src/OpenIddict.Validation.DataProtection/OpenIddictValidationDataProtectionFormatter.cs b/src/OpenIddict.Validation.DataProtection/OpenIddictValidationDataProtectionFormatter.cs index a27d1c96..9d73173d 100644 --- a/src/OpenIddict.Validation.DataProtection/OpenIddictValidationDataProtectionFormatter.cs +++ b/src/OpenIddict.Validation.DataProtection/OpenIddictValidationDataProtectionFormatter.cs @@ -13,6 +13,7 @@ using System.Text.Json; using OpenIddict.Abstractions; using static OpenIddict.Abstractions.OpenIddictConstants; using Properties = OpenIddict.Validation.DataProtection.OpenIddictValidationDataProtectionConstants.Properties; +using SR = OpenIddict.Abstractions.OpenIddictResources; namespace OpenIddict.Validation.DataProtection { @@ -63,7 +64,7 @@ namespace OpenIddict.Validation.DataProtection var version = reader.ReadInt32(); if (version != 5) { - return (null, ImmutableDictionary.Create()); + throw new InvalidOperationException(SR.GetResourceString(SR.ID0287)); } // Read the authentication scheme associated to the ticket. @@ -147,9 +148,9 @@ namespace OpenIddict.Validation.DataProtection { // Read the version of the format used to serialize the properties. var version = reader.ReadInt32(); - if (version != 5) + if (version != 1) { - return ImmutableDictionary.Create(); + throw new InvalidOperationException(SR.GetResourceString(SR.ID0287)); } var count = reader.ReadInt32();