如何在 Azure AD B2C 中存储来自 IdentityServer 3 的声明或仅将其包含在 AAD B2C 颁发的令牌中

2024-02-28

我想知道是否可以将 oid 声明或基本上由 Identity Server 3 发出的任何其他声明传播到 AAD B2C,并使其成为 Azure AD B2C 发出的令牌的一部分?我们需要在客户端拥有一个原始 ID,而我们从 sub 和 oid 声明中可以获得的只是 AAD B2C 用户帐户的 ID。我也想对角色声明做同样的事情。任何帮助将非常感激。

[EDITED]

以下是我的 Identity Server 配置的 TechnicalProfile 在自定义策略 (TrustFrameworkExtensions.xml) 中的样子:

<TechnicalProfile Id="IdentityServerProfile">
    <DisplayName>IdentityServer</DisplayName>
    <Description>Login with your IdentityServer account</Description>
    <Protocol Name="OpenIdConnect"/>
    <OutputTokenFormat>JWT</OutputTokenFormat>
    <Metadata>
        <Item Key="METADATA">https://{identity_server_hostname}/identity/.well-known/openid-configuration</Item>
        <Item Key="ProviderName">https://{identity_server_hostname}/identity</Item>
        <Item Key="client_id">00000000-0000-0000-0000-000000000000</Item>
        <Item Key="IdTokenAudience">00000000-0000-0000-0000-000000000000</Item>
        <Item Key="response_types">code</Item>
        <Item Key="scope">openid profile customScope</Item>
        <Item Key="UsePolicyInRedirectUri">false</Item>
        <Item Key="AccessTokenResponseFormat">json</Item>
        <Item Key="HttpBinding">POST</Item>
    </Metadata>
    <CryptographicKeys>
        <Key Id="client_secret" StorageReferenceId="B2C_1A_IdentityServerAppSecret"/>
    </CryptographicKeys>
    <OutputClaims>      
        <OutputClaim ClaimTypeReferenceId="authenticationSource" DefaultValue="IdentityServer" />
        <OutputClaim ClaimTypeReferenceId="displayName" PartnerClaimType="name" />
        <OutputClaim ClaimTypeReferenceId="identityProvider" DefaultValue="tid" />
        <OutputClaim ClaimTypeReferenceId="socialIdpUserId" PartnerClaimType="sub" />
    </OutputClaims>
    <OutputClaimsTransformations>
        <OutputClaimsTransformation ReferenceId="CreateRandomUPNUserName"/>
        <OutputClaimsTransformation ReferenceId="CreateUserPrincipalName"/>
        <OutputClaimsTransformation ReferenceId="CreateAlternativeSecurityId"/>
    </OutputClaimsTransformations>
    <UseTechnicalProfileForSessionManagement ReferenceId="SM-Noop"/>
</TechnicalProfile>

以下是来自具有给定correlationId 的日志的 Application Insights 的原始日志:

{  

"TenantId":"{租户}.onmicrosoft.com", "PolicyId":"B2C_1A_signup_signin_capcom", “重定向Uri”:“http://本地主机:3000/ http://localhost:3000/“, “附加参数”:{
"client_info":"1", "x-client-SKU":"MSAL.JS", "x-client-Ver":"0.1.5", “客户端请求ID”:“a0ef9d95-ba21-4796-ad65-bc9e2b8c5e89” }, “随机数”:“bf198ee6-e084-433d-885c-2bd8f0292b3d”, “州”:“7f732141-498e-4445-9efe-9b0d54178ef6”, "ClientId":"012c0f85-4568-483f-9bca-054d6201ac00", "ResponseType":"id_token", "ResponseMode":"片段", “响应重定向器”:{
“URI”:“http://本地主机:3000/ http://localhost:3000/“, “D”:假, “WF”:正确, “R”:假, “S”:假 }, “应用程序模型版本”:1, “范围提供者”:[

] }

我注意到并且觉得奇怪的是 ResponseType 值。在我们的 TechnicalProfile 中设置为 code,这里它的值为 id_token。

[编辑2] SocialIdpUserId 的声明终于通过了。下面还有一个答案,问题是什么。现在,我仍然有一个关于firstName、lastName 和displayName 的问题。我遵循与 SocialIdpUserId 相同的模式,但我唯一能看到的是默认值。 这是我对它们的配置:

1)索赔类型定义:

<ClaimType Id="displayName">
    <DisplayName>Display Name</DisplayName>
    <DataType>string</DataType>
    <DefaultPartnerClaimTypes>
      <Protocol Name="OAuth2" PartnerClaimType="unique_name" />
      <Protocol Name="OpenIdConnect" PartnerClaimType="displayName" />
      <Protocol Name="SAML2" PartnerClaimType="http://schemas.xmlsoap.org/ws/2005/05/identity/claims/name" />
    </DefaultPartnerClaimTypes>
    <UserHelpText>Your display name.</UserHelpText>
    <UserInputType>TextBox</UserInputType>
 </ClaimType>
...
<ClaimType Id="givenName">
    <DisplayName>Given Name</DisplayName>
    <DataType>string</DataType>
    <DefaultPartnerClaimTypes>
      <Protocol Name="OAuth2" PartnerClaimType="given_name" />
      <Protocol Name="OpenIdConnect" PartnerClaimType="given_name" />
      <Protocol Name="SAML2" PartnerClaimType="http://schemas.xmlsoap.org/ws/2005/05/identity/claims/givenname" />
    </DefaultPartnerClaimTypes>
    <UserHelpText>Your given name (also known as first name).</UserHelpText>
    <UserInputType>TextBox</UserInputType>
 </ClaimType>
<ClaimType Id="surname">
    <DisplayName>Surname</DisplayName>
    <DataType>string</DataType>
    <DefaultPartnerClaimTypes>
      <Protocol Name="OAuth2" PartnerClaimType="family_name" />
      <Protocol Name="OpenIdConnect" PartnerClaimType="family_name" />
      <Protocol Name="SAML2" PartnerClaimType="http://schemas.xmlsoap.org/ws/2005/05/identity/claims/surname" />
    </DefaultPartnerClaimTypes>
    <UserHelpText>Your surname (also known as family name or last name).</UserHelpText>
    <UserInputType>TextBox</UserInputType>
 </ClaimType>

并在我的 IdP 的技术配置文件中输出声明:

<TechnicalProfiles>
    <TechnicalProfile Id="CapcomProfile">
...
   <OutputClaims>
    <OutputClaim ClaimTypeReferenceId="displayName" />
    <OutputClaim ClaimTypeReferenceId="givenName" PartnerClaimType="firstName" DefaultValue="No" />
    <OutputClaim ClaimTypeReferenceId="surname" PartnerClaimType="lastName" DefaultValue="Name" />
...

最后,RP 输出定义:

<OutputClaims>
  <OutputClaim ClaimTypeReferenceId="displayName" PartnerClaimType="displayName" />
  <OutputClaim ClaimTypeReferenceId="givenName" PartnerClaimType="givenName"  />
  <OutputClaim ClaimTypeReferenceId="surname" PartnerClaimType="surname" DefaultValue="Not found in IdP" />
...

有什么建议么?


为此,您必须从内置策略转向自定义策略 https://learn.microsoft.com/en-us/azure/active-directory-b2c/active-directory-b2c-overview-custom,它将来自身份提供者的传入声明通过传出声明传递到应用程序。

例如,如果您创建自定义策略入门包 https://github.com/Azure-Samples/active-directory-b2c-custom-policy-starterpack,那么您可以将用户标识符从 Facebook 传递到应用程序,如下所示:

1) 确保社交 IDP 用户 ID声明索赔:

<ClaimType Id="socialIdpUserId">
  <DisplayName>Username</DisplayName>
  <DataType>string</DataType>
</ClaimType>

2) 确保社交 IDP 用户 ID索赔被添加到<OutputClaims />Facebook 技术简介集合:

<ClaimsProvider>
  <Domain>facebook.com</Domain>
  ...
  <TechnicalProfiles>
    <TechnicalProfile Id="Facebook-OAUTH">
      <DisplayName>Facebook</DisplayName>
      ...
      <OutputClaims>
        <OutputClaim ClaimTypeReferenceId="socialIdpUserId" PartnerClaimType="id" />
        ...
      </OutputClaims>
      ...
    </TechnicalProfile>
  </TechnicalProfiles>
</ClaimsProvider>

3)确保社交 IDP 用户 ID索赔被添加到<OutputClaims />依赖方技术简介的集合:

<RelyingParty>
  <DefaultUserJourney ReferenceId="SignUpOrSignIn" />
  <TechnicalProfile Id="PolicyProfile">
    <DisplayName>PolicyProfile</DisplayName>
    ...
    <OutputClaims>
      ...
      <OutputClaim ClaimTypeReferenceId="socialIdpUserId" PartnerClaimType="ext_id" />
    </OutputClaims>
    ...
  </TechnicalProfile>
</RelyingParty>

您可以对其他外部声明遵循相同的模式。

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

如何在 Azure AD B2C 中存储来自 IdentityServer 3 的声明或仅将其包含在 AAD B2C 颁发的令牌中 的相关文章

随机推荐

  • 如何将所有项目模板数据设置到 Xamarin Carousel 中的单个视图中

    我尝试将 itemtemplate 中的所有项目制作为单个视图 如下图所示 如何使用 Xamarin CarouselView 实现此目的 我正在使用这样的 carousel new CarouselView carousel Bindin
  • 如何只在部分网站上实现HTTPS?

    我想知道 如何在网站的某一部分实现HTTPS 比方说 我想创建网上商店 我希望能够在没有 HTTPS 的情况下浏览所有项目 这样更快 对吧 当我想要付款时 我想使用 HTTPS 正如我在其他文章中读到的那样 当 IIS 配置为使用 HTTP
  • java中'Float a = 3f'和'Float a = 3.0'有什么区别?

    如果我表演 97346822 3f result is 2 9204048E8 however 97346822 3 0 gives me 2 92040466E8 请解释 号码3 0 is the 字面表示 http docs oracl
  • gcc 在链接时忽略符号名称的大小写

    我正在开发的一个软件使用全小写符号名称将 NETLIB BLAS LAPACK 嵌入到其源代码中 但现在将应用程序移植到 Windows 时我发现 Intel MKL 和该平台的其他几个 BLAS LAPACK 实现使用全大写符号名称 有没
  • 为什么需要绑定 `T: 'a` 来存储引用 `&'a T`?

    鉴于此代码 struct RefWrapper lt a T gt r a T 编译器抱怨 错误 参数类型T可能活得不够长 考虑添加显式生命周期界限T a这样引用类型 a T不会比它所指向的数据更长久 我已经多次看到这个错误 到目前为止我只
  • 清除 Android 浏览器历史记录

    我正在为客户编写一个应用程序 该应用程序将有多个可供客户查看和使用的设备 他们希望能够定期清除浏览器历史记录 这样 如果客户打开浏览器访问不适当的网站 下一个客户就不会看到此内容 我目前正在使用它来清除历史记录和搜索 Browser cle
  • 面试问题:递归生成素数最快的方法是什么? [关闭]

    就目前情况而言 这个问题不太适合我们的问答形式 我们希望答案得到事实 参考资料或专业知识的支持 但这个问题可能会引发辩论 争论 民意调查或扩展讨论 如果您觉得这个问题可以改进并可能重新开放 访问帮助中心 help reopen questi
  • 您遇到的 C 语言常见的未定义/未指定行为有哪些? [关闭]

    Closed 这个问题需要多问focused help closed questions 目前不接受答案 C 语言中未指定行为的一个示例是函数参数的求值顺序 它可能是从左到右或从右到左 你只是不知道 这会影响如何foo c c or foo
  • 将浮点异常转换为 C++ 异常

    是否可以在 x86 Linux 上将浮点异常 信号 转换为 C 异常 这是出于调试目的 因此不可移植性和不完善性是可以的 例如 如果不能 100 保证调用所有析构函数 如果您的 C 标准库实现支持 TR1 函数fetestexcept fe
  • 最终字段和线程安全

    为了线程安全 它应该是特意不可变的 java 类 final 的所有字段 包括超级字段 还是没有修饰符方法就足够了 假设我有一个带有非最终字段的 POJO 其中所有字段都是某个不可变类的类型 这个 POJO 有 getters setter
  • 安装下载的 .apk 文件时解析错误

    嗨 两周后我又开始了我的研究并与这个错误作斗争 解析错误 解析包时出现问题 我的实现范围是尝试从服务器更新我的应用程序 我在该服务器上有更新的 apk 文件 并使用服务通过我的应用程序下载它 现在我在舞台边缘 我可以从该服务器下载文件 我可
  • Android 媒体播放器在 ICS 上永远循环

    我想播放通知声音 但我的问题是声音永远循环 而它应该只响一次 我尝试过两种方法 notification sound Uri parse content media internal audio media 38 and mMediaPla
  • 如何使用 Jersey Rest Webservices 和 Java 解析 JSON 数组

    我从 iOS 客户端获取 Json 数组 并希望使用 Java jersey 和 Gson 在服务器端解析 Json 我正在从 iOS 发送 POST 方法中的 JSON 数组 我想使用 json 但坚持如何在 Java 类中保存 json
  • C++ 的链接迭代器

    Python 的 itertools 实现了chain http docs python org library itertools html itertools chain迭代器本质上连接了许多不同的迭代器以提供单个迭代器的所有内容 C
  • jQuery 等效选择器

    以下内容完全等价吗 你使用哪种习语 为什么 form1 edit field input form1 edit field find input edit field input form1 input form1 edit field 我
  • EF 4.1 Code First:类型中的每个属性名称必须是唯一的查找表关联错误

    这是我第一次尝试创建自己的 EF 模型 我发现自己在尝试使用 Code First 创建查找表关联时陷入困境 以便我可以访问 myProduct Category AltCategoryID 我已经设置了模型和映射 据我所知是正确的 但继续
  • 在R中寻找SIR模型参数的问题

    我正在尝试使用 R 中的 SIR 模型来模拟冠状病毒感染率 但是 如您所见 我的 beta 控制易感者和感染者之间的过渡 和 gamma 控制感染者和康复者之间的过渡 值不正确 beta gamma 1 0000000 0 8407238
  • 如果存在则不能批量工作

    我正在尝试创建一个 bat 文件来创建一个简单的文本文件 我的问题是 Windows XP 主文件夹是C Documents and Settings而 vista 及以上C Users 我正在运行这个 无论我为路径名输入什么 我总是得到i
  • Express 中跨子域的会话

    我正在使用 Express 中的 vhost 功能和 Node 来管理我的应用程序的多个子域 该应用程序使用相同的会话密钥和密钥 并且我相信我已经使用了正确的会话 cookie 设置 cookie path domain example c
  • 如何在 Azure AD B2C 中存储来自 IdentityServer 3 的声明或仅将其包含在 AAD B2C 颁发的令牌中

    我想知道是否可以将 oid 声明或基本上由 Identity Server 3 发出的任何其他声明传播到 AAD B2C 并使其成为 Azure AD B2C 发出的令牌的一部分 我们需要在客户端拥有一个原始 ID 而我们从 sub 和 o