AzureAD / microsoft-identity-web

Helps creating protected web apps and web APIs with Microsoft identity platform and Azure AD B2C
MIT License
676 stars 208 forks source link

Resource not found for the segment 'bookingBusinesses' using Microsoft.Identity.Web.MicrosoftGraphBeta #2117

Closed leah-mq closed 1 year ago

leah-mq commented 1 year ago

Microsoft.Identity.Web Library

Microsoft.Identity.Web.GraphBeta

Microsoft.Identity.Web version

2.5.0

Web app

Sign-in users

Web API

Protected web APIs (validating tokens)

Token cache serialization

In-memory caches

Description

I wanted to get the list of booking businesses. I have the code working fwith Microsoft.Identity.Web.MicrosoftGraph so I decided to try with GraphBeta.

When calling Booking businesses from the graph service client I get the following error : Resource not found for the segment 'bookingBusinesses'

This is the line of code getting the error : var bookingBusinesses = _graphServiceClient.BookingBusinesses.Request().GetAsync().Result;

Reproduction steps

  1. Create a new project ASP.NET Core Web App ( Model-View-Controller) - Framework .NET 7.0 - Authentication type : Microsoft identity platform
  2. Configure the project to connect Azure Ad ( App registration, fill appsettings.json)
  3. Install Microsoft.Identity.Web and Microsoft.Identity.Web.MicrosoftGraphBeta
  4. Configure Program.cs

string[]? initialScopes = builder.Configuration.GetValue<string>("Graph:Scopes")?.Split(' '); // Add services to the container. builder.Services.AddAuthentication(OpenIdConnectDefaults.AuthenticationScheme) .AddMicrosoftIdentityWebApp(builder.Configuration.GetSection("AzureAd")) .EnableTokenAcquisitionToCallDownstreamApi(initialScopes) .AddMicrosoftGraph(builder.Configuration.GetSection("Graph)) .AddInMemoryTokenCaches();

  1. Home controller contructor

private readonly ILogger<HomeController> _logger; private readonly GraphServiceClient _graphServiceClient; public HomeController(ILogger<HomeController> logger,GraphServiceClient graphServiceClient) { _logger = logger; _graphServiceClient = graphServiceClient; }

  1. Add code to Index() of Home controller [AuthorizeForScopes(Scopes = new[] { "Bookings.Read.All" })] public IActionResult Index() { var bookingBusinesses = _graphServiceClient.BookingBusinesses.Request().GetAsync().Result; // It fails here return View(); }

Error message

System.AggregateException: 'One or more errors occurred. (Code: BadRequest Message: Resource not found for the segment 'bookingBusinesses'.

One or more errors occurred. (Code: BadRequest Message: Resource not found for the segment 'bookingBusinesses'. Inner error: AdditionalData: date: 2023-03-17T15:32:49 request-id: 75886252-5534-4123-881d-b52b26ebc5e5 client-request-id: 75886252-5534-4123-881d-b52b26ebc5e5 ClientRequestId: 75886252-5534-4123-881d-b52b26ebc5e5 )

Inner Exception Message

Code: BadRequest Message: Resource not found for the segment 'bookingBusinesses'. Inner error: AdditionalData: date: 2023-03-17T15:32:49 request-id: 75886252-5534-4123-881d-b52b26ebc5e5 client-request-id: 75886252-5534-4123-881d-b52b26ebc5e5 ClientRequestId: 75886252-5534-4123-881d-b52b26ebc5e5

Id Web logs

No response

Relevant code snippets

var bookingBusinesses = _graphServiceClient.BookingBusinesses.Request().GetAsync().Result;

Regression

No response

Expected behavior

I expect to get the list of booking businesses

jmprieur commented 1 year ago

@leah-mq the best would be to check with the Microsoft Graph SDK repository :https://github.com/microsoftgraph/msgraph-sdk-dotnet