microsoftgraph / msgraph-sample-blazor-clientside

This sample demonstrates how to use the Microsoft Graph .NET SDK to access data in Office 365 from Blazor WebAssembly apps.
MIT License
33 stars 11 forks source link

me request returns HTTP 400 "Invalid version." #94

Closed lostmsu closed 1 year ago

lostmsu commented 1 year ago

Where did you get the code?

Describe the bug

When I login with Microsoft personal account and the app tries to query my information, I receive HTTP 400 bad request

For https://graph.microsoft.com/me?%24select=displayName,mail,mailboxSettings,userPrincipalName:

{
  "error": {
      "code": "BadRequest",
      "message": "Invalid version.",
      "innerError": {
          "date": "2023-07-13T00:22:11",
          "request-id": "6fe204d7-5b75-4c36-8bf1-acaa8cd743da",
          "client-request-id": "6fe204d7-5b75-4c36-8bf1-acaa8cd743da"
      }
  }
}

To Reproduce

Steps to reproduce the behavior:

  1. Follow the setup instructions
  2. Click on Sign In

Expected behavior

User information is retrieved.

Screenshots

image

Desktop

Dependency versions

jasonjoh commented 1 year ago

Thanks for reporting this. I can reproduce. I'll investigate.

jasonjoh commented 1 year ago

Update: It's not limited to personal accounts. The SDK is not including the version segment in the URL. This URL is wrong:

https://graph.microsoft.com/me?%24select=displayName,mail,mailboxSettings,userPrincipalName

Between the graph.microsoft.com and the /me should be a version segment, /v1.0. The correct URL should be:

https://graph.microsoft.com/v1.0/me?%24select=displayName,mail,mailboxSettings,userPrincipalName

This appears to be an issue with the SDK. I'm finding out more from the engineering team.

jasonjoh commented 1 year ago

Ok, so while they sort out this issue, here's a workaround. In GraphClientFactory.cs, change the line that creates the requestAdapter to:

var requestAdapter = new HttpClientRequestAdapter(
    new BlazorAuthProvider(accessor), null, null, httpClient)
        {
            BaseUrl = "https://graph.microsoft.com/v1.0"
        };