Azure AD 和 Power 中的访问令牌范围问题

问题描述 投票:0回答:2

我正在使用 Power Bi REST API,为此我需要一个天蓝色广告令牌。

我已在 Azure AD 中设置了一个应用程序,并将其配置为。

a.我打算在我的 React 应用程序中使用该访问令牌,因此我已将其配置为 SPA。 b.我已经允许公共客户流动。 ** 我没有选中“访问令牌”和“ID 令牌”复选框,因为我使用的是 msal 2.0。

c.还指定重定向 uri 为 http://localhost:4200 d.还授予了它访问我的 powerbi 内容所需的所有权限(我需要“Dataset.ReadWrite.All”)

这些是我的 Azure 应用程序端点

我已将我的 REACT 应用程序设置为: 我正在使用 @azure/msal-browser 和 @azure/msal-react 库。

这是我的 msalConfig 对象 -

const configuration: Configuration = {
  auth: {
      clientId: "myclientidhere",//,
      authority: "https://login.microsoftonline.com/mytenantidhere",
      redirectUri: "http://localhost:4200/",
  },
  cache: {
    cacheLocation: "localStorage",
    storeAuthStateInCookie: false,
  },

}

而且,这是我的范围:

    export const loginRequest = {
  scopes: ["Dataset.ReadWrite.All"]
};

运行我的应用程序后,我看到身份验证弹出窗口。我把我的凭据放进去了。突然它抛出这个错误-

invalid_client: AADSTS650053: The application 'dashboard.xyz.work' asked for scope 'Dataset.ReadWrite.All' that doesn't exist on the resource '00000003-0000-0000-c000-000000000000'. Contact the app vendor. Trace ID: 77e47883-fdd3-444a-bdd3-9f3a53bc1500 Correlation ID: aa77d724-0d9f-41aa-8e47-251c6b6f9293 Timestamp: 2023-02-09 13:51:46Z

我已在我的天蓝色广告应用程序中授予了相同的权限。但是我的应用程序尚未获得“管理员同意”,但作为用户,我的帐户有权在 powerbi 中使用此范围。

注意:如果我将范围更改为“user.read”或任何其他 ms graph API 资源,那么我就能够获取该范围的访问令牌来访问 graph API 资源。但我无法获取访问令牌来访问我的 powerbi 资源。

Azure AD 中的一切看起来都很棒。

我在某处读到此资源“00000003-0000-0000-c000-000000000000”表示 graph.microsoft.com 资源。我正在点击 https://login.microsoftonline.com/{myTenantId} 。这些是我的应用程序端点。

我不确定 powerbi 资源是否属于 graph.microsoft.com ('00000003-0000-0000-c000-000000000000) 资源!!??

也在我的应用程序的 API 权限页面上阅读,它们位于 https://analysis.windows.net/powerbi/api 即 00000009-0000-0000-c000-000000000000??

我是否到达了错误的端点或者问题是其他的?

azure powerbi azure-active-directory powerbi-embedded powerbi-rest-api
2个回答
3
投票

我尝试在我的环境中重现相同的结果,并得到如下相同的错误:

enter image description here

要解决该错误,请尝试以下操作:

我创建了一个 Azure AD SPA 应用程序并添加了 API 权限:

enter image description here

注意:确保给出范围

https://analysis.windows.net/powerbi/api/Dataset.ReadWrite.All
访问 PowerBI 内容

我使用以下端点生成了身份验证代码

https://login.microsoftonline.com/TenantID/oauth2/v2.0/authorize?
client_id=ClientID
&response_type=code
&redirect_uri=https://jwt.ms
&response_mode=query
&scope=https://analysis.windows.net/powerbi/api/Dataset.ReadWrite.All
&state=12345
&code_challenge=codeChallenge
&code_challenge_method=S256

由于 API 权限未获得管理员同意,您将看到如下同意屏幕

enter image description here

auth-code已成功生成,没有任何错误,如下所示:

enter image description here

现在,我使用以下参数生成了访问令牌

https://login.microsoftonline.com/TenantID/oauth2/v2.0/token

grant_type:authorization_code
client_id:ClientID
scope:https://analysis.windows.net/powerbi/api/Dataset.ReadWrite.All
code:code
redirect_uri:https://jwt.ms
code_verifier:S256

enter image description here

成功生成的访问令牌,范围为

Dataset.ReadWrite.All
,如下所示:

enter image description here

要解决该错误,请修改以下代码:

   export const loginRequest = {
  scopes: ["https://analysis.windows.net/powerbi/api/Dataset.ReadWrite.All"]
};

如果问题仍然存在,请尝试将范围设置为

https://analysis.windows.net/powerbi/api/.default


0
投票

看起来我迟到了几个月,但想知道你们用于 Power BI REST API 的端点是什么?

© www.soinside.com 2019 - 2024. All rights reserved.