通过 MSAL 将 Power BI 连接到 Angular 应用

发布于 2025-01-11 01:58:52 字数 1909 浏览 2 评论 0原文

我已经尝试了几个月,但仍然没有找到任何关于如何使用 PowerBI 服务以及使用 MSAL 的 Microsoft 身份验证对用户进行身份验证的解决方案。

尝试使用 https://analysis.windows.net/powerbi/api/ 此网址为在 powerBI 端点中,

export const protectedResources = {
    powerBI: {
        endpoint: "https://graph.microsoft.com/.default",
        scopes: ["Report.Read.All"],
    },
    graphMe: {
        endpoint: "https://graph.microsoft.com/v1.0/me",
        scopes: ["User.Read"],
    },
    armTenants: {
        endpoint: "https://management.azure.com/tenants",
        scopes: ["https://management.azure.com/user_impersonation"],
    }
}

配置中的范围代码上方和下方是从 Microsoft 文档获取的代码,该代码对于使用图形 api 验证用户并能够获取用户详细信息来说工作得非常好。

export function MSALInstanceFactory(): IPublicClientApplication {
  return new PublicClientApplication(msalConfig);
}


export function MSALInterceptorConfigFactory(): MsalInterceptorConfiguration {
  const protectedResourceMap = new Map<string, Array<string>>();

  protectedResourceMap.set(protectedResources.graphMe.endpoint, protectedResources.graphMe.scopes);
  protectedResourceMap.set(protectedResources.armTenants.endpoint, protectedResources.armTenants.scopes);
  protectedResourceMap.set(protectedResources.powerBI.endpoint, protectedResources.powerBI.scopes);

  return {
    interactionType: InteractionType.Redirect,
    protectedResourceMap
  };
}
export function MSALGuardConfigFactory(): MsalGuardConfiguration {
  return {
    interactionType: InteractionType.Redirect,
    authRequest: loginRequest
  };
}

但问题是,在用户获得身份验证后,用户仍然必须单击 iframe 内的其他登录按钮才能再次通过 PowerBI 进行身份验证。

输入图片此处描述

查看图片。

请为我提供一种只需一次登录即可一次性验证用户身份的方法,我应该能够在我的应用程序和 powerBI 服务中登录用户。

I have been trying this from months and still I did not find any solution on how to authenticate user with PowerBI service along with the Microsoft Authentication using MSAL.

Tried with https://analysis.windows.net/powerbi/api/ this url as well in powerBI endpoint

export const protectedResources = {
    powerBI: {
        endpoint: "https://graph.microsoft.com/.default",
        scopes: ["Report.Read.All"],
    },
    graphMe: {
        endpoint: "https://graph.microsoft.com/v1.0/me",
        scopes: ["User.Read"],
    },
    armTenants: {
        endpoint: "https://management.azure.com/tenants",
        scopes: ["https://management.azure.com/user_impersonation"],
    }
}

Above the scopes code in config and below is the code got from Microsoft documentation which is working perfectly fine for Authenticating user with graph api and able to get user details.

export function MSALInstanceFactory(): IPublicClientApplication {
  return new PublicClientApplication(msalConfig);
}


export function MSALInterceptorConfigFactory(): MsalInterceptorConfiguration {
  const protectedResourceMap = new Map<string, Array<string>>();

  protectedResourceMap.set(protectedResources.graphMe.endpoint, protectedResources.graphMe.scopes);
  protectedResourceMap.set(protectedResources.armTenants.endpoint, protectedResources.armTenants.scopes);
  protectedResourceMap.set(protectedResources.powerBI.endpoint, protectedResources.powerBI.scopes);

  return {
    interactionType: InteractionType.Redirect,
    protectedResourceMap
  };
}
export function MSALGuardConfigFactory(): MsalGuardConfiguration {
  return {
    interactionType: InteractionType.Redirect,
    authRequest: loginRequest
  };
}

But the Problem is after user gets authenticated still user has to click on additional sign in button inside the iframe in order to again get authenticated with PowerBI.

enter image description here

See the image.

Please provide me a way to authenticate user in one shot just by single login I should be able to login user in both my app and powerBI service.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

毁梦 2025-01-18 01:58:52

您可以在此处找到 Power BI API 的说明:https://learn.microsoft。 com/rest/api/power-bi/

请注意,Power BI API 位于 https://api.powerbi.com/v1.0/(不是 graph.microsoft.com),范围将类似于 https://analysis.windows.net/powerbi/ api/<范围名称>

按照说明将 PowerBI 添加到门户中的应用程序,然后您应该能够配置 MSAL 以获取具有您使用的每个 PowerBI 终结点的相关范围的令牌。

例如:

powerBI: {
        endpoint: "https://api.powerbi.com/v1.0/myorg/reports",
        scopes: ["https://analysis.windows.net/powerbi/api/Report.Read.All"],
    }

You can find instructions for the Power BI APIs here: https://learn.microsoft.com/rest/api/power-bi/

Note that the Power BI APIs are on https://api.powerbi.com/v1.0/ (not graph.microsoft.com) and scopes will be similar to https://analysis.windows.net/powerbi/api/<scope name>

Follow the instructions to add PowerBI to your application in the Portal, and then you should be able to configure MSAL to acquire tokens with relevant scopes for each PowerBI endpoint you use.

For example:

powerBI: {
        endpoint: "https://api.powerbi.com/v1.0/myorg/reports",
        scopes: ["https://analysis.windows.net/powerbi/api/Report.Read.All"],
    }

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文