Skip to content

Commit

Permalink
Throw an ArgumentException if tenant is 'common' or 'organizations' f…
Browse files Browse the repository at this point in the history
…or acquire token for app scenarios (#795)

* Add support for tenant selection when using AppOnly Microsoft Graph.

* Add Common tenant to meta tenant identifiers and check for TenantId not to match when obtaining token via client_credentials flow.

Fixes #793

* Allow client_credentials to function with consumers endpoint.

* Explicitly provide tenantId from configuration if not specified when obtaining token via client_credentials. Streamline argument validation.
  • Loading branch information
hajekj authored Dec 2, 2020
1 parent 8fa27af commit d566dca
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/Microsoft.Identity.Web/TokenAcquisition.cs
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,8 @@ public TokenAcquisition(
private readonly ISet<string> _metaTenantIdentifiers = new HashSet<string>(
new[]
{
Constants.Common,
Constants.Organizations,
Constants.Consumers,
},
StringComparer.OrdinalIgnoreCase);

Expand Down Expand Up @@ -271,6 +271,11 @@ public async Task<string> GetAccessTokenForAppAsync(
throw new ArgumentException(IDWebErrorMessage.ClientCredentialScopeParameterShouldEndInDotDefault, nameof(scope));
}

if (string.IsNullOrEmpty(tenant))
{
tenant = _applicationOptions.TenantId ?? _microsoftIdentityOptions.TenantId;
}

if (!string.IsNullOrEmpty(tenant) && _metaTenantIdentifiers.Contains(tenant))
{
throw new ArgumentException(IDWebErrorMessage.ClientCredentialTenantShouldBeTenanted, nameof(tenant));
Expand Down

0 comments on commit d566dca

Please sign in to comment.