通过 API 向 AAS 多维数据集验证 AAD 用户

Authenticate AAD user through API to AAS cube

我们有一个带身份验证的 AAS OLAP 多维数据集,并希望将其提供给当前通过 API 查询它的 AAD 用户。

目前 Azure 处理我们网站 API 的身份验证。我们基本上在 Azure 门户中勾选了 Azure AD 启用的身份验证。

按照建议,授权在多维数据集本身中。这意味着我必须以某种方式向 Azure AD 用户提供它。

我调查了 Impersonator class 发现 here but this is probably only suited for Windows context. I have also looked into 但这需要使用应用程序 ID 和应用程序机密,根据我的基本知识,这会破坏目的。

我已尝试 ADOMD.NET 并将令牌和用户 ID 添加到连接字符串,如所述 here. But then I receive the following error: "Exception has been thrown by the target of an invocation. Federated service at https://sts.blank.com/adfs/services/trust/13/usernamemixed 返回错误:ID3242:无法验证或授权安全令牌。”。它可以是我在这里将错误的声明插入到连接字符串中。我对此的了解有限。

这是我用来测试的测试代码ADOMD.NET:

string token = ClaimsPrincipal.Current.Claims.First(fod => fod.Type == "aio").Value;
string userId = ClaimsPrincipal.Current.Claims.First(fod => fod.Type == "http://schemas.xmlsoap.org/ws/2005/05/identity/claims/upn").Value;

using (AdomdConnection conn = new AdomdConnection($"Data Source=asazure://blank.asazure.windows.net/blank;Initial Catalog=blank;user id={userId};password={token}"))
{
    conn.Open();
    StringBuilder result = new StringBuilder();
    foreach (CubeDef cube in conn.Cubes)
    {
        result.AppendLine(cube.Name);

        foreach (Dimension dim in cube.Dimensions)
        {
            result.Append("\t");
            result.AppendLine(dim.Name);
        }
    }

    conn.Close();
}

为了查询 OLAP 多维数据集,我还测试了 NuGet 包 LinqToDAX,因为这里没有人知道 DAX。但这给了我错误:"The 'MSOLAP' provider is not registered on the local machine."。我不知道如何在 Azure 中注册此提供程序或如何将凭据传递给它。由于之前的错误,我不确定通过简单地在连接字符串中输入值来使用相同的方法是否可行。

这是我用来测试 LinqToDAX 的测试代码:

string token = ClaimsPrincipal.Current.Claims.First(fod => fod.Type == "aio").Value;
string userId = ClaimsPrincipal.Current.Claims.First(fod => fod.Type == "http://schemas.xmlsoap.org/ws/2005/05/identity/claims/upn").Value;
DbContextOlap dbContextOlap = new DbContextOlap($"Provider=MSOLAP;Data Source=asazure://blank.asazure.windows.net/blank;Initial Catalog=blank;user id={userId};password={token}");

有人能给我指出正确的方向吗?

编辑:使用建议的包 here 我收到以下错误:"Exception has been thrown by the target of an invocation.; parsing_wstrust_response_failed: Parsing WS-Trust response failed"。我可以连接 DAX studio,所以问题一定出在我的代码中。

解决这个问题其实很简单。

  1. 按照此处找到的示例项目进行操作:https://github.com/Azure-Samples/active-directory-dotnet-webapi-onbehalfof. But instead of connecting to the Graph API, you connect to the AAS cube. The ResourceId to get the on behalf of token should therefore be set to "https://datacenter.asazure.windows.net",其中数据中心是您的 AAS 的位置,例如 westeurope。
  2. 将连接字符串设置为:"Provider=MSOLAP;Data Source=asazure://datacenter.asazure.windows.net/nameofyourserver;Initial Catalog=nameofyourcube;User ID=;Password=onBehalfOfToken;Persist Security Info=True;Impersonation Level=Impersonate"。将用户 ID 留空。将密码设置为您从 AcquireTokenAsync() 获得的代表令牌。
  3. 使用官方 NuGet 包:Microsoft.AnalysisServices.AdomdClient.retail.amd64.