1. ユーザー登録前スクリプト

ユーザー登録前スクリプトの例

Version:
日本語翻訳に関する免責事項

このページの翻訳はAIによって自動的に行われました。可能な限り正確な翻訳を心掛けていますが、原文と異なる表現や解釈が含まれる場合があります。正確で公式な情報については、必ず英語の原文をご参照ください。

これは、新しいユーザーが Sitecore Content Hub™ に登録される前に実行されるユーザー登録前スクリプトの例です。外部プロバイダーが Google の場合にのみ、特定のメール アドレス タイプを許可します。

ユース ケース

  1. 新しいユーザーが登録される予定です。
  2. スクリプトは、プロバイダーが Google かどうかを確認します。この場合、末尾が @Stylelabs.com のメール アドレスのみが許可されます。

スクリプト

if (Context.ExternalUserInfo?.Provider == "Google")
{
var info = Context.ExternalUserInfo;
if (string.IsNullOrEmpty(info.Email))
{
throw new InvalidOperationException("Provider was 'Google' but email was 'null'.");
}

if (!info.Email.EndsWith("@stylelabs.com"))
{
throw new ForbiddenException("You are not allowed to access the system. Please contact the administrator.");
}
}

スクリプトの説明

  1. 外部ユーザー プロバイダーを確認します。「Google」プロバイダーのみが対象です。

    if (Context.ExternalUserInfo?.Provider == "Google")
  2. 外部ユーザー情報を取得します。

    var info = Context.ExternalUserInfo;
    ヒント

    ExternalUserInfo の詳細については、「API リファレンス ノート」を参照してください。

  3. ユーザーのメールが null または空の場合は、InvalidOperationException をスローします。

    if (string.IsNullOrEmpty(info.Email))
    {
    throw new InvalidOperationException("Provider was 'Google' but email was 'null'.");
    }
  4. メールの末尾が「@stylelabs.com」でない場合、ForbiddenException をスローします。

    if (!info.Email.EndsWith("@stylelabs.com"))
    {
    throw new ForbiddenException("You are not allowed to access the system. Please contact the administrator.");
    }

セットアップ

  • 上記のソース コードを使用したユーザー登録前スクリプトを作成し、パブリッシュして有効にします。
この記事を改善するための提案がある場合は、 お知らせください!