登录用户的Azure资源信息的Azure身份?

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

我到目前为止有什么

我正在使用两个不同的Node.js项目,但我想将它们放在一起。

  1. 首先使用交互式登录(在浏览器中提交的代码),然后找到我的所有(登录用户)租户。
  2. 第二种用法是单击按钮以登录并从Microsoft Graph获取信息。

Azure应用程序API权限

Azure应用程序都具有user_impersonation权限(用于租户/订阅信息)和user.read权限(配置文件信息)。

enter image description here

交互式登录代码

import * as msRestNodeAuth from "@azure/ms-rest-nodeauth";

const main = async () => {
     const creds: any = await msRestNodeAuth.interactiveLogin();
     ...continue - get tenant info from logged in user
}

React应用程序的代码

我使用了此tutorial provided by Microsoft。我所做的唯一更改是添加user_impersonation的范围。

module.exports = {
    appId: '1760c31a-....-baf68c2b3244',
    redirectUri: 'http://localhost:3000',
    scopes: [  'user.read',
    'user.impersonation'
    ]
  };

它使用以下身份验证库和登录功能:

  import { UserAgentApplication } from 'msal';

  async login() {
    try {
      await this.userAgentApplication.loginPopup(
        {
          scopes: config.scopes,
          prompt: "select_account"
        });
      await this.getUserProfile();
    }
    catch (err) {
      var error = {};

      if (typeof (err) === 'string') {
        var errParts = err.split('|');
        error = errParts.length > 1 ?
          { message: errParts[1], debug: errParts[0] } :
          { message: err };
      } else {
        error = {
          message: err.message,
          debug: JSON.stringify(err)
        };
      }

      this.setState({
        isAuthenticated: false,
        user: {},
        error: error
      });
    }
  }

我收到错误:

{"errorCode":"invalid_scope","errorMessage":"The provided value for the input parameter 'scope' is not valid. The scope 'user.read user.impersonation openid profile' does not exist.","name":"ServerError"}

azure azure-active-directory identity msal react-aad-msal
1个回答
0
投票

范围不正确。没有称为user.impersonation的范围。应该是https://management.azure.com/user_impersonation

此外,您不能将一个令牌带给多个受众。 https://management.azure.com用于天蓝色资源。 user.readhttps://graph.microsoft.com/User.Read)用于Azure AD资源。

您应该针对不同的受众群体两次调用acquireTokenSilent方法。

var accessToken = await this.userAgentApplication.acquireTokenSilent({
        scopes: config.scopes
      });

更新:

enter image description here

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