microsoft-identity-web icon indicating copy to clipboard operation
microsoft-identity-web copied to clipboard

[Bug] Azure function 4.0 does not work (method not found exception in Microsoft.IdentityModel)

Open craigmaddux opened this issue 2 years ago • 5 comments

Which version of Microsoft Identity Web are you using? Note that to get help, you need to run the latest version. Microsoft.Identity.Web 1,24,1 Also tried downgrading to 1.5.1 to see if issue reported in issue #1428

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)
    • [X ] Protected web APIs call downstream web APIs
  • Token cache serialization
    • [ ] In-memory caches
    • [ ] Session caches
    • [ ] Distributed caches
  • Other

Is this a new or an existing app? c. This is a new app or an experiment. --> Specifically, I initially tried on an existing small Azure Function App.
When that didn't work, I built the dotnet new func2 --auth SingleOrg in a new project to validate.

Repro

services.AddAuthentication(sharedOptions =>
            {
                sharedOptions.DefaultScheme = Microsoft.Identity.Web.Constants.Bearer;
                sharedOptions.DefaultChallengeScheme = Microsoft.Identity.Web.Constants.Bearer;
            })
                .AddMicrosoftIdentityWebApi(Configuration.GetSection("AzureAd"));

Expected behavior Azure App Function should start normally and allow calling of Azure Functions - in the case of the template, SampleFunc.

Actual behavior Code works as expected in local environment, the issue is when it is deployed to Azure. Azure Function Startup fails:

image

Debugging shows that no exceptions are thrown by the above code, but regardless, the app fails to start, instead giving:

Possible solution

Additional context / logs / screenshots / link to code As found in other issues such as #1428 I have also put in:

 <_FunctionsSkipCleanOutput>true</_FunctionsSkipCleanOutput>

but to no success. I've attempted several other versions, even running the template as net6.0 on v4. The result has always been the same: if I comment out the one bit of code mentioned in the Repro section, function app comes up perfectly fine. Add back in that services causes the app to fail on startup, and no exceptions/traces in the logs indicate any sort of failure. (The traces, in fact, say the host came up fine. Go figure!) I've verified that the Configuration.GetSection has the correct information for AzureAd, thinking that perhaps the appsettings.json wasn't being read for some reason.

Been scratching my head and reading through the bug submissions for a few days now, and hoping I've just missed something fairly obvious.

craigmaddux avatar May 05 '22 14:05 craigmaddux

@craigmaddux : this is a known issue with Azure functions. The Azure function team has a fix for the Azure function runtime. It's being deployed in all environments. When that's done it will be brought to the dev environments too with Visual Studio.

jmprieur avatar May 05 '22 15:05 jmprieur

@jmprieur Thanks for the information Jean-Marc! Is there a PR or equivalent to follow to see when this makes it out into production?

craigmaddux avatar May 05 '22 15:05 craigmaddux

@craigmaddux I would follow this issue

jennyf19 avatar May 05 '22 17:05 jennyf19

Any update on this? I see #1548 is also still open even though an Azure Functions PR that looks like it might have fixed it has been merged: https://github.com/Azure/azure-functions-host/pull/8129

briandunnington avatar Jul 08 '22 17:07 briandunnington

@briandunnington The PR did not fix the issue, which is why the issues here are still open.

jennyf19 avatar Jul 10 '22 02:07 jennyf19

Any updates on this?

juantarquino-ssb avatar Mar 08 '23 12:03 juantarquino-ssb

I have been struggling today to find any combination of .NET/assembly versions/Azure Functions runtime which will work but I haven't found a combination. I'm on a greenfield project so very flexible so if anyone can suggest a combination of versions that works, that would be very helpful....

johnnycardy avatar Apr 21 '23 16:04 johnnycardy

This issue should be fixed now w/the latest Azure Functions. And you can also leverage this sample instead.

Closing as this is now fixed, appreciate all your patience while the functions team worked to fix this issue.

jennyf19 avatar Mar 28 '24 02:03 jennyf19

Hi @jennyf19 , that sample you linked to does not represent an Azure Function. I am not sure if you meant to include it as a general guide to the identity library outside of function apps or if you meant to include it as an actual function app example.

juantarquino-ssb avatar Mar 28 '24 14:03 juantarquino-ssb