Member-only story
How to Implement Microsoft.Identity.Web in Azure Functions V4 and .NET 6
Having trouble getting Microsoft.Identity.Web working on the latest Azure Functions V4? This guide is for you!
I recently decided to upgrade my serverless Azure Functions Applications from .NET Core 3.1 to the latest .NET 6.
As with .NET Core 3.1, I’ve also had a LOT of trouble, implementing the Microsoft.Identity.Web
package in Azure Functions. After hours of research, I found a way, to finally get it working, and to save you some trouble, I created this guide for you.
What is Microsoft.Identity.Web?
The Microsoft Identity Web authentication library adds authentication and authorization support on your Web APIs by using Microsoft identity platform in the background. With this library, you are able to add an authentication middleware and use Microsoft Authentication Library (MSAL). (see Microsoft docs)
On Azure Functions you will be able to authenticate and authorize requests against your Azure Active Directory (AAD).
Problems during Implementation
After a bit of research, I stumbled accross this documentation, on how to implement Microsoft Identity Web with Azure Functions:
If you go ahead, and implement it that way, change all references to the latest .NET 6 and Azure Functions v4, you will face the first issue. The latest Microsoft.Identity.Web (to this date: V1.23.0
) still has some compatibility issues with Azure Functions. You will receive the following exception:
System.Private.CoreLib: Exception while executing function: SampleFunc. Microsoft.Identity.Web: Could not load file or assembly 'Microsoft.IdentityModel.Tokens, Version=6.15.1.0.
So I continued researching, until I found a promising guide here: