แก้ไข

แชร์ผ่าน


Configure your App Service or Azure Functions app to use Facebook login

This article shows how to configure Azure App Service or Azure Functions to use Facebook as an authentication provider.

To complete the procedure in this article, you need a Facebook account that has a verified email address and a mobile phone number. To create a new Facebook account, go to facebook.com.

Register your application with Facebook

  1. Go to the Facebook Developers website and sign in with your Facebook account credentials.

    If you don't have a Facebook for Developers account, select Get Started and follow the registration steps.

  2. Select My Apps > Add New App.

  3. In Display Name field:

    1. Type a unique name for your app.
    2. Provide your Contact Email.
    3. Select Create App ID.
    4. Complete the security check.

    The developer dashboard for your new Facebook app opens.

  4. Select Dashboard > Facebook Login > Set up > Web.

  5. In the left navigation under Facebook Login, select Settings.

  6. In the Valid OAuth redirect URIs field, enter https://<app-name>.azurewebsites.net/.auth/login/facebook/callback. Remember to replace <app-name> with the name of your Azure App Service app.

  7. Select Save Changes.

  8. In the left pane, select Settings > Basic.

  9. In the App Secret field, select Show. Copy the values of App ID and App Secret. You use them later to configure your App Service app in Azure.

    Important

    The app secret is an important security credential. Do not share this secret with anyone or distribute it within a client application.

  10. The Facebook account that you used to register the application is an administrator of the app. At this point, only administrators can sign in to this application.

    To authenticate other Facebook accounts, select App Review and enable Make <your-app-name> public to enable the general public to access the app by using Facebook authentication.

Add Facebook information to your application

  1. Sign in to the Azure portal and navigate to your app.

  2. Select Authentication in the menu on the left. Click Add identity provider.

  3. Select Facebook in the identity provider dropdown. Paste in the App ID and App Secret values that you obtained previously.

    The secret will be stored as a slot-sticky application setting named FACEBOOK_PROVIDER_AUTHENTICATION_SECRET. You can update that setting later to use Key Vault references if you wish to manage the secret in Azure Key Vault.

  4. If this is the first identity provider configured for the application, you will also be prompted with an App Service authentication settings section. Otherwise, you may move on to the next step.

    These options determine how your application responds to unauthenticated requests, and the default selections will redirect all requests to log in with this new provider. You can change customize this behavior now or adjust these settings later from the main Authentication screen by choosing Edit next to Authentication settings. To learn more about these options, see Authentication flow.

  5. (Optional) Click Next: Scopes and add any scopes needed by the application. These will be requested at login time for browser-based flows.

  6. Click Add.

You're now ready to use Facebook for authentication in your app. The provider will be listed on the Authentication screen. From there, you can edit or delete this provider configuration.

Next steps