尝试更改资源 URI:
var result = authenticationContext.AcquireToken(resource: "https://management.core.windows.net/", clientCredential: credential);
to
var result = authenticationContext.AcquireToken(resource: **"https://analysis.windows.net/powerbi/api"**, clientCredential: credential);
您想要获取 power bi api 的令牌。
希望有帮助。
编辑根据OP评论更新答案:
这是您需要做的。
在 Azure AD 中创建一个“本机应用程序”并获取该客户端 ID,其中不会有任何秘密。
确保您拥有 Nuget Active Directory 身份验证库 2.23.302261847 中的最新版本 ADAL
您将需要使用此获取令牌重载:
authContext.AcquireToken("https://analysis.windows.net/powerbi/api", clientID, new UserCredential(<Username>, <Password>));
编辑:2016-11-11
阿达尔3.13.7UserCredentail 不再具有上面定义的构造函数。有一个新的密封类 UserPasswordCredential
public sealed class UserPasswordCredential : UserCredential
其中具有与以前的 UserCredential 对象匹配的构造函数
public UserPasswordCredential(string userName, string password)
您可以通过执行以下操作获取令牌:
authContext.AcquireToken("https://analysis.windows.net/powerbi/api", clientID, new UserPasswordCredential(<Username>, <Password>));