التحقق من البريد الإلكتروني المخصص باستخدام SendGrid
قبل أن تبدأ استخدم اختر نوع النهجالمحدد لاختيار نوع النهج التي تقوم بإعدادها. يوفر Azure Active Directory B2C طريقتين لتحديد كيفية تفاعل المستخدمين مع تطبيقاتك: من خلال تدفقات محددة مسبقا للمستخدمين أو من خلال سياسات مخصصة قابلة للتكوين بشكل كامل. تختلف الخطوات المطلوبة في هذه المقالة لكل أسلوب.
استخدم البريد الإلكتروني المخصص في Azure Active Directory B2C (Azure AD B2C) لإرسال بريد إلكتروني مخصص للمستخدمين الذين يسجلون لاستخدام تطبيقاتك. باستخدام موفر البريد الإلكتروني التابع لجهة خارجية، SendGrid، يمكنك استخدام قالب البريد الإلكتروني الخاص بك ومن:العنوان والموضوع، بالإضافة إلى دعم إعدادات الترجمة وكلمة المرور المخصصة لمرة واحدة (OTP).
هذه الميزة متاحة فقط للسياسات المخصصة. لخطوات الإعداد، حدد نهج مخصص في المحدد السابق.
يتطلب التحقق من البريد الإلكتروني المخصص استخدام موفر بريد إلكتروني تابع لجهة خارجية مثلSendGrid أوMailjetأوSparkPostأوواجهة برمجة تطبيقات REST مخصصة أوأي موفر بريد إلكتروني يستند إلى HTTP (بما في ذلك موفر خدمة البريد الإلكتروني الخاص بك). توضح هذه المقالة إعداد حل يستخدم SendGrid.
قم بإنشاء حساب SendGrid
إذا لم يكن لديك حساب بالفعل، فابدأ بإعداد حساب SendGrid. للحصول على إرشادات الإعداد، راجعقسم إنشاء حساب SendGridفيكيفية إرسال بريد إلكتروني باستخدام SendGrid مع Azure.
تأكد من إكمال القسم الذي تقوم فيه بإنشاء مفتاح واجهة برمجة تطبيقات SendGrid. سجل مفتاح API لاستخدامه في خطوة لاحقة.
هام
تقدم SendGrid للعملاء القدرة على إرسال رسائل البريد الإلكتروني من عناوين IP المشتركة وعناوين IP المخصصة. عند استخدام عناوين IP مخصصة، فأنت بحاجة إلى بناء سمعتك الخاصة بشكل صحيح من خلال إحماء عنوان IP. لمزيد من المعلومات، راجع إعداد عنوان IP.
قم بإنشاء مفتاح نهج Microsoft Azure Active Directory B2C
بعد ذلك، قم بتخزين مفتاح SendGrid API في مفتاح نهج Microsoft Azure Active Directory B2C لنُهجك للرجوع إليها.
- سجل دخولك إلى مدخل Azure.
- إذا كان لديك حق الوصول إلى عدة مستأجرين، فحدد رمز الإعدادات في القائمة العلوية للتبديل إلى مستأجر Azure AD B2C من قائمة Directories + subscriptions.
- في الزاوية العلوية اليمنى من مدخل Microsoft Azure، اختر All services، ثم ابحث عن Azure AD B2C وحدده.
- في صفحة نظرة عامة، حدد Identity Experience Framework.
- حدد Policy Keys ثم حدد Add.
- بالنسبة إلىالخيارات، اختريدوي.
- أدخِل اسمًا لمفتاح النهج. على سبيل المثال،
SendGridSecret
. تتم إضافة البادئةB2C_1A_
تلقائيًا إلى اسم مفتاحك. - في Secret، أدخل مفتاح SendGrid API الذي سجلته مسبقًا.
- لاستخدام المفتاح ، حدد التوقيع .
- حدد إنشاء.
إنشاء قالب SendGrid
مع إنشاء حساب SendGrid وتخزين مفتاح SendGrid API في مفتاح نهج Microsoft Azure Active Directory B2C، قم بإنشاءقالب معاملات ديناميكي لـ SendGrid.
في موقع SendGrid، افتحصفحة قوالب المعاملات وحددإنشاء قالب ديناميكي.
أدخل اسم قالب فريدًا مثل
Verification email
ثم حددإنشاء.لبدء تحرير القالب الجديد، حدد القالب الذي هو ،
Verification email
ثم حدد إضافة إصدار.حددقالب فارغثم محرر التعليمات البرمجية.
في محرر HTML، الصق قالب HTML التالي أو استخدم قالب HTML الخاص بك.
{{otp}}
يتم استبدال المعلمات و{{email}}
ديناميكيا بقيمة كلمة المرور لمرة واحدة وعنوان البريد الإلكتروني للمستخدم.<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" dir="ltr" lang="en"><head id="Head1"> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"><title>Contoso demo account email verification code</title><meta name="ROBOTS" content="NOINDEX, NOFOLLOW"> <style> table td {border-collapse:collapse;margin:0;padding:0;} </style> </head> <body dir="ltr" lang="en"> <table width="100%" cellpadding="0" cellspacing="0" border="0" dir="ltr" lang="en"> <tr> <td valign="top" width="50%"></td> <td valign="top"> <!-- Email Header --> <table width="640" cellpadding="0" cellspacing="0" border="0" dir="ltr" lang="en" style="border-left:1px solid #e3e3e3;border-right: 1px solid #e3e3e3;"> <tr style="background-color: #0072C6;"> <td width="1" style="background:#0072C6; border-top:1px solid #e3e3e3;"></td> <td width="24" style="border-top:1px solid #e3e3e3;border-bottom:1px solid #e3e3e3;"> </td> <td width="310" valign="middle" style="border-top:1px solid #e3e3e3; border-bottom:1px solid #e3e3e3;padding:12px 0;"> <h1 style="line-height:20pt;font-family:Segoe UI Light; font-size:18pt; color:#ffffff; font-weight:normal;"> <span id="HeaderPlaceholder_UserVerificationEmailHeader"><font color="#FFFFFF">Verify your email address</font></span> </h1> </td> <td width="24" style="border-top: 1px solid #e3e3e3;border-bottom: 1px solid #e3e3e3;"> </td> </tr> </table> <!-- Email Content --> <table width="640" cellpadding="0" cellspacing="0" border="0" dir="ltr" lang="en"> <tr> <td width="1" style="background:#e3e3e3;"></td> <td width="24"> </td> <td id="PageBody" width="640" valign="top" colspan="2" style="border-bottom:1px solid #e3e3e3;padding:10px 0 20px;border-bottom-style:hidden;"> <table cellpadding="0" cellspacing="0" border="0"> <tr> <td width="630" style="font-size:10pt; line-height:13pt; color:#000;"> <table cellpadding="0" cellspacing="0" border="0" width="100%" style="" dir="ltr" lang="en"> <tr> <td> <div style="font-family:'Segoe UI', Tahoma, sans-serif; font-size:14px; color:#333;"> <span id="BodyPlaceholder_UserVerificationEmailBodySentence1">Thanks for verifying your {{email}} account!</span> </div> <br> <div style="font-family:'Segoe UI', Tahoma, sans-serif; font-size:14px; color:#333; font-weight: bold"> <span id="BodyPlaceholder_UserVerificationEmailBodySentence2">Your code is: {{otp}}</span> </div> <br> <br> <div style="font-family:'Segoe UI', Tahoma, sans-serif; font-size:14px; color:#333;"> Sincerely, </div> <div style="font-family:'Segoe UI', Tahoma, sans-serif; font-size:14px; font-style:italic; color:#333;"> Contoso </div> </td> </tr> </table> </td> </tr> </table> </td> <td width="1"> </td> <td width="1"></td> <td width="1"> </td> <td width="1" valign="top"></td> <td width="29"> </td> <td width="1" style="background:#e3e3e3;"></td> </tr> <tr> <td width="1" style="background:#e3e3e3; border-bottom:1px solid #e3e3e3;"></td> <td width="24" style="border-bottom:1px solid #e3e3e3;"> </td> <td id="PageFooterContainer" width="585" valign="top" colspan="6" style="border-bottom:1px solid #e3e3e3;padding:0px;"> </td> <td width="29" style="border-bottom:1px solid #e3e3e3;"> </td> <td width="1" style="background:#e3e3e3; border-bottom:1px solid #e3e3e3;"></td> </tr> </table> </td> <td valign="top" width="50%"></td> </tr> </table> </body> </html>
قم بتوسيع قائمة الإعدادات، وبالنسبة إلى اسم الإصدار، أدخل إصدار قالب.
بالنسبة للموضوع، أدخل
{{subject}}
.حدد حفظ.
ارجع إلى صفحةنماذج المعاملاتعن طريق تحديد سهم الرجوع.
سجل معرّفالنموذج الذي أنشأته للاستخدام في خطوة لاحقة. على سبيل المثال،
d-989077fbba9746e89f3f6411f596fb96
. يمكنك تحديد هذا المعرف عند إضافة تحويل المطالبات.
هام
توضح لك الخطوات التالية كيفية إنشاء ملفات XML للنهج المخصصة. نوصي باستخدام نهج مخصصة نموذج للتحقق من البريد الإلكتروني المخصص المتوفرة على GitHub. DisplayControl_TrustFrameworkExtensions.xml
يستخدم TrustFrameworkExtensions.xml
باعتباره الملف الأساسي خاصته ومن ثم التأكد من تضمين الملفات TrustFrameworkBase.xml
، TrustFrameworkLocalization.xml
و TrustFrameworkExtensions.xml
من حزمة البدء SocialAndLocalAccountsفينهجك.
أضف أنواع مطالبة Microsoft Azure Active Directory B2C
في وثيقتك، أضف أنواع المطالبات التالية إلى <ClaimsSchema>
العنصر الموجود بداخلها<BuildingBlocks>
.
تعد أنواع المطالبات هذه ضرورية لإنشاء عنوان البريد الإلكتروني والتحقق منه باستخدام رمز كلمة المرور لمرة واحدة (OTP).
<!--
<BuildingBlocks>
<ClaimsSchema> -->
<ClaimType Id="Otp">
<DisplayName>Secondary One-time password</DisplayName>
<DataType>string</DataType>
</ClaimType>
<ClaimType Id="emailRequestBody">
<DisplayName>SendGrid request body</DisplayName>
<DataType>string</DataType>
</ClaimType>
<ClaimType Id="VerificationCode">
<DisplayName>Secondary Verification Code</DisplayName>
<DataType>string</DataType>
<UserHelpText>Enter your email verification code</UserHelpText>
<UserInputType>TextBox</UserInputType>
</ClaimType>
<!--
</ClaimsSchema>
</BuildingBlocks> -->
إضافة تحويل المطالبات
بعد ذلك، تحتاج إلى تحويل مطالبات لإخراج مطالبة سلسلة JSON التي تشكل نص الطلب المرسل إلى SendGrid.
يتم تعريف بنية كائن JSON عن طريق المعرفات في تدوين نقطة من معلمات الإدخال وأنواع مطالبات التحويلات في مطالبات الإدخال. تتضمن الأرقام في رمز النقطة المصفوفات. تأتي القيم من قيم مطالبات الإدخال وخصائص "القيمة" معلمات الإدخال. لمزيد من المعلومات حول تحويلات مطالبات JSON، راجع تحويلات مطالبات JSON.
أضف تحويل المطالبات التالي إلى <ClaimsTransformations>
العنصر الموجود بداخله<BuildingBlocks>
. قم بإجراء التحديثات التالية على XML الخاص بتحويل المطالبات:
- قم بتحديث قيمة
template_id
InputParameter بمعرف قالب معاملات SendGrid الذي قمت بإنشائه مسبقًا في إنشاء قالب SendGrid. - قم بتحديث
from.email
قيمة العنوان. استخدم عنوان بريد إلكتروني صالحًا للمساعدة في منع رسالة التحقق من وضع علامة عليها كرسائل غير مرغوب فيها.إشعار
يجب التحقق من عنوان البريد الإلكتروني هذا في SendGrid ضمن مصادقة المرسل إما بمصادقة المجال أو مصادقة المرسل الفردي.
- قم بتحديث قيمة
personalizations.0.dynamic_template_data.subject
معلمة إدخال سطر الموضوع بسطر موضوع مناسب لمؤسستك.
<!--
<BuildingBlocks>
<ClaimsTransformations> -->
<ClaimsTransformation Id="GenerateEmailRequestBody" TransformationMethod="GenerateJson">
<InputClaims>
<InputClaim ClaimTypeReferenceId="email" TransformationClaimType="personalizations.0.to.0.email" />
<InputClaim ClaimTypeReferenceId="otp" TransformationClaimType="personalizations.0.dynamic_template_data.otp" />
<InputClaim ClaimTypeReferenceId="email" TransformationClaimType="personalizations.0.dynamic_template_data.email" />
</InputClaims>
<InputParameters>
<!-- Update the template_id value with the ID of your SendGrid template. -->
<InputParameter Id="template_id" DataType="string" Value="d-989077fbba9746e89f3f6411f596fb96"/>
<InputParameter Id="from.email" DataType="string" Value="my_email@mydomain.com"/>
<!-- Update with a subject line appropriate for your organization. -->
<InputParameter Id="personalizations.0.dynamic_template_data.subject" DataType="string" Value="Contoso account email verification code"/>
</InputParameters>
<OutputClaims>
<OutputClaim ClaimTypeReferenceId="emailRequestBody" TransformationClaimType="outputClaim"/>
</OutputClaims>
</ClaimsTransformation>
<!--
</ClaimsTransformations>
</BuildingBlocks> -->
أضف تعريف لمحتوى DataUri
أسفل تحويلات المطالبات داخل<BuildingBlocks>
، أضف ContentDefinition التالي للإشارة إلى URI لبيانات الإصدار 2.1.2:
<!--
<BuildingBlocks> -->
<ContentDefinitions>
<ContentDefinition Id="api.localaccountsignup">
<DataUri>urn:com:microsoft:aad:b2c:elements:contract:selfasserted:2.1.2</DataUri>
</ContentDefinition>
<ContentDefinition Id="api.localaccountpasswordreset">
<DataUri>urn:com:microsoft:aad:b2c:elements:contract:selfasserted:2.1.2</DataUri>
</ContentDefinition>
</ContentDefinitions>
<!--
</BuildingBlocks> -->
قم بإنشاء DisplayControl
يتم استخدام عنصر تحكم عرض التحقق للتحقق من عنوان البريد الإلكتروني باستخدام رمز التحقق الذي يتلقاه المستخدم.
تم تكوين عنصر التحكم في العرض هذا من أجل:
اجمع
email
نوع مطالبة العنوان من المستخدم.باستخدام
SendCode
هذا الإجراء، أنشئ رمز OTP وأرسل بريدًا إلكترونيًا يحتوي على رمز OTP إلى المستخدم.انتظر حتى يقدم المستخدم
verificationCode
نوع المطالبة مع الرمز المرسل إلى المستخدم.قم بإعادة
email
الجزء الخلفي إلى ملف التعريف الفني المؤكد ذاتيًا والذي يحتوي على مرجع لعنصر التحكم في العرض هذا.
ضمن تعريفات المحتوى، لا يزال داخل<BuildingBlocks>
، أضف DisplayControl التالي من نوع VerificationControl إلى النهج الخاص بك.
<!--
<BuildingBlocks> -->
<DisplayControls>
<DisplayControl Id="emailVerificationControl" UserInterfaceControlType="VerificationControl">
<DisplayClaims>
<DisplayClaim ClaimTypeReferenceId="email" Required="true" />
<DisplayClaim ClaimTypeReferenceId="verificationCode" ControlClaimType="VerificationCode" Required="true" />
</DisplayClaims>
<OutputClaims>
<OutputClaim ClaimTypeReferenceId="email" />
</OutputClaims>
<Actions>
<Action Id="SendCode">
<ValidationClaimsExchange>
<ValidationClaimsExchangeTechnicalProfile TechnicalProfileReferenceId="GenerateOtp" />
<ValidationClaimsExchangeTechnicalProfile TechnicalProfileReferenceId="SendOtp" />
</ValidationClaimsExchange>
</Action>
<Action Id="VerifyCode">
<ValidationClaimsExchange>
<ValidationClaimsExchangeTechnicalProfile TechnicalProfileReferenceId="VerifyOtp" />
</ValidationClaimsExchange>
</Action>
</Actions>
</DisplayControl>
</DisplayControls>
<!--
</BuildingBlocks> -->
إضافة ملفات التعريف الفنية OTP
ينشئ GenerateOtp
ملف التعريف الفني رمزًا لعنوان البريد الإلكتروني. يتحقق VerifyOtp
الملف الشخصي الفني من الرمز المرتبط بعنوان البريد الإلكتروني. يمكنك تغيير تكوين التنسيق وانتهاء صلاحية كلمة المرور لمرة واحدة. لمزيد من المعلومات حول ملفات التعريف الفنية لمرة واحدة، راجع تحديد ملف تعريف تقني لكلمة المرور لمرة واحدة.
إشعار
رموز OTP التي تم إنشاؤها بواسطة بروتوكول Web.TPEngine.Providers.OneTimePasswordProtocolProvider مرتبطة بجلسة المتصفح. هذا يعني أنه يمكن للمستخدم إنشاء رموز OTP فريدة في جلسات المتصفح المختلفة التي تكون كل منها صالحة لجلساتها المقابلة. على النقيض من ذلك، فإن رمز OTP الذي تم إنشاؤه بواسطة مزود البريد الإلكتروني المدمج مستقل عن جلسة المتصفح، لذلك إذا قام المستخدم بإنشاء رمز OTP جديد في جلسة متصفح جديدة، فإنه يحل محل رمز OTP السابق.
أضف الملفات الفنية التالية إلى <ClaimsProviders>
العنصر.
<!--
<ClaimsProviders> -->
<ClaimsProvider>
<DisplayName>One time password technical profiles</DisplayName>
<TechnicalProfiles>
<TechnicalProfile Id="GenerateOtp">
<DisplayName>Generate one time password</DisplayName>
<Protocol Name="Proprietary" Handler="Web.TPEngine.Providers.OneTimePasswordProtocolProvider, Web.TPEngine, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" />
<Metadata>
<Item Key="Operation">GenerateCode</Item>
<Item Key="CodeExpirationInSeconds">600</Item>
<Item Key="CodeLength">6</Item>
<Item Key="CharacterSet">0-9</Item>
<Item Key="NumRetryAttempts">5</Item>
<Item Key="NumCodeGenerationAttempts">10</Item>
<Item Key="ReuseSameCode">false</Item>
</Metadata>
<InputClaims>
<InputClaim ClaimTypeReferenceId="email" PartnerClaimType="identifier" />
</InputClaims>
<OutputClaims>
<OutputClaim ClaimTypeReferenceId="otp" PartnerClaimType="otpGenerated" />
</OutputClaims>
</TechnicalProfile>
<TechnicalProfile Id="VerifyOtp">
<DisplayName>Verify one time password</DisplayName>
<Protocol Name="Proprietary" Handler="Web.TPEngine.Providers.OneTimePasswordProtocolProvider, Web.TPEngine, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" />
<Metadata>
<Item Key="Operation">VerifyCode</Item>
</Metadata>
<InputClaims>
<InputClaim ClaimTypeReferenceId="email" PartnerClaimType="identifier" />
<InputClaim ClaimTypeReferenceId="verificationCode" PartnerClaimType="otpToVerify" />
</InputClaims>
</TechnicalProfile>
</TechnicalProfiles>
</ClaimsProvider>
<!--
</ClaimsProviders> -->
إضافة ملف تعريف تقني لواجهة برمجة تطبيقات REST
ينشئ ملف التعريف الفني REST API محتوى البريد الإلكتروني (باستخدام تنسيق SendGrid). لمزيد من المعلومات حول ملفات التعريف RESTful التقنية، راجع تعريف ملف تعريف RESTful تقني.
كما هو الحال مع ملفات تعريف OTP الفنية، أضف الملفات الفنية التالية إلى <ClaimsProviders>
العنصر.
<ClaimsProvider>
<DisplayName>RestfulProvider</DisplayName>
<TechnicalProfiles>
<TechnicalProfile Id="SendOtp">
<DisplayName>Use SendGrid's email API to send the code to the user</DisplayName>
<Protocol Name="Proprietary" Handler="Web.TPEngine.Providers.RestfulProvider, Web.TPEngine, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" />
<Metadata>
<Item Key="ServiceUrl">https://api.sendgrid.com/v3/mail/send</Item>
<Item Key="AuthenticationType">Bearer</Item>
<Item Key="SendClaimsIn">Body</Item>
<Item Key="ClaimUsedForRequestPayload">emailRequestBody</Item>
</Metadata>
<CryptographicKeys>
<Key Id="BearerAuthenticationToken" StorageReferenceId="B2C_1A_SendGridSecret" />
</CryptographicKeys>
<InputClaimsTransformations>
<InputClaimsTransformation ReferenceId="GenerateEmailRequestBody" />
</InputClaimsTransformations>
<InputClaims>
<InputClaim ClaimTypeReferenceId="emailRequestBody" />
</InputClaims>
</TechnicalProfile>
</TechnicalProfiles>
</ClaimsProvider>
قم بعمل مرجع إلى DisplayControl
في الخطوة الأخيرة، أضف مرجعًا إلى DisplayControl الذي قمت بإنشائه. تجاوز ملفات التعريف التقنية LocalAccountSignUpWithLogonEmail
و LocalAccountDiscoveryUsingEmailAddress
الموجودة والمؤكدة ذاتيًا والتي تم تكوينها في السياسة الأساسية باستخدام قصاصة XML البرمجية التالية. إذا كنت تستخدم إصداراً سابقاً من نهج Microsoft Azure Active Directory B2C، فإن ملفات التعريف الفنية هذه تستخدم DisplayClaims
مع الإشارة إلى DisplayControl
.
لمزيد من المعلومات، راجع ملف تعريف تقني مؤكد ذاتيًا وعرض عنصر التحكم.
<ClaimsProvider>
<DisplayName>Local Account</DisplayName>
<TechnicalProfiles>
<TechnicalProfile Id="LocalAccountSignUpWithLogonEmail">
<DisplayClaims>
<DisplayClaim DisplayControlReferenceId="emailVerificationControl" />
<DisplayClaim ClaimTypeReferenceId="displayName" Required="true" />
<DisplayClaim ClaimTypeReferenceId="givenName" Required="true" />
<DisplayClaim ClaimTypeReferenceId="surName" Required="true" />
<DisplayClaim ClaimTypeReferenceId="newPassword" Required="true" />
<DisplayClaim ClaimTypeReferenceId="reenterPassword" Required="true" />
</DisplayClaims>
</TechnicalProfile>
<TechnicalProfile Id="LocalAccountDiscoveryUsingEmailAddress">
<DisplayClaims>
<DisplayClaim DisplayControlReferenceId="emailVerificationControl" />
</DisplayClaims>
</TechnicalProfile>
</TechnicalProfiles>
</ClaimsProvider>
[اختياري] ترجمة بريدك الإلكتروني
لترجمة البريد الإلكتروني، يجب عليك إرسال سلاسل مترجمة إلى SendGrid أو موفر البريد الإلكتروني الخاص بك. على سبيل المثال، يمكنك ترجمة موضوع البريد الإلكتروني أو النص الأساسي أو رسالة التعليمات البرمجية أو توقيع البريد الإلكتروني. للقيام بذلك، يمكنك استخدام تحويل مطالبات GetLocalizedString Transformation لنسخ السلاسل المترجمة إلى أنواع المطالبات. يستخدم GenerateEmailRequestBody
تحويل المطالبات، الذي ينشئ حمولة JSON، مطالبات الإدخال التي تحتوي على السلاسل المترجمة.
في سياستك، حدد مطالبات السلسلة التالية: الموضوع والرسالة و codeIntro والتوقيع.
حدد تحويل مطالبات GetLocalizedStringsTransformation لاستبدال قيم السلسلة المترجمة في المطالبات من الخطوة 1.
قم بتغيير
GenerateEmailRequestBody
تحويل المطالبات لاستخدام مطالبات الإدخال مع مقتطف XML التالي.قم بتحديث قالب SendGrid لاستخدام المعلمات الديناميكية بدلا من جميع السلاسل التي يقوم Azure AD B2C بترجمتها.
<ClaimsTransformation Id="GetLocalizedStringsForEmail" TransformationMethod="GetLocalizedStringsTransformation"> <OutputClaims> <OutputClaim ClaimTypeReferenceId="subject" TransformationClaimType="email_subject" /> <OutputClaim ClaimTypeReferenceId="message" TransformationClaimType="email_message" /> <OutputClaim ClaimTypeReferenceId="codeIntro" TransformationClaimType="email_code" /> <OutputClaim ClaimTypeReferenceId="signature" TransformationClaimType="email_signature" /> </OutputClaims> </ClaimsTransformation> <ClaimsTransformation Id="GenerateEmailRequestBody" TransformationMethod="GenerateJson"> <InputClaims> <InputClaim ClaimTypeReferenceId="email" TransformationClaimType="personalizations.0.to.0.email" /> <InputClaim ClaimTypeReferenceId="subject" TransformationClaimType="personalizations.0.dynamic_template_data.subject" /> <InputClaim ClaimTypeReferenceId="otp" TransformationClaimType="personalizations.0.dynamic_template_data.otp" /> <InputClaim ClaimTypeReferenceId="email" TransformationClaimType="personalizations.0.dynamic_template_data.email" /> <InputClaim ClaimTypeReferenceId="message" TransformationClaimType="personalizations.0.dynamic_template_data.message" /> <InputClaim ClaimTypeReferenceId="codeIntro" TransformationClaimType="personalizations.0.dynamic_template_data.codeIntro" /> <InputClaim ClaimTypeReferenceId="signature" TransformationClaimType="personalizations.0.dynamic_template_data.signature" /> </InputClaims> <InputParameters> <InputParameter Id="template_id" DataType="string" Value="d-1234567890" /> <InputParameter Id="from.email" DataType="string" Value="my_email@mydomain.com" /> </InputParameters> <OutputClaims> <OutputClaim ClaimTypeReferenceId="emailRequestBody" TransformationClaimType="outputClaim" /> </OutputClaims> </ClaimsTransformation>
أضف عنصر الترجمة التالي.
<!-- <BuildingBlocks> --> <Localization Enabled="true"> <SupportedLanguages DefaultLanguage="en" MergeBehavior="ReplaceAll"> <SupportedLanguage>en</SupportedLanguage> <SupportedLanguage>es</SupportedLanguage> </SupportedLanguages> <LocalizedResources Id="api.custom-email.en"> <LocalizedStrings> <!--Email template parameters--> <LocalizedString ElementType="GetLocalizedStringsTransformationClaimType" StringId="email_subject">Contoso account email verification code</LocalizedString> <LocalizedString ElementType="GetLocalizedStringsTransformationClaimType" StringId="email_message">Thanks for validating the account</LocalizedString> <LocalizedString ElementType="GetLocalizedStringsTransformationClaimType" StringId="email_code">Your code is</LocalizedString> <LocalizedString ElementType="GetLocalizedStringsTransformationClaimType" StringId="email_signature">Sincerely</LocalizedString> </LocalizedStrings> </LocalizedResources> <LocalizedResources Id="api.custom-email.es"> <LocalizedStrings> <!--Email template parameters--> <LocalizedString ElementType="GetLocalizedStringsTransformationClaimType" StringId="email_subject">Código de verificación del correo electrónico de la cuenta de Contoso</LocalizedString> <LocalizedString ElementType="GetLocalizedStringsTransformationClaimType" StringId="email_message">Gracias por comprobar la cuenta de </LocalizedString> <LocalizedString ElementType="GetLocalizedStringsTransformationClaimType" StringId="email_code">Su código es</LocalizedString> <LocalizedString ElementType="GetLocalizedStringsTransformationClaimType" StringId="email_signature">Sinceramente</LocalizedString> </LocalizedStrings> </LocalizedResources> </Localization> <!-- </BuildingBlocks> -->
أضف مراجع إلى عناصر LocalizedResources عن طريق تحديث عنصرContentDefinitions.
<!-- <BuildingBlocks> --> <ContentDefinitions> <ContentDefinition Id="api.localaccountsignup"> <DataUri>urn:com:microsoft:aad:b2c:elements:contract:selfasserted:2.1.2</DataUri> <LocalizedResourcesReferences MergeBehavior="Prepend"> <LocalizedResourcesReference Language="en" LocalizedResourcesReferenceId="api.custom-email.en" /> <LocalizedResourcesReference Language="es" LocalizedResourcesReferenceId="api.custom-email.es" /> </LocalizedResourcesReferences> </ContentDefinition> <ContentDefinition Id="api.localaccountpasswordreset"> <DataUri>urn:com:microsoft:aad:b2c:elements:contract:selfasserted:2.1.2</DataUri> <LocalizedResourcesReferences MergeBehavior="Prepend"> <LocalizedResourcesReference Language="en" LocalizedResourcesReferenceId="api.custom-email.en" /> <LocalizedResourcesReference Language="es" LocalizedResourcesReferenceId="api.custom-email.es" /> </LocalizedResourcesReferences> </ContentDefinition> </ContentDefinitions> <!-- </BuildingBlocks> -->
أخيرًا، أضف تحويل مطالبات المدخلات التالية إلى
LocalAccountSignUpWithLogonEmail
الملفات الشخصية وLocalAccountDiscoveryUsingEmailAddress
التقنية.<InputClaimsTransformations> <InputClaimsTransformation ReferenceId="GetLocalizedStringsForEmail" /> </InputClaimsTransformations>
[اختياري] قم بترجمة واجهة المستخدم
يسمح لك عنصر الترجمةبدعم لغات أو لغات متعددة في نهج رحلات المستخدم. يتيح لك دعم الترجمة في السياسات توفير سلاسل خاصة باللغة لكل من عناصر واجهة مستخدم التحكم في عرض التحقق ورسائل خطأ كلمة المرور لمرة واحدة. قم بإضافة LocalizedString التالية إلى LocalizedResources.
<LocalizedResources Id="api.custom-email.en">
<LocalizedStrings>
...
<!-- Display control UI elements-->
<LocalizedString ElementType="DisplayControl" ElementId="emailVerificationControl" StringId="intro_msg">Verification is necessary. Please click Send button.</LocalizedString>
<LocalizedString ElementType="DisplayControl" ElementId="emailVerificationControl" StringId="success_send_code_msg">Verification code has been sent to your inbox. Please copy it to the input box below.</LocalizedString>
<LocalizedString ElementType="DisplayControl" ElementId="emailVerificationControl" StringId="failure_send_code_msg">We are having trouble verifying your email address. Please enter a valid email address and try again.</LocalizedString>
<LocalizedString ElementType="DisplayControl" ElementId="emailVerificationControl" StringId="success_verify_code_msg">E-mail address verified. You can now continue.</LocalizedString>
<LocalizedString ElementType="DisplayControl" ElementId="emailVerificationControl" StringId="failure_verify_code_msg">We are having trouble verifying your email address. Please try again.</LocalizedString>
<LocalizedString ElementType="DisplayControl" ElementId="emailVerificationControl" StringId="but_send_code">Send verification code</LocalizedString>
<LocalizedString ElementType="DisplayControl" ElementId="emailVerificationControl" StringId="but_verify_code">Verify code</LocalizedString>
<LocalizedString ElementType="DisplayControl" ElementId="emailVerificationControl" StringId="but_send_new_code">Send new code</LocalizedString>
<LocalizedString ElementType="DisplayControl" ElementId="emailVerificationControl" StringId="but_change_claims">Change e-mail</LocalizedString>
<!-- Claims-->
<LocalizedString ElementType="ClaimType" ElementId="emailVerificationCode" StringId="DisplayName">Verification Code</LocalizedString>
<LocalizedString ElementType="ClaimType" ElementId="emailVerificationCode" StringId="UserHelpText">Verification code received in the email.</LocalizedString>
<LocalizedString ElementType="ClaimType" ElementId="emailVerificationCode" StringId="AdminHelpText">Verification code received in the email.</LocalizedString>
<LocalizedString ElementType="ClaimType" ElementId="email" StringId="DisplayName">Email</LocalizedString>
<!-- Email validation error messages-->
<LocalizedString ElementType="ErrorMessage" StringId="UserMessageIfSessionDoesNotExist">You have exceeded the maximum time allowed.</LocalizedString>
<LocalizedString ElementType="ErrorMessage" StringId="UserMessageIfMaxRetryAttempted">You have exceeded the number of retries allowed.</LocalizedString>
<LocalizedString ElementType="ErrorMessage" StringId="UserMessageIfMaxNumberOfCodeGenerated">You have exceeded the number of code generation attempts allowed.</LocalizedString>
<LocalizedString ElementType="ErrorMessage" StringId="UserMessageIfInvalidCode">You have entered the wrong code.</LocalizedString>
<LocalizedString ElementType="ErrorMessage" StringId="UserMessageIfSessionConflict">Cannot verify the code, please try again later.</LocalizedString>
<LocalizedString ElementType="ErrorMessage" StringId="UserMessageIfVerificationFailedRetryAllowed">The verification has failed, please try again.</LocalizedString>
</LocalizedStrings>
</LocalizedResources>
الخطوات التالية
- ابحث عن مثال للتحقق من البريد الإلكتروني المخصص - نهج DisplayControls المخصص على GitHub.
- تعرف على كيفية استخدام واجهة برمجة تطبيقات REST مخصصة أو أي موفر بريد إلكتروني SMTP مستند إلى HTTP، راجع تعريف ملف تعريف تقني RESTful في نهج مخصص Azure AD B2C.