Browse Source

Remove OpenIddictServerOwinProperties and OpenIddictValidationOwinProperties

pull/1322/head
Kévin Chalet 5 years ago
parent
commit
ab84147548
  1. 13
      src/OpenIddict.Server.Owin/OpenIddictServerOwinHandler.cs
  2. 91
      src/OpenIddict.Server.Owin/OpenIddictServerOwinProperties.cs
  3. 8
      src/OpenIddict.Validation.Owin/OpenIddictValidationOwinHandler.cs
  4. 91
      src/OpenIddict.Validation.Owin/OpenIddictValidationOwinProperties.cs

13
src/OpenIddict.Server.Owin/OpenIddictServerOwinHandler.cs

@ -155,7 +155,7 @@ namespace OpenIddict.Server.Owin
return null;
}
var properties = new OpenIddictServerOwinProperties(new Dictionary<string, string?>
var properties = new AuthenticationProperties(new Dictionary<string, string?>
{
[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);

91
src/OpenIddict.Server.Owin/OpenIddictServerOwinProperties.cs

@ -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
{
/// <inheritdoc/>
public class OpenIddictServerOwinProperties : AuthenticationProperties
{
/// <inheritdoc/>
public OpenIddictServerOwinProperties()
: this(items: null)
{
}
/// <inheritdoc/>
public OpenIddictServerOwinProperties(IDictionary<string, string?>? items)
: this(items, parameters: null)
{
}
/// <summary>
/// Initializes a new instance of the <see cref="OpenIddictServerOwinProperties"/> class.
/// </summary>
/// <param name="items">State values dictionary to use.</param>
/// <param name="parameters">Parameters dictionary to use.</param>
public OpenIddictServerOwinProperties(
IDictionary<string, string?>? items,
IDictionary<string, object?>? parameters)
: base(items)
=> Parameters = parameters is not null ?
new(parameters, StringComparer.Ordinal) :
new(StringComparer.Ordinal);
/// <summary>
/// Gets the collection of parameters passed to the authentication handler.
/// </summary>
/// <remarks>
/// Note: these properties are not intended for serialization or persistence,
/// only for flowing data between call sites.
/// </remarks>
public Dictionary<string, object?> Parameters { get; }
/// <summary>
/// Gets a parameter from the <see cref="Parameters"/> collection.
/// </summary>
/// <typeparam name="T">The parameter type.</typeparam>
/// <param name="name">The parameter name.</param>
/// <returns>The parameter value or a default value if the property is not set.</returns>
public T? GetParameter<T>(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;
}
/// <summary>
/// Sets a parameter value in the <see cref="Parameters"/> collection.
/// </summary>
/// <typeparam name="T">The parameter type.</typeparam>
/// <param name="name">The parameter key.</param>
/// <param name="value">The value to set.</param>
public void SetParameter<T>(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;
}
}
}
}

8
src/OpenIddict.Validation.Owin/OpenIddictValidationOwinHandler.cs

@ -152,7 +152,7 @@ namespace OpenIddict.Validation.Owin
return null;
}
var properties = new OpenIddictValidationOwinProperties(new Dictionary<string, string?>
var properties = new AuthenticationProperties(new Dictionary<string, string?>
{
[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);

91
src/OpenIddict.Validation.Owin/OpenIddictValidationOwinProperties.cs

@ -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
{
/// <inheritdoc/>
public class OpenIddictValidationOwinProperties : AuthenticationProperties
{
/// <inheritdoc/>
public OpenIddictValidationOwinProperties()
: this(items: null)
{
}
/// <inheritdoc/>
public OpenIddictValidationOwinProperties(IDictionary<string, string?>? items)
: this(items, parameters: null)
{
}
/// <summary>
/// Initializes a new instance of the <see cref="OpenIddictValidationOwinProperties"/> class.
/// </summary>
/// <param name="items">State values dictionary to use.</param>
/// <param name="parameters">Parameters dictionary to use.</param>
public OpenIddictValidationOwinProperties(
IDictionary<string, string?>? items,
IDictionary<string, object?>? parameters)
: base(items)
=> Parameters = parameters is not null ?
new(parameters, StringComparer.Ordinal) :
new(StringComparer.Ordinal);
/// <summary>
/// Gets the collection of parameters passed to the authentication handler.
/// </summary>
/// <remarks>
/// Note: these properties are not intended for serialization or persistence,
/// only for flowing data between call sites.
/// </remarks>
public Dictionary<string, object?> Parameters { get; }
/// <summary>
/// Gets a parameter from the <see cref="Parameters"/> collection.
/// </summary>
/// <typeparam name="T">The parameter type.</typeparam>
/// <param name="name">The parameter name.</param>
/// <returns>The parameter value or a default value if the property is not set.</returns>
public T? GetParameter<T>(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;
}
/// <summary>
/// Sets a parameter value in the <see cref="Parameters"/> collection.
/// </summary>
/// <typeparam name="T">The parameter type.</typeparam>
/// <param name="name">The parameter key.</param>
/// <param name="value">The value to set.</param>
public void SetParameter<T>(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;
}
}
}
}
Loading…
Cancel
Save