Search code examples
reactjsazure-ad-msalmicrosoft-graph-toolkit

Use Microsoft Graph Toolkit with msal-browser


I am working on a React App and am using the @azure/msal-react library for authentication.

This is working great , but then I realized I'd quite like to use the people picker widget from the @microsoft/mgt-react library.

Is there any way I can wire up my existing @azure/msal-react / @azure/msal-browser libraries to the MGT library?

Or do I have to refactor my code to use the MGT style auth methods?

If that's the case I'll just build my own People Picker component I think, but I thought I'd see if it was possible anyway.


Solution

  • If you already have a way to get an access token, you can use MGT with the SimpleProvider.

    import {Providers, SimpleProvider, ProviderState} from '@microsoft/mgt-element';
    
    Providers.globalProvider = new SimpleProvider((scopes: string[]) => {
      // return a promise with accessToken
    });
    
    // set state to signal to all components to start calling graph
    Providers.globalProvider.setState(ProviderState.SignedIn)