Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug] FormatException using the TokenAcquisitionCredentialProvider #673

Closed
1 task done
davesmits opened this issue Oct 9, 2020 · 4 comments
Closed
1 task done
Assignees
Labels
bug Something isn't working fixed P1
Milestone

Comments

@davesmits
Copy link
Contributor

davesmits commented Oct 9, 2020

Which version of Microsoft Identity Web are you using?
Note that to get help, you need to run the latest version.

Where is the issue?

  • Web API
    • Protected web APIs call downstream web APIs

Is this a new or an existing app?

This is a new app or an experiment.

Repro

[HttpGet]
        public async Task<ActionResult> Register()
        {
            var result = await _graphServiceClient.Subscriptions.Request()
                .GetAsync();

            var notificationChannel = result.FirstOrDefault();

            if (notificationChannel is null)
            {
                var r = await _graphServiceClient.Subscriptions.Request().AddAsync(new Microsoft.Graph.Subscription
                {
                    ChangeType = "created",
                    NotificationUrl = "https://teamer.servicebus.windows.net/dave-apidesktop-ojevm42/api/webhook",
                    Resource = "/chats/getAllMessages",
                    ExpirationDateTime = new DateTimeOffset(DateTime.UtcNow.AddMinutes(30)),
                    ClientState = "TeamerNotifications",
                });
            }
            else
            {

            }

            return Ok();

Expected behavior
Subscription in the graph is created or an exception from the Graph API it self

Actual behavior
Exception in .net code

fail: Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware[1]
      An unhandled exception has occurred while executing the request.
Status Code: 0
Microsoft.Graph.ServiceException: Code: generalException
Message: An error occurred sending the request.

 ---> System.FormatException: Cannot add value because header 'Authorization' does not support multiple values.
   at System.Net.Http.Headers.HttpHeaders.ParseAndAddValue(HeaderDescriptor descriptor, HeaderStoreItemInfo info, String value)
   at System.Net.Http.Headers.HttpHeaders.Add(String name, String value)
   at Microsoft.Identity.Web.TokenAcquisitionCredentialProvider.AuthenticateRequestAsync(HttpRequestMessage request)
   at Microsoft.Graph.AuthenticationHandler.SendRetryAsync(HttpResponseMessage httpResponseMessage, IAuthenticationProvider authProvider, CancellationToken cancellationToken)
   at Microsoft.Graph.AuthenticationHandler.SendAsync(HttpRequestMessage httpRequestMessage, CancellationToken cancellationToken)
   at System.Net.Http.HttpClient.FinishSendAsyncBuffered(Task`1 sendTask, HttpRequestMessage request, CancellationTokenSource cts, Boolean disposeCts)
   at Microsoft.Graph.HttpProvider.SendRequestAsync(HttpRequestMessage request, HttpCompletionOption completionOption, CancellationToken cancellationToken)
   --- End of inner exception stack trace ---
   at Microsoft.Graph.HttpProvider.SendRequestAsync(HttpRequestMessage request, HttpCompletionOption completionOption, CancellationToken cancellationToken)
   at Microsoft.Graph.HttpProvider.SendAsync(HttpRequestMessage request, HttpCompletionOption completionOption, CancellationToken cancellationToken)
   at Microsoft.Graph.BaseRequest.SendRequestAsync(Object serializableObject, CancellationToken cancellationToken, HttpCompletionOption completionOption)
   at Microsoft.Graph.BaseRequest.SendAsync[T](Object serializableObject, CancellationToken cancellationToken, HttpCompletionOption completionOption)
   at Teamer.WebApi.Controllers.SubscriptionController.Register() in C:\Users\dave\source\repos\Dave\Teamer\Teamer.WebApi\Controllers\SubscriptionController.cs:line 40

Possible solution
https://github.com/AzureAD/microsoft-identity-web/blob/fde36879183cd3ef2ec386cdea704429dffa7b32/src/Microsoft.Identity.Web.MicrosoftGraph/TokenAcquisitionCredentialProvider.cs

Don't keep adding the authorization header but set it once. Happy to make the PR

@davesmits davesmits changed the title [Bug] [Bug] FormatException using the TokenAcquisitionCredentialProvider Oct 9, 2020
@jmprieur jmprieur added bug Something isn't working P1 labels Oct 10, 2020
@jmprieur jmprieur added this to the 1.2.0 milestone Oct 10, 2020
@jmprieur
Copy link
Collaborator

Thanks for the heads-up @davesmits

@jmprieur
Copy link
Collaborator

oh @davesmits, sure, if you can make the PR, please go ahead.

@jennyf19
Copy link
Collaborator

Included in 1.2.0 release.

@jmprieur
Copy link
Collaborator

Thanks again for your contribution @davesmits
As @jennyf19 was writing, this has now released

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working fixed P1
Projects
None yet
Development

No branches or pull requests

3 participants