VOOZH about

URL: https://www.nuget.org/packages/DarkLoop.Azure.Functions.Authorize/

⇱ NuGet Gallery | DarkLoop.Azure.Functions.Authorize 4.0.0




👁 Image
DarkLoop.Azure.Functions.Authorize 4.0.0

Suggested Alternatives

DarkLoop.Azure.Functions.Authorization.InProcess

Additional Details

The new package is now DarkLoop.Azure.Functions.Authorization.InProcess which has support for Azure Functions hosting environments.

dotnet add package DarkLoop.Azure.Functions.Authorize --version 4.0.0
 
 
NuGet\Install-Package DarkLoop.Azure.Functions.Authorize -Version 4.0.0
 
 
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="DarkLoop.Azure.Functions.Authorize" Version="4.0.0" />
 
 
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="DarkLoop.Azure.Functions.Authorize" Version="4.0.0" />
 
Directory.Packages.props
<PackageReference Include="DarkLoop.Azure.Functions.Authorize" />
 
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add DarkLoop.Azure.Functions.Authorize --version 4.0.0
 
 
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: DarkLoop.Azure.Functions.Authorize, 4.0.0"
 
 
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package DarkLoop.Azure.Functions.Authorize@4.0.0
 
 
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=DarkLoop.Azure.Functions.Authorize&version=4.0.0
 
Install as a Cake Addin
#tool nuget:?package=DarkLoop.Azure.Functions.Authorize&version=4.0.0
 
Install as a Cake Tool
The NuGet Team does not provide support for this client. Please contact its maintainers for support.

functions-authorize

Bringing AuthorizeAttribute Behavior to Azure Functions v3 and v4 (In-Process)

It hooks into .NET Core dependency injection container to enable authentication and authorization in the same way ASP.NET Core does.

Using the package

Installing the package

dotnet add package DarkLoop.Azure.Functions.Authorize

Setting up authentication

The goal is to utilize the same authentication framework provided for ASP.NET Core

using Microsoft.Azure.Functions.Extensions.DependencyInjection;
using MyFunctionAppNamespace;

[assembly: FunctionsStartup(typeof(Startup))]
namespace MyFunctionAppNamespace
{
 class Startup : FunctionsStartup
 {
 public void Configure(IFunctionsHostBuilder builder)
 {
 builder
 .AddAuthentication(options =>
 {
 options.DefaultAuthenticationScheme = JwtBearerDefaults.AuthenticationScheme;
 options.DefaultChallengeScheme = JwtBearerDefaults.AuthenticationScheme;
 })
 .AddOpenIdConnect(options =>
 {
 options.ClientId = "<my-client-id>";
 // ... more options here
 })
 .AddJwtBearer(options =>
 {
 options.Audience = "<my-audience>";
 // ... more options here
 });

 builder
 .AddAuthorization(options =>
 {
 options.AddPolicy("OnlyAdmins", policyBuilder =>
 {
 // configure my policy requirements
 });
 });
 }
 }
}

No need to register the middleware the way we do for ASP.NET Core applications.

Using the attribute

And now lets use FunctionAuthorizeAttribute the same way we use AuthorizeAttribute in our ASP.NET Core applications.

public class Functions
{
 [FunctionAuthorize]
 [FunctionName("get-record")]
 public async Task<IActionResult> GetRecord(
 [HttpTrigger(AuthorizationLevel.Anonymous, "get")] HttpRequest req,
 ILogger log)
 {
 var user = req.HttpContext.User;
 var record = GetUserData(user.Identity.Name);
 return new OkObjectResult(record);
 }

 [FunctionAuthorize(Policy = "OnlyAdmins")]
 [FunctionName("get-all-records")]
 public async Task<IActionResult> GetAllRecords(
 [HttpTrigger(AuthorizationLevel.Anonymous, "get")] HttpRequest req,
 ILogger log)
 {
 var records = GetAllData();
 return new OkObjectResult(records);
 }
}
Product Versions Compatible and additional computed target framework versions.
.NET net6.0 net6.0 is compatible.  net6.0-android net6.0-android was computed.  net6.0-ios net6.0-ios was computed.  net6.0-maccatalyst net6.0-maccatalyst was computed.  net6.0-macos net6.0-macos was computed.  net6.0-tvos net6.0-tvos was computed.  net6.0-windows net6.0-windows was computed.  net7.0 net7.0 is compatible.  net7.0-android net7.0-android was computed.  net7.0-ios net7.0-ios was computed.  net7.0-maccatalyst net7.0-maccatalyst was computed.  net7.0-macos net7.0-macos was computed.  net7.0-tvos net7.0-tvos was computed.  net7.0-windows net7.0-windows was computed.  net8.0 net8.0 was computed.  net8.0-android net8.0-android was computed.  net8.0-browser net8.0-browser was computed.  net8.0-ios net8.0-ios was computed.  net8.0-maccatalyst net8.0-maccatalyst was computed.  net8.0-macos net8.0-macos was computed.  net8.0-tvos net8.0-tvos was computed.  net8.0-windows net8.0-windows was computed.  net9.0 net9.0 was computed.  net9.0-android net9.0-android was computed.  net9.0-browser net9.0-browser was computed.  net9.0-ios net9.0-ios was computed.  net9.0-maccatalyst net9.0-maccatalyst was computed.  net9.0-macos net9.0-macos was computed.  net9.0-tvos net9.0-tvos was computed.  net9.0-windows net9.0-windows was computed.  net10.0 net10.0 was computed.  net10.0-android net10.0-android was computed.  net10.0-browser net10.0-browser was computed.  net10.0-ios net10.0-ios was computed.  net10.0-maccatalyst net10.0-maccatalyst was computed.  net10.0-macos net10.0-macos was computed.  net10.0-tvos net10.0-tvos was computed.  net10.0-windows net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
4.0.0 4,312 3/19/2024 4.0.0 is deprecated because it is no longer maintained.
4.0.0-preview-240319-1 188 3/19/2024
4.0.0-preview-240311-16 191 3/11/2024
4.0.0-preview-240304-38 223 3/4/2024
3.1.3 12,993 2/12/2024
3.1.3-preview-240211-5 271 2/11/2024
3.1.3-preview-240211-2 260 2/11/2024
3.1.2 78,452 11/30/2022
3.1.2-preview-221118-1 403 11/18/2022
3.1.1 18,525 11/7/2022
3.1.1-preview-221107-1 382 11/7/2022
3.1.1-preview-220811-1 530 8/11/2022
3.1.0 147,463 12/6/2021
3.1.0-preview-211123-1 5,587 11/23/2021
3.0.12-preview-211118-1 646 11/18/2021
3.0.12-preview-210730-1 858 7/30/2021
3.0.11-preview-210408-4 2,562 4/8/2021
3.0.11-preview-210408-3 505 4/8/2021
3.0.11-preview-210408-2 577 4/8/2021
Loading failed