Forbidden error Power BI API GenerateTokenInGroup & GenerateTokenForCreateInGroup

huangapple go评论115阅读模式
英文:

Forbidden error Power BI API GenerateTokenInGroup & GenerateTokenForCreateInGroup

问题

最近我遇到了GenerateTokenInGroup和GenerateTokenForCreateInGroup API的问题,并收到了"操作返回了无效的状态代码 'Forbidden'"错误消息。上周它还能正常工作。然而,使用相同的设置,我可以成功执行GetReportsInGroup API。

  1. public class Secrets
  2. {
  3. private static string authorityUrl = "https://login.microsoftonline.com/organizations/";
  4. private static string resourceUrl = "https://analysis.windows.net/powerbi/api";
  5. public static string apiUrl = "https://api.powerbi.com/";
  6. private static string ClientID = ""; // Azure AD应用程序 - 应用程序ID/客户端ID
  7. private static string ClientSecret = ""; // Azure AD应用程序 - 客户端密钥
  8. private static string TenantId = ""; // Azure AD租户ID
  9. public static Guid groupId = Guid.Parse(""); // Power BI工作区ID
  10. private static ClientCredential credential = null;
  11. private static AuthenticationResult authenticationResult = null;
  12. public static TokenCredentials tokenCredentials = null;
  13. public static Task Authorize()
  14. {
  15. return Task.Run(async () =>
  16. {
  17. credential = new ClientCredential(ClientID, ClientSecret);
  18. authenticationResult = null;
  19. tokenCredentials = null;
  20. var tenantSpecificURL = authorityUrl.Replace("organizations", Secrets.TenantId);
  21. var authenticationContext = new AuthenticationContext(tenantSpecificURL);
  22. authenticationResult = await authenticationContext.AcquireTokenAsync(resourceUrl, credential);
  23. if (authenticationResult != null)
  24. {
  25. tokenCredentials = new TokenCredentials(authenticationResult.AccessToken, "Bearer");
  26. }
  27. });
  28. }
  29. }
  30. public class PowerBIController : ApiController
  31. {
  32. private PowerBIClient PowerBIClient { get; set; }
  33. public PowerBIController()
  34. {
  35. Secrets.Authorize().Wait();
  36. PowerBIClient = new(new Uri(Secrets.apiUrl), Secrets.tokenCredentials);
  37. }
  38. [HttpGet]
  39. public object GetReportsInGroup()
  40. {
  41. return PowerBIClient.Reports.GetReportsInGroup(Secrets.groupId).Value;
  42. }
  43. [HttpGet]
  44. public object GenerateTokenInGroup(Guid reportId, Guid datasetId)
  45. {
  46. return PowerBIClient.Reports.GenerateTokenInGroup(Secrets.groupId, reportId, new GenerateTokenRequest(accessLevel: "View", datasetId: datasetId.ToString()));
  47. }
  48. [HttpGet]
  49. public object GenerateTokenForCreateInGroup(Guid datasetId)
  50. {
  51. return PowerBIClient.Reports.GenerateTokenForCreateInGroup(Secrets.groupId, new GenerateTokenRequest(accessLevel: "Create", datasetId: datasetId.ToString(), allowSaveAs: true));
  52. }
  53. }

我已分配了这些API权限。

英文:

I am recently having an issue with GenerateTokenInGroup & GenerateTokenForCreateInGroup API and getting the "Operation returned an invalid status code 'Forbidden'" error. It was working fine last week. However, with the same settings, I can execute GetReportsInGroup API successfully.

  1. public class Secrets
  2. {
  3. private static string authorityUrl = "https://login.microsoftonline.com/organizations/";
  4. private static string resourceUrl = "https://analysis.windows.net/powerbi/api";
  5. public static string apiUrl = "https://api.powerbi.com/";
  6. private static string ClientID = ""; // The Azure AD App - Application ID/Client ID
  7. private static string ClientSecret = ""; // The Azure AD App - Client Secret
  8. private static string TenantId = ""; // The Azure AD Tenant Id
  9. public static Guid groupId = Guid.Parse("");//Power BI Workspace ID
  10. private static ClientCredential credential = null;
  11. private static AuthenticationResult authenticationResult = null;
  12. public static TokenCredentials tokenCredentials = null;
  13. public static Task Authorize()
  14. {
  15. return Task.Run(async () =>
  16. {
  17. credential = new ClientCredential(ClientID, ClientSecret);
  18. authenticationResult = null;
  19. tokenCredentials = null;
  20. var tenantSpecificURL = authorityUrl.Replace("organizations", Secrets.TenantId);
  21. var authenticationContext = new AuthenticationContext(tenantSpecificURL);
  22. authenticationResult = await authenticationContext.AcquireTokenAsync(resourceUrl, credential);
  23. if (authenticationResult != null)
  24. {
  25. tokenCredentials = new TokenCredentials(authenticationResult.AccessToken, "Bearer");
  26. }
  27. });
  28. }
  29. }
  30. public class PowerBIController : ApiController
  31. {
  32. private PowerBIClient PowerBIClient { get; set; }
  33. public PowerBIController()
  34. {
  35. Secrets.Authorize().Wait();
  36. PowerBIClient = new(new Uri(Secrets.apiUrl), Secrets.tokenCredentials);
  37. }
  38. [HttpGet]
  39. public object GetReportsInGroup()
  40. {
  41. return PowerBIClient.Reports.GetReportsInGroup(Secrets.groupId).Value;
  42. }
  43. [HttpGet]
  44. public object GenerateTokenInGroup(Guid reportId, Guid datasetId)
  45. {
  46. return PowerBIClient.Reports.GenerateTokenInGroup(Secrets.groupId, reportId, new GenerateTokenRequest(accessLevel: "View", datasetId: datasetId.ToString()));
  47. }
  48. [HttpGet]
  49. public object GenerateTokenForCreateInGroup(Guid datasetId)
  50. {
  51. return PowerBIClient.Reports.GenerateTokenForCreateInGroup(Secrets.groupId, new GenerateTokenRequest(accessLevel: "Create", datasetId: datasetId.ToString(), allowSaveAs: true));
  52. }
  53. }

I have assigned these API Permissions

答案1

得分: 0

我已经自己找到了解决方法。实际上,我正在使用Power BI嵌入试用版,现在已经完全消耗完了。可以使用GetAvailableFeatures API来检查。但是,与特定容量错误不同,生成令牌的API只会响应一个简单的禁止错误。

英文:

I have figured it out myself. Actually, I was using the Power BI Embed trail and now it is completely consumed. It can be checked by using GetAvailableFeatures API.
But instead of a specific capacity error, token-generating APIs are responding with just a simple Forbidden error.

huangapple
  • 本文由 发表于 2023年8月10日 17:10:22
  • 转载请务必保留本文链接:https://go.coder-hub.com/76874254.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定