Microsoft Graph Toolkit MSAL 2.0 Provider
The Microsoft Graph Toolkit (mgt) library is a collection of authentication providers and UI components powered by Microsoft Graph.
The `@vonrehberg.consulting/mgt-msal2-providerpackage exposes the
Msal2Provider` class which uses msal-browser to sign in users and acquire tokens to use with Microsoft Graph.
Usage
Install the packages
npm install @vonrehberg.consulting/mgt-element @vonrehberg.consulting/mgt-msal2-provider
Initialize the provider in code with
Msal2Config
import {Providers, LoginType} from '@vonrehberg.consulting/mgt-element'; import {Msal2Provider, PromptType} from '@vonrehberg.consulting/mgt-msal2-provider'; // initialize the auth provider globally Providers.globalProvider = new Msal2Provider({ clientId: 'clientId', scopes?: string[], authority?: string, redirectUri?: string, loginType?: LoginType, // LoginType.Popup or LoginType.Redirect (redirect is default) prompt?: PromptType, // PromptType.CONSENT, PromptType.LOGIN or PromptType.SELECT_ACCOUNT sid?: string, // Session ID loginHint?: string, domainHint?: string, isIncrementalConsentDisabled?: boolean, //Disable incremental consent, true by default options?: Configuration // msal js Configuration object });
Initialize the provider in code with
Msal2PublicClientApplicationConfig
if aPublicClientApplication
is already instantiated. For example,msal-angular
instantiatesPublicClientApplication
on startup.import {Providers, LoginType} from '@vonrehberg.consulting/mgt-element'; import {Msal2Provider, PromptType} from '@vonrehberg.consulting/mgt-msal2-provider'; import {PublicClientApplication} from '@azure/msal-browser'; // initialize the auth provider globally Providers.globalProvider = new Msal2Provider({ publicClientApplication: PublicClientApplication, scopes?: string[], authority?: string, redirectUri?: string, loginType?: LoginType, // LoginType.Popup or LoginType.Redirect (redirect is default) prompt?: PromptType, // PromptType.CONSENT, PromptType.LOGIN or PromptType.SELECT_ACCOUNT sid?: string, // Session ID loginHint?: string, domainHint?: string, isIncrementalConsentDisabled?: boolean, //Disable incremental consent, true by default options?: Configuration // msal js Configuration object });
Alternatively, initialize the provider in html (only
client-id
is required):<script type="module" src="../node_modules/@vonrehberg.consulting/mgt-msal2-provider/dist/es6/index.js" /> <mgt-msal2-provider client-id="<YOUR_CLIENT_ID>" login-type="redirect/popup" scopes="user.read,people.read" redirect-uri="https://my.redirect/uri" authority=""> </mgt-msal2-provider>
Add the
incremental-consent-disabled
boolean attribute if you wish to disable incremental consent.
See provider usage documentation to learn about how to use the providers with the mgt components, to sign in/sign out, get access tokens, call Microsoft Graph, and more.