1. Cloud development

ユーザー事前登録スクリプト

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

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

この例は、新しいユーザーがSitecore Content Hubに追加される前に実行される ユーザー事前登録 ウェブスクリプトを示しています。入力を検証し、外部プロバイダーがGoogleでメールドメインがyahoo.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("@yahoo.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;

  3. ユーザーメールがnullまたは空の場合は例外を投げてください。

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

  4. メールの末尾が '@yahoo.com'でない場合は例外を投げてください。

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

セットアップ

  • ユーザー事前登録スクリプトを作成、公開、有効化します。
この記事を改善するための提案がある場合は、 お知らせください!