You are currently viewing Using the Same Authentication Token for Multiple Domains in a Mobile App
Learn how to configure Azure Active Directory to use the same authentication token for multiple domains in a mobile app.

Using the Same Authentication Token for Multiple Domains in a Mobile App

Using the Same Authentication Token for Multiple Domains in a Mobile App

As a mobile app developer, you may come across a scenario where you have two or more domains that use the same authentication mechanism, such as 1.com and 2.com, both utilizing 365 login. In this case, you would want to ensure that the user can seamlessly switch between these domains without having to sign in again.

To achieve this, you can configure Azure Active Directory (AAD) to allow single authentication for multiple domains. Here’s how you can do it:

Step 1: Registering Domains under the Same Azure AD Tenant

First, you need to register both domains (1.com and 2.com) under the same Azure AD tenant. This will enable you to manage the authentication and authorization process for both domains through a single authentication provider.

Step 2: Configuring Azure AD Authentication

Once the domains are registered, you can configure the Azure AD authentication settings to allow single sign-on across multiple domains. This can be done through the Azure portal by following these steps:

  1. Go to the Azure portal and navigate to the Azure AD tenant where the domains are registered.
  2. Select the ‘Authentication’ tab under the ‘Manage’ section.
  3. In the ‘Authentication’ settings, enable the ‘Multiple Tokens per User’ option.
  4. Save the changes.

Step 3: Implementing Authentication in the Mobile App

Next, you need to implement the authentication mechanism in your mobile app. You can use the Microsoft Authentication Library (MSAL) for .NET to handle the authentication process. MSAL provides a simple and secure way to acquire tokens from Azure AD.

Here’s an example of using MSAL in C# to acquire an authentication token:

using Microsoft.Identity.Client;

// Create a public client application
IPublicClientApplication publicClientApp = PublicClientApplicationBuilder
    .Create(clientId)
    .WithAuthority(authority)
    .Build();

// Acquire an authentication token
AuthenticationResult authResult = await publicClientApp.AcquireTokenAsync(scopes);

// Use the authentication token
string accessToken = authResult.AccessToken;

Leave a Reply