Skip to content

Authority Override

Peter M edited this page Aug 6, 2022 · 6 revisions

In many scenarios, such as client credential flow in multi-tenant apps, it is useful to specify the Azure AD tenant in the request builder instead of the application builder. WithTenantId is the recommended API to use in this scenario, which accepts the tenant ID string. WithTenantIdFromAuthority is another similar method that is available in MSAL 4.46.0+. You can also use WithAuthority, however, the authority in the application and the request builders must always be for the same cloud, i.e. the host of the authority URL must not be different.

var app =  ConfidentialClientApplicationBuilder
                .Create(PublicCloudConfidentialClientID)
                .WithAuthority("https://login.microsoftonline.com/common", true)
                .Build();

var result = await app.AcquireTokenForClient(scopes)
                      .WithTenantId("123456-1234-2345-1234561234");
// OR
var result = await app.AcquireTokenForClient(scopes)
                      .WithTenantIdFromAuthority("https://login.microsoftonline.com/123456-1234-2345-1234561234");

A public or confidential client application instance can only be associated with one cloud. If your client application needs to handle multiple clouds at the same time, create a separate public of confidential client instance for each of them.

Getting started with MSAL.NET

Acquiring tokens

Web Apps / Web APIs / daemon apps

Desktop/Mobile apps

Advanced topics

FAQ

Other resources

Clone this wiki locally