【问题标题】:can't get power Bi access token无法获得电力 Bi 访问令牌
【发布时间】:2017-12-13 10:12:36
【问题描述】:
【问题讨论】:
标签:
javascript
angular
powerbi
powerbi-embedded
【解决方案1】:
如果您使用的是 C#.Net,您可以查看有关如何获取 Power BI AAD 令牌的官方文档:
https://docs.microsoft.com/en-us/power-bi/developer/get-azuread-access-token
using Microsoft.IdentityModel.Clients.ActiveDirectory;
protected void Page_Load(object sender, EventArgs e)
{
//Redirect uri must match the redirect_uri used when requesting Authorization code.
string redirectUri = String.Format("{0}Redirect", Properties.Settings.Default.RedirectUrl);
string authorityUri = Properties.Settings.Default.AADAuthorityUri;
// Get the auth code
string code = Request.Params.GetValues(0)[0];
// Get auth token from auth code
TokenCache TC = new TokenCache();
AuthenticationContext AC = new AuthenticationContext(authorityUri, TC);
ClientCredential cc = new ClientCredential
(Properties.Settings.Default.ClientID,
Properties.Settings.Default.ClientSecret);
AuthenticationResult AR = AC.AcquireTokenByAuthorizationCode(code, new Uri(redirectUri), cc);
//Set Session "authResult" index string to the AuthenticationResult
Session[_Default.authResultString] = AR;
//Redirect back to Default.aspx
Response.Redirect("/Default.aspx");
}
如果您使用任何其他语言,您可以使用合适的 AAD 库(例如,用于 js\node.js 的 ADAL.js)或仅使用相同属性的 AAD 端点的 HTTP 调用。