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.
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 Microsoft API.
Form1 in the App Browser.
Go to the Code view to see the code for
__init__ method, add these lines:
anvil.microsoft.auth.login() print("You are logged in as: %s" % anvil.microsoft.auth.get_user_email())
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 Output Panel has printed the email address you logged in with:
Click on the button below to clone a finished version of this app into your account.
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.