device-code-confirmation 画面は、デバイス認可フロー中に表示されます。この画面では、ユーザーに確認用の code が表示され、デバイス有効化リクエストを承認するか拒否するよう求められます。
各画面には、それぞれ固有のフックとメソッドのセットがあります。SDK は、各画面について partial import と root import をサポートしています。
- partial import を使用すると、特定のユースケースに必要なコードだけを含めることができます。
- root import を使用すると、単一のバンドルからすべての画面を読み込めます。これは、想定されるすべての画面を 1 つの統一されたビルドで処理したい場合に便利です。
// ルートインポート
import { useDeviceCodeConfirmation } from '@auth0/auth0-acul-react';
// 部分インポート
import {
useDeviceCodeConfirmation,
// コンテキストフック
useUser,
useTenant,
useBranding,
useClient,
useOrganization,
usePrompt,
useScreen,
useTransaction,
useUntrustedData,
// 共通フック
useCurrentScreen,
useAuth0Themes,
useErrors,
// ユーティリティフック
useChangeLanguage,
// メソッド
confirm,
cancel,
} from '@auth0/auth0-acul-react/device-code-confirmation';
function DeviceCodeConfirmationScreen() {
const { confirm, cancel } = useDeviceCodeConfirmation();
return (
<>
<button onClick={() => confirm()}>Confirm</button>
<button onClick={() => cancel()}>Cancel</button>
</>
);
}
device-code-confirmation 画面で Auth0 のコンテキストデータへの読み取り専用アクセスを提供する、画面スコープのフックです。@auth0/auth0-acul-react/device-code-confirmation からインポートします。
このフックは、device-code-confirmation 画面に表示されるロゴ、色、テーマ設定などのブランディング構成を提供します。import { useBranding } from '@auth0/auth0-acul-react/device-code-confirmation';
function CustomTheme() {
const branding = useBranding();
}
このフックは、device-code-confirmation 画面の id、name、logoUrl など、クライアント関連の構成を提供します。import { useClient } from '@auth0/auth0-acul-react/device-code-confirmation';
function AppInfo() {
const client = useClient();
}
このフックは、デバイス確認が組織スコープの場合に、ユーザーの組織に関する情報を提供します。組織コンテキストが存在しない場合は null を返します。import { useOrganization } from '@auth0/auth0-acul-react/device-code-confirmation';
function OrgSelector() {
const organization = useOrganization();
if (!organization) {
return <p>No Organization context</p>;
}
}
このフックには、認証フロー内の現在のプロンプトに関するデータが含まれます。import { usePrompt } from '@auth0/auth0-acul-react/device-code-confirmation';
function FlowInfo() {
const prompt = usePrompt();
}
このフックには、設定やコンテキストなど、device-code-confirmation 画面固有の詳細が含まれます。import { useScreen } from '@auth0/auth0-acul-react/device-code-confirmation';
function ScreenDebug() {
const screen = useScreen();
}
このフックには、id や関連メタデータなど、テナントに関連するデータが含まれます。import { useTenant } from '@auth0/auth0-acul-react/device-code-confirmation';
function TenantInfo() {
const tenant = useTenant();
}
このフックは、アクティブな接続や現在のフロー状態など、device-code-confirmation 画面に関するトランザクション固有のデータを提供します。import { useTransaction } from '@auth0/auth0-acul-react/device-code-confirmation';
function TransactionInfo() {
const transaction = useTransaction();
}
このフックは、URL パラメーターで事前入力されたデバイスコードなど、画面に渡される信頼できないデータを扱います。import { useUntrustedData } from '@auth0/auth0-acul-react/device-code-confirmation';
function PrefilledForm() {
const untrustedData = useUntrustedData();
}
このフックは、現在のユーザーの詳細 (username、email、利用可能な認証方法など) を提供します。import { useUser } from '@auth0/auth0-acul-react/device-code-confirmation';
function UserProfile() {
const user = useUser();
}
useDeviceCodeConfirmation
このフックは、device-code-confirmation 画面で利用できるすべてのメソッドとコンテキストを返します。
このメソッドはデバイスコードフローをキャンセルし、アクティベーションリクエストを拒否します。import { useDeviceCodeConfirmation } from '@auth0/auth0-acul-react/device-code-confirmation';
function CancelButton() {
const { cancel } = useDeviceCodeConfirmation();
return (
<button onClick={() => cancel()}>
Cancel
</button>
);
}
このメソッドはデバイスコードを確認したうえで、アクティベーションリクエストを承認します。import { useDeviceCodeConfirmation } from '@auth0/auth0-acul-react/device-code-confirmation';
function ConfirmButton() {
const { confirm } = useDeviceCodeConfirmation();
return (
<button onClick={() => confirm()}>
Confirm
</button>
);
}
このフックは、ブランディングコンテキストから、フラット化された設定を含む現在のテーマオプションを取得します。
このフックは、現在の ACUL 画面の表示言語を変更する関数を返します。
このフックは、現在の画面のコンテキストと状態を取得します。
このフックは、画面上のサーバーエラー、クライアントエラー、開発者エラーを読み取り、管理します。