From ab84147548cccab2428fe1e326902d1472ec39cf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?K=C3=A9vin=20Chalet?= Date: Fri, 10 Sep 2021 18:32:53 +0200 Subject: [PATCH] Remove OpenIddictServerOwinProperties and OpenIddictValidationOwinProperties --- .../OpenIddictServerOwinHandler.cs | 13 +-- .../OpenIddictServerOwinProperties.cs | 91 ------------------- .../OpenIddictValidationOwinHandler.cs | 8 +- .../OpenIddictValidationOwinProperties.cs | 91 ------------------- 4 files changed, 4 insertions(+), 199 deletions(-) delete mode 100644 src/OpenIddict.Server.Owin/OpenIddictServerOwinProperties.cs delete mode 100644 src/OpenIddict.Validation.Owin/OpenIddictValidationOwinProperties.cs diff --git a/src/OpenIddict.Server.Owin/OpenIddictServerOwinHandler.cs b/src/OpenIddict.Server.Owin/OpenIddictServerOwinHandler.cs index 2238f199..98178927 100644 --- a/src/OpenIddict.Server.Owin/OpenIddictServerOwinHandler.cs +++ b/src/OpenIddict.Server.Owin/OpenIddictServerOwinHandler.cs @@ -155,7 +155,7 @@ namespace OpenIddict.Server.Owin return null; } - var properties = new OpenIddictServerOwinProperties(new Dictionary + var properties = new AuthenticationProperties(new Dictionary { [Properties.Error] = context.Error, [Properties.ErrorDescription] = context.ErrorDescription, @@ -168,9 +168,6 @@ namespace OpenIddict.Server.Owin else { // A single main claims-based principal instance can be attached to an authentication ticket. - // To return the most appropriate one, the principal is selected based on the endpoint type. - // Independently of the selected main principal, all principals resolved from validated tokens - // are attached to the authentication properties bag so they can be accessed from user code. var principal = context.EndpointType switch { OpenIddictServerEndpointType.Authorization or OpenIddictServerEndpointType.Logout @@ -203,7 +200,7 @@ namespace OpenIddict.Server.Owin return null; } - var properties = new OpenIddictServerOwinProperties + var properties = new AuthenticationProperties { ExpiresUtc = principal.GetExpirationDate(), IssuedUtc = principal.GetCreationDate() @@ -215,37 +212,31 @@ namespace OpenIddict.Server.Owin if (context.AccessTokenPrincipal is not null && !string.IsNullOrEmpty(context.AccessToken)) { properties.Dictionary[TokenTypeHints.AccessToken] = context.AccessToken; - properties.SetParameter(Properties.AccessTokenPrincipal, context.AccessTokenPrincipal); } if (context.AuthorizationCodePrincipal is not null && !string.IsNullOrEmpty(context.AuthorizationCode)) { properties.Dictionary[TokenTypeHints.AuthorizationCode] = context.AuthorizationCode; - properties.SetParameter(Properties.AuthorizationCodePrincipal, context.AuthorizationCodePrincipal); } if (context.DeviceCodePrincipal is not null && !string.IsNullOrEmpty(context.DeviceCode)) { properties.Dictionary[TokenTypeHints.DeviceCode] = context.DeviceCode; - properties.SetParameter(Properties.DeviceCodePrincipal, context.DeviceCodePrincipal); } if (context.IdentityTokenPrincipal is not null && !string.IsNullOrEmpty(context.IdentityToken)) { properties.Dictionary[TokenTypeHints.IdToken] = context.IdentityToken; - properties.SetParameter(Properties.IdentityTokenPrincipal, context.IdentityTokenPrincipal); } if (context.RefreshTokenPrincipal is not null && !string.IsNullOrEmpty(context.RefreshToken)) { properties.Dictionary[TokenTypeHints.RefreshToken] = context.RefreshToken; - properties.SetParameter(Properties.RefreshTokenPrincipal, context.RefreshTokenPrincipal); } if (context.UserCodePrincipal is not null && !string.IsNullOrEmpty(context.UserCode)) { properties.Dictionary[TokenTypeHints.UserCode] = context.UserCode; - properties.SetParameter(Properties.UserCodePrincipal, context.UserCodePrincipal); } return new AuthenticationTicket((ClaimsIdentity) principal.Identity, properties); diff --git a/src/OpenIddict.Server.Owin/OpenIddictServerOwinProperties.cs b/src/OpenIddict.Server.Owin/OpenIddictServerOwinProperties.cs deleted file mode 100644 index 20397037..00000000 --- a/src/OpenIddict.Server.Owin/OpenIddictServerOwinProperties.cs +++ /dev/null @@ -1,91 +0,0 @@ -/* - * Licensed under the Apache License, Version 2.0 (http://www.apache.org/licenses/LICENSE-2.0) - * See https://github.com/openiddict/openiddict-core for more information concerning - * the license and the contributors participating to this project. - */ - -using System; -using System.Collections.Generic; -using Microsoft.Owin.Security; -using SR = OpenIddict.Abstractions.OpenIddictResources; - -namespace OpenIddict.Server.Owin -{ - /// - public class OpenIddictServerOwinProperties : AuthenticationProperties - { - /// - public OpenIddictServerOwinProperties() - : this(items: null) - { - } - - /// - public OpenIddictServerOwinProperties(IDictionary? items) - : this(items, parameters: null) - { - } - - /// - /// Initializes a new instance of the class. - /// - /// State values dictionary to use. - /// Parameters dictionary to use. - public OpenIddictServerOwinProperties( - IDictionary? items, - IDictionary? parameters) - : base(items) - => Parameters = parameters is not null ? - new(parameters, StringComparer.Ordinal) : - new(StringComparer.Ordinal); - - /// - /// Gets the collection of parameters passed to the authentication handler. - /// - /// - /// Note: these properties are not intended for serialization or persistence, - /// only for flowing data between call sites. - /// - public Dictionary Parameters { get; } - - /// - /// Gets a parameter from the collection. - /// - /// The parameter type. - /// The parameter name. - /// The parameter value or a default value if the property is not set. - public T? GetParameter(string name) - { - if (string.IsNullOrEmpty(name)) - { - throw new ArgumentException(SR.ID0190, nameof(name)); - } - - return Parameters.TryGetValue(name, out var parameter) && parameter is T value ? value : default; - } - - /// - /// Sets a parameter value in the collection. - /// - /// The parameter type. - /// The parameter key. - /// The value to set. - public void SetParameter(string name, T? value) - { - if (string.IsNullOrEmpty(name)) - { - throw new ArgumentException(SR.ID0190, nameof(name)); - } - - if (value is null) - { - Parameters.Remove(name); - } - - else - { - Parameters[name] = value; - } - } - } -} diff --git a/src/OpenIddict.Validation.Owin/OpenIddictValidationOwinHandler.cs b/src/OpenIddict.Validation.Owin/OpenIddictValidationOwinHandler.cs index e604d9f9..a65e2ca5 100644 --- a/src/OpenIddict.Validation.Owin/OpenIddictValidationOwinHandler.cs +++ b/src/OpenIddict.Validation.Owin/OpenIddictValidationOwinHandler.cs @@ -152,7 +152,7 @@ namespace OpenIddict.Validation.Owin return null; } - var properties = new OpenIddictValidationOwinProperties(new Dictionary + var properties = new AuthenticationProperties(new Dictionary { [Properties.Error] = context.Error, [Properties.ErrorDescription] = context.ErrorDescription, @@ -165,9 +165,6 @@ namespace OpenIddict.Validation.Owin else { // A single main claims-based principal instance can be attached to an authentication ticket. - // To return the most appropriate one, the principal is selected based on the endpoint type. - // Independently of the selected main principal, all principals resolved from validated tokens - // are attached to the authentication properties bag so they can be accessed from user code. var principal = context.EndpointType switch { OpenIddictValidationEndpointType.Unknown => context.AccessTokenPrincipal, @@ -180,7 +177,7 @@ namespace OpenIddict.Validation.Owin return null; } - var properties = new OpenIddictValidationOwinProperties + var properties = new AuthenticationProperties { ExpiresUtc = principal.GetExpirationDate(), IssuedUtc = principal.GetCreationDate() @@ -192,7 +189,6 @@ namespace OpenIddict.Validation.Owin if (context.AccessTokenPrincipal is not null && !string.IsNullOrEmpty(context.AccessToken)) { properties.Dictionary[TokenTypeHints.AccessToken] = context.AccessToken; - properties.SetParameter(Properties.AccessTokenPrincipal, context.AccessTokenPrincipal); } return new AuthenticationTicket((ClaimsIdentity) principal.Identity, properties); diff --git a/src/OpenIddict.Validation.Owin/OpenIddictValidationOwinProperties.cs b/src/OpenIddict.Validation.Owin/OpenIddictValidationOwinProperties.cs deleted file mode 100644 index 1dfb6230..00000000 --- a/src/OpenIddict.Validation.Owin/OpenIddictValidationOwinProperties.cs +++ /dev/null @@ -1,91 +0,0 @@ -/* - * Licensed under the Apache License, Version 2.0 (http://www.apache.org/licenses/LICENSE-2.0) - * See https://github.com/openiddict/openiddict-core for more information concerning - * the license and the contributors participating to this project. - */ - -using System; -using System.Collections.Generic; -using Microsoft.Owin.Security; -using SR = OpenIddict.Abstractions.OpenIddictResources; - -namespace OpenIddict.Validation.Owin -{ - /// - public class OpenIddictValidationOwinProperties : AuthenticationProperties - { - /// - public OpenIddictValidationOwinProperties() - : this(items: null) - { - } - - /// - public OpenIddictValidationOwinProperties(IDictionary? items) - : this(items, parameters: null) - { - } - - /// - /// Initializes a new instance of the class. - /// - /// State values dictionary to use. - /// Parameters dictionary to use. - public OpenIddictValidationOwinProperties( - IDictionary? items, - IDictionary? parameters) - : base(items) - => Parameters = parameters is not null ? - new(parameters, StringComparer.Ordinal) : - new(StringComparer.Ordinal); - - /// - /// Gets the collection of parameters passed to the authentication handler. - /// - /// - /// Note: these properties are not intended for serialization or persistence, - /// only for flowing data between call sites. - /// - public Dictionary Parameters { get; } - - /// - /// Gets a parameter from the collection. - /// - /// The parameter type. - /// The parameter name. - /// The parameter value or a default value if the property is not set. - public T? GetParameter(string name) - { - if (string.IsNullOrEmpty(name)) - { - throw new ArgumentException(SR.ID0190, nameof(name)); - } - - return Parameters.TryGetValue(name, out var parameter) && parameter is T value ? value : default; - } - - /// - /// Sets a parameter value in the collection. - /// - /// The parameter type. - /// The parameter key. - /// The value to set. - public void SetParameter(string name, T? value) - { - if (string.IsNullOrEmpty(name)) - { - throw new ArgumentException(SR.ID0190, nameof(name)); - } - - if (value is null) - { - Parameters.Remove(name); - } - - else - { - Parameters[name] = value; - } - } - } -}