Skip to content

Commit 1360d65

Browse files
authored
Add AddOptions to AddAuthorizationCore (#18911)
Fixes: #18471 AddAuthorizationCore previously assumed that options were already registered. This isn't the case in 5.0 in Blazor WASM. We don't want Blazor to register options in the default host because it prevents options from being linked out. note: we will have some remaining work for this issue after this change is merged. The Blazor WASM hosting changes haven't landed in master yet, so we'll need to update that code to remove options from the host.
1 parent 950fa4b commit 1360d65

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

src/Security/Authorization/Core/src/AuthorizationServiceCollectionExtensions.cs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ namespace Microsoft.Extensions.DependencyInjection
1414
public static class AuthorizationServiceCollectionExtensions
1515
{
1616
/// <summary>
17-
/// Adds authorization services to the specified <see cref="IServiceCollection" />.
17+
/// Adds authorization services to the specified <see cref="IServiceCollection" />.
1818
/// </summary>
1919
/// <param name="services">The <see cref="IServiceCollection" /> to add services to.</param>
2020
/// <returns>The <see cref="IServiceCollection"/> so that additional calls can be chained.</returns>
@@ -24,7 +24,11 @@ public static IServiceCollection AddAuthorizationCore(this IServiceCollection se
2424
{
2525
throw new ArgumentNullException(nameof(services));
2626
}
27-
27+
28+
// These services depend on options, and they are used in Blazor WASM, where options
29+
// aren't included by default.
30+
services.AddOptions();
31+
2832
services.TryAdd(ServiceDescriptor.Transient<IAuthorizationService, DefaultAuthorizationService>());
2933
services.TryAdd(ServiceDescriptor.Transient<IAuthorizationPolicyProvider, DefaultAuthorizationPolicyProvider>());
3034
services.TryAdd(ServiceDescriptor.Transient<IAuthorizationHandlerProvider, DefaultAuthorizationHandlerProvider>());
@@ -35,7 +39,7 @@ public static IServiceCollection AddAuthorizationCore(this IServiceCollection se
3539
}
3640

3741
/// <summary>
38-
/// Adds authorization services to the specified <see cref="IServiceCollection" />.
42+
/// Adds authorization services to the specified <see cref="IServiceCollection" />.
3943
/// </summary>
4044
/// <param name="services">The <see cref="IServiceCollection" /> to add services to.</param>
4145
/// <param name="configure">An action delegate to configure the provided <see cref="AuthorizationOptions"/>.</param>

src/Security/build.sh

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#!/usr/bin/env bash
2+
3+
set -euo pipefail
4+
5+
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
6+
repo_root="$DIR/../.."
7+
"$repo_root/build.sh" --projects "$DIR/**/*.*proj" "$@"

0 commit comments

Comments
 (0)