首页 > 解决方案 > AcquireToken_In_Progress:登录调用期间出错 - 登录已在进行中

问题描述

我正在调用 microsoft graph api 也从 azure 门户获取用户,当时我无法获取用户而不是我需要用户列表,而且我正在获取登录 microsoft 的对话框。

const msalConfig = {
  auth: {
    clientId: "app-id",
    redirectUri: `http://localhost:port`,
    authority: "auth_url",
    navigateToLoginRequestUrl: false,
  },
  cache: {
    cacheLocation: "localStorage",
    storeAuthStateInCookie: true,
  },
};

const graphScopes = [
  "User.ReadBasic.All",
  "User.Read.All",
  "User.ReadWrite.All",
  "Directory.Read.All",
  "Directory.AccessAsUser.All",
  "Directory.ReadWrite.All",
];

const options = {
  loginType: LoginType.Redirect,
  tokenRefreshUri: window.location.origin + "/auth.html",
};


const msalApplication = new UserAgentApplication(msalConfig);
const scope = new MSALAuthenticationProviderOptions(graphScopes);
const authProvider = new ImplicitMSALAuthenticationProvider(msalApplication, scope);

const option = {
  authProvider,
};

const client = Client.initWithMiddleware(option);

我正在使用这段代码来调用 api:

const getUser = async () => {
  let list = [];
  try {
      list = await client.api(“https://graph.microsoft.com/beta/users?$count=true&$top=5”).header("ConsistencyLevel", "eventual").get();
  } catch (error) {
    throw error;
  }
  return list;
};

标签: reactjsazureazure-active-directorymicrosoft-graph-apimsal

解决方案


推荐阅读