如何使用Azure AD B2C获取Facebook个人资料照片

10

我正在使用MSAL.js,并成功地使用Facebook作为身份提供者,在Azure AD B2C中登录/注册用户。问题是,在登录后,我无法检索到用户的个人资料图片。

Azure AD B2C返回一个与用户Facebook ID没有关联的对象标识符。


你使用自定义策略吗? - Chris Padgett
不,据我所知,要使用自定义策略,我需要拥有AD B2C高级帐户。 - armache
1
嗨@armache。自定义策略是配置文件,为任何Azure AD B2C租户定义行为;它们不需要特殊租户。下面,我发布了如何使用自定义策略检索Facebook用户的图片字段,然后在ID令牌中发出图片声明的方法。 - Chris Padgett
1个回答

18

使用自定义策略,您可以检索Facebook用户的图片字段,然后在ID令牌中发出图片声明,具体如下。

1:按照社交帐户策略(例如SocialAndLocalAccounts)之一完成Azure Active Directory B2C:开始使用自定义策略步骤。

2:在扩展文件中声明“picture”声明:

<ClaimType Id="picture">
  <DisplayName>Picture</DisplayName>
  <DataType>string</DataType>
</ClaimType>

3:在扩展策略中,将“picture”字段添加到“ClaimsEndpoint”元数据项和“Facebook-OAUTH”技术配置文件的“picture”输出声明中:

<ClaimsProvider>
  <DisplayName>Facebook</DisplayName>
  <TechnicalProfiles>
    <TechnicalProfile Id="Facebook-OAUTH">
      <Metadata>
        <Item Key="client_id">facebook_clientid</Item>
        <Item Key="scope">email public_profile</Item>
        <Item Key="ClaimsEndpoint">https://graph.facebook.com/me?fields=id,first_name,last_name,name,email,picture</Item>
      </Metadata>
      <OutputClaims>
        <OutputClaim ClaimTypeReferenceId="picture" PartnerClaimType="picture" />
      </OutputClaims>
    </TechnicalProfile>
  </TechnicalProfiles>
</ClaimsProvider>

4:在注册或登录依赖方策略中发布“picture”声明:

<RelyingParty>
  <DefaultUserJourney ReferenceId="SignUpOrSignIn" />
  <TechnicalProfile Id="PolicyProfile">
    <DisplayName>PolicyProfile</DisplayName>
    <Protocol Name="OpenIdConnect" />
    <OutputClaims>
      <OutputClaim ClaimTypeReferenceId="displayName" />
      <OutputClaim ClaimTypeReferenceId="givenName" />
      <OutputClaim ClaimTypeReferenceId="surname" />
      <OutputClaim ClaimTypeReferenceId="email" />
      <OutputClaim ClaimTypeReferenceId="picture" />
      <OutputClaim ClaimTypeReferenceId="objectId" PartnerClaimType="sub"/>
      <OutputClaim ClaimTypeReferenceId="identityProvider" />
    </OutputClaims>
    <SubjectNamingInfo ClaimType="sub" />
  </TechnicalProfile>
</RelyingParty>

步骤2中提到的XML文件,我在基础文件中看到了类似的内容,而不是扩展文件中。 我需要把它放在基础文件中吗?@armache - Raas Masood
嗨@RaasMasood。您可以在基本文件或扩展文件中添加“picture”声明类型。 - Chris Padgett
1
这对我没有用,令人遗憾的是,这些实现中没有一个能够直接支持这个重要功能。 - Jaider
@YangLuo,你能为 Google 完成这个任务吗? - Mário Meyrelles
@MárioMeyrelles 你能用谷歌实现吗?我需要从谷歌和Facebook获取年龄范围和性别。 - deen
显示剩余4条评论

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接