簡體   English   中英

通過 Azure AD B2C 自定義策略登錄 Facebook

[英]Facebook login via Azure AD B2C custom policy

我已經使用 Identity Experience Framework 創建了自定義策略。 我可以使用本地帳戶注冊和登錄用戶,但是當我嘗試使用 Facebook 作為社交登錄時,我遇到了一些錯誤。

問題:當我從自定義策略單擊 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"": {}
          }
        }
      }
    ]
  }
}

},

有什么想法嗎?

<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>

您還必須將以下項目添加到<Metadata />

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

有關更多信息,請參見此博客文章

你也加了...

<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