Repository navigation
Description
Which version of Microsoft Identity Web are you using?
Microsoft.Identity.Web 1.15.2
Where is the issue?
- Web app
- Sign-in users
- Sign-in users and call web APIs
- Web API
- Protected web APIs (validating tokens)
- Protected web APIs (validating scopes)
- Protected web APIs call downstream web APIs
- Token cache serialization
- In-memory caches
- Session caches
- Distributed caches
- Other (please describe)
Is this a new or an existing app?
c. This is a new app or an experiment.
Repro
- Create a new Functions app with the func2 template and SingleOrg auth:
dotnet new func2 -i Microsoft.Identity.Web.ProjectTemplates --auth SingleOrg - Make sure the Microsoft.Identity.Web dependency is version 1.15.2
- Add
.EnableTokenAcquisitionToCallDownstreamApi().AddInMemoryTokenCaches()to the auth setup - Configure the
AzureAdsettings in appsettings.json - Add a new timer function that injects
ITokenAcquisitionand callsGetAccessTokenForAppAsync
Full code: https://github.com/Choonster/AzureFunctionsMicrosoftIdentityWebTest/tree/1.15.2
Expected behavior
Function receives access token for the application.
Actual behavior
The System.IdentityModel.Tokens.Jwt assembly fails to load:
System.IO.FileNotFoundException: Could not load file or assembly 'System.IdentityModel.Tokens.Jwt, Version=6.12.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'. The system cannot find the file specified.
File name: 'System.IdentityModel.Tokens.Jwt, Version=6.12.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'
at Microsoft.Identity.Web.TokenAcquisition.GetEffectiveAuthenticationScheme(String authenticationScheme)
at Microsoft.Identity.Web.TokenAcquisition.GetAuthenticationResultForAppAsync(String scope, String authenticationScheme, String tenant, TokenAcquisitionOptions tokenAcquisitionOptions)
at Microsoft.Identity.Web.TokenAcquisition.GetAccessTokenForAppAsync(String scope, String authenticationScheme, String tenant, TokenAcquisitionOptions tokenAcquisitionOptions)
at azure_functions_ms_identity_web.TimerFunc.RunAsync(TimerInfo myTimer, ILogger log) in C:\Users\USER\source\repos\azure-functions-ms-identity-web\TimerFunc.cs:line 26
Possible solution
Downgrading or relaxing System.IdentityModel.Tokens.Jwt dependency.
Additional context / logs / screenshots
azure-functions-core-tools currently depends on version 5.5.0 of System.IdentityModel.Tokens.Jwt, via Microsoft.Azure.AppService.Middleware.NetCore 1.4.0, Microsoft.Azure.WebSites.DataProtection 2.1.91-alpha and Microsoft.IdentityModel.Protocols.OpenIdConnect 5.5.0.
Microsoft.Identity.Web 1.14.1 only depended on System.IdentityModel.Tokens.Jwt for net5.0, but 1.15.0 added this dependency for netcoreapp3.1 as well (diff), making it incompatible with azure-functions-core-tools.
Activity
spplante commentedon Aug 20, 2021
I opened the exact same problem here and didn't quite understand the answer I got...For me downgrading the nuget to 1.14.1 did work, until I added another nuget (PnP.Core) then the problem comes back during runtime...
czb182 commentedon Apr 21, 2023
This is still an issue. Running .NET 6 on V4 Azure Function. Can't upgrade past 1.15.1 which apparently is coming up on 2 years old now. Would like to upgrade to newer version. Perhaps some coordination across teams is needed?
Azure/azure-functions-host#8587
jennyf19 commentedon Mar 28, 2024
This is fixed in the latest Azure Functions, or you can use this sample instead. Please re-open if the issue persists.