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 ‘Blank App’. Choose the Material Design theme.
Enable the Microsoft API Service
To add the Microsoft API service to your app, click the blue plus button in the Sidebar Menu.
You’ll see a list of available services and integrations. Click on Microsoft API .
In the App Browser, click the + next to Services.
You’ll see a list of available services and integrations. Click on Microsoft API.
Call the Active Directory login function
Click on Form1
in the App Browser.
Go to the Code view to see the code for Form1
.
In the __init__
method, add these lines:
anvil.microsoft.auth.login()
print(f"You are logged in as: {anvil.microsoft.auth.get_user_email()}")
Run your app and log in
Now click the ‘Run’ button at the top of the screen.
Your app will run and display a dialog informing you that 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 App Console has printed the email address you logged in with:
You are now logged into your app. The Output Panel has printed the email address you logged in with:
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.
Do you still have questions?
Our Community Forum is full of helpful information and Anvil experts.