Azure B2C中如何在SelfAssertedAttributeProvider显示已有Claim值
问题描述
我正在构建登录流程,用户可能需要重新同意服务条款。已通过Restful Provider收集到所需版本,该Claim包含预期字符串,复选框也能正常显示,但无法在SelfAssertedAttributeProvider中展示之前编排步骤收集到的consentVersion Claim值。我只需要展示这个字符串,格式可以通过JavaScript调整。
Claim Definitions
<ClaimType Id="consentVersion"> <DisplayName>consentVersion</DisplayName> <DataType>string</DataType> <UserInputType>TextBox</UserInputType> <AdminHelpText>The new version the user has to accept.</AdminHelpText> </ClaimType> <ClaimType Id="termsOfUseCheckBox"> <DisplayName></DisplayName> <DataType>string</DataType> <UserInputType>CheckboxMultiSelect</UserInputType> <Restriction> <Enumeration Text=" I agree" Value="True" SelectByDefault="false" /> </Restriction> </ClaimType>
ClaimProvider TechnicalProfile
<ClaimsProvider> <DisplayName>Self Asserted</DisplayName> <TechnicalProfiles> <TechnicalProfile Id="SelfAsserted-Input-ToU-SignIn"> <DisplayName>Self Asserted ToU</DisplayName> <Protocol Name="Proprietary" Handler="Web.TPEngine.Providers.SelfAssertedAttributeProvider, Web.TPEngine, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" /> <Metadata> <Item Key="ContentDefinitionReferenceId">api.updatedtou</Item> <Item Key="AllowGenerationOfClaimsWithNullValues">true</Item> </Metadata> <CryptographicKeys> <Key Id="issuer_secret" StorageReferenceId="B2C_1A_TokenSigningKeyContainer" /> </CryptographicKeys> <InputClaims> <InputClaim ClaimTypeReferenceId="objectId" /> <InputClaim ClaimTypeReferenceId="termsOfUseCheckBox" DefaultValue="False" /> <InputClaim ClaimTypeReferenceId="consentVersion" /> </InputClaims> <OutputClaims> <OutputClaim ClaimTypeReferenceId="termsOfUseCheckBox" /> </OutputClaims> </TechnicalProfile> </TechnicalProfiles> </ClaimsProvider>
解决方案
1. 调整ClaimType定义
将consentVersion的UserInputType改为DisplayControl,明确该字段仅用于展示而非用户输入:
<ClaimType Id="consentVersion"> <DisplayName>服务条款版本</DisplayName> <DataType>string</DataType> <UserInputType>DisplayControl</UserInputType> <AdminHelpText>用户需要接受的新版本号</AdminHelpText> </ClaimType>
2. 在SelfAsserted TechnicalProfile中添加OutputClaim
SelfAssertedAttributeProvider默认只会渲染OutputClaims内的字段,把consentVersion加入其中才能在页面显示:
<OutputClaims> <OutputClaim ClaimTypeReferenceId="termsOfUseCheckBox" /> <OutputClaim ClaimTypeReferenceId="consentVersion" /> </OutputClaims>
3. (可选)用JavaScript自定义展示样式
如果需要更灵活的格式控制,可在自定义页面的JS中读取Claim值并渲染:
window.addEventListener('load', function() { const consentVersion = window.SelfAssertedContext?.inputClaims.consentVersion; if (consentVersion) { // 替换为页面中实际用于展示的元素ID document.getElementById('consent-version').innerText = `请同意版本:${consentVersion} 的服务条款`; } });
关键校验点
- 确认Restful Provider的TechnicalProfile已将
consentVersion加入<OutputClaims>,确保Claim能传递到后续流程; - 检查用户旅程编排,保证Restful Provider的执行步骤在SelfAsserted Provider之前,确保Claim已被收集。
内容的提问来源于stack exchange,提问作者tpschmidt
相关产品推荐
相关产品推荐

