Member-only story

How to Implement Microsoft.Identity.Web in Azure Functions V4 and .NET 6

Tobias Streng
Better Programming
Published in
5 min readFeb 24, 2022
Photo by Brett Jordan on Unsplash

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:

Create an account to read the full story.

The author made this story available to Medium members only.
If you’re new to Medium, create a new account to read this story on us.

Or, continue in mobile web

Already have an account? Sign in

Tobias Streng
Tobias Streng

Written by Tobias Streng

Senior Software and Cloud Solutions Architect

Write a response

Lots of fancy schnizzle. Good luck with this. I'm neither impressed nor interested . . . so many Medium hooplas end up being a waste of time. We just want what's fair for a decent day's work.

--

Boy, this was a lot of work! Thanks for having our ackbizzles (is that right?)

--

Thanks, Robin! I always appreciate how much time and effort you put into your Medium information pieces. Hope you have a nice Wednesday❣️ A.J. (she, her)

--