Connect Your Native App to Microsoft Azure Active Directory Using Resource Owner Flow

In addition to the WS-Federation and OpenID Connect flows, it's also possible to use the Resource Owner flow with Azure AD. This flow allows you to capture and validate a user's credentials (email and password) instead of showing the Azure AD login page. For security and Single Sign-on (SSO) reasons, this is not the recommended approach; still, Resource Owner flow can be useful in Native mobile scenarios or to batch-process authentication with Azure AD.

This configuration requires two applications: a Web Application and/or Web API and a Native Client Application. From Azure AD's point of view, users will be authenticated using the Native Client Application to gain access to the Web Application and/or Web API.

Overview Diagram of Azure AD Apps using Resource Owner flow

Prerequisites

Before beginning:

Steps

To connect your application using Resource Owner flow, you must:

  1. Set up your applications in the Microsoft Azure portal.
  2. Create an enterprise connection in Auth0.
  3. Enable the enterprise connection for your Auth0 Application.
  4. Test the connection.

Microsoft Azure Account

Before proceeding, you will need a valid Microsoft Azure account and must have your own Microsoft Azure AD directory for which you are a Global administrator.

If you don't have a Microsoft Azure account, you can sign up for free; then, if necessary, set up an Azure AD directory by following Microsoft's Quickstart: Create a new tenant in Azure Active Directory - Create a new tenant for your organization.

Alternatively, if you have an Office 365 account, you can use the account's Azure AD instance instead of creating a new one. To access your Office 365 account's Azure AD instance:

  1. Sign in to Office 365, and navigate to the Office 365 Admin Center.
  2. Open the Admin centers menu drawer located in the left menu, and click on Azure AD.

Set up your applications in the Microsoft Azure portal

Before proceeding, you must have already set up your own Microsoft Azure AD directory for which you are a Global administrator. To learn how, follow Microsoft's Quickstart: Create a new tenant in Azure Active Directory - Create a new tenant for your organization.

Register a new web application

To learn how to register your application with Azure AD, follow Microsoft's Quickstart: Register an application with the Microsoft identity platform doc.

If you have more than one Azure AD directory, make sure you are in the correct directory when you register your app.

While setting up your app, make sure you use the following settings:

  • If you want to allow users from external organizations (like other Azure AD directories), then when asked to choose Supported account types, choose the appropriate multitenant option. Multitenant options include the following: Accounts in any organizational directory (Any Azure AD directory - Multitenant).
  • When asked to set a Redirect URI, make sure Web is selected and enter your callback URL: https://YOUR_DOMAIN/login/callback.

Find your Auth0 domain name for redirects

If your Auth0 domain name is not shown above and you are not using our custom domains feature, your domain name is your tenant name, your regional subdomain (unless your tenant is in the US region and was created before June 2020), plus.auth0.com. For example, if your tenant name were exampleco-enterprises, your Auth0 domain name would be exampleco-enterprises.us.auth0.com and your redirect URI would be https://exampleco-enterprises.us.auth0.com/login/callback. (If your tenant is in the US and was created before June 2020, then your domain name would be https://exampleco-enterprises.auth0.com.)

If you are using custom domains, your redirect URI will have the following format: https://<YOUR CUSTOM DOMAIN>/login/callback.

During this process, Microsoft will generate an Application (client) ID for your application; you can find this on the app's Overview screen. Make note of this value.

Configure your web application to expose an API

To learn how to configure your Web application to expose an API with Azure AD, follow Microsoft's Quickstart: Configure an application to expose web APIs.

While configuring your app, make sure you use the following settings:

  • When asked to set a Scope name, enter API.Access.

During this process, Microsoft will generate an Application ID URI. Make note of this value.

Register a new native application

Again, follow Microsoft's Quickstart: Register an application with the Microsoft identity platform doc.

If you have more than one Azure AD directory, make sure you are in the correct directory when you register your app.

While setting up your app, make sure you use the following settings:

  • If you want to allow users from external organizations (like other Azure AD directories), then when asked to choose Supported account types, choose the appropriate multitenant option. Multitenant options include the following: Accounts in any organizational directory (Any Azure AD directory - Multitenant).
  • When asked to set a Redirect URI, make sure Public client/native (mobile & desktop) is selected and enter your callback URL. Your callback URL format will vary depending on your platform. For details about the format for your platform, see our Native Quickstarts.

During this process, Microsoft will generate an Application (client) ID for your application; you can find this on the app's Overview screen. Make note of this value.

Create a client secret for your native application

To learn how to create a client secret, follow Microsoft's Quickstart: Configure a client application to access web APIs - Add Credentials to your web application. You want to generate a Client secret. Once generated, make note of this value.

If you configure an expiring secret, make sure to record the expiration date; you will need to renew the key before that day to avoid a service interruption.

Add permissions for your native application

To learn how to add permissions for your Native application, follow Microsoft's Quickstart: Configure a client application to access web APIs - Add permissions to access web APIs. You want to configure permissions for the Microsoft Graph API and for the Web application you configured to expose an API.

While setting up your permissions, make sure you use the following settings for Microsoft Graph API:

  • When asked for a permission type, choose Delegated permissions. Under User, select User.Read so your app can sign in users and read the signed-in user's profile. Under Directory, select Directory.Read.All so your app can read directory data on the signed-in user's behalf.

For your Web app that you configured to expose an API, make sure you use the following settings:

  • When asked for a permission type, choose Delegated permissions. Under API, select API.Access so your app can access your API on the user's behalf.

Configure the connection in Auth0

After creating both applications in Azure AD, you can configure the Auth0 connection.

  1. Navigate to the Auth0 Dashboard > Authentication > Enterprise, locate Microsoft Azure AD, and click its +.

Create Connection Type

  1. Enter details for your connection, and select Create:
Field Description
Connection name Logical identifier for your connection; it must be unique for your tenant. Once set, this name can't be changed.
Microsoft Azure AD Domain Your Azure AD domain name. You can find this on your Azure AD directory's overview page in the Microsoft Azure portal.
Client ID Unique identifier for your registered Azure AD application. Enter the saved value of the Application (client) ID for the Native application you registered in Azure AD.
Client Secret String used to gain access to your registered Azure AD application. Enter the saved value of the Client secret for the Native app you registered in Azure AD.
Use common endpoint (optional) When enabled, your application will dynamically accept users from new directories. Typically enabled if you selected a multitenant option for Supported account types for the application you registered in Azure AD. When enabled, Auth0 will redirect users to Azure's common login endpoint, and Azure will perform Home Realm Discovery based on the domain of the user's email address.
Identity API API used by Auth0 to interact with Azure AD endpoints. Learn about the differences in behavior in Microsoft's Why update to Microsoft identity platform (v2.0) doc. Select Azure Active Directory (v1), and for App ID URI, enter the saved value of the Application ID URI that was created when you configured your Web application to expose an API.
Attributes Basic attributes for the signed-in user that your app can access. Indicates how much information you want stored in the Auth0 User Profile.
Extended Attributes (optional) Extended attributes for the signed-in user that your app can access.
Auth0 APIs (optional) When selected, indicates that you require the ability to make calls to the Azure AD Users API.
Sync user profile attributes at each login When enabled, Auth0 automatically syncs user profile data with each user login, thereby ensuring that changes made in the connection source are automatically updated in Auth0.
Email Verification Choose how Auth0 sets the email_verified field in the user profile. To learn more, see Email Verification for Azure AD and ADFS.

Configure Microsoft Azure AD Settings

Enable the enterprise connection for your Auth0 application

To use your new Azure AD enterprise connection, you must first enable the connection for your Auth0 Applications.

Test the connection

Now you're ready to test your connection.

Group Memberships and Advanced Profile Information

In this native flow, Auth0 will receive an Access Token from Azure AD which has been issued for your Azure AD Web application. As a result, features like loading group memberships and advanced profile information will no longer work because the Access Token received by Azure AD can no longer be used to query the Azure AD Graph API for this additional information.

However, if you depend on group memberships and advanced profile information, you can change your configuration to accommodate your needs.

  1. Configure your Native application with additional permissions for the Microsoft Graph API:

    • When asked for a permission type, choose Delegated permissions. Under Directory, select Directory.AccessAsUser.All, so your app can access the directory as the signed-in user.
  2. In Auth0, modify your Azure AD enterprise connection as follows, then Save Changes:

    • In Identity API, select Azure Active Directory (v1), and for App ID URI, enter the URI of the Azure AD Graph API:
https://graph.windows.net