@azure/msal-react package
介面
| IMsalContext |
類型別名
| AccountIdentifiers | |
| AuthenticatedTemplateProps | |
| MsalAuthenticationProps | |
| MsalAuthenticationResult | |
| MsalProviderProps | |
| SetComplement | |
| SetDifference | |
| Subtract | |
| UnauthenticatedTemplateProps | |
| WithMsalProps |
函式
函式詳細資料
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 }>
傳回
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">>)
給定一個或多個 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 或 2 個 accountIdentifiers 以判斷特定使用者是否已登入
function useIsAuthenticated(matchAccount?: Partial<Pick<AccountInfo, "homeAccountId" | "localAccountId" | "username">>): boolean
參數
- matchAccount
-
Partial<Pick<AccountInfo, "homeAccountId" | "localAccountId" | "username">>
傳回
boolean
useMsal()
useMsalAuthentication(InteractionType, PopupRequest | RedirectRequest | Partial<Omit<CommonAuthorizationUrlRequest, "responseMode" | "earJwk" | "codeChallenge" | "codeChallengeMethod" | "requestedClaimsHash" | "platformBroker">>, Partial<Pick<AccountInfo, "homeAccountId" | "localAccountId" | "username">>)
如果使用者目前未登入,這個鉤子會觸發登入。 登入失敗後可透過回撥回訪重新嘗試。 如果使用者目前已登入,這個鉤子會嘗試取得一個代幣。 後續的令牌請求可以使用回傳的 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 上下文值注入元件的道具,為 component 提供 msal。
function withMsal<P>(Component: ComponentType<P>): FunctionComponent<Subtract<P, WithMsalProps>>
參數
- Component
-
ComponentType<P>
傳回
FunctionComponent<Subtract<P, WithMsalProps>>
變數詳細資料
MsalConsumer
MsalContext
version
version: "3.0.29"
類型
"3.0.29"