Rudi.Dev.Azure.Functions.Isolated.Authz 1.1.1

dotnet add package Rudi.Dev.Azure.Functions.Isolated.Authz --version 1.1.1
NuGet\Install-Package Rudi.Dev.Azure.Functions.Isolated.Authz -Version 1.1.1
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="Rudi.Dev.Azure.Functions.Isolated.Authz" Version="1.1.1" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Rudi.Dev.Azure.Functions.Isolated.Authz --version 1.1.1
#r "nuget: Rudi.Dev.Azure.Functions.Isolated.Authz, 1.1.1"
#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.
// Install Rudi.Dev.Azure.Functions.Isolated.Authz as a Cake Addin
#addin nuget:?package=Rudi.Dev.Azure.Functions.Isolated.Authz&version=1.1.1

// Install Rudi.Dev.Azure.Functions.Isolated.Authz as a Cake Tool
#tool nuget:?package=Rudi.Dev.Azure.Functions.Isolated.Authz&version=1.1.1

Rudi.Dev.Azure.Functions.Isolated.Authz

Add Authentication / Authorization Middleware to Azure Functions (running Isolated on .NET 7) when using the built in Azure App Service authentication.

This only supports App Roles (not Scopes).

Why

  • Azure Functions don't have a built in way to access the ClaimsPrincipal
  • Documentation for this has code for In-Process (which this mostly uses)

Can I use this In-Process?

Don't. Accept a ClaimsPrincipal and use a Filter instead.

Usage

Add Rudi.Dev.Azure.Functions.Isolated.Authz from NuGet.

Add the middleware to your Function worker:

.ConfigureFunctionsWorkerDefaults(app =>
    {
        app.AddAuthz(); // <-- Add me
    })

Add a good old [Authorize(..)] attribute to your functions:

[Authorize] // Requires an authenticated user (although don't use this, App Service should be doing this for you)
[Authorize("Required.AppRole")]
[Authorize(new [] { "Required.AppRole", "Another.Required.AppRole" })]

What this actually does

It basically uses the code referenced above from Microsoft to parse the ClientPrincipal, and translate it to a ClaimsPrincipal but with Roles correctly mapped so you can use principal.IsInRole("") in your own code.

The Attribute is just a helper so that you don't have to do that.

Product Compatible and additional computed target framework versions.
.NET 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. 
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
1.1.1 166 7/23/2023
1.1.0 125 5/16/2023
1.0.0 117 5/13/2023
0.0.0-alpha.0 63 5/13/2023