Azure Ad WebApp MSGraph Value cannot be null

AdamBlankenship-4615 26 Reputation points
2022-03-02T13:58:50.66+00:00

I'm running into an issue with AzureAd/Graph configuration between Azure and Local. I'm using Vs2019 .Net Core 5 Identity.Web 1.23 On local both in Visual Studio and stand alone exe. I am able to connect to Graph get my roles and details when the same code is deployed to the Azure Web App I get the follow.

Code: generalException Message: An error occurred sending the request. Value cannot be null. (Parameter 'headers') at Microsoft.Identity.Web.AppServicesAuthenticationInformation.GetIdToken(IDictionary2 headers) at Microsoft.Identity.Web.AppServicesAuthenticationTokenAcquisition.GetAuthenticationResultForUserAsync(IEnumerable1 scopes, String authenticationScheme, String tenantId, String userFlow, ClaimsPrincipal user, TokenAcquisitionOptions tokenAcquisitionOptions) at Microsoft.Identity.Web.TokenAcquisitionAuthenticationProvider.AuthenticateRequestAsync(HttpRequestMessage request) at Microsoft.Graph.AuthenticationHandler.SendAsync(HttpRequestMessage httpRequestMessage, CancellationToken cancellationToken) at System.Net.Http.HttpClient.SendAsyncCore(HttpRequestMessage request, HttpCompletionOption completionOption, Boolean async, Boolean emitTelemetryStartStop, CancellationToken cancellationToken) at Microsoft.Graph.HttpProvider.SendRequestAsync(HttpRequestMessage request, HttpCompletionOption completionOption, CancellationToken cancellationToken)

Microsoft Entra ID
Microsoft Entra ID
A Microsoft Entra identity service that provides identity management and access control capabilities. Replaces Azure Active Directory.
19,472 questions
{count} votes

4 answers

Sort by: Most helpful
  1. Hatch 16 Reputation points
    2022-06-22T12:51:20.297+00:00

    I was having this same issue as soon as I deployed the app to an Azure app service - took longer than expected to resolve but tracked it back to Microsoft.Identity.Web which, it turns out, uses the HttpContext to get the token. Short answer - turn on Settings > Configuration > General Settings > Web Sockets in the app service which will include the httpcontext information in the socket calls to your app and it should the null reference exception.

    3 people found this answer helpful.
    0 comments No comments

  2. Nikhil Garg 5 Reputation points
    2023-12-07T17:51:06.6633333+00:00

    It turned out that problem was related to having Authentication enabled in the Azure app service itself, while also having Azure AD configured as a connected service in the Blazor server project within Visual Studio. By turning off authentication on the web app in Azure and relying solely on the settings within the project, everything started working correctly.

    1 person found this answer helpful.
    0 comments No comments

  3. Bruce (SqlWork.com) 56,021 Reputation points
    2022-03-04T16:03:06.017+00:00

    Because azure is a webfarm, you can not use the In memory token cache. You need to use a distributed cache solution.

    https://learn.microsoft.com/en-us/aspnet/core/performance/caching/distributed?view=aspnetcore-6.0

    0 comments No comments

  4. AdamBlankenship-4615 26 Reputation points
    2022-03-08T02:46:25.08+00:00

    I did find my issue, I changed the memory token cache which did not fix the issue.
    My issue was related to the web app running under its own resource id