Я собираюсь использовать API бронирования для получения списка bookingBusiness для одной конкретной учетной записи пользователя, которая:
а. подтверждена учетная запись пользователя Office Premium Business Office 365
б. учетная запись может вызывать заказы API для получения списка bookingBusiness через "Graph Explorer" после входа в систему с неявным потоком (способ входа на страницу)
Когда я пытаюсь получить токен доступа из «потока владельца ресурса» (успешно получил токен доступа) и использовать его в вызовах Api с Graph Beta SDK (предварительный просмотр Microsoft.Graph.Beta v0.6), вызов GET никогда не получится не возвращен ни набор результатов, ни ошибка для завершения вызова.
public static class GraphHelper
{
public static void GetBusinessListTest()
{
var graphClient = GetAuthenticatedClient();
var bookingBusinesses = graphClient.BookingBusinesses.Request();
// the calling below never return a result back or throw error code
var res= bookingBusinesses.GetAsync().Result;
return;
}
private static GraphServiceClient GetAuthenticatedClient()
{
var authProvider = GetAuthProvider();
return new GraphServiceClient(authProvider);
}
private static IAuthenticationProvider GetAuthProvider()
{
string tenantId = "xxxx-xxxx-xxxx-xxxx-xxxx";
string authority = $"https://login.microsoftonline.com/{tenantId}";
//scopes string - Bookings.Manage.All User.Read
string[] scopes = graphScopes.Split(' ');
IPublicClientApplication app;
//GET access token from user login and credentials
app = PublicClientApplicationBuilder.Create(appId)
.WithTenantId(tenantId)
.WithAuthority(authority)
.Build();
var accounts = app.GetAccountsAsync().Result;
AuthenticationResult result = null;
if (accounts.Any())
{
var acct = accounts.FirstOrDefault();
result = app.AcquireTokenSilent(scopes, acct)
.ExecuteAsync().Result;
}
else
{
try
{
var securePassword = new SecureString();
foreach (char c in "login user password") // you should fetch the password
securePassword.AppendChar(c); // keystroke by keystroke
result = app.AcquireTokenByUsernamePassword(scopes,"loginuser@EmailAddress",securePassword).ExecuteAsync().Result;
}
catch (MsalException ex)
{
var ss = ex.Message;
}
}
//assign access token to Grapth Deletegate access provider HTTP request header - bearer token
var authenticationProvider = new Microsoft.Graph.DelegateAuthenticationProvider(
async (requestMessage) =>
{
requestMessage.Headers.Authorization =
new AuthenticationHeaderValue("Bearer", result.AccessToken);
});
return authenticationProvider;
}
}
// call to booking Businesses https://graph.microsoft.com/beta/bookingBusinesses
public IGraphServiceBookingBusinessesCollectionRequest Request(IEnumerable<Option> options)
{
return new GraphServiceBookingBusinessesCollectionRequest(this.RequestUrl, this.Client, options);
}
public async System.Threading.Tasks.Task<IGraphServiceBookingBusinessesCollectionPage> GetAsync(CancellationToken cancellationToken)
{
this.Method = "GET";
// *********the code execution is eactly stucking in the line below, a normal HTTP Get Call from Base Request**********
var response = await this.SendAsync<GraphServiceBookingBusinessesCollectionResponse>(null, cancellationToken).ConfigureAwait(false);
if (response != null && response.Value != null && response.Value.CurrentPage != null)
{
if (response.AdditionalData != null)
{
object nextPageLink;
response.AdditionalData.TryGetValue("@odata.nextLink", out nextPageLink);
var nextPageLinkString = nextPageLink as string;
if (!string.IsNullOrEmpty(nextPageLinkString))
{
response.Value.InitializeNextPageRequest(
this.Client,
nextPageLinkString);
}
// Copy the additional data collection to the page itself so that information is not lost
response.Value.AdditionalData = response.AdditionalData;
}
return response.Value;
}
return null;
}
Я ожидаю, что список рассылки bookingBuusiness вернется или будет получен ответ с кодом ошибки.
Может ли какой-либо эксперт ответить на вопрос, может ли API бронирования заказов поддерживать токен доступа, предоставленный из потока «Учетные данные владельца ресурса»? если да, то в чем проблема с моей имплементацией
Любой совет или ответ будет оценен
--------------- UPDATE ----------
В Azure AD приложение настроило соответствующий параметр, чтобы разрешить владельцу ресурса тип доступа