将主用户迁移到服务主体以在嵌入式电源双电源上进行身份验证

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

我正在尝试将身份验证方法从Power BI主用户迁移到服务主体。

在主用户上,我正在使用msal,其身份验证流程如下所示:登录到AAD->请求AAD令牌->使用AAD令牌作为凭据,使用其余API导入pbix文件

这是代码

    $(document).ready(function(){
        myMSALObj.loginPopup(requestObj).then(function (loginResponse) {
            acquireTokenPopup();
        });
        Msal.UserAgentApplication
    });

    function acquireTokenPopup() {
        myMSALObj.acquireTokenSilent(requestObj).then(function (tokenResponse) {
            AADToken = tokenResponse.accessToken;
            importPBIX(AADToken);
        });
    }

    function importPBIX(accessToken) {
        xmlHttp.open("GET","./importPBIX?accessToken="+accessToken+"&pbixTemplate=" + pbixTemplate,true);
    //the rest of import process//
}

所以有两个问题:1.如果我改为使用服务主体,它将是什么样的流程?在我的头上,从我从Microsoft文档中读取的信息中,它会变得更简单:使用应用程序密钥请求令牌->使用令牌使用其余API导入pbix文件它是否正确?2.我可以使用哪种代码在javascript上执行此操作?我认为MSAL无法通过使用服务主体来执行令牌请求。将不胜感激任何信息或教程。

最佳,

javascript azure-active-directory powerbi powerbi-embedded service-principal
1个回答
0
投票
  1. 如果我改为使用服务主体,它将是什么样的流程?在我的头上,从我从Microsoft文档中读取的信息中,它会更简单:使用应用程序密钥请求令牌->使用令牌使用rest API导入pbix文件是否正确?

根据我的研究,如果要使用服务主体来获取Azure AD访问令牌,则可以使用client credentials grant flowenter image description here

  1. 客户端应用程序向Azure AD令牌发行端点进行身份验证并请求访问令牌。

  2. Azure AD令牌颁发终结点颁发访问令牌。

  3. 访问令牌用于对安全资源进行身份验证。

  4. 来自受保护资源的数据返回到客户端应用程序。

关于如何获取访问令牌,请参考以下步骤

  1. 注册Azure AD应用程序enter image description hereenter image description here

  2. 配置API权限enter image description here

  3. 获取访问令牌

POST https://login.microsoftonline.com/<tenant id>/oauth2/token
Content-Type: application/x-www-form-urlencoded

grant_type=client_credentials
&client_id=<>
&client_secret=<>
&resource=https://analysis.windows.net/powerbi/api

2。我可以使用哪种代码在javascript上执行此操作?我认为MSAL无法通过使用服务主体来执行令牌请求。将不胜感激任何信息或教程。

如果要使用sdk实现客户端凭据授予流,则可以使用adal-node。有关更多详细信息,请参阅https://www.npmjs.com/package/adal-node

例如

var AuthenticationContext = require('adal-node').AuthenticationContext;

var authorityHostUrl = 'https://login.microsoftonline.com/';
var tenant = 'myTenant.onmicrosoft.com'; // AAD Tenant name.
var authorityUrl = authorityHostUrl + '/' + tenant;
var applicationId = 'yourApplicationIdHere'; // Application Id of app registered under AAD.
var clientSecret = 'yourAADIssuedClientSecretHere'; // Secret generated for app. Read this environment variable.
var resource = ''; // URI that identifies the resource for which the token is valid.

var context = new AuthenticationContext(authorityUrl);

context.acquireTokenWithClientCredentials(resource, applicationId, clientSecret, function(err, tokenResponse) {
  if (err) {
    console.log('well that didn\'t work: ' + err.stack);
  } else {
    console.log(tokenResponse);
  }
});
© www.soinside.com 2019 - 2024. All rights reserved.