Browse Source

Update OpenIddictMvcConfiguration to use BindingSourceMetadataProvider

pull/711/head
Kévin Chalet 8 years ago
parent
commit
e1a7832a6c
  1. 17
      src/OpenIddict.Abstractions/Managers/IOpenIddictApplicationManager.cs
  2. 37
      src/OpenIddict.Abstractions/Managers/IOpenIddictAuthorizationManager.cs
  3. 17
      src/OpenIddict.Abstractions/Managers/IOpenIddictScopeManager.cs
  4. 17
      src/OpenIddict.Abstractions/Managers/IOpenIddictTokenManager.cs
  5. 13
      src/OpenIddict.Mvc/Internal/OpenIddictMvcConfiguration.cs
  6. 3
      src/OpenIddict.Mvc/OpenIddictMvcExtensions.cs
  7. 19
      test/OpenIddict.Mvc.Tests/Internal/OpenIddictMvcConfigurationTests.cs

17
src/OpenIddict.Abstractions/Managers/IOpenIddictApplicationManager.cs

@ -140,7 +140,8 @@ namespace OpenIddict.Abstractions
/// A <see cref="Task"/> that can be used to monitor the asynchronous operation,
/// whose result returns the first element returned when executing the query.
/// </returns>
Task<TResult> GetAsync<TResult>([NotNull] Func<IQueryable<object>, IQueryable<TResult>> query, CancellationToken cancellationToken = default);
Task<TResult> GetAsync<TResult>(
[NotNull] Func<IQueryable<object>, IQueryable<TResult>> query, CancellationToken cancellationToken = default);
/// <summary>
/// Executes the specified query and returns the first element.
@ -154,7 +155,9 @@ namespace OpenIddict.Abstractions
/// A <see cref="Task"/> that can be used to monitor the asynchronous operation,
/// whose result returns the first element returned when executing the query.
/// </returns>
Task<TResult> GetAsync<TState, TResult>([NotNull] Func<IQueryable<object>, TState, IQueryable<TResult>> query, [CanBeNull] TState state, CancellationToken cancellationToken = default);
Task<TResult> GetAsync<TState, TResult>(
[NotNull] Func<IQueryable<object>, TState, IQueryable<TResult>> query,
[CanBeNull] TState state, CancellationToken cancellationToken = default);
/// <summary>
/// Retrieves the client identifier associated with an application.
@ -287,7 +290,8 @@ namespace OpenIddict.Abstractions
/// A <see cref="Task"/> that can be used to monitor the asynchronous operation,
/// whose result returns all the elements returned when executing the specified query.
/// </returns>
Task<ImmutableArray<object>> ListAsync([CanBeNull] int? count = null, [CanBeNull] int? offset = null, CancellationToken cancellationToken = default);
Task<ImmutableArray<object>> ListAsync(
[CanBeNull] int? count = null, [CanBeNull] int? offset = null, CancellationToken cancellationToken = default);
/// <summary>
/// Executes the specified query and returns all the corresponding elements.
@ -299,7 +303,8 @@ namespace OpenIddict.Abstractions
/// A <see cref="Task"/> that can be used to monitor the asynchronous operation,
/// whose result returns all the elements returned when executing the specified query.
/// </returns>
Task<ImmutableArray<TResult>> ListAsync<TResult>([NotNull] Func<IQueryable<object>, IQueryable<TResult>> query, CancellationToken cancellationToken = default);
Task<ImmutableArray<TResult>> ListAsync<TResult>(
[NotNull] Func<IQueryable<object>, IQueryable<TResult>> query, CancellationToken cancellationToken = default);
/// <summary>
/// Executes the specified query and returns all the corresponding elements.
@ -313,7 +318,9 @@ namespace OpenIddict.Abstractions
/// A <see cref="Task"/> that can be used to monitor the asynchronous operation,
/// whose result returns all the elements returned when executing the specified query.
/// </returns>
Task<ImmutableArray<TResult>> ListAsync<TState, TResult>([NotNull] Func<IQueryable<object>, TState, IQueryable<TResult>> query, [CanBeNull] TState state, CancellationToken cancellationToken = default);
Task<ImmutableArray<TResult>> ListAsync<TState, TResult>(
[NotNull] Func<IQueryable<object>, TState, IQueryable<TResult>> query,
[CanBeNull] TState state, CancellationToken cancellationToken = default);
/// <summary>
/// Populates the specified descriptor using the properties exposed by the application.

37
src/OpenIddict.Abstractions/Managers/IOpenIddictAuthorizationManager.cs

@ -39,7 +39,8 @@ namespace OpenIddict.Abstractions
/// A <see cref="Task"/> that can be used to monitor the asynchronous operation,
/// whose result returns the number of authorizations that match the specified query.
/// </returns>
Task<long> CountAsync<TResult>([NotNull] Func<IQueryable<object>, IQueryable<TResult>> query, CancellationToken cancellationToken = default);
Task<long> CountAsync<TResult>(
[NotNull] Func<IQueryable<object>, IQueryable<TResult>> query, CancellationToken cancellationToken = default);
/// <summary>
/// Creates a new permanent authorization based on the specified parameters.
@ -54,7 +55,10 @@ namespace OpenIddict.Abstractions
/// <returns>
/// A <see cref="Task"/> that can be used to monitor the asynchronous operation, whose result returns the authorization.
/// </returns>
Task<object> CreateAsync([NotNull] ClaimsPrincipal principal, [NotNull] string subject, [NotNull] string client, [NotNull] string type, ImmutableArray<string> scopes, [CanBeNull] ImmutableDictionary<string, string> properties, CancellationToken cancellationToken = default);
Task<object> CreateAsync(
[NotNull] ClaimsPrincipal principal, [NotNull] string subject, [NotNull] string client,
[NotNull] string type, ImmutableArray<string> scopes,
[CanBeNull] ImmutableDictionary<string, string> properties, CancellationToken cancellationToken = default);
/// <summary>
/// Creates a new authorization based on the specified descriptor.
@ -110,7 +114,9 @@ namespace OpenIddict.Abstractions
/// A <see cref="Task"/> that can be used to monitor the asynchronous operation,
/// whose result returns the authorizations corresponding to the criteria.
/// </returns>
Task<ImmutableArray<object>> FindAsync([NotNull] string subject, [NotNull] string client, [NotNull] string status, CancellationToken cancellationToken = default);
Task<ImmutableArray<object>> FindAsync(
[NotNull] string subject, [NotNull] string client,
[NotNull] string status, CancellationToken cancellationToken = default);
/// <summary>
/// Retrieves the authorizations matching the specified parameters.
@ -124,7 +130,9 @@ namespace OpenIddict.Abstractions
/// A <see cref="Task"/> that can be used to monitor the asynchronous operation,
/// whose result returns the authorizations corresponding to the criteria.
/// </returns>
Task<ImmutableArray<object>> FindAsync([NotNull] string subject, [NotNull] string client, [NotNull] string status, [NotNull] string type, CancellationToken cancellationToken = default);
Task<ImmutableArray<object>> FindAsync(
[NotNull] string subject, [NotNull] string client,
[NotNull] string status, [NotNull] string type, CancellationToken cancellationToken = default);
/// <summary>
/// Retrieves the authorizations matching the specified parameters.
@ -139,7 +147,9 @@ namespace OpenIddict.Abstractions
/// A <see cref="Task"/> that can be used to monitor the asynchronous operation,
/// whose result returns the authorizations corresponding to the criteria.
/// </returns>
Task<ImmutableArray<object>> FindAsync([NotNull] string subject, [NotNull] string client, [NotNull] string status, [NotNull] string type, ImmutableArray<string> scopes, CancellationToken cancellationToken = default);
Task<ImmutableArray<object>> FindAsync(
[NotNull] string subject, [NotNull] string client, [NotNull] string status,
[NotNull] string type, ImmutableArray<string> scopes, CancellationToken cancellationToken = default);
/// <summary>
/// Retrieves the list of authorizations corresponding to the specified application identifier.
@ -195,7 +205,8 @@ namespace OpenIddict.Abstractions
/// A <see cref="Task"/> that can be used to monitor the asynchronous operation,
/// whose result returns the first element returned when executing the query.
/// </returns>
Task<TResult> GetAsync<TResult>([NotNull] Func<IQueryable<object>, IQueryable<TResult>> query, CancellationToken cancellationToken = default);
Task<TResult> GetAsync<TResult>(
[NotNull] Func<IQueryable<object>, IQueryable<TResult>> query, CancellationToken cancellationToken = default);
/// <summary>
/// Executes the specified query and returns the first element.
@ -209,7 +220,9 @@ namespace OpenIddict.Abstractions
/// A <see cref="Task"/> that can be used to monitor the asynchronous operation,
/// whose result returns the first element returned when executing the query.
/// </returns>
Task<TResult> GetAsync<TState, TResult>([NotNull] Func<IQueryable<object>, TState, IQueryable<TResult>> query, [CanBeNull] TState state, CancellationToken cancellationToken = default);
Task<TResult> GetAsync<TState, TResult>(
[NotNull] Func<IQueryable<object>, TState, IQueryable<TResult>> query,
[CanBeNull] TState state, CancellationToken cancellationToken = default);
/// <summary>
/// Retrieves the unique identifier associated with an authorization.
@ -317,7 +330,8 @@ namespace OpenIddict.Abstractions
/// A <see cref="Task"/> that can be used to monitor the asynchronous operation,
/// whose result returns all the elements returned when executing the specified query.
/// </returns>
Task<ImmutableArray<object>> ListAsync([CanBeNull] int? count = null, [CanBeNull] int? offset = null, CancellationToken cancellationToken = default);
Task<ImmutableArray<object>> ListAsync(
[CanBeNull] int? count = null, [CanBeNull] int? offset = null, CancellationToken cancellationToken = default);
/// <summary>
/// Executes the specified query and returns all the corresponding elements.
@ -329,7 +343,8 @@ namespace OpenIddict.Abstractions
/// A <see cref="Task"/> that can be used to monitor the asynchronous operation,
/// whose result returns all the elements returned when executing the specified query.
/// </returns>
Task<ImmutableArray<TResult>> ListAsync<TResult>([NotNull] Func<IQueryable<object>, IQueryable<TResult>> query, CancellationToken cancellationToken = default);
Task<ImmutableArray<TResult>> ListAsync<TResult>(
[NotNull] Func<IQueryable<object>, IQueryable<TResult>> query, CancellationToken cancellationToken = default);
/// <summary>
/// Executes the specified query and returns all the corresponding elements.
@ -343,7 +358,9 @@ namespace OpenIddict.Abstractions
/// A <see cref="Task"/> that can be used to monitor the asynchronous operation,
/// whose result returns all the elements returned when executing the specified query.
/// </returns>
Task<ImmutableArray<TResult>> ListAsync<TState, TResult>([NotNull] Func<IQueryable<object>, TState, IQueryable<TResult>> query, [CanBeNull] TState state, CancellationToken cancellationToken = default);
Task<ImmutableArray<TResult>> ListAsync<TState, TResult>(
[NotNull] Func<IQueryable<object>, TState, IQueryable<TResult>> query,
[CanBeNull] TState state, CancellationToken cancellationToken = default);
/// <summary>
/// Populates the specified descriptor using the properties exposed by the authorization.

17
src/OpenIddict.Abstractions/Managers/IOpenIddictScopeManager.cs

@ -124,7 +124,8 @@ namespace OpenIddict.Abstractions
/// A <see cref="Task"/> that can be used to monitor the asynchronous operation,
/// whose result returns the first element returned when executing the query.
/// </returns>
Task<TResult> GetAsync<TResult>([NotNull] Func<IQueryable<object>, IQueryable<TResult>> query, CancellationToken cancellationToken = default);
Task<TResult> GetAsync<TResult>(
[NotNull] Func<IQueryable<object>, IQueryable<TResult>> query, CancellationToken cancellationToken = default);
/// <summary>
/// Executes the specified query and returns the first element.
@ -138,7 +139,9 @@ namespace OpenIddict.Abstractions
/// A <see cref="Task"/> that can be used to monitor the asynchronous operation,
/// whose result returns the first element returned when executing the query.
/// </returns>
Task<TResult> GetAsync<TState, TResult>([NotNull] Func<IQueryable<object>, TState, IQueryable<TResult>> query, [CanBeNull] TState state, CancellationToken cancellationToken = default);
Task<TResult> GetAsync<TState, TResult>(
[NotNull] Func<IQueryable<object>, TState, IQueryable<TResult>> query,
[CanBeNull] TState state, CancellationToken cancellationToken = default);
/// <summary>
/// Retrieves the description associated with a scope.
@ -205,7 +208,8 @@ namespace OpenIddict.Abstractions
/// A <see cref="Task"/> that can be used to monitor the asynchronous operation,
/// whose result returns all the elements returned when executing the specified query.
/// </returns>
Task<ImmutableArray<object>> ListAsync([CanBeNull] int? count = null, [CanBeNull] int? offset = null, CancellationToken cancellationToken = default);
Task<ImmutableArray<object>> ListAsync(
[CanBeNull] int? count = null, [CanBeNull] int? offset = null, CancellationToken cancellationToken = default);
/// <summary>
/// Executes the specified query and returns all the corresponding elements.
@ -217,7 +221,8 @@ namespace OpenIddict.Abstractions
/// A <see cref="Task"/> that can be used to monitor the asynchronous operation,
/// whose result returns all the elements returned when executing the specified query.
/// </returns>
Task<ImmutableArray<TResult>> ListAsync<TResult>([NotNull] Func<IQueryable<object>, IQueryable<TResult>> query, CancellationToken cancellationToken = default);
Task<ImmutableArray<TResult>> ListAsync<TResult>(
[NotNull] Func<IQueryable<object>, IQueryable<TResult>> query, CancellationToken cancellationToken = default);
/// <summary>
/// Executes the specified query and returns all the corresponding elements.
@ -231,7 +236,9 @@ namespace OpenIddict.Abstractions
/// A <see cref="Task"/> that can be used to monitor the asynchronous operation,
/// whose result returns all the elements returned when executing the specified query.
/// </returns>
Task<ImmutableArray<TResult>> ListAsync<TState, TResult>([NotNull] Func<IQueryable<object>, TState, IQueryable<TResult>> query, [CanBeNull] TState state, CancellationToken cancellationToken = default);
Task<ImmutableArray<TResult>> ListAsync<TState, TResult>(
[NotNull] Func<IQueryable<object>, TState, IQueryable<TResult>> query,
[CanBeNull] TState state, CancellationToken cancellationToken = default);
/// <summary>
/// Lists all the resources associated with the specified scopes.

17
src/OpenIddict.Abstractions/Managers/IOpenIddictTokenManager.cs

@ -203,7 +203,8 @@ namespace OpenIddict.Abstractions
/// A <see cref="Task"/> that can be used to monitor the asynchronous operation,
/// whose result returns the first element returned when executing the query.
/// </returns>
Task<TResult> GetAsync<TResult>([NotNull] Func<IQueryable<object>, IQueryable<TResult>> query, CancellationToken cancellationToken = default);
Task<TResult> GetAsync<TResult>(
[NotNull] Func<IQueryable<object>, IQueryable<TResult>> query, CancellationToken cancellationToken = default);
/// <summary>
/// Executes the specified query and returns the first element.
@ -217,7 +218,9 @@ namespace OpenIddict.Abstractions
/// A <see cref="Task"/> that can be used to monitor the asynchronous operation,
/// whose result returns the first element returned when executing the query.
/// </returns>
Task<TResult> GetAsync<TState, TResult>([NotNull] Func<IQueryable<object>, TState, IQueryable<TResult>> query, [CanBeNull] TState state, CancellationToken cancellationToken = default);
Task<TResult> GetAsync<TState, TResult>(
[NotNull] Func<IQueryable<object>, TState, IQueryable<TResult>> query,
[CanBeNull] TState state, CancellationToken cancellationToken = default);
/// <summary>
/// Retrieves the optional authorization identifier associated with a token.
@ -354,7 +357,8 @@ namespace OpenIddict.Abstractions
/// A <see cref="Task"/> that can be used to monitor the asynchronous operation,
/// whose result returns all the elements returned when executing the specified query.
/// </returns>
Task<ImmutableArray<object>> ListAsync([CanBeNull] int? count = null, [CanBeNull] int? offset = null, CancellationToken cancellationToken = default);
Task<ImmutableArray<object>> ListAsync(
[CanBeNull] int? count = null, [CanBeNull] int? offset = null, CancellationToken cancellationToken = default);
/// <summary>
/// Executes the specified query and returns all the corresponding elements.
@ -366,7 +370,8 @@ namespace OpenIddict.Abstractions
/// A <see cref="Task"/> that can be used to monitor the asynchronous operation,
/// whose result returns all the elements returned when executing the specified query.
/// </returns>
Task<ImmutableArray<TResult>> ListAsync<TResult>([NotNull] Func<IQueryable<object>, IQueryable<TResult>> query, CancellationToken cancellationToken = default);
Task<ImmutableArray<TResult>> ListAsync<TResult>(
[NotNull] Func<IQueryable<object>, IQueryable<TResult>> query, CancellationToken cancellationToken = default);
/// <summary>
/// Executes the specified query and returns all the corresponding elements.
@ -380,7 +385,9 @@ namespace OpenIddict.Abstractions
/// A <see cref="Task"/> that can be used to monitor the asynchronous operation,
/// whose result returns all the elements returned when executing the specified query.
/// </returns>
Task<ImmutableArray<TResult>> ListAsync<TState, TResult>([NotNull] Func<IQueryable<object>, TState, IQueryable<TResult>> query, [CanBeNull] TState state, CancellationToken cancellationToken = default);
Task<ImmutableArray<TResult>> ListAsync<TState, TResult>(
[NotNull] Func<IQueryable<object>, TState, IQueryable<TResult>> query,
[CanBeNull] TState state, CancellationToken cancellationToken = default);
/// <summary>
/// Populates the specified descriptor using the properties exposed by the token.

13
src/OpenIddict.Mvc/Internal/OpenIddictMvcConfiguration.cs

@ -9,6 +9,7 @@ using AspNet.Security.OpenIdConnect.Primitives;
using JetBrains.Annotations;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.ModelBinding;
using Microsoft.AspNetCore.Mvc.ModelBinding.Metadata;
using Microsoft.Extensions.Options;
namespace OpenIddict.Mvc.Internal
@ -32,8 +33,16 @@ namespace OpenIddict.Mvc.Internal
}
options.ModelBinderProviders.Insert(0, new OpenIddictMvcBinderProvider());
options.ModelMetadataDetailsProviders.Add(new SuppressChildValidationMetadataProvider(typeof(OpenIdConnectRequest)));
options.ModelMetadataDetailsProviders.Add(new SuppressChildValidationMetadataProvider(typeof(OpenIdConnectResponse)));
options.ModelMetadataDetailsProviders.Add(
new BindingSourceMetadataProvider(typeof(OpenIdConnectRequest), BindingSource.Special));
options.ModelMetadataDetailsProviders.Add(
new BindingSourceMetadataProvider(typeof(OpenIdConnectResponse), BindingSource.Special));
options.ModelMetadataDetailsProviders.Add(
new SuppressChildValidationMetadataProvider(typeof(OpenIdConnectRequest)));
options.ModelMetadataDetailsProviders.Add(
new SuppressChildValidationMetadataProvider(typeof(OpenIdConnectResponse)));
}
}
}

3
src/OpenIddict.Mvc/OpenIddictMvcExtensions.cs

@ -33,7 +33,8 @@ namespace Microsoft.Extensions.DependencyInjection
// Register the options initializer used by the OpenIddict MVC binding/validation components.
// Note: TryAddEnumerable() is used here to ensure the initializer is only registered once.
builder.Services.TryAddEnumerable(ServiceDescriptor.Singleton<IConfigureOptions<MvcOptions>, OpenIddictMvcConfiguration>());
builder.Services.TryAddEnumerable(
ServiceDescriptor.Singleton<IConfigureOptions<MvcOptions>, OpenIddictMvcConfiguration>());
return new OpenIddictMvcBuilder(builder.Services);
}

19
test/OpenIddict.Mvc.Tests/Internal/OpenIddictMvcConfigurationTests.cs

@ -9,6 +9,7 @@ using System.Linq;
using AspNet.Security.OpenIdConnect.Primitives;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.ModelBinding;
using Microsoft.AspNetCore.Mvc.ModelBinding.Metadata;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Options;
using OpenIddict.Mvc.Internal;
@ -63,9 +64,21 @@ namespace OpenIddict.Mvc.Tests
var options = services.BuildServiceProvider().GetRequiredService<IOptions<MvcOptions>>();
// Assert
var providers = options.Value.ModelMetadataDetailsProviders.OfType<SuppressChildValidationMetadataProvider>();
Assert.Contains(providers, provider => provider.Type == typeof(OpenIdConnectRequest));
Assert.Contains(providers, provider => provider.Type == typeof(OpenIdConnectResponse));
Assert.Contains(
options.Value.ModelMetadataDetailsProviders.OfType<BindingSourceMetadataProvider>(),
provider => provider.Type == typeof(OpenIdConnectRequest) &&
provider.BindingSource == BindingSource.Special);
Assert.Contains(
options.Value.ModelMetadataDetailsProviders.OfType<BindingSourceMetadataProvider>(),
provider => provider.Type == typeof(OpenIdConnectResponse) &&
provider.BindingSource == BindingSource.Special);
Assert.Contains(
options.Value.ModelMetadataDetailsProviders.OfType<SuppressChildValidationMetadataProvider>(),
provider => provider.Type == typeof(OpenIdConnectRequest));
Assert.Contains(
options.Value.ModelMetadataDetailsProviders.OfType<SuppressChildValidationMetadataProvider>(),
provider => provider.Type == typeof(OpenIdConnectResponse));
}
}
}

Loading…
Cancel
Save