简体   繁体   English

通过 Azure AD B2C 自定义策略登录 Facebook

[英]Facebook login via Azure AD B2C custom policy

I have created custom policy using Identity Experience Framework.我已经使用 Identity Experience Framework 创建了自定义策略。 I am able to signup and signin user using the local account but when I am trying to use Facebook as social login I am running into some error.我可以使用本地帐户注册和登录用户,但是当我尝试使用 Facebook 作为社交登录时,我遇到了一些错误。

Issue: When I click Facebook login (Social Login) from my custom policy, I am being redirected to FB for login, but after login from FB I am seeing below error from application insights.问题:当我从自定义策略单击 Facebook 登录(社交登录)时,我被重定向到 FB 进行登录,但在从 FB 登录后,我看到以下来自应用程序洞察的错误。

{
""Kind"": ""HandlerResult"",
""Content"": {
  ""Result"": true,
  ""RecorderRecord"": {
    ""Values"": [
      {
        ""Key"": ""SendErrorTechnicalProfile"",
        ""Value"": ""OAuth2ProtocolProvider""
      },
      {
        ""Key"": ""Exception"",
        ""Value"": {
          ""Kind"": ""Handled"",
          ""HResult"": ""80131500"",
          ""Message"": ""An exception was caught when making a request to URL \""https://graph.facebook.com/oauth/access_token\"" using method \""Get\"". The exception status code was \""ProtocolError\"" with the following message: {scrubbed}."",
          ""Data"": {},
          ""Exception"": {
            ""Kind"": ""Handled"",
            ""HResult"": ""80131509"",
            ""Message"": ""The remote server returned an error: (400) Bad Request."",
            ""Data"": {}
          }
        }
      }
    ]
  }
}

}, },

any thoughts?有什么想法吗?

<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="ClaimsEndpoint">https://graph.facebook.com/me?fields=id,first_name,last_name,name,email,picture</Item>
        <Item Key="scope">email</Item>
        <Item Key="HttpBinding">GET</Item>
        <Item Key="client_id">xxxxxxxx</Item>
        <Item Key="UsePolicyInRedirectUri">0</Item>
      </Metadata>
      <CryptographicKeys>
        <Key Id="client_secret" StorageReferenceId="B2C_1A_FacebookSecret" />
      </CryptographicKeys>
      <InputClaims />
      <OutputClaims>
        <OutputClaim ClaimTypeReferenceId="userId" 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" />
        <OutputClaim ClaimTypeReferenceId="authenticationSource" DefaultValue="socialIdpAuthentication" />
        <OutputClaim ClaimTypeReferenceId="extension_picture"  PartnerClaimType="picture"/>
      </OutputClaims>
      <OutputClaimsTransformations>
        <OutputClaimsTransformation ReferenceId="CreateRandomUPNUserName" />
        <OutputClaimsTransformation ReferenceId="CreateUserPrincipalName" />
        <OutputClaimsTransformation ReferenceId="CreateAlternativeSecurityId" />
        <OutputClaimsTransformation ReferenceId="CreateSubjectClaimFromAlternativeSecurityId" />
      </OutputClaimsTransformations>
      <UseTechnicalProfileForSessionManagement ReferenceId="SM-SocialLogin" />
    </TechnicalProfile>
  </TechnicalProfiles>

You must also add the following item to <Metadata /> : 您还必须将以下项目添加到<Metadata />

<Item Key="AccessTokenResponseFormat">json</Item>

See this blog post for more information. 有关更多信息,请参见此博客文章

You have add as well...你也加了...

<Metadata>
   <Item Key="AccessTokenResponseFormat">json</Item>
</Metadata>

<OutputClaims>
   <OutputClaim ClaimTypeReferenceId="identityProviderAccessToken" PartnerClaimType="{oauth2:access_token}" />
</OutputClaims>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM