Live Chat

We'll need to share your messages (and your email address if you're logged in) with our live chat provider, Drift. Here's their privacy policy.

If you don't want to do this, you can email us instead at

Quickstart: Microsoft APIs

Use Active Directory in your Anvil app

Anvil provides a one-line login function to log users in to their Microsoft account. You can also restrict access to only users in your own Active Directory. You can easily use Microsoft Azure’s many REST APIs from Anvil client or server code.

Follow this quickstart to enable the Microsoft Service and set up a login that uses Microsoft’s Single Sign On system.

Create an app

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

Location of the Create App button

Enable the Microsoft API Service

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 Microsoft API.

Services list with Microsoft highlighted

Call the Active Directory login function

Click on Form1 in the App Browser.

Form1 in the App Browser

Go to the Code view to see the code for Form1.

Form1 in the App Browser

In the __init__ method, add these lines:

    print(f"You are logged in as: {}")

Run your app and log in

Now click the ‘Run’ button at the top of the screen.

Run app button at the top of the Anvil Editor

Your app will run and display a dialog informing you that you are about to log in with Microsoft.

A running app showing a dialog with 'cancel' and 'log in' buttons, and a message informing you you are about to log in with Microsoft.

Click ‘Log In’. The Microsoft Single Sign On page will open in a new browser window. Log in with a Microsoft account (if you don’t already have a Microsoft account, you can create one using this window.)

You are now logged into your app. The Output Panel has printed the email address you logged in with:

The Output Panel with a message giving the email address you are logged in with via Microsoft Azure.

Copy the example app

Click on the button below to clone a finished version of this app into your account.

Next Up

Want more depth on this subject?

You can restrict access to only users in your own Azure Active Directory. Read Using your own Azure Active Directory for more details.

It’s easy to access Microsoft Azure APIs via your Active Directory. Anvil fetches an API token for you, so you just have to make the relevant HTTP requests. Read Accessing Microsoft APIs for more details.

Want another quickstart?

Every quickstart is on the Quickstarts page.