Edit

@azure/msal-react package

Interfaces

IMsalContext

Functions

AuthenticatedTemplate(PropsWithChildrenInfo, "homeAccountId" | "localAccountId" | "username">>>)

Renders child components if user is authenticated

MsalAuthenticationTemplate(PropsWithChildrenInfo, "homeAccountId" | "localAccountId" | "username">> & { authenticationRequest?: PopupRequest | RedirectRequest | PartialAuthorizationUrlRequest, "responseMode" | "earJwk" | "codeChallenge" | "codeChallengeMethod" | "requestedClaimsHash" | "platformBroker">>, errorComponent?: any, interactionType: InteractionType, loadingComponent?: any }>)

Attempts to authenticate user if not already authenticated, then renders child components

MsalProvider(PropsWithChildren<{ instance: IPublicClientApplication }>)

MSAL context provider component. This must be rendered above any other components that use MSAL.

UnauthenticatedTemplate(PropsWithChildrenInfo, "homeAccountId" | "localAccountId" | "username">>>)

Renders child components if user is unauthenticated

useAccount(PartialInfo, "homeAccountId" | "localAccountId" | "username">>)

Given 1 or more accountIdentifiers, returns the Account object if the user is signed-in

useIsAuthenticated(PartialInfo, "homeAccountId" | "localAccountId" | "username">>)

Returns whether or not a user is currently signed-in. Optionally provide 1 or more accountIdentifiers to determine if a specific user is signed-in

useMsal()

Returns Msal Context values

useMsalAuthentication(InteractionType, PopupRequest | RedirectRequest | PartialAuthorizationUrlRequest, "responseMode" | "earJwk" | "codeChallenge" | "codeChallengeMethod" | "requestedClaimsHash" | "platformBroker">>, PartialInfo, "homeAccountId" | "localAccountId" | "username">>)

If a user is not currently signed in this hook invokes a login. Failed logins can be retried using the login callback returned. If a user is currently signed in this hook attempts to acquire a token. Subsequent token requests can use the acquireToken callback returned. Optionally provide a request object to be used in the login/acquireToken call. Optionally provide a specific user that should be logged in.

withMsal

(ComponentType

)

Higher order component wraps provided component with msal by injecting msal context values into the component's props

Function Details

AuthenticatedTemplate(PropsWithChildrenInfo, "homeAccountId" | "localAccountId" | "username">>>)

Renders child components if user is authenticated

function AuthenticatedTemplate(props: PropsWithChildren>>): React.ReactElement | null

Parameters

props

PropsWithChildrenAccountInfo, "homeAccountId" | "localAccountId" | "username">>>

Returns

React.ReactElement | null

MsalAuthenticationTemplate(PropsWithChildrenInfo, "homeAccountId" | "localAccountId" | "username">> & { authenticationRequest?: PopupRequest | RedirectRequest | PartialAuthorizationUrlRequest, "responseMode" | "earJwk" | "codeChallenge" | "codeChallengeMethod" | "requestedClaimsHash" | "platformBroker">>, errorComponent?: any, interactionType: InteractionType, loadingComponent?: any }>)

Attempts to authenticate user if not already authenticated, then renders child components

function MsalAuthenticationTemplate(props: PropsWithChildren> & { authenticationRequest?: PopupRequest | RedirectRequest | Partial>, errorComponent?: any, interactionType: InteractionType, loadingComponent?: any }>): React.ReactElement | null

Parameters

props

PropsWithChildrenAccountInfo, "homeAccountId" | "localAccountId" | "username">> & { authenticationRequest?: PopupRequest | RedirectRequest | Partial>, errorComponent?: any, interactionType: InteractionType, loadingComponent?: any }>

Returns

React.ReactElement | null

MsalProvider(PropsWithChildren<{ instance: IPublicClientApplication }>)

MSAL context provider component. This must be rendered above any other components that use MSAL.

function MsalProvider(__namedParameters: PropsWithChildren<{ instance: IPublicClientApplication }>): React.ReactElement

Parameters

__namedParameters

PropsWithChildren<{ instance: IPublicClientApplication }>

Returns

React.ReactElement

UnauthenticatedTemplate(PropsWithChildrenInfo, "homeAccountId" | "localAccountId" | "username">>>)

Renders child components if user is unauthenticated

function UnauthenticatedTemplate(props: PropsWithChildren>>): React.ReactElement | null

Parameters

props

PropsWithChildrenAccountInfo, "homeAccountId" | "localAccountId" | "username">>>

Returns

React.ReactElement | null

useAccount(PartialInfo, "homeAccountId" | "localAccountId" | "username">>)

Given 1 or more accountIdentifiers, returns the Account object if the user is signed-in

function useAccount(accountIdentifiers?: Partial>): AccountInfo | null

Parameters

accountIdentifiers

PartialAccountInfo, "homeAccountId" | "localAccountId" | "username">>

Returns

AccountInfo | null

useIsAuthenticated(PartialInfo, "homeAccountId" | "localAccountId" | "username">>)

Returns whether or not a user is currently signed-in. Optionally provide 1 or more accountIdentifiers to determine if a specific user is signed-in

function useIsAuthenticated(matchAccount?: Partial>): boolean

Parameters

matchAccount

PartialAccountInfo, "homeAccountId" | "localAccountId" | "username">>

Returns

boolean

useMsal()

Returns Msal Context values

function useMsal(): IMsalContext

Returns

useMsalAuthentication(InteractionType, PopupRequest | RedirectRequest | PartialAuthorizationUrlRequest, "responseMode" | "earJwk" | "codeChallenge" | "codeChallengeMethod" | "requestedClaimsHash" | "platformBroker">>, PartialInfo, "homeAccountId" | "localAccountId" | "username">>)

If a user is not currently signed in this hook invokes a login. Failed logins can be retried using the login callback returned. If a user is currently signed in this hook attempts to acquire a token. Subsequent token requests can use the acquireToken callback returned. Optionally provide a request object to be used in the login/acquireToken call. Optionally provide a specific user that should be logged in.

function useMsalAuthentication(interactionType: InteractionType, authenticationRequest?: PopupRequest | RedirectRequest | Partial>, accountIdentifiers?: Partial>): MsalAuthenticationResult

Parameters

interactionType
InteractionType
authenticationRequest

PopupRequest | RedirectRequest | PartialCommonAuthorizationUrlRequest, "responseMode" | "earJwk" | "codeChallenge" | "codeChallengeMethod" | "requestedClaimsHash" | "platformBroker">>

accountIdentifiers

PartialAccountInfo, "homeAccountId" | "localAccountId" | "username">>

Returns

withMsal

(ComponentType

)

Higher order component wraps provided component with msal by injecting msal context values into the component's props

function withMsal

(Component: ComponentType

): FunctionComponent>

Parameters

Component

ComponentType

Returns

FunctionComponent<SubtractWithMsalProps>>

Variable Details

MsalConsumer

MsalConsumer: React.Consumer

Type

React.Consumer<IMsalContext>

MsalContext

MsalContext: React.Context

Type

React.Context<IMsalContext>

version

version: "3.0.29"

Type

"3.0.29"