登录到Azure AD后获取Power BI访问令牌

问题描述

我有将我登录到Azure AD的代码,但是我无法弄清楚如何获取访问令牌以调用REST API或PowerBI

解决方法

有用于获取Power BI REST API访问令牌的示例代码。

//The client id that Azure AD created when you registered your client app.
string clientID = "{Client_ID}";

//RedirectUri you used when you register your app.
//For a client app,a redirect uri gives Azure AD more details on the application that it will authenticate.
// You can use this redirect uri for your client app
string redirectUri = "https://login.live.com/oauth20_desktop.srf";

//Resource Uri for Power BI API
string resourceUri = "https://analysis.windows.net/powerbi/api";

//OAuth2 authority Uri
string authorityUri = "https://login.microsoftonline.com/common/";

// AcquireToken will acquire an Azure access token
// Call AcquireToken to get an Azure token from Azure Active Directory token issuance endpoint
AuthenticationContext authContext = new AuthenticationContext(authorityUri);
var token = authContext.AcquireTokenAsync(resourceUri,clientID,new Uri(redirectUri)).Result.AccessToken;

Console.WriteLine(token);

有关更多详细信息,请参见here

相关问答

依赖报错 idea导入项目后依赖报错,解决方案:https://blog....
错误1:代码生成器依赖和mybatis依赖冲突 启动项目时报错如下...
错误1:gradle项目控制台输出为乱码 # 解决方案:https://bl...
错误还原:在查询的过程中,传入的workType为0时,该条件不起...
报错如下,gcc版本太低 ^ server.c:5346:31: 错误:‘struct...