Set up sign-up and sign-in with a Facebook account using Azure Active Directory B2C
Before you begin, use the Choose a policy type selector at the top of this page to choose the type of policy you’re setting up. Azure Active Directory B2C offers two methods to define how users interact with your applications: through predefined user flows or through fully configurable custom policies. The steps required in this article are different for each method.
Note
In Azure Active Directory B2C, custom policies are designed primarily to address complex scenarios. For most scenarios, we recommend that you use built-in user flows. If you've not done so, learn about custom policy starter pack in Get started with custom policies in Active Directory B2C.
Prerequisites
- Create a user flow so users can sign up and sign in to your application.
- Register a web application.
- Complete the steps in Get started with custom policies in Active Directory B2C. This tutorial guides you how to update custom policy files to use your Azure AD B2C tenant configuration.
- Register a web application.
Create a Facebook application
To enable sign-in for users with a Facebook account in Azure Active Directory B2C (Azure AD B2C), you need to create an application in Facebook App Dashboard. For more information, see App Development.
If you don't already have a Facebook account, sign up at https://www.facebook.com. After you sign-up or sign-in with your Facebook account, start the Facebook developer account registration process. For more information, see Register as a Facebook Developer.
- Sign in to Facebook for developers with your Facebook developer account credentials.
- Select Create App.
- For the Select an app type, select Consumer, then select Next.
- Enter an App Display Name and a valid App Contact Email.
- Select Create App. This step may require you to accept Facebook platform policies and complete an online security check.
- Select Settings > Basic.
- Copy the value of App ID.
- Select Show and copy the value of App Secret. You use both of them to configure Facebook as an identity provider in your tenant. App Secret is an important security credential.
- Enter a URL for the Privacy Policy URL, for example
https://www.contoso.com/privacy
. The policy URL is a page you maintain to provide privacy information for your application. - Enter a URL for the Terms of Service URL, for example
https://www.contoso.com/tos
. The policy URL is a page you maintain to provide terms and conditions for your application. - Enter a URL for the User Data Deletion, for example
https://www.contoso.com/delete_my_data
. The User Data Deletion URL is a page you maintain to provide away for users to request that their data be deleted. - Choose a Category, for example
Business and Pages
. This value is required by Facebook, but not used for Azure AD B2C.
- At the bottom of the page, select Add Platform, and then select Website.
- In Site URL, enter the address of your website, for example
https://contoso.com
. - Select Save Changes.
- From the menu, select the plus sign or Add Product link next to PRODUCTS. Under the Add Products to Your App, select Set up under Facebook Login.
- From the menu, select Facebook Login, select Settings.
- In Valid OAuth redirect URIs, enter
https://your-tenant-name.b2clogin.com/your-tenant-name.onmicrosoft.com/oauth2/authresp
. If you use a custom domain, enterhttps://your-domain-name/your-tenant-id.onmicrosoft.com/oauth2/authresp
. Replaceyour-tenant-id
with the id of your tenant, andyour-domain-name
with your custom domain. - Select Save Changes at the bottom of the page.
- To make your Facebook application available to Azure AD B2C, select the Status selector at the top right of the page and turn it On to make the Application public, and then select Switch Mode. At this point, the Status should change from Development to Live. For more information, see Facebook App Development.
Configure Facebook as an identity provider
- Sign in to the Azure portal as the global administrator of your Azure AD B2C tenant.
- If you have access to multiple tenants, select the Settings icon in the top menu to switch to your Azure AD B2C tenant from the Directories + subscriptions menu.
- Choose All services in the top-left corner of the Azure portal, search for and select Azure AD B2C.
- Select Identity providers, then select Facebook.
- Enter a Name. For example, Facebook.
- For the Client ID, enter the App ID of the Facebook application that you created earlier.
- For the Client secret, enter the App Secret that you recorded.
- Select Save.
Add Facebook identity provider to a user flow
At this point, the Facebook identity provider has been set up, but it's not yet available in any of the sign-in pages. To add the Facebook identity provider to a user flow:
- In your Azure AD B2C tenant, select User flows.
- Click the user flow that you want to add the Facebook identity provider.
- Under the Social identity providers, select Facebook.
- Select Save.
- To test your policy, select Run user flow.
- For Application, select the web application named testapp1 that you previously registered. The Reply URL should show
https://jwt.ms
. - Select the Run user flow button.
- From the sign-up or sign-in page, select Facebook to sign in with Facebook account.
If the sign-in process is successful, your browser is redirected to https://jwt.ms
, which displays the contents of the token returned by Azure AD B2C.
Create a policy key
You need to store the App Secret that you previously recorded in your Azure AD B2C tenant.
- Sign in to the Azure portal.
- If you have access to multiple tenants, select the Settings icon in the top menu to switch to your Azure AD B2C tenant from the Directories + subscriptions menu.
- Choose All services in the top-left corner of the Azure portal, and then search for and select Azure AD B2C.
- On the Overview page, select Identity Experience Framework.
- Select Policy Keys and then select Add.
- For Options, choose
Manual
. - Enter a Name for the policy key. For example,
FacebookSecret
. The prefixB2C_1A_
is added automatically to the name of your key. - In Secret, enter your App Secret that you previously recorded.
- For Key usage, select
Signature
. - Click Create.
Configure a Facebook account as an identity provider
In the
SocialAndLocalAccounts/
TrustFrameworkExtensions.xml
file, replace the value ofclient_id
with the Facebook application ID:<TechnicalProfile Id="Facebook-OAUTH"> <Metadata> <!--Replace the value of client_id in this technical profile with the Facebook app ID"--> <Item Key="client_id">00000000000000</Item>
Upload and test the policy
Update the relying party (RP) file that initiates the user journey that you created.
- Upload the TrustFrameworkExtensions.xml file to your tenant.
- Under Custom policies, select B2C_1A_signup_signin.
- For Select Application, select the web application named testapp1 that you previously registered. The Reply URL should show
https://jwt.ms
. - Select the Run now button.
- From the sign-up or sign-in page, select Facebook to sign in with Facebook account.
If the sign-in process is successful, your browser is redirected to https://jwt.ms
, which displays the contents of the token returned by Azure AD B2C.
Next steps
- Learn how to pass Facebook token to your application.
- Check out the Facebook federation Live demo, and how to pass Facebook access token Live demo
Σχόλια
https://aka.ms/ContentUserFeedback.
Σύντομα διαθέσιμα: Καθ' όλη τη διάρκεια του 2024 θα καταργήσουμε σταδιακά τα ζητήματα GitHub ως μηχανισμό ανάδρασης για το περιεχόμενο και θα το αντικαταστήσουμε με ένα νέο σύστημα ανάδρασης. Για περισσότερες πληροφορίες, ανατρέξτε στο θέμα:Υποβολή και προβολή σχολίων για