DarkLoop.Azure.Functions.Authorization.InProcess
4.1.0-preview-240521-1
See the version list below for details.
dotnet add package DarkLoop.Azure.Functions.Authorization.InProcess --version 4.1.0-preview-240521-1
NuGet\Install-Package DarkLoop.Azure.Functions.Authorization.InProcess -Version 4.1.0-preview-240521-1
<PackageReference Include="DarkLoop.Azure.Functions.Authorization.InProcess" Version="4.1.0-preview-240521-1" />
paket add DarkLoop.Azure.Functions.Authorization.InProcess --version 4.1.0-preview-240521-1
#r "nuget: DarkLoop.Azure.Functions.Authorization.InProcess, 4.1.0-preview-240521-1"
// Install DarkLoop.Azure.Functions.Authorization.InProcess as a Cake Addin #addin nuget:?package=DarkLoop.Azure.Functions.Authorization.InProcess&version=4.1.0-preview-240521-1&prerelease // Install DarkLoop.Azure.Functions.Authorization.InProcess as a Cake Tool #tool nuget:?package=DarkLoop.Azure.Functions.Authorization.InProcess&version=4.1.0-preview-240521-1&prerelease
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
})
// This is important as Bearer scheme is used by the platform
.AddJwtFunctionsBearer(options =>
{
options.Audience = "<my-audience>";
// ... more options here
});
builder
.AddAuthorization(options =>
{
options.AddPolicy("OnlyAdmins", policyBuilder =>
{
// configure my policy requirements
});
});
}
}
}
Starting with version 4.1.0, the default Bearer scheme is not supported by this framework. You can use a custom scheme or make use of
AddJwtFunctionsBearer(Action<JwtBearerOptions>)
as shown above. This one adds the"FunctionsBearer"
scheme. Clients still submit token for Authorization header in the format:Bearer <token>
.
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 is compatible. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 is compatible. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. |
-
net6.0
- DarkLoop.Azure.Functions.Authorization.Abstractions (>= 4.1.0-preview-240521-1)
- Microsoft.AspNetCore.Authentication.JwtBearer (>= 6.0.0)
- Microsoft.AspNetCore.Authorization (>= 6.0.0)
- Microsoft.Azure.Functions.Extensions (>= 1.1.0)
- Microsoft.Azure.WebJobs (>= 3.0.39)
- Microsoft.Azure.WebJobs.Extensions.Http (>= 3.2.0)
-
net7.0
- DarkLoop.Azure.Functions.Authorization.Abstractions (>= 4.1.0-preview-240521-1)
- Microsoft.AspNetCore.Authentication.JwtBearer (>= 7.0.0)
- Microsoft.AspNetCore.Authorization (>= 7.0.0)
- Microsoft.Azure.Functions.Extensions (>= 1.1.0)
- Microsoft.Azure.WebJobs (>= 3.0.39)
- Microsoft.Azure.WebJobs.Extensions.Http (>= 3.2.0)
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.1.3 | 69 | 11/22/2024 |
4.1.3-preview-241121-5 | 60 | 11/21/2024 |
4.1.2 | 3,227 | 8/20/2024 |
4.1.2-preview-240819-12 | 103 | 8/19/2024 |
4.1.2-preview-240818-2 | 109 | 8/18/2024 |
4.1.1 | 128 | 8/17/2024 |
4.1.1-preview-240816-18 | 109 | 8/16/2024 |
4.1.1-preview-240719-1 | 101 | 7/19/2024 |
4.1.0 | 320 | 5/27/2024 |
4.1.0-preview-240522-2 | 105 | 5/22/2024 |
4.1.0-preview-240522-1 | 102 | 5/22/2024 |
4.1.0-preview-240521-1 | 96 | 5/21/2024 |
4.0.1 | 5,606 | 3/19/2024 |