microsoftgraph / microsoft-graph-toolkit

Authentication Providers and UI components for Microsoft Graph 🦒
https://docs.microsoft.com/graph/toolkit/overview
Other
924 stars 287 forks source link

[FEATURE] Allow a component to receive it's provider via props #2629

Open gavinbarron opened 11 months ago

gavinbarron commented 11 months ago

Add a provider property to the MgtBaseComponent.

This will allow for usages in scenarios where the an application needs to have both the ability to sign in and to provide mock data when users are not authenticated, the existing Providers.globalProvider can be set to the mock provider while the mgt-login component could have an Msal2Provider object supplied as a property like this:

      <mgt-login></mgt-login>
      <mgt-agenda group-by-day></mgt-agenda>
      <script type="module">
        import { Providers, MockProvider, Msal2Provider } from './packages/mgt/dist/es6/index.js';
        const authProvider = new Msal2Provider({clientId: "client-id",
          redirectUri: "redirectUrl",
          scopes: ["user.read", "user.read.all", "calendars.read"]
        });
        const login = document.querySelector('mgt-login');
        login.provider = authProvider;
        const mockProvider = new MockProvider(true);
        Providers.globalProvider = mockProvider;
      </script>
musale commented 11 months ago

Will this component provider always take precedence over the globalProvider?

gavinbarron commented 11 months ago

In the scope of that component tree, yes