Skip to content

Commit

Permalink
Add Common tenant to meta tenant identifiers and check for TenantId n…
Browse files Browse the repository at this point in the history
…ot to match when obtaining token via client_credentials flow.

Fixes AzureAD#793
  • Loading branch information
hajekj committed Dec 1, 2020
1 parent 3b3698f commit 8b61888
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/Microsoft.Identity.Web/TokenAcquisition.cs
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ public TokenAcquisition(
private readonly ISet<string> _metaTenantIdentifiers = new HashSet<string>(
new[]
{
Constants.Common,
Constants.Organizations,
Constants.Consumers,
},
Expand Down Expand Up @@ -276,6 +277,11 @@ public async Task<string> GetAccessTokenForAppAsync(
throw new ArgumentException(IDWebErrorMessage.ClientCredentialTenantShouldBeTenanted, nameof(tenant));
}

if (!string.IsNullOrEmpty(_microsoftIdentityOptions.TenantId) && _metaTenantIdentifiers.Contains(_microsoftIdentityOptions.TenantId))
{
throw new ArgumentException(IDWebErrorMessage.ClientCredentialTenantShouldBeTenanted, nameof(_microsoftIdentityOptions.TenantId));
}

// Use MSAL to get the right token to call the API
_application = await GetOrBuildConfidentialClientApplicationAsync().ConfigureAwait(false);
string authority = CreateAuthorityBasedOnTenantIfProvided(_application, tenant);
Expand Down

0 comments on commit 8b61888

Please sign in to comment.