必须使用登录组件才能使用其他组件

It is mandatory to use the login component in order to use the other components

我正在用 React 开发一个应用程序,我正在使用 MSAL 进行应用程序登录,一旦用户通过身份验证,我想使用一个人的卡片组件,但我无法让它工作。 我告诉你我已经实施了什么,以防我忘记了一些步骤。我在组件本身中添加了以下标签:

<mgt-msal-provider client-id={process.env.REACT_APP_MSALCLIENTID}></mgt-msal-provider>

我在 MSal 上使用的那个客户端对用户进行身份验证。我也尝试在构建器本身中定义它:

Providers.globalProvider = new MsalProvider({clientId:process.env.REACT_APP_MSALCLIENTID});

现在,如果我将登录标签放在卡片组件上并单击它,它就会完美运行。

是否可以将我的应用程序的相同 msal 与图形工具包 msal 提供程序一起使用?

工具包组件需要有一种调用图形的方法,这是通过提供程序实现的。如果您已经使用自己的 msal 进行了身份验证,则无需使用 MsalProvider,您可以创建一个 SimpleProvider or create your own provider。提供者有两个主要目的 - 在身份验证状态更改时通知组件(签名 in/signed out),并获取 accessToken 以使用提供的范围调用图形。例如,您至少可以这样做:

Providers.globalProvider = new SimpleProvider((scopes) => { 
 //return accessToken for scopes using your msal instance
});

// when the user signs in, set the provider state to signedIn
// this will notify all components that the user is signed in 
// and they can call the graph
Providers.globalProvider.setState(ProviderState.SignedIn);