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.
Log in to Anvil and click ‘create app’. Choose the Material Design theme.
In the App Browser, click the + next to Services.
You’ll see a list of available services and integrations. Click on Facebook API.
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.
Go to the Code View for Form1.
Add this line to the
Now add this line below it to print the logged-in user’s email:
print('Logged in with Facebook as: %s' % anvil.facebook.auth.get_user_email())
Run your app.
You will see a Facebook login alert:
If you click the ‘Log In’ button, the Facebook login screen will open in a new window:
You can now login with Facebook. When you’re logged in, you’ll see your email address in the Output Panel.
And that’s all there is to it!
Other SSO integrations
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
You can add any of these login options to the multi-purpose login form presented by the Users Service as well.
Want another quickstart?
Every quickstart is on the Quickstarts page.