@azure/msal-react package

接口

IMsalContext

函数

AuthenticatedTemplate(PropsWithChildren<Partial<Pick<AccountInfo, "homeAccountId" | "localAccountId" | "username">>>)

如果用户已经过身份验证,则呈现子组件

MsalAuthenticationTemplate(PropsWithChildren<Partial<Pick<AccountInfo, "homeAccountId" | "localAccountId" | "username">> & { authenticationRequest?: PopupRequest | RedirectRequest | Partial<Omit<CommonAuthorizationUrlRequest, "responseMode" | "earJwk" | "codeChallenge" | "codeChallengeMethod" | "requestedClaimsHash" | "platformBroker">>, errorComponent?: any, interactionType: InteractionType, loadingComponent?: any }>)

尝试对用户进行身份验证(如果尚未进行身份验证),然后呈现子组件

MsalProvider(PropsWithChildren<{ instance: IPublicClientApplication }>)

MSAL 上下文提供程序组件。 这必须呈现在任何其他使用 MSAL 的组件之上。

UnauthenticatedTemplate(PropsWithChildren<Partial<Pick<AccountInfo, "homeAccountId" | "localAccountId" | "username">>>)

如果用户未经身份验证,则呈现子组件

useAccount(Partial<Pick<AccountInfo, "homeAccountId" | "localAccountId" | "username">>)

给定 1 个或多个 accountIdentifiers,如果用户已登录,则返回 Account 对象

useIsAuthenticated(Partial<Pick<AccountInfo, "homeAccountId" | "localAccountId" | "username">>)

返回用户当前是否已登录。 (可选)提供 1 个或多个 accountIdentifier,以确定特定用户是否已登录

useMsal()

返回 Msal 上下文值

useMsalAuthentication(InteractionType, PopupRequest | RedirectRequest | Partial<Omit<CommonAuthorizationUrlRequest, "responseMode" | "earJwk" | "codeChallenge" | "codeChallengeMethod" | "requestedClaimsHash" | "platformBroker">>, Partial<Pick<AccountInfo, "homeAccountId" | "localAccountId" | "username">>)

如果用户当前未登录此挂钩,则调用登录名。 可以使用返回的登录回调重试失败的登录名。 如果用户当前已登录此挂钩,则尝试获取令牌。 后续令牌请求可以使用返回的 acquireToken 回调。 (可选)提供在登录/acquireToken 调用中使用的请求对象。 (可选)提供应登录的特定用户。

withMsal<P>(ComponentType<P>)

通过将 msal 上下文值注入组件属性,使用 msal 包装提供的组件

函数详细信息

AuthenticatedTemplate(PropsWithChildren<Partial<Pick<AccountInfo, "homeAccountId" | "localAccountId" | "username">>>)

如果用户已经过身份验证,则呈现子组件

function AuthenticatedTemplate(props: PropsWithChildren<Partial<Pick<AccountInfo, "homeAccountId" | "localAccountId" | "username">>>): React.ReactElement | null

参数

props

PropsWithChildren<Partial<Pick<AccountInfo, "homeAccountId" | "localAccountId" | "username">>>

返回

React.ReactElement | null

MsalAuthenticationTemplate(PropsWithChildren<Partial<Pick<AccountInfo, "homeAccountId" | "localAccountId" | "username">> & { authenticationRequest?: PopupRequest | RedirectRequest | Partial<Omit<CommonAuthorizationUrlRequest, "responseMode" | "earJwk" | "codeChallenge" | "codeChallengeMethod" | "requestedClaimsHash" | "platformBroker">>, errorComponent?: any, interactionType: InteractionType, loadingComponent?: any }>)

尝试对用户进行身份验证(如果尚未进行身份验证),然后呈现子组件

function MsalAuthenticationTemplate(props: PropsWithChildren<Partial<Pick<AccountInfo, "homeAccountId" | "localAccountId" | "username">> & { authenticationRequest?: PopupRequest | RedirectRequest | Partial<Omit<CommonAuthorizationUrlRequest, "responseMode" | "earJwk" | "codeChallenge" | "codeChallengeMethod" | "requestedClaimsHash" | "platformBroker">>, errorComponent?: any, interactionType: InteractionType, loadingComponent?: any }>): React.ReactElement | null

参数

props

PropsWithChildren<Partial<Pick<AccountInfo, "homeAccountId" | "localAccountId" | "username">> & { authenticationRequest?: PopupRequest | RedirectRequest | Partial<Omit<CommonAuthorizationUrlRequest, "responseMode" | "earJwk" | "codeChallenge" | "codeChallengeMethod" | "requestedClaimsHash" | "platformBroker">>, errorComponent?: any, interactionType: InteractionType, loadingComponent?: any }>

返回

React.ReactElement | null

MsalProvider(PropsWithChildren<{ instance: IPublicClientApplication }>)

MSAL 上下文提供程序组件。 这必须呈现在任何其他使用 MSAL 的组件之上。

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

参数

__namedParameters

PropsWithChildren<{ instance: IPublicClientApplication }>

返回

React.ReactElement

UnauthenticatedTemplate(PropsWithChildren<Partial<Pick<AccountInfo, "homeAccountId" | "localAccountId" | "username">>>)

如果用户未经身份验证,则呈现子组件

function UnauthenticatedTemplate(props: PropsWithChildren<Partial<Pick<AccountInfo, "homeAccountId" | "localAccountId" | "username">>>): React.ReactElement | null

参数

props

PropsWithChildren<Partial<Pick<AccountInfo, "homeAccountId" | "localAccountId" | "username">>>

返回

React.ReactElement | null

useAccount(Partial<Pick<AccountInfo, "homeAccountId" | "localAccountId" | "username">>)

给定 1 个或多个 accountIdentifiers,如果用户已登录,则返回 Account 对象

function useAccount(accountIdentifiers?: Partial<Pick<AccountInfo, "homeAccountId" | "localAccountId" | "username">>): AccountInfo | null

参数

accountIdentifiers

Partial<Pick<AccountInfo, "homeAccountId" | "localAccountId" | "username">>

返回

AccountInfo | null

useIsAuthenticated(Partial<Pick<AccountInfo, "homeAccountId" | "localAccountId" | "username">>)

返回用户当前是否已登录。 (可选)提供 1 个或多个 accountIdentifier,以确定特定用户是否已登录

function useIsAuthenticated(matchAccount?: Partial<Pick<AccountInfo, "homeAccountId" | "localAccountId" | "username">>): boolean

参数

matchAccount

Partial<Pick<AccountInfo, "homeAccountId" | "localAccountId" | "username">>

返回

boolean

useMsal()

返回 Msal 上下文值

function useMsal(): IMsalContext

返回

useMsalAuthentication(InteractionType, PopupRequest | RedirectRequest | Partial<Omit<CommonAuthorizationUrlRequest, "responseMode" | "earJwk" | "codeChallenge" | "codeChallengeMethod" | "requestedClaimsHash" | "platformBroker">>, Partial<Pick<AccountInfo, "homeAccountId" | "localAccountId" | "username">>)

如果用户当前未登录此挂钩,则调用登录名。 可以使用返回的登录回调重试失败的登录名。 如果用户当前已登录此挂钩,则尝试获取令牌。 后续令牌请求可以使用返回的 acquireToken 回调。 (可选)提供在登录/acquireToken 调用中使用的请求对象。 (可选)提供应登录的特定用户。

function useMsalAuthentication(interactionType: InteractionType, authenticationRequest?: PopupRequest | RedirectRequest | Partial<Omit<CommonAuthorizationUrlRequest, "responseMode" | "earJwk" | "codeChallenge" | "codeChallengeMethod" | "requestedClaimsHash" | "platformBroker">>, accountIdentifiers?: Partial<Pick<AccountInfo, "homeAccountId" | "localAccountId" | "username">>): MsalAuthenticationResult

参数

interactionType
InteractionType
authenticationRequest

PopupRequest | RedirectRequest | Partial<Omit<CommonAuthorizationUrlRequest, "responseMode" | "earJwk" | "codeChallenge" | "codeChallengeMethod" | "requestedClaimsHash" | "platformBroker">>

accountIdentifiers

Partial<Pick<AccountInfo, "homeAccountId" | "localAccountId" | "username">>

返回

withMsal<P>(ComponentType<P>)

通过将 msal 上下文值注入组件属性,使用 msal 包装提供的组件

function withMsal<P>(Component: ComponentType<P>): FunctionComponent<Subtract<P, WithMsalProps>>

参数

Component

ComponentType<P>

返回

FunctionComponent<Subtract<P, WithMsalProps>>

变量详细信息

MsalConsumer

MsalConsumer: React.Consumer<IMsalContext>

类型

React.Consumer<IMsalContext>

MsalContext

MsalContext: React.Context<IMsalContext>

类型

React.Context<IMsalContext>

version

version: "3.0.29"

类型

"3.0.29"