Browse Source

Add a SetProductInformation() overload accepting an assembly from which the product information is derived

pull/1519/head
Kévin Chalet 4 years ago
parent
commit
421a668948
  1. 6
      sandbox/OpenIddict.Sandbox.AspNet.Client/Startup.cs
  2. 6
      sandbox/OpenIddict.Sandbox.AspNet.Server/Startup.cs
  3. 6
      sandbox/OpenIddict.Sandbox.AspNetCore.Client/Startup.cs
  4. 7
      sandbox/OpenIddict.Sandbox.AspNetCore.Server/Startup.cs
  5. 3
      src/OpenIddict.Abstractions/OpenIddictResources.resx
  6. 53
      src/OpenIddict.Client.SystemNetHttp/OpenIddictClientSystemNetHttpBuilder.cs
  7. 2
      src/OpenIddict.Core/Caches/OpenIddictScopeCache.cs
  8. 2
      src/OpenIddict.Core/Managers/OpenIddictScopeManager.cs
  9. 2
      src/OpenIddict.EntityFramework/Stores/OpenIddictEntityFrameworkScopeStore.cs
  10. 2
      src/OpenIddict.EntityFrameworkCore/Stores/OpenIddictEntityFrameworkCoreScopeStore.cs
  11. 2
      src/OpenIddict.MongoDb/Stores/OpenIddictMongoDbScopeStore.cs
  12. 4
      src/OpenIddict.Server/OpenIddictServerBuilder.cs
  13. 55
      src/OpenIddict.Validation.SystemNetHttp/OpenIddictValidationSystemNetHttpBuilder.cs
  14. 2
      src/OpenIddict.Validation/OpenIddictValidationBuilder.cs

6
sandbox/OpenIddict.Sandbox.AspNet.Client/Startup.cs

@ -92,9 +92,11 @@ namespace OpenIddict.Sandbox.AspNet.Client
.EnableRedirectionEndpointPassthrough()
.EnablePostLogoutRedirectionEndpointPassthrough();
// Register the System.Net.Http integration and configure the HTTP options.
// Register the System.Net.Http integration and use the identity of the current
// assembly as a more specific user agent, which can be useful when dealing with
// providers that use the user agent as a way to throttle requests (e.g Reddit).
options.UseSystemNetHttp()
.SetProductInformation("DemoApp", "1.0.0");
.SetProductInformation(typeof(Startup).Assembly);
// Add a client registration matching the client application definition in the server project.
options.AddRegistration(new OpenIddictClientRegistration

6
sandbox/OpenIddict.Sandbox.AspNet.Server/Startup.cs

@ -140,9 +140,11 @@ namespace OpenIddict.Sandbox.AspNet.Server
options.UseOwin()
.EnableRedirectionEndpointPassthrough();
// Register the System.Net.Http integration and configure the HTTP options.
// Register the System.Net.Http integration and use the identity of the current
// assembly as a more specific user agent, which can be useful when dealing with
// providers that use the user agent as a way to throttle requests (e.g Reddit).
options.UseSystemNetHttp()
.SetProductInformation("DemoApp", "1.0.0");
.SetProductInformation(typeof(Startup).Assembly);
// Register the Web providers integrations.
options.UseWebProviders()

6
sandbox/OpenIddict.Sandbox.AspNetCore.Client/Startup.cs

@ -102,9 +102,11 @@ public class Startup
.EnableRedirectionEndpointPassthrough()
.EnablePostLogoutRedirectionEndpointPassthrough();
// Register the System.Net.Http integration and configure the HTTP options.
// Register the System.Net.Http integration and use the identity of the current
// assembly as a more specific user agent, which can be useful when dealing with
// providers that use the user agent as a way to throttle requests (e.g Reddit).
options.UseSystemNetHttp()
.SetProductInformation("DemoApp", "1.0.0");
.SetProductInformation(typeof(Startup).Assembly);
// Add a client registration matching the client application definition in the server project.
options.AddRegistration(new OpenIddictClientRegistration

7
sandbox/OpenIddict.Sandbox.AspNetCore.Server/Startup.cs

@ -1,4 +1,3 @@
using System.Net.Http.Headers;
using Microsoft.AspNetCore.Identity;
using Microsoft.EntityFrameworkCore;
using OpenIddict.Sandbox.AspNetCore.Server.Models;
@ -87,9 +86,11 @@ public class Startup
.EnableStatusCodePagesIntegration()
.EnableRedirectionEndpointPassthrough();
// Register the System.Net.Http integration and configure the HTTP options.
// Register the System.Net.Http integration and use the identity of the current
// assembly as a more specific user agent, which can be useful when dealing with
// providers that use the user agent as a way to throttle requests (e.g Reddit).
options.UseSystemNetHttp()
.SetProductInformation("DemoApp", "1.0.0");
.SetProductInformation(typeof(Startup).Assembly);
// Register the Web providers integrations.
options.UseWebProviders()

3
src/OpenIddict.Abstractions/OpenIddictResources.resx

@ -1331,6 +1331,9 @@ Alternatively, you can disable the token storage feature by calling 'services.Ad
<data name="ID0344" xml:space="preserve">
<value>The request forgery protection claim cannot be resolved from the sign-out context.</value>
</data>
<data name="ID0345" xml:space="preserve">
<value>The product name cannot be null or empty.</value>
</data>
<data name="ID2000" xml:space="preserve">
<value>The security token is missing.</value>
</data>

53
src/OpenIddict.Client.SystemNetHttp/OpenIddictClientSystemNetHttpBuilder.cs

@ -6,6 +6,7 @@
using System.ComponentModel;
using System.Net.Http.Headers;
using System.Reflection;
using OpenIddict.Client.SystemNetHttp;
using Polly;
@ -52,8 +53,15 @@ public class OpenIddictClientSystemNetHttpBuilder
/// </summary>
/// <param name="policy">The HTTP Polly error policy.</param>
/// <returns>The <see cref="OpenIddictClientSystemNetHttpBuilder"/>.</returns>
public OpenIddictClientSystemNetHttpBuilder SetHttpErrorPolicy(IAsyncPolicy<HttpResponseMessage>? policy)
=> Configure(options => options.HttpErrorPolicy = policy);
public OpenIddictClientSystemNetHttpBuilder SetHttpErrorPolicy(IAsyncPolicy<HttpResponseMessage> policy)
{
if (policy is null)
{
throw new ArgumentNullException(nameof(policy));
}
return Configure(options => options.HttpErrorPolicy = policy);
}
/// <summary>
/// Sets the product information used in the user agent header that is attached
@ -61,8 +69,15 @@ public class OpenIddictClientSystemNetHttpBuilder
/// </summary>
/// <param name="information">The product information.</param>
/// <returns>The <see cref="OpenIddictClientSystemNetHttpBuilder"/>.</returns>
public OpenIddictClientSystemNetHttpBuilder SetProductInformation(ProductInfoHeaderValue? information)
=> Configure(options => options.ProductInformation = information);
public OpenIddictClientSystemNetHttpBuilder SetProductInformation(ProductInfoHeaderValue information)
{
if (information is null)
{
throw new ArgumentNullException(nameof(information));
}
return Configure(options => options.ProductInformation = information);
}
/// <summary>
/// Sets the product information used in the user agent header that is attached
@ -71,8 +86,34 @@ public class OpenIddictClientSystemNetHttpBuilder
/// <param name="name">The product name.</param>
/// <param name="version">The product version.</param>
/// <returns>The <see cref="OpenIddictClientSystemNetHttpBuilder"/>.</returns>
public OpenIddictClientSystemNetHttpBuilder SetProductInformation(string? name, string? version)
=> SetProductInformation(!string.IsNullOrEmpty(name) ? new ProductInfoHeaderValue(name, version) : null);
public OpenIddictClientSystemNetHttpBuilder SetProductInformation(string name, string? version)
{
if (string.IsNullOrEmpty(name))
{
throw new ArgumentException(SR.GetResourceString(SR.ID0345), nameof(name));
}
return SetProductInformation(new ProductInfoHeaderValue(name, version));
}
/// <summary>
/// Sets the product information used in the user agent header that is attached
/// to the backchannel HTTP requests sent to the authorization server based
/// on the identity of the specified .NET assembly (name and version).
/// </summary>
/// <param name="assembly">The assembly from which the product information is created.</param>
/// <returns>The <see cref="OpenIddictClientSystemNetHttpBuilder"/>.</returns>
public OpenIddictClientSystemNetHttpBuilder SetProductInformation(Assembly assembly)
{
if (assembly is null)
{
throw new ArgumentNullException(nameof(assembly));
}
return SetProductInformation(new ProductInfoHeaderValue(
productName: assembly.GetName().Name!,
productVersion: assembly.GetName().Version!.ToString()));
}
/// <inheritdoc/>
[EditorBrowsable(EditorBrowsableState.Never)]

2
src/OpenIddict.Core/Caches/OpenIddictScopeCache.cs

@ -160,7 +160,7 @@ public class OpenIddictScopeCache<TScope> : IOpenIddictScopeCache<TScope>, IDisp
/// <inheritdoc/>
public IAsyncEnumerable<TScope> FindByNamesAsync(ImmutableArray<string> names, CancellationToken cancellationToken)
{
if (names.Any(name => string.IsNullOrEmpty(name)))
if (names.Any(string.IsNullOrEmpty))
{
throw new ArgumentException(SR.GetResourceString(SR.ID0203), nameof(names));
}

2
src/OpenIddict.Core/Managers/OpenIddictScopeManager.cs

@ -274,7 +274,7 @@ public class OpenIddictScopeManager<TScope> : IOpenIddictScopeManager where TSco
public virtual IAsyncEnumerable<TScope> FindByNamesAsync(
ImmutableArray<string> names, CancellationToken cancellationToken = default)
{
if (names.Any(name => string.IsNullOrEmpty(name)))
if (names.Any(string.IsNullOrEmpty))
{
throw new ArgumentException(SR.GetResourceString(SR.ID0203), nameof(names));
}

2
src/OpenIddict.EntityFramework/Stores/OpenIddictEntityFrameworkScopeStore.cs

@ -161,7 +161,7 @@ public class OpenIddictEntityFrameworkScopeStore<TScope, TContext, TKey> : IOpen
public virtual IAsyncEnumerable<TScope> FindByNamesAsync(
ImmutableArray<string> names, CancellationToken cancellationToken)
{
if (names.Any(name => string.IsNullOrEmpty(name)))
if (names.Any(string.IsNullOrEmpty))
{
throw new ArgumentException(SR.GetResourceString(SR.ID0203), nameof(names));
}

2
src/OpenIddict.EntityFrameworkCore/Stores/OpenIddictEntityFrameworkCoreScopeStore.cs

@ -177,7 +177,7 @@ public class OpenIddictEntityFrameworkCoreScopeStore<TScope, TContext, TKey> : I
public virtual IAsyncEnumerable<TScope> FindByNamesAsync(
ImmutableArray<string> names, CancellationToken cancellationToken)
{
if (names.Any(name => string.IsNullOrEmpty(name)))
if (names.Any(string.IsNullOrEmpty))
{
throw new ArgumentException(SR.GetResourceString(SR.ID0203), nameof(names));
}

2
src/OpenIddict.MongoDb/Stores/OpenIddictMongoDbScopeStore.cs

@ -129,7 +129,7 @@ public class OpenIddictMongoDbScopeStore<TScope> : IOpenIddictScopeStore<TScope>
/// <inheritdoc/>
public virtual IAsyncEnumerable<TScope> FindByNamesAsync(ImmutableArray<string> names, CancellationToken cancellationToken)
{
if (names.Any(name => string.IsNullOrEmpty(name)))
if (names.Any(string.IsNullOrEmpty))
{
throw new ArgumentException(SR.GetResourceString(SR.ID0203), nameof(names));
}

4
src/OpenIddict.Server/OpenIddictServerBuilder.cs

@ -1676,7 +1676,7 @@ public class OpenIddictServerBuilder
throw new ArgumentNullException(nameof(claims));
}
if (claims.Any(claim => string.IsNullOrEmpty(claim)))
if (claims.Any(string.IsNullOrEmpty))
{
throw new ArgumentException(SR.GetResourceString(SR.ID0073), nameof(claims));
}
@ -1697,7 +1697,7 @@ public class OpenIddictServerBuilder
throw new ArgumentNullException(nameof(scopes));
}
if (scopes.Any(scope => string.IsNullOrEmpty(scope)))
if (scopes.Any(string.IsNullOrEmpty))
{
throw new ArgumentException(SR.GetResourceString(SR.ID0074), nameof(scopes));
}

55
src/OpenIddict.Validation.SystemNetHttp/OpenIddictValidationSystemNetHttpBuilder.cs

@ -6,6 +6,7 @@
using System.ComponentModel;
using System.Net.Http.Headers;
using System.Reflection;
using OpenIddict.Validation.SystemNetHttp;
using Polly;
@ -48,12 +49,19 @@ public class OpenIddictValidationSystemNetHttpBuilder
}
/// <summary>
/// Replaces the default HTTP error policy used by the OpenIddict validation services.
/// Replaces the default HTTP error policy used by the OpenIddict client services.
/// </summary>
/// <param name="policy">The HTTP Polly error policy.</param>
/// <returns>The <see cref="OpenIddictValidationSystemNetHttpBuilder"/>.</returns>
public OpenIddictValidationSystemNetHttpBuilder SetHttpErrorPolicy(IAsyncPolicy<HttpResponseMessage>? policy)
=> Configure(options => options.HttpErrorPolicy = policy);
public OpenIddictValidationSystemNetHttpBuilder SetHttpErrorPolicy(IAsyncPolicy<HttpResponseMessage> policy)
{
if (policy is null)
{
throw new ArgumentNullException(nameof(policy));
}
return Configure(options => options.HttpErrorPolicy = policy);
}
/// <summary>
/// Sets the product information used in the user agent header that is attached
@ -61,8 +69,15 @@ public class OpenIddictValidationSystemNetHttpBuilder
/// </summary>
/// <param name="information">The product information.</param>
/// <returns>The <see cref="OpenIddictValidationSystemNetHttpBuilder"/>.</returns>
public OpenIddictValidationSystemNetHttpBuilder SetProductInformation(ProductInfoHeaderValue? information)
=> Configure(options => options.ProductInformation = information);
public OpenIddictValidationSystemNetHttpBuilder SetProductInformation(ProductInfoHeaderValue information)
{
if (information is null)
{
throw new ArgumentNullException(nameof(information));
}
return Configure(options => options.ProductInformation = information);
}
/// <summary>
/// Sets the product information used in the user agent header that is attached
@ -71,8 +86,34 @@ public class OpenIddictValidationSystemNetHttpBuilder
/// <param name="name">The product name.</param>
/// <param name="version">The product version.</param>
/// <returns>The <see cref="OpenIddictValidationSystemNetHttpBuilder"/>.</returns>
public OpenIddictValidationSystemNetHttpBuilder SetProductInformation(string? name, string? version)
=> SetProductInformation(!string.IsNullOrEmpty(name) ? new ProductInfoHeaderValue(name, version) : null);
public OpenIddictValidationSystemNetHttpBuilder SetProductInformation(string name, string? version)
{
if (string.IsNullOrEmpty(name))
{
throw new ArgumentException(SR.GetResourceString(SR.ID0345), nameof(name));
}
return SetProductInformation(new ProductInfoHeaderValue(name, version));
}
/// <summary>
/// Sets the product information used in the user agent header that is attached
/// to the backchannel HTTP requests sent to the authorization server based
/// on the identity of the specified .NET assembly (name and version).
/// </summary>
/// <param name="assembly">The assembly from which the product information is created.</param>
/// <returns>The <see cref="OpenIddictValidationSystemNetHttpBuilder"/>.</returns>
public OpenIddictValidationSystemNetHttpBuilder SetProductInformation(Assembly assembly)
{
if (assembly is null)
{
throw new ArgumentNullException(nameof(assembly));
}
return SetProductInformation(new ProductInfoHeaderValue(
productName: assembly.GetName().Name!,
productVersion: assembly.GetName().Version!.ToString()));
}
/// <inheritdoc/>
[EditorBrowsable(EditorBrowsableState.Never)]

2
src/OpenIddict.Validation/OpenIddictValidationBuilder.cs

@ -358,7 +358,7 @@ public class OpenIddictValidationBuilder
throw new ArgumentNullException(nameof(audiences));
}
if (audiences.Any(audience => string.IsNullOrEmpty(audience)))
if (audiences.Any(string.IsNullOrEmpty))
{
throw new ArgumentException(SR.GetResourceString(SR.ID0123), nameof(audiences));
}

Loading…
Cancel
Save