Azure Active Directory B2C özel ilkesini kullanarak sosyal bir hesapla kaydolma ve oturum açma akışı ayarlama
Azure Active Directory B2C özel ilkesi kullanarak kaydolma ve oturum açma akışı ayarlama makalesinde, Azure Active Directory B2C (Azure AD B2C) kullanarak yerel bir hesap için oturum açma akışı ayarlarız.
Bu makalede, Facebook gibi bir sosyal hesap gibi bir dış hesap için oturum açma akışı ekleyeceğiz. Bu durumda Azure AD B2C, bir kullanıcının bir dış sosyal kimlik sağlayıcısının (IdP) kimlik bilgileriyle uygulamanızda oturum açmasına olanak tanır.
Yerel hesaplar için kullanıcı hesabı, kullanıcı özniteliği kullanılarak objectId
benzersiz olarak tanımlanır. Dış IdP için kullanıcı özniteliğini hala mevcut objectId
olsa da kullanırızalternativeSecurityId
.
Ön koşullar
Henüz bir kiracınız yoksa, Azure aboneliğinize bağlı bir Azure AD B2C kiracısı oluşturun.
Bir web uygulaması kaydedin ve kimlik belirteci örtük verme özelliğini etkinleştirin. Yeniden Yönlendirme URI'sinde kullanın https://jwt.ms.
Bilgisayarınızda Visual Studio Code (VS Code) yüklü olmalıdır.
Azure Active Directory B2C özel ilkesini kullanarak yerel hesap için kaydolma ve oturum açma akışı ayarlama sayfasındaki adımları tamamlayın. Bu makale, Kendi özel ilkelerinizi oluşturma ve çalıştırma kılavuz serisinin bir parçasıdır.
Dekont
Bu makale, Azure Active Directory B2C'de kendi özel ilkelerinizi oluşturma ve çalıştırma nasıl yapılır kılavuzu serisinin bir parçasıdır. Bu seriyi ilk makaleden başlatmanızı öneririz.
1. Adım - Facebook uygulaması oluşturma
Facebook Uygulama Kimliği ve Uygulama Gizli Anahtarı'nı almak için Facebook uygulaması oluşturma bölümünde açıklanan adımları kullanın. Facebook hesabıyla kaydolma ve oturum açma ayarlama makalesindeki önkoşulları ve diğer adımları atlayın.
2. Adım - Facebook ilke anahtarı oluşturma
Azure AD B2C kiracınızda Facebook anahtarı depolama ilke anahtarı oluşturma bölümünde açıklanan adımları kullanın. Facebook hesabıyla kaydolma ve oturum açma ayarlama makalesindeki önkoşulları ve diğer adımları atlayın.
3. Adım - Facebook ile oturum açmayı yapılandırma
Facebook ile oturum açmayı yapılandırmak için aşağıdaki adımları gerçekleştirmeniz gerekir:
- Daha fazla talep bildirin
- oluşturma
AlternativeSecurityId
gibi talep işlemelerine yardımcı olmak için daha fazla talep dönüştürmesi tanımlayın. - Facebook talep sağlayıcısını yapılandırma
- Microsoft Entra teknik profillerini Microsoft Entra veritabanından sosyal hesabı okuyacak ve yazacak şekilde yapılandırın.
- Kendi kendine onaylanan bir teknik profil (kullanıcıdan ek giriş kabul etmek veya kullanıcı ayrıntılarını güncelleştirmek için) ve içerik tanımını yapılandırın.
Adım 3.1 - Daha fazla talep bildirme
ContosoCustomPolicy.XML
dosyasında bölümünü bulun ClaimsSchema
ve aşağıdaki kodu kullanarak daha fazla talep bildirin:
<!--<ClaimsSchema>-->
...
<ClaimType Id="issuerUserId">
<DisplayName>Username</DisplayName>
<DataType>string</DataType>
<UserHelpText/>
<UserInputType>TextBox</UserInputType>
<Restriction>
<Pattern RegularExpression="^[a-zA-Z0-9]+[a-zA-Z0-9_-]*$" HelpText="The username you provided is not valid. It must begin with an alphabet or number and can contain alphabets, numbers and the following symbols: _ -" />
</Restriction>
</ClaimType>
<ClaimType Id="identityProvider">
<DisplayName>Identity Provider</DisplayName>
<DataType>string</DataType>
<UserHelpText/>
</ClaimType>
<ClaimType Id="authenticationSource">
<DisplayName>AuthenticationSource</DisplayName>
<DataType>string</DataType>
<UserHelpText>Specifies whether the user was authenticated at Social IDP or local account.</UserHelpText>
</ClaimType>
<ClaimType Id="upnUserName">
<DisplayName>UPN User Name</DisplayName>
<DataType>string</DataType>
<UserHelpText>The user name for creating user principal name.</UserHelpText>
</ClaimType>
<ClaimType Id="alternativeSecurityId">
<DisplayName>AlternativeSecurityId</DisplayName>
<DataType>string</DataType>
<UserHelpText/>
</ClaimType>
<ClaimType Id="mailNickName">
<DisplayName>MailNickName</DisplayName>
<DataType>string</DataType>
<UserHelpText>Your mail nick name as stored in the Azure Active Directory.</UserHelpText>
</ClaimType>
<ClaimType Id="newUser">
<DisplayName>User is new or not</DisplayName>
<DataType>boolean</DataType>
<UserHelpText/>
</ClaimType>
<!--</ClaimsSchema>-->
Adım 3.2 - Talep dönüştürmelerini tanımlama
ContosoCustomPolicy.XML
dosyasında öğesini bulun ClaimsTransformations
ve aşağıdaki kodu kullanarak talep dönüştürmeleri ekleyin:
<!--<ClaimsTransformations>-->
...
<ClaimsTransformation Id="CreateRandomUPNUserName" TransformationMethod="CreateRandomString">
<InputParameters>
<InputParameter Id="randomGeneratorType" DataType="string" Value="GUID" />
</InputParameters>
<OutputClaims>
<OutputClaim ClaimTypeReferenceId="upnUserName" TransformationClaimType="outputClaim" />
</OutputClaims>
</ClaimsTransformation>
<ClaimsTransformation Id="CreateAlternativeSecurityId" TransformationMethod="CreateAlternativeSecurityId">
<InputClaims>
<InputClaim ClaimTypeReferenceId="issuerUserId" TransformationClaimType="key" />
<InputClaim ClaimTypeReferenceId="identityProvider" TransformationClaimType="identityProvider" />
</InputClaims>
<OutputClaims>
<OutputClaim ClaimTypeReferenceId="alternativeSecurityId" TransformationClaimType="alternativeSecurityId" />
</OutputClaims>
</ClaimsTransformation>
<ClaimsTransformation Id="CreateUserPrincipalName" TransformationMethod="FormatStringClaim">
<InputClaims>
<InputClaim ClaimTypeReferenceId="upnUserName" TransformationClaimType="inputClaim" />
</InputClaims>
<InputParameters>
<InputParameter Id="stringFormat" DataType="string" Value="cpim_{0}@{RelyingPartyTenantId}" />
</InputParameters>
<OutputClaims>
<OutputClaim ClaimTypeReferenceId="userPrincipalName" TransformationClaimType="outputClaim" />
</OutputClaims>
</ClaimsTransformation>
<!--</ClaimsTransformations>-->
ve userPrincipalName
talepleri için değer oluşturmak için alternativeSecurityId
kullandığımız üç Talep Dönüşümü tanımladık. Bu ClaimsTransformations, 3.3. adımda OAuth2 teknik profilinde çağrılır.
3.3. Adım - Facebook talep sağlayıcısını yapılandırma
Kullanıcıların Facebook hesabı kullanarak oturum açmasını sağlamak için hesabı Azure AD B2C'nin bir uç nokta üzerinden iletişim kurabileceği bir talep sağlayıcısı olarak tanımlamanız gerekir. Bir Facebook hesabını talep sağlayıcısı olarak tanımlayabilirsiniz.
ContosoCustomPolicy.XML
dosyasında öğesini bulunClaimsProviders
, aşağıdaki kodu kullanarak yeni bir talep sağlayıcısı ekleyin:
<!--<ClaimsProviders>-->
...
<ClaimsProvider>
<!-- The following Domain element allows this profile to be used if the request comes with domain_hint
query string parameter, e.g. domain_hint=facebook.com -->
<Domain>facebook.com</Domain>
<DisplayName>Facebook</DisplayName>
<TechnicalProfiles>
<TechnicalProfile Id="Facebook-OAUTH">
<!-- The text in the following DisplayName element is shown to the user on the claims provider
selection screen. -->
<DisplayName>Facebook</DisplayName>
<Protocol Name="OAuth2" />
<Metadata>
<Item Key="ProviderName">facebook</Item>
<Item Key="authorization_endpoint">https://www.facebook.com/dialog/oauth</Item>
<Item Key="AccessTokenEndpoint">https://graph.facebook.com/oauth/access_token</Item>
<Item Key="HttpBinding">GET</Item>
<Item Key="UsePolicyInRedirectUri">0</Item>
<Item Key="client_id">facebook-app-id</Item>
<Item Key="scope">email public_profile</Item>
<Item Key="ClaimsEndpoint">https://graph.facebook.com/me?fields=id,first_name,last_name,name,email</Item>
<Item Key="AccessTokenResponseFormat">json</Item>
</Metadata>
<CryptographicKeys>
<Key Id="client_secret" StorageReferenceId="facebook-policy-key" />
</CryptographicKeys>
<InputClaims />
<OutputClaims>
<OutputClaim ClaimTypeReferenceId="issuerUserId" PartnerClaimType="id" />
<OutputClaim ClaimTypeReferenceId="givenName" PartnerClaimType="first_name" />
<OutputClaim ClaimTypeReferenceId="surname" PartnerClaimType="last_name" />
<OutputClaim ClaimTypeReferenceId="displayName" PartnerClaimType="name" />
<OutputClaim ClaimTypeReferenceId="email" PartnerClaimType="email" />
<OutputClaim ClaimTypeReferenceId="identityProvider" DefaultValue="facebook.com" AlwaysUseDefaultValue="true" />
<OutputClaim ClaimTypeReferenceId="authenticationSource" DefaultValue="socialIdpAuthentication" AlwaysUseDefaultValue="true" />
</OutputClaims>
<OutputClaimsTransformations>
<OutputClaimsTransformation ReferenceId="CreateRandomUPNUserName" />
<OutputClaimsTransformation ReferenceId="CreateUserPrincipalName" />
<OutputClaimsTransformation ReferenceId="CreateAlternativeSecurityId" />
</OutputClaimsTransformations>
</TechnicalProfile>
</TechnicalProfiles>
</ClaimsProvider>
<!--</ClaimsProviders>-->
Değiştirme:
facebook-app-id
1. adımda elde ettiğiniz FacebookappID
değeriyle.facebook-policy-key
2. adımda edindiğiniz Facebook ilke anahtarının adıyla.
Koleksiyondaki 3.2. adımda tanımladığımız talep dönüştürmelerine OutputClaimsTransformations
dikkat edin.
Adım 3.4 - Microsoft Entra teknik profilleri oluşturma
Yerel bir hesapla oturum açarken olduğu gibi, bir kullanıcı sosyal hesabını depolamak veya okumak için Microsoft Entra ID depolamaya bağlanmak için kullandığınız Microsoft Entra Teknik Profillerini yapılandırmanız gerekir.
ContosoCustomPolicy.XML
Dosyasında, teknik profili bulunAAD-UserUpdate
ve aşağıdaki kodu kullanarak yeni bir teknik profil ekleyin:<TechnicalProfile Id="AAD-UserWriteUsingAlternativeSecurityId"> <DisplayName>Azure Active Directory technical profile for handling social accounts</DisplayName> <Protocol Name="Proprietary" Handler="Web.TPEngine.Providers.AzureActiveDirectoryProvider, Web.TPEngine, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" /> <Metadata> <Item Key="Operation">Write</Item> <Item Key="RaiseErrorIfClaimsPrincipalAlreadyExists">true</Item> </Metadata> <CryptographicKeys> <Key Id="issuer_secret" StorageReferenceId="B2C_1A_TokenSigningKeyContainer" /> </CryptographicKeys> <InputClaims> <InputClaim ClaimTypeReferenceId="alternativeSecurityId" PartnerClaimType="alternativeSecurityId" Required="true" /> </InputClaims> <PersistedClaims> <!-- Required claims --> <PersistedClaim ClaimTypeReferenceId="alternativeSecurityId" /> <PersistedClaim ClaimTypeReferenceId="userPrincipalName" /> <PersistedClaim ClaimTypeReferenceId="mailNickName" DefaultValue="unknown" /> <PersistedClaim ClaimTypeReferenceId="displayName" DefaultValue="unknown" /> <!-- Optional claims --> <PersistedClaim ClaimTypeReferenceId="givenName" /> <PersistedClaim ClaimTypeReferenceId="surname" /> </PersistedClaims> <OutputClaims> <OutputClaim ClaimTypeReferenceId="objectId" /> <OutputClaim ClaimTypeReferenceId="newUser" PartnerClaimType="newClaimsPrincipalCreated" /> </OutputClaims> </TechnicalProfile>
Microsoft Entra Id'ye yeni bir sosyal hesap yazan yeni bir Microsoft Entra Teknik Profili
AAD-UserWriteUsingAlternativeSecurityId
ekledik.B2C_1A_TokenSigningKeyContainer değerini İmzayı yapılandırma bölümünde oluşturduğunuz belirteç imzalama anahtarıyla değiştirin.
ContosoCustomPolicy.XML
Dosyasında, aşağıdaki kodu kullanarak Teknik Profil'inAAD-UserWriteUsingAlternativeSecurityId
arkasına başka bir Microsoft Entra teknik profili ekleyin:<TechnicalProfile Id="AAD-UserReadUsingAlternativeSecurityId"> <DisplayName>Azure Active Directory</DisplayName> <Protocol Name="Proprietary" Handler="Web.TPEngine.Providers.AzureActiveDirectoryProvider, Web.TPEngine, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" /> <Metadata> <Item Key="Operation">Read</Item> <Item Key="RaiseErrorIfClaimsPrincipalDoesNotExist">false</Item> </Metadata> <CryptographicKeys> <Key Id="issuer_secret" StorageReferenceId="B2C_1A_TokenSigningKeyContainer" /> </CryptographicKeys> <InputClaims> <InputClaim ClaimTypeReferenceId="alternativeSecurityId" PartnerClaimType="alternativeSecurityId" Required="true" /> </InputClaims> <OutputClaims> <!-- Required claims --> <OutputClaim ClaimTypeReferenceId="objectId" /> <!-- Optional claims --> <OutputClaim ClaimTypeReferenceId="userPrincipalName" /> <OutputClaim ClaimTypeReferenceId="displayName" /> <OutputClaim ClaimTypeReferenceId="givenName" /> <OutputClaim ClaimTypeReferenceId="surname" /> </OutputClaims> </TechnicalProfile>
Microsoft Entra Id'den yeni bir sosyal hesap okuyan yeni bir Microsoft Entra Teknik Profili
AAD-UserReadUsingAlternativeSecurityId
ekledik. Sosyal hesap için benzersiz bir tanımlayıcı olarak kullanıralternativeSecurityId
.B2C_1A_TokenSigningKeyContainer değerini İmzayı yapılandırma bölümünde oluşturduğunuz belirteç imzalama anahtarıyla değiştirin.
Adım 3.5 - İçerik tanımını yapılandırma
Bir kullanıcı oturum açtığında, kendi kendine onaylanan bir teknik profil kullanarak onlardan bazı bilgiler toplayabilirsiniz. Bu nedenle, kendi kendine onaylanan teknik profil için içerik tanımını yapılandırmanız gerekir.
ContosoCustomPolicy.XML
dosyasında öğesini bulun ContentDefinitions
ve aşağıdaki kodu kullanarak koleksiyona ContentDefinitions
yeni bir içerik tanımı ekleyin:
<ContentDefinition Id="socialAccountsignupContentDefinition">
<LoadUri>~/tenant/templates/AzureBlue/selfAsserted.cshtml</LoadUri>
<RecoveryUri>~/common/default_page_error.html</RecoveryUri>
<DataUri>urn:com:microsoft:aad:b2c:elements:contract:selfasserted:2.1.7</DataUri>
<Metadata>
<Item Key="DisplayName">Collect information from user page alongside those from social Idp.</Item>
</Metadata>
</ContentDefinition>
Bu içerik tanımını bir sonraki adımda (3.6. adım) kendi kendine onaylanan bir teknik profilde meta veri olarak kullanacağız.
Adım 3.6 - Kendi kendine onaylanan bir teknik profil yapılandırma
Bu adımda yapılandırdığınız kendi kendine onaylanan teknik profil, kullanıcıdan daha fazla bilgi toplamak veya sosyal hesaptan alınan benzer bilgileri güncelleştirmek için kullanılır.
ContosoCustomPolicy.XML
dosyasında bölümünü bulun ClaimsProviders
ve aşağıdaki kodu kullanarak yeni bir talep sağlayıcısı ekleyin:
<!--<ClaimsProviders>-->
...
<ClaimsProvider>
<DisplayName>Self Asserted for social sign in</DisplayName>
<TechnicalProfiles>
<TechnicalProfile Id="SelfAsserted-Social">
<DisplayName>Collect more info during social signup</DisplayName>
<Protocol Name="Proprietary" Handler="Web.TPEngine.Providers.SelfAssertedAttributeProvider, Web.TPEngine, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" />
<Metadata>
<Item Key="ContentDefinitionReferenceId">socialAccountsignupContentDefinition</Item>
</Metadata>
<CryptographicKeys>
<Key Id="issuer_secret" StorageReferenceId="B2C_1A_TokenSigningKeyContainer" />
</CryptographicKeys>
<InputClaims>
<!-- These claims ensure that any values retrieved in the previous steps (e.g. from an external IDP) are prefilled.
Note that some of these claims may not have any value, for example, if the external IDP did not provide any of
these values, or if the claim did not appear in the OutputClaims section of the IDP.
In addition, if a claim is not in the InputClaims section, but it is in the OutputClaims section, then its
value will not be prefilled, but the user will still be prompted for it (with an empty value). -->
<InputClaim ClaimTypeReferenceId="displayName" />
<InputClaim ClaimTypeReferenceId="givenName" />
<InputClaim ClaimTypeReferenceId="surname" />
</InputClaims>
<!---User will be asked to input or update these values-->
<DisplayClaims>
<DisplayClaim ClaimTypeReferenceId="displayName"/>
<DisplayClaim ClaimTypeReferenceId="givenName"/>
<DisplayClaim ClaimTypeReferenceId="surname"/>
</DisplayClaims>
<OutputClaims>
<!-- These claims are not shown to the user because their value is obtained through the "ValidationTechnicalProfiles"
referenced below, or a default value is assigned to the claim. A claim is only shown to the user to provide a
value if its value cannot be obtained through any other means. -->
<OutputClaim ClaimTypeReferenceId="objectId" />
<OutputClaim ClaimTypeReferenceId="newUser" />
<!---<OutputClaim ClaimTypeReferenceId="executed-SelfAsserted-Input" DefaultValue="true" />-->
<!-- Optional claims. These claims are collected from the user and can be modified. If a claim is to be persisted in the directory after having been
collected from the user, it needs to be added as a PersistedClaim in the ValidationTechnicalProfile referenced below, i.e.
in AAD-UserWriteUsingAlternativeSecurityId. -->
<OutputClaim ClaimTypeReferenceId="displayName" />
<OutputClaim ClaimTypeReferenceId="givenName" />
<OutputClaim ClaimTypeReferenceId="surname" />
</OutputClaims>
<ValidationTechnicalProfiles>
<ValidationTechnicalProfile ReferenceId="AAD-UserWriteUsingAlternativeSecurityId" />
</ValidationTechnicalProfiles>
</TechnicalProfile>
</TechnicalProfiles>
</ClaimsProvider>
<!--</ClaimsProviders>-->
Eklediğimiz talep sağlayıcısı, kendi kendine onaylanan bir teknik profil içerir. SelfAsserted-Social
Kendi kendine onaylanan teknik profil, doğrulama teknik profili olarak Teknik Profili kullanır AAD-UserWriteUsingAlternativeSecurityId
. Bu nedenle, AAD-UserWriteUsingAlternativeSecurityId
kullanıcı Devam düğmesini seçtiğinde Teknik Profil yürütülür (7. adımda ekran görüntüsüne bakın).
Ayrıca, meta veriler bölümünde 3.5. adımda yapılandırdığımız içerik tanımını socialAccountsignupContentDefinition
da eklediğimize dikkat edin.
4. Adım - Kullanıcı yolculuğu düzenleme adımlarını güncelleştirme
ContosoCustomPolicy.XML
Dosyasında kullanıcı yolculuğunu HelloWorldJourney
bulun ve tüm düzenleme adımlarını aşağıdaki kodda gösterilen adımlarla değiştirin:
<!--<OrchestrationSteps>-->
...
<OrchestrationStep Order="1" Type="CombinedSignInAndSignUp">
<ClaimsProviderSelections>
<ClaimsProviderSelection TargetClaimsExchangeId="FacebookExchange" />
</ClaimsProviderSelections>
</OrchestrationStep>
<OrchestrationStep Order="2" Type="ClaimsExchange">
<ClaimsExchanges>
<ClaimsExchange Id="FacebookExchange"
TechnicalProfileReferenceId="Facebook-OAUTH" />
</ClaimsExchanges>
</OrchestrationStep>
<!-- For social IDP authentication, attempt to find the user account in the
directory. -->
<OrchestrationStep Order="3" Type="ClaimsExchange">
<ClaimsExchanges>
<ClaimsExchange Id="AADUserReadUsingAlternativeSecurityId" TechnicalProfileReferenceId="AAD-UserReadUsingAlternativeSecurityId" />
</ClaimsExchanges>
</OrchestrationStep>
<!-- Show self-asserted page only if the directory does not have the user account
already (i.e. we don't have an objectId). -->
<OrchestrationStep Order="4" Type="ClaimsExchange">
<Preconditions>
<Precondition Type="ClaimsExist" ExecuteActionsIf="true">
<Value>objectId</Value>
<Action>SkipThisOrchestrationStep</Action>
</Precondition>
</Preconditions>
<ClaimsExchanges>
<ClaimsExchange Id="SelfAsserted-Social" TechnicalProfileReferenceId="SelfAsserted-Social" />
</ClaimsExchanges>
</OrchestrationStep>
<OrchestrationStep Order="5" Type="ClaimsExchange">
<Preconditions>
<Precondition Type="ClaimsExist" ExecuteActionsIf="true">
<Value>objectId</Value>
<Action>SkipThisOrchestrationStep</Action>
</Precondition>
</Preconditions>
<ClaimsExchanges>
<ClaimsExchange Id="AADUserWrite" TechnicalProfileReferenceId="AAD-UserWriteUsingAlternativeSecurityId" />
</ClaimsExchanges>
</OrchestrationStep>
<OrchestrationStep Order="6" Type="SendClaims" CpimIssuerTechnicalProfileReferenceId="JwtIssuer" />
<!--</OrchestrationSteps>-->
Düzenlemede, kullanıcının sosyal hesap kullanarak oturum açmasını sağlayan teknik profillere başvuruda bulunduk.
Özel ilke çalıştırıldığında:
Düzenleme Adım 1 - Bu adım, bir kullanıcının seçebileceği kullanılabilir oturum açma seçeneklerini listeleyen bir
ClaimsProviderSelections
öğe içerir. Bu durumda, tek bir seçeneğiniz vardır,FacebookExchange
bu nedenle ilke çalıştırıldığında, kullanıcılar özniteliği tarafındanTargetClaimsExchangeId
gösterildiği gibi 2. adımda doğrudan Facebook.com alınır.Düzenleme Adım 2 - Teknik
Facebook-OAUTH
profil yürütülür, böylece kullanıcı oturum açmak için Facebook'a yönlendirilir.Düzenleme 3 . Adım: 3. adımda teknik
AAD-UserReadUsingAlternativeSecurityId
profil, Microsoft Entra ID depolama alanından kullanıcı sosyal hesabını okumaya çalışmak için yürütülür. Sosyal hesap bulunursa çıkışobjectId
talebi olarak döndürülür.Düzenleme Adımı 4 - Kullanıcı zaten yoksa (
objectId
yoksa) bu adım çalışır. Kullanıcıdan daha fazla bilgi toplayan veya sosyal hesaptan alınan benzer bilgileri güncelleştiren formu gösterir.Düzenleme Adımı 5 - Kullanıcı zaten yoksa (
objectId
mevcut değilse) bu adım çalıştırılır, bu nedenleAAD-UserWriteUsingAlternativeSecurityId
Teknik Profil sosyal hesabı Microsoft Entra Id'ye yazmak için yürütülür.Düzenleme Adım 6 - Son olarak, 6. adım ilkenin yürütmesinin sonunda JWT belirtecini bir araya getirir ve döndürür.
5. Adım - Bağlı olan taraf çıktı taleplerini güncelleştirme
ContosoCustomPolicy.XML
dosyasında öğesini bulun RelyingParty
ve ardından tüm çıkış talepleri koleksiyonunu aşağıdaki kodla değiştirin:
<OutputClaim ClaimTypeReferenceId="displayName" />
<OutputClaim ClaimTypeReferenceId="givenName" />
<OutputClaim ClaimTypeReferenceId="surname" />
<OutputClaim ClaimTypeReferenceId="email" />
<OutputClaim ClaimTypeReferenceId="objectId" PartnerClaimType="sub"/>
<OutputClaim ClaimTypeReferenceId="identityProvider" />
Kimlik sağlayıcısını (identityProvider) çıkış talebi olarak ekledik, bu nedenle bağlı olan taraf uygulamasına döndürülen JWT belirtecine dahil edilecek.
6. Adım - İlkeyi karşıya yükleme
İlke dosyanızı karşıya yüklemek için Özel ilke dosyasını karşıya yükleme bölümünde yer alan adımları izleyin. Portalda bulunan dosyayla aynı ada sahip bir dosyayı karşıya yüklüyorsanız, zaten varsa Özel ilkenin üzerine yaz'ı seçtiğinizden emin olun.
7. Adım - Test ilkesi
Özel ilkenizi test etmek için Özel ilkeyi test etme'deki adımları izleyin.
Bir Facebook oturum açma sayfasına yönlendirilirsiniz. Facebook kimlik bilgilerinizi girin ve Oturum Aç'ı seçin. Seçebileceğimiz birden fazla oturum açma seçeneği olmadığından düzenleme adımlarımızda bu şekilde ayarlarken doğrudan Facebook'a yönlendirilirsiniz. Normalde, bir uygulamada, seçildiğinde ilkeyi çalıştıran Facebook ile oturum aç gibi bir düğme eklersiniz.
Bu ilkeyi ilk kez çalıştırıyorsanız (sosyal hesap Microsoft Entra depolama alanında zaten mevcut değilse), aşağıda gösterilen gibi bir ekran görüntüsü görürsünüz. Sosyal hesap Microsoft Entra depolama alanında zaten mevcut olduğundan, sonraki ilke yürütmelerinde bu ekranı görmezsiniz.
Görünen Ad, Verilen Ad ve Soyadı girin veya güncelleştirin ve ardından Devam düğmesini seçin.
İlke yürütmeyi tamamladıktan sonra adresine yönlendirilirsiniz https://jwt.msve kodu çözülen bir JWT belirteci görürsünüz. Aşağıdaki JWT belirteci kod parçacığına benzer:
{
"typ": "JWT",
"alg": "RS256",
"kid": "pxLOMWFgP4T..."
}.{
...
"acr": "b2c_1a_contosocustompolicy",
...
"given_name": "Maurice",
"family_name": "Paulet",
"name": "Maurice Paulet",
"email": "maurice.p@contoso.com",
"idp": "facebook.com"
}.[Signature]
kimlik sağlayıcısının "idp": "facebook.com"
JWT belirtecinde yer aldığına dikkat edin.
Birleşik yerel ve sosyal oturum açma
Bu makalede, kullanıcı yolculuğu düzenleme adımlarımız yalnızca kullanıcının sosyal hesap kullanarak oturum açmasını sağlayan teknik profillere başvurur. Düzenleme adımlarını değiştirerek kullanıcının yerel bir hesap veya sosyal hesap kullanarak oturum açmasını sağlayabiliriz. Bunu yapmak için, ilk düzenleme adımının ClaimsProviderSelections
öğesinde kullanıcının kullanabileceği oturum açma seçenekleri listelenir.
Birleşik bir yerel ve sosyal hesap eklemek için aşağıdaki adımları kullanın:
ContosoCustomPolicy.XML
dosyasında, kendi kendine onaylanan teknik profili bulunAccountTypeInputCollector
ve ardından aşağıdaki kodu kullanarak çıkış talepleri koleksiyonuna talep ekleyinauthenticationSource
:<OutputClaim ClaimTypeReferenceId="authenticationSource" DefaultValue="localIdpAuthentication" AlwaysUseDefaultValue="true" />
UserJourneys
bölümünde, aşağıdaki kodu kullanarak yeni bir kullanıcı yolculuğuLocalAndSocialSignInAndSignUp
ekleyin:<!--<UserJourneys>--> ... <UserJourney Id="LocalAndSocialSignInAndSignUp"> <OrchestrationSteps> <!--Orchestration steps will be added here--> </OrchestrationSteps> </UserJourney> <!--</UserJourneys>-->
Oluşturduğunuz kullanıcı yolculuğunda,
LocalAndSocialSignInAndSignUp
aşağıdaki kodu kullanarak düzenleme adımları ekleyin:<!--<UserJourneys> ... <UserJourney Id="LocalAndSocialSignInAndSignUp"> <OrchestrationSteps>--> <OrchestrationStep Order="1" Type="CombinedSignInAndSignUp" ContentDefinitionReferenceId="SignupOrSigninContentDefinition"> <ClaimsProviderSelections> <ClaimsProviderSelection TargetClaimsExchangeId="FacebookExchange" /> <ClaimsProviderSelection ValidationClaimsExchangeId="LocalAccountSigninEmailExchange" /> </ClaimsProviderSelections> <ClaimsExchanges> <ClaimsExchange Id="LocalAccountSigninEmailExchange" TechnicalProfileReferenceId="UserSignInCollector" /> </ClaimsExchanges> </OrchestrationStep> <!-- Check if the user has selected to sign in using one of the social providers --> <OrchestrationStep Order="2" Type="ClaimsExchange"> <Preconditions> <Precondition Type="ClaimsExist" ExecuteActionsIf="true"> <Value>objectId</Value> <Action>SkipThisOrchestrationStep</Action> </Precondition> </Preconditions> <ClaimsExchanges> <ClaimsExchange Id="FacebookExchange" TechnicalProfileReferenceId="Facebook-OAUTH" /> <ClaimsExchange Id="AccountTypeInputCollectorClaimsExchange" TechnicalProfileReferenceId="AccountTypeInputCollector"/> </ClaimsExchanges> </OrchestrationStep> <!--For Local sign in option start--> <OrchestrationStep Order="3" Type="ClaimsExchange"> <Preconditions> <Precondition Type="ClaimsExist" ExecuteActionsIf="true"> <Value>objectId</Value> <Action>SkipThisOrchestrationStep</Action> </Precondition> <Precondition Type="ClaimEquals" ExecuteActionsIf="true"> <Value>accountType</Value> <Value>work</Value> <Action>SkipThisOrchestrationStep</Action> </Precondition> <Precondition Type="ClaimEquals" ExecuteActionsIf="true"> <Value>authenticationSource</Value> <Value>socialIdpAuthentication</Value> <Action>SkipThisOrchestrationStep</Action> </Precondition> </Preconditions> <ClaimsExchanges> <ClaimsExchange Id="GetAccessCodeClaimsExchange" TechnicalProfileReferenceId="AccessCodeInputCollector" /> </ClaimsExchanges> </OrchestrationStep> <OrchestrationStep Order="4" Type="ClaimsExchange"> <Preconditions> <Precondition Type="ClaimsExist" ExecuteActionsIf="true"> <Value>objectId</Value> <Action>SkipThisOrchestrationStep</Action> </Precondition> <Precondition Type="ClaimEquals" ExecuteActionsIf="true"> <Value>authenticationSource</Value> <Value>socialIdpAuthentication</Value> <Action>SkipThisOrchestrationStep</Action> </Precondition> </Preconditions> <ClaimsExchanges> <ClaimsExchange Id="SignUpWithLogonEmailExchange" TechnicalProfileReferenceId="UserInformationCollector" /> </ClaimsExchanges> </OrchestrationStep> <OrchestrationStep Order="5" Type="ClaimsExchange"> <Preconditions> <Precondition Type="ClaimEquals" ExecuteActionsIf="true"> <Value>authenticationSource</Value> <Value>socialIdpAuthentication</Value> <Action>SkipThisOrchestrationStep</Action> </Precondition> </Preconditions> <ClaimsExchanges> <ClaimsExchange Id="AADUserReaderExchange" TechnicalProfileReferenceId="AAD-UserRead"/> </ClaimsExchanges> </OrchestrationStep> <!--For Local sign in option end--> <!--For social sign in option start--> <!-- For social IDP authentication, attempt to find the user account in the directory. --> <OrchestrationStep Order="6" Type="ClaimsExchange"> <Preconditions> <Precondition Type="ClaimEquals" ExecuteActionsIf="true"> <Value>authenticationSource</Value> <Value>localIdpAuthentication</Value> <Action>SkipThisOrchestrationStep</Action> </Precondition> </Preconditions> <ClaimsExchanges> <ClaimsExchange Id="AADUserReadUsingAlternativeSecurityId" TechnicalProfileReferenceId="AAD-UserReadUsingAlternativeSecurityId" /> </ClaimsExchanges> </OrchestrationStep> <!-- Show self-asserted page only if the directory does not have the user account already (i.e. we do not have an objectId). --> <OrchestrationStep Order="7" Type="ClaimsExchange"> <Preconditions> <Precondition Type="ClaimsExist" ExecuteActionsIf="true"> <Value>objectId</Value> <Action>SkipThisOrchestrationStep</Action> </Precondition> <Precondition Type="ClaimEquals" ExecuteActionsIf="true"> <Value>authenticationSource</Value> <Value>localIdpAuthentication</Value> <Action>SkipThisOrchestrationStep</Action> </Precondition> </Preconditions> <ClaimsExchanges> <ClaimsExchange Id="SelfAsserted-Social" TechnicalProfileReferenceId="SelfAsserted-Social" /> </ClaimsExchanges> </OrchestrationStep> <OrchestrationStep Order="8" Type="ClaimsExchange"> <Preconditions> <Precondition Type="ClaimsExist" ExecuteActionsIf="true"> <Value>objectId</Value> <Action>SkipThisOrchestrationStep</Action> </Precondition> <Precondition Type="ClaimEquals" ExecuteActionsIf="true"> <Value>authenticationSource</Value> <Value>localIdpAuthentication</Value> <Action>SkipThisOrchestrationStep</Action> </Precondition> </Preconditions> <ClaimsExchanges> <ClaimsExchange Id="AADUserWrite" TechnicalProfileReferenceId="AAD-UserWriteUsingAlternativeSecurityId" /> </ClaimsExchanges> </OrchestrationStep> <!--For social sign in option end--> <OrchestrationStep Order="9" Type="ClaimsExchange"> <ClaimsExchanges> <ClaimsExchange Id="GetMessageClaimsExchange" TechnicalProfileReferenceId="UserInputMessageClaimGenerator"/> </ClaimsExchanges> </OrchestrationStep> <OrchestrationStep Order="10" Type="SendClaims" CpimIssuerTechnicalProfileReferenceId="JwtIssuer" /> <!-- </OrchestrationSteps> </UserJourney> </UserJourneys>-->
İlk adımda, bir kullanıcının yolculuğunda, yerel veya sosyal kimlik doğrulamasında seçmesi gereken seçenekleri belirtiriz. İzleyen adımlarda, kullanıcının seçtiği seçeneği veya kullanıcının bulunduğu yolculuğun aşamasını izlemek için önkoşulları kullanırız. Örneğin, talebi yerel kimlik doğrulama yolculuğuyla sosyal kimlik doğrulama yolculuğu arasında ayrım yapmak için kullanırız
authenticationSource
.RelyingParty
bölümünde DefaultUserJourney'sReferenceId
öğesini olarak değiştirinLocalAndSocialSignInAndSignUp
İlkenizi karşıya yüklemek ve çalıştırmak için 6. ve 7. adımdaki yordamı kullanın. İlkeyi çalıştırdıktan sonra aşağıdaki ekran görüntüsüne benzer bir ekran görürsünüz.
Bir kullanıcının yerel bir hesap veya sosyal hesap kullanarak kaydolabildiğini veya oturum açabildiğini gözlemleyebilirsiniz.
Sonraki adımlar
- Azure Active Directory B2C özel ilkesinde OAuth2 teknik profili tanımlama hakkında daha fazla bilgi edinin.