You are currently viewing the new Anvil Editor Docs.
Switch to the Classic Editor Docs
You are currently viewing the Classic Editor Docs.
Switch to the new Anvil Editor Docs

Quickstart: Facebook Integration

Log users in using Facebook accounts

Anvil provides a one-line login function to log users in to their Facebook account. You can also add a Facebook login option to the Users Service login form.

Follow this quickstart to enable the Facebook Service and log users in with Facebook.

Create an app

Log in to Anvil and click ‘Blank App’. Choose the Material Design theme.

Location of the Create App button

Log in to Anvil and click ‘Blank App’. Choose the Material Design theme.

Location of the Create App button

Enable the Facebook Service

To add the Facebook service to your app, click the blue plus button Add button sidebar menu in the Sidebar Menu.

You’ll see a list of available services and integrations. Click on the Facebook API Facebook API Icon.

Services list with Facebook highlighted

In the App Browser, click the + next to Services.

App Browser showing the plus next to Services

You’ll see a list of available services and integrations. Click on Facebook API.

Services list with Facebook highlighted

Make Facebook aware of your Anvil app

Facebook needs to know about your Anvil app in order for the OAuth login flow to work. You’ll use the Facebook for Developers console for this - it only takes a few minutes.

Run through the Linking Facebook and Anvil guide and continue from here when you’re done.

Add a Facebook Login dialog

Go to the Code View for Form1.

Add this line to the __init__ method:

    anvil.facebook.auth.login()

Now add this line below it to print the logged-in user’s email:

    print(f'Logged in with Facebook as: {anvil.facebook.auth.get_user_email()}')

Run your app

Run your app.

The Anvil Designer's Run App button.

The Anvil Designer's Run App button.

You will see a Facebook login alert:

A running Anvil app with a modal that has buttons saying 'Log In with Facebook' and 'Cancel'.

If you click the ‘Log In’ button, the Facebook login screen will open in a new window:

The Facebook Single Sign On window.

You can now login with Facebook. When you’re logged in, you’ll see your email address in the App Console.

The App Console with 'Logged in with Facebook as: shaun@anvil.works' displayed.

You can now login with Facebook. When you’re logged in, you’ll see your email address in the Output Panel.

The Output Panel with 'Logged in with Facebook as: shaun@anvil.works' displayed.

And that’s all there is to it!

Next up

Other SSO integrations

Similar Single Sign On login functionality is available for Microsoft and Google (and there are some other integrations for Microsoft and Google too).

Just as users can log in with their Facebook accounts using anvil.facebook.auth.login(), they can log in with Microsoft accounts using anvil.microsoft.auth.login(), and Google accounts using anvil.google.auth.login().

You can add any of these login options to the multi-purpose login form presented by the Users Service as well.

The various log-in options in the Users Service.

The various log-in options in the Users Service.

Want another quickstart?

Every quickstart is on the Quickstarts page.


Do you still have questions?

Our Community Forum is full of helpful information and Anvil experts.