Anvil has a built-in integration with Microsoft’s Azure Active Directory. This means you can allow users to sign in to their Microsoft accounts from your app. This includes Skype and Office 365 accounts. If users are already logged in to their Microsoft account, they can log in to your app simply by clicking a button.
To display a login dialog, enable the Microsoft API Service and run this line of Python on the client side:
The resulting login dialog looks like this:
If the user’s browser is not logged in to their Microsoft account, they will be presented with the Microsoft Single Sign On dialog in another browser window.
If the user’s browser is already logged in to Microsoft’s Single Sign On, clicking on the Log In box will log them in without requiring them to enter their password. This might be the case if they are logged in to the Azure Portal in another tab, for example.
If the ‘Cancel’ button is clicked, the
None. You can use this to
restrict part or all of your app to logged-in users.
Once the user has logged in, you can get the email address they are logged in with using:
If you’re already using the Users Service, it is not necessary to enable the Microsoft API Service
anvil.microsoft.auth.login(). You can enable Microsoft login from the standard Users Service login dialog
by checking the ‘Microsoft (Azure AD/Office 365)’ box:
With this box checked, the Users Service login dialog will show a ‘Login with Microsoft’ option:
Users that log in this way will be added to the
Users Data Table just like users that signed up using any other
Users Service method.
You can restrict access to only users in your own 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 Azure APIs for more details.