Skip to content

Commit 4ac18fe

Browse files
authored
Updating readme, types documentation and moving to release version (#40)
1 parent 8f07bb3 commit 4ac18fe

28 files changed

+113
-44
lines changed

.build/release.props

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22

33
<PropertyGroup>
44
<PackageId>$(AssmeblyName)</PackageId>
5-
<Authors>Arturo Martinez</Authors>
5+
<Authors>DarkLoop</Authors>
66
<Company>DarkLoop</Company>
77
<Copyright>DarkLoop - All rights reserved</Copyright>
88
<Product>DarkLoop's Azure Functions Authorization</Product>
9-
<IsPreview>true</IsPreview>
9+
<IsPreview>false</IsPreview>
1010
<AssemblyVersion>4.0.0.0</AssemblyVersion>
1111
<Version>4.0.0</Version>
1212
<FileVersion>$(Version).0</FileVersion>
@@ -20,6 +20,7 @@
2020
<AssemblyOriginatorKeyFile>../dl-sftwr-sn-key.snk</AssemblyOriginatorKeyFile>
2121
<PublicKey>0024000004800000940000000602000000240000525341310004000001000100791e7f618a12452d7ced5310f6203d0d227f9d26b146555e7e67a1801695dcf7c552421620a662f54b072f7be1efa885c074d4b9c76a4d6d154721d1c3b1f39164cfaf9ebdf9b7672ff320c89c5a64c90e25330f90a12bf42a1c57b70523e785167dbbfb7a0fdc9eb8d15112f758b89bab51953b08cfb2218095bc45171c99c5</PublicKey>
2222
<IsPackable>true</IsPackable>
23+
<GenerateDocumentationFile>true</GenerateDocumentationFile>
2324
<PackageReadmeFile>README.md</PackageReadmeFile>
2425
</PropertyGroup>
2526

README.md

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,23 @@ This projects is open source and may be redistributed under the terms of the [Ap
2121
Adding change log starting with version 3.1.3
2222

2323
### 4.0.0
24-
Information will be added soon.
24+
Starting from 4.0.0, support for Azure Functions V4 Isolated mode with ASPNET Core integration is added.
25+
The package is now split into two separate packages, one for each mode.
26+
27+
The package for Azure Functions V3+ In-Proc mode is now called `DarkLoop.Azure.Functions.Authorization.InProcess` and the package for Azure Functions V4 Isolated mode with ASPNET Core integration is called `DarkLoop.Azure.Functions.Authorize.Isolated`.
28+
29+
- #### .NET 6 support
30+
Starting with version 4.0.0, the package is now targeting .NET 6.0. This means that the package is no longer compatible with .NET 5 or lower. If you are using .NET 5 or lower, you should use version 3.1.3 of the package.
31+
32+
- #### DarkLoop.Azure.Functions.Authorize v4.0.0
33+
This package is published but is now deprecated in favor of `DarkLoop.Azure.Functions.Authorization.InProcess`. All it's functionality remains the same. It's just a way to keep package naming in sync.
34+
35+
- #### Introducing IFunctionsAuthorizationProvider interface
36+
The `IFunctionsAuthorizationProvider` interface is introduced to allow for custom authorization filter provisioning to the framework.
37+
By default the framework relies on decorating the function or type with `[FunctionAuthorize]`. You could skip this decoration and provide the middleware with an authorization filter sourced from your own mechanism, for example a database.
38+
At this moment this can be done only with Isolated mode even when the interface is defined in the shared package.<br/>
39+
Support for In-Process will be added in a future version, once source generators are introduced, as the in-process framework relies on Invocation Filters to enable authorization.
40+
Replacing the service in the application services would break the authorization for in-process mode at this point.
2541

2642
### 3.1.3
2743
3.1.3 and lower versions only support Azure Functions V3 In-Proc mode. Starting from 4.0.0, support for Azure Functions V4 Isolated mode with ASPNET Core integration is added.

src/abstractions/Cache/FunctionsAuthorizationFilterCache.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
namespace DarkLoop.Azure.Functions.Authorization.Cache
88
{
99
/// <inheritdoc cref="IFunctionsAuthorizationFilterCache{TIdentifier}"/>
10-
internal class FunctionsAuthorizationFilterCache<TIdentifier> : IFunctionsAuthorizationFilterCache<TIdentifier>
10+
internal sealed class FunctionsAuthorizationFilterCache<TIdentifier> : IFunctionsAuthorizationFilterCache<TIdentifier>
1111
where TIdentifier : notnull
1212
{
1313
private readonly ConcurrentDictionary<TIdentifier, FunctionAuthorizationFilter> _filters = new();

src/abstractions/Cache/IFunctionsAuthorizationFilterCache.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ public interface IFunctionsAuthorizationFilterCache<TIdentifier>
1818
/// Sets the authorization filter for the specified function.
1919
/// </summary>
2020
/// <param name="functionIdentifier">The function unique identifier</param>
21-
/// <param name="builder"></param>
21+
/// <param name="filter">The filter to cache.</param>
2222
/// <returns></returns>
2323
bool SetFilter(TIdentifier functionIdentifier, FunctionAuthorizationFilter filter);
2424
}

src/abstractions/FunctionAuthorizationMetadata.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,10 @@
1010

1111
namespace DarkLoop.Azure.Functions.Authorization
1212
{
13-
public class FunctionAuthorizationMetadata
13+
/// <summary>
14+
/// Authorization metadata for a function or type.
15+
/// </summary>
16+
public sealed class FunctionAuthorizationMetadata
1417
{
1518
private readonly int _key;
1619
private readonly string? _functionName;
@@ -68,7 +71,7 @@ internal FunctionAuthorizationMetadata(Type declaringType) : this()
6871
/// Gets the name of the type declaring the function method.
6972
/// </summary>
7073
/// <remarks>The returned value is never <see langword="null"/>. Only for <see cref="Empty"/></remarks>
71-
public virtual Type? DeclaringType => _declaringType;
74+
public Type? DeclaringType => _declaringType;
7275

7376
/// <summary>
7477
/// Gets a value indicating whether the function allows anonymous access.

src/abstractions/FunctionAuthorizationMetadataCollection.cs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ internal sealed class FunctionAuthorizationMetadataCollection
2323

2424
/// <summary>
2525
/// Gets the number of authorization metadata items in the collection.
26+
/// </summary>
2627
internal int Count => _items.Count;
2728

2829
/// <summary>
@@ -41,15 +42,11 @@ internal FunctionAuthorizationMetadata Add(Type declaringType, out bool existing
4142
/// </summary>
4243
/// <param name="functionName">The name of the function.</param>
4344
/// <param name="declaringType">The type declaring the function method.</param>
44-
4545
/// <returns>An instance of <see cref="FunctionAuthorizationMetadata"/></returns>
46-
/// <exception cref="InvalidOperationException">
47-
/// When a rule already exists and defines a different value than the one specified in <paramref name="allowAnonymous"/>
48-
/// </exception>
4946
internal FunctionAuthorizationMetadata Add(string functionName, Type declaringType)
5047
{
5148
this.RegisterFunctionDeclaringType(functionName, declaringType);
52-
49+
5350
return this.GetOrAdd(functionName, declaringType, out _);
5451
}
5552

src/abstractions/FunctionsAuthorizationOptions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ namespace DarkLoop.Azure.Functions.Authorization
1212
/// </summary>
1313
[ExcludeFromCodeCoverage]
1414
// Important to keep this class POCO, any special functionality should be done with extension methods.
15-
public class FunctionsAuthorizationOptions
15+
public sealed class FunctionsAuthorizationOptions
1616
{
1717
internal readonly FunctionAuthorizationMetadataCollection AuthorizationMetadata = new();
1818

src/abstractions/FunctionsAuthorizationProvider.cs

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,11 @@ internal class FunctionsAuthorizationProvider : IFunctionsAuthorizationProvider
3131
/// <summary>
3232
/// Initializes a new instance of the <see cref="FunctionsAuthorizationProvider"/> class.
3333
/// </summary>
34-
/// <param name="cache"></param>
35-
/// <param name="schemeProvider"></param>
34+
/// <param name="schemeProvider">ASP.NET Core's scheme provider.</param>
35+
/// <param name="cache">The function filter cache.</param>
36+
/// <param name="options">The options object serving metadata. This doesn't change through the life of the application.</param>
37+
/// <param name="configOptions">The options object to manage configuration settings that might change from config source.</param>
38+
/// <param name="logger">Logger for class.</param>
3639
public FunctionsAuthorizationProvider(
3740
IAuthenticationSchemeProvider schemeProvider,
3841
IFunctionsAuthorizationFilterCache<int> cache,
@@ -62,6 +65,7 @@ public async Task<FunctionAuthorizationFilter> GetAuthorizationAsync(string func
6265

6366
if (_filterCache.TryGetFilter(key, out var filter))
6467
{
68+
_logger.LogDebug("Found cached filter for function.");
6569
return filter!;
6670
}
6771

@@ -73,9 +77,11 @@ public async Task<FunctionAuthorizationFilter> GetAuthorizationAsync(string func
7377
{
7478
if (_filterCache.TryGetFilter(key, out filter))
7579
{
80+
_logger.LogDebug("Found cached filter for function while trying to generate one.");
7681
return filter!;
7782
}
7883

84+
_logger.LogDebug("Generating filter for function.");
7985
var functionMetadata = _metadataStore.GetMetadata(functionName);
8086

8187
if (functionMetadata == FunctionAuthorizationMetadata.Empty)
@@ -97,7 +103,7 @@ public async Task<FunctionAuthorizationFilter> GetAuthorizationAsync(string func
97103
if (policyProvider.AllowsCachingPolicies)
98104
{
99105
#endif
100-
_filterCache.SetFilter(key, filter);
106+
_filterCache.SetFilter(key, filter);
101107
#if NET7_0_OR_GREATER
102108
}
103109
#endif
@@ -124,10 +130,12 @@ public async Task<FunctionAuthorizationFilter> GetAuthorizationAsync(string func
124130

125131
if (!needsScheme)
126132
{
133+
_logger.LogDebug("Using provided authentication schemes.");
127134
return await AuthorizationPolicy.CombineAsync(policyProvider, authorizationData);
128135
}
129136
else
130137
{
138+
_logger.LogDebug("Using empty scheme strategy to assign schemes for policy.");
131139
var strategy = _options.CurrentValue.EmptySchemeStrategy;
132140

133141
if (strategy is EmptySchemeStrategy.UseDefaultScheme && defaultScheme is null)
@@ -146,10 +154,12 @@ public async Task<FunctionAuthorizationFilter> GetAuthorizationAsync(string func
146154

147155
if (strategy is EmptySchemeStrategy.UseDefaultScheme)
148156
{
157+
_logger.LogDebug("Using default authentication scheme.");
149158
copy[0].AuthenticationSchemes = defaultScheme!.Name;
150159
}
151160
else
152161
{
162+
_logger.LogDebug("Using all available authentication schemes.");
153163
var schemes = (await _schemeProvider.GetRequestHandlerSchemesAsync()).Select(s => s.Name).ToList();
154164
schemes = schemes.Count > 0 ? schemes : (await _schemeProvider.GetAllSchemesAsync()).Select(s => s.Name).ToList();
155165

src/abstractions/FunctionsAuthorizationResultHandler.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
namespace DarkLoop.Azure.Functions.Authorization
1818
{
1919
/// <inheritdoc cref="IFunctionsAuthorizationResultHandler"/>
20-
internal class FunctionsAuthorizationResultHandler : IFunctionsAuthorizationResultHandler
20+
internal sealed class FunctionsAuthorizationResultHandler : IFunctionsAuthorizationResultHandler
2121
{
2222
private readonly IOptionsMonitor<FunctionsAuthorizationOptions> _options;
2323

src/abstractions/Internal/FunctionsAuthorizationOptionsExtensions.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ internal static class FunctionsAuthorizationOptionsExtensions
1717
/// <summary>
1818
/// Registers all the functions in the specified <paramref name="declaringType"/>.
1919
/// </summary>
20+
/// <param name="options">The current options.</param>
2021
/// <param name="declaringType">The type containing the functions.</param>
2122
/// <param name="existing">A value indicating whether the function declaring type is already registered.</param>
2223
/// <returns>Return a <see cref="FunctionAuthorizationMetadata"/> to keep configuring.</returns>
@@ -32,6 +33,7 @@ internal static FunctionAuthorizationMetadata SetTypeAuthorizationInfo(
3233
/// Registers the function with the specified name in <paramref name="functionName"/>
3334
/// in the type specified in <paramref name="declaringType"/>.
3435
/// </summary>
36+
/// <param name="options">The current options.</param>
3537
/// <param name="functionName">The name of the function.</param>
3638
/// <param name="declaringType">The type declaring the function.</param>
3739
/// <returns>Return a <see cref="FunctionAuthorizationMetadata"/> to keep configuring.</returns>
@@ -54,7 +56,7 @@ internal static bool IsFunctionRegistered(this FunctionsAuthorizationOptions opt
5456
/// Registers the authorization metadata for the function extracted from attribute.
5557
/// </summary>
5658
/// <typeparam name="TAuthAttribute">The type of authorization attribute to lookup.</typeparam>
57-
/// <param name="options">The current options object</param>
59+
/// <param name="options">The current options.</param>
5860
/// <param name="functionName">The name of the function.</param>
5961
/// <param name="declaringType">The type declaring the function.</param>
6062
/// <param name="functionMethod">The entry point method for the function.</param>

0 commit comments

Comments
 (0)