我是一个POC,我必须从c#连接到Fabric Rest API,我想创建Item.我可以按照https://learn.microsoft.com/en-us/rest/api/fabric/articles/get-started/fabric-api-quickstart上提供的指示创建项目. 我面临的挑战是创造 token .根据此页面上提供的说明,我将获得一个登录页面,并在成功验证后,生成令牌. 我将在api内部使用令牌创建调用,但我没有进行身份验证的规定.如果可能的话,我需要一些关于如何使用客户端密钥生成令牌的指导.我目前使用的代码如下:
using Microsoft.Identity.Client;
#region parameters section
string ClientId = "clientID";
string Authority = "https://login.microsoftonline.com/organizations";
string RedirectURI = "http://localhost";
#endregion
#region Acquire a token for Fabric APIs
// In this sample we acquire a token for Fabric service with the scopes
// Workspace.ReadWrite.All and Item.ReadWrite.All
string[] scopes = new string[] { "https://api.fabric.microsoft.com/Workspace.ReadWrite.All https://api.fabric.microsoft.com/Item.ReadWrite.All" };
PublicClientApplicationBuilder PublicClientAppBuilder =
PublicClientApplicationBuilder.Create(ClientId)
.WithAuthority(Authority)
.WithRedirectUri(RedirectURI);
IPublicClientApplication PublicClientApplication = PublicClientAppBuilder.Build();
AuthenticationResult result = await PublicClientApplication.AcquireTokenInteractive(scopes)
.ExecuteAsync()
.ConfigureAwait(false);
Console.WriteLine(result.AccessToken);
#endregion
我已经在Azure active directory中创建了一个新的应用注册,并为Power Bi和Azure存储添加了api权限.我还提供了管理员同意新添加的权限.我创建了一个客户机密,并试图在postman 中创建一个令牌.创建了令牌,但当使用该令牌时,它给了我一个错误的请求.当使用从c#代码生成的令牌时,它的工作正常.