Skip to content

Commit

Permalink
fix merged options with azure region
Browse files Browse the repository at this point in the history
  • Loading branch information
jennyf19 committed Nov 18, 2021
1 parent e92ceab commit 7d7b7e2
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
2 changes: 2 additions & 0 deletions src/Microsoft.Identity.Web/MergedOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ public ConfidentialClientApplicationOptions ConfidentialClientApplicationOptions
public LogLevel LogLevel { get; set; }
public string? RedirectUri { get; set; }
public bool EnableCacheSynchronization { get; set; }
internal bool MergedWithCca { get; set; }

internal static void UpdateMergedOptionsFromMicrosoftIdentityOptions(MicrosoftIdentityOptions microsoftIdentityOptions, MergedOptions mergedOptions)
{
Expand Down Expand Up @@ -254,6 +255,7 @@ internal static void UpdateMergedOptionsFromMicrosoftIdentityOptions(MicrosoftId

internal static void UpdateMergedOptionsFromConfidentialClientApplicationOptions(ConfidentialClientApplicationOptions confidentialClientApplicationOptions, MergedOptions mergedOptions)
{
mergedOptions.MergedWithCca = true;
mergedOptions.AadAuthorityAudience = confidentialClientApplicationOptions.AadAuthorityAudience;
mergedOptions.AzureCloudInstance = confidentialClientApplicationOptions.AzureCloudInstance;
if (string.IsNullOrEmpty(mergedOptions.AzureRegion) && !string.IsNullOrEmpty(confidentialClientApplicationOptions.AzureRegion))
Expand Down
14 changes: 11 additions & 3 deletions src/Microsoft.Identity.Web/TokenAcquisition.cs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,14 @@ public TokenAcquisition(

internal MergedOptions GetOptions(string authenticationScheme)
{
return _mergedOptionsMonitor.Get(authenticationScheme);
var mergedOptions = _mergedOptionsMonitor.Get(authenticationScheme);
if (!mergedOptions.MergedWithCca)
{
var ccaOptionsMonitor = _serviceProvider.GetService<IOptionsMonitor<ConfidentialClientApplicationOptions>>();
ccaOptionsMonitor?.Get(authenticationScheme);
}

return mergedOptions;
}

/// <summary>
Expand Down Expand Up @@ -363,13 +370,14 @@ public Task<AuthenticationResult> GetAuthenticationResultForAppAsync(
}

authenticationScheme = GetEffectiveAuthenticationScheme(authenticationScheme);

MergedOptions mergedOptions = GetOptions(authenticationScheme);

// Case of an anonymous controller, no [Authorize] attribute will trigger the merge options
if (string.IsNullOrEmpty(mergedOptions.Instance))
{
var mergedOptionsMonitor = _serviceProvider.GetRequiredService<IOptionsMonitor<JwtBearerOptions>>();
mergedOptionsMonitor.Get(JwtBearerDefaults.AuthenticationScheme);
var mergedOptionsMonitor = _serviceProvider.GetService<IOptionsMonitor<JwtBearerOptions>>();
mergedOptionsMonitor?.Get(JwtBearerDefaults.AuthenticationScheme);
}

if (string.IsNullOrEmpty(tenant))
Expand Down

0 comments on commit 7d7b7e2

Please sign in to comment.