@@ -77,42 +77,6 @@ public ConfidentialClientApplicationOptions ConfidentialClientApplicationOptions
7777 */
7878 internal bool PreserveAuthority { get ; set ; }
7979
80- // Latch: once true, never reverts to false. Distinguishes user-configured Authority
81- // from the synthetic value computed by MicrosoftEntraApplicationOptions.Authority getter.
82- private bool _authorityExplicitlyConfigured ;
83- internal bool AuthorityExplicitlyConfigured
84- {
85- get => _authorityExplicitlyConfigured ;
86- set { if ( value ) _authorityExplicitlyConfigured = true ; }
87- }
88-
89- // Latch: once true, never reverts to false. Distinguishes user-configured
90- // Instance/TenantId from values derived by ParseAuthorityIfNecessary.
91- private bool _instanceOrTenantIdExplicitlyConfigured ;
92- internal bool InstanceOrTenantIdExplicitlyConfigured
93- {
94- get => _instanceOrTenantIdExplicitlyConfigured ;
95- set { if ( value ) _instanceOrTenantIdExplicitlyConfigured = true ; }
96- }
97-
98- // Set after ParseAuthorityIfNecessary runs; makes subsequent calls no-op.
99- private bool _authorityParsed ;
100-
101- // Throws if the user explicitly configured BOTH Authority AND Instance/TenantId.
102- internal void ThrowIfAuthorityConflict ( )
103- {
104- if ( AuthorityExplicitlyConfigured &&
105- InstanceOrTenantIdExplicitlyConfigured &&
106- ! string . IsNullOrEmpty ( Authority ) &&
107- ( ! string . IsNullOrEmpty ( Instance ) || ! string . IsNullOrEmpty ( TenantId ) ) )
108- {
109- throw new InvalidOperationException (
110- $ "[MsIdWeb] Both 'Authority' ('{ Authority } ') and 'Instance'/'TenantId' " +
111- $ "('{ Instance ?? string . Empty } ', '{ TenantId ?? string . Empty } ') are configured. " +
112- "These settings conflict. Remove either 'Authority' or 'Instance'/'TenantId' from the configuration." ) ;
113- }
114- }
115-
11680 /// <summary>
11781 /// Id Web will modify the instance so that it can be used by MSAL.
11882 /// This modifies this property so that the original value is not changed.
@@ -317,7 +281,6 @@ internal static void UpdateMergedOptionsFromMicrosoftIdentityOptions(MicrosoftId
317281 if ( string . IsNullOrEmpty ( mergedOptions . Instance ) && ! string . IsNullOrEmpty ( microsoftIdentityOptions . Instance ) )
318282 {
319283 mergedOptions . Instance = microsoftIdentityOptions . Instance ;
320- mergedOptions . InstanceOrTenantIdExplicitlyConfigured = true ;
321284 }
322285
323286 if ( microsoftIdentityOptions . ResetPasswordPath != Constants . ResetPasswordPath )
@@ -335,7 +298,6 @@ internal static void UpdateMergedOptionsFromMicrosoftIdentityOptions(MicrosoftId
335298 if ( string . IsNullOrEmpty ( mergedOptions . Authority ) && ! string . IsNullOrEmpty ( microsoftIdentityOptions . Authority ) )
336299 {
337300 mergedOptions . Authority = microsoftIdentityOptions . Authority ;
338- mergedOptions . AuthorityExplicitlyConfigured = true ;
339301 }
340302
341303 mergedOptions . ClientCredentials ??= microsoftIdentityOptions . ClientCredentials ;
@@ -377,7 +339,6 @@ internal static void UpdateMergedOptionsFromMicrosoftIdentityOptions(MicrosoftId
377339 if ( string . IsNullOrEmpty ( mergedOptions . TenantId ) && ! string . IsNullOrEmpty ( microsoftIdentityOptions . TenantId ) )
378340 {
379341 mergedOptions . TenantId = microsoftIdentityOptions . TenantId ;
380- mergedOptions . InstanceOrTenantIdExplicitlyConfigured = true ;
381342 }
382343
383344 mergedOptions . TokenDecryptionCertificates ??= microsoftIdentityOptions . TokenDecryptionCertificates ;
@@ -432,7 +393,6 @@ internal static void UpdateMergedOptionsFromConfidentialClientApplicationOptions
432393 if ( string . IsNullOrEmpty ( mergedOptions . Instance ) && ! string . IsNullOrEmpty ( confidentialClientApplicationOptions . Instance ) )
433394 {
434395 mergedOptions . Instance = confidentialClientApplicationOptions . Instance ;
435- mergedOptions . InstanceOrTenantIdExplicitlyConfigured = true ;
436396 }
437397
438398 mergedOptions . IsDefaultPlatformLoggingEnabled |= confidentialClientApplicationOptions . IsDefaultPlatformLoggingEnabled ;
@@ -447,7 +407,6 @@ internal static void UpdateMergedOptionsFromConfidentialClientApplicationOptions
447407 if ( string . IsNullOrEmpty ( mergedOptions . TenantId ) && ! string . IsNullOrEmpty ( confidentialClientApplicationOptions . TenantId ) )
448408 {
449409 mergedOptions . TenantId = confidentialClientApplicationOptions . TenantId ;
450- mergedOptions . InstanceOrTenantIdExplicitlyConfigured = true ;
451410 }
452411
453412 mergedOptions . _confidentialClientApplicationOptions = null ;
@@ -514,20 +473,22 @@ internal static void UpdateConfidentialClientApplicationOptionsFromMergedOptions
514473 */
515474 internal static void ParseAuthorityIfNecessary ( MergedOptions mergedOptions , IdWebLogger . ILogger ? logger = null )
516475 {
517- if ( mergedOptions . _authorityParsed )
518- {
519- return ;
520- }
521-
522- if ( ! string . IsNullOrEmpty ( mergedOptions . Authority ) &&
523- ( ! string . IsNullOrEmpty ( mergedOptions . Instance ) || ! string . IsNullOrEmpty ( mergedOptions . TenantId ) ) )
524- {
525- mergedOptions . ThrowIfAuthorityConflict ( ) ;
526-
527- // Authority was synthesized (e.g. by MicrosoftEntraApplicationOptions computed getter) -- not a real conflict.
528- mergedOptions . _authorityParsed = true ;
529- return ;
530- }
476+ // Check if Authority is configured but being ignored due to Instance/TenantId taking precedence
477+ if ( ! string . IsNullOrEmpty ( mergedOptions . Authority ) &&
478+ ( ! string . IsNullOrEmpty ( mergedOptions . Instance ) || ! string . IsNullOrEmpty ( mergedOptions . TenantId ) ) )
479+ {
480+ // Log warning that Authority is being ignored
481+ if ( logger != null )
482+ {
483+ MergedOptionsLogging . AuthorityIgnored (
484+ logger ,
485+ mergedOptions . Authority ! ,
486+ mergedOptions . Instance ?? string . Empty ,
487+ mergedOptions . TenantId ?? string . Empty ) ;
488+ }
489+ // Authority is ignored; Instance and TenantId take precedence
490+ return ;
491+ }
531492
532493 if ( string . IsNullOrEmpty ( mergedOptions . TenantId ) && string . IsNullOrEmpty ( mergedOptions . Instance ) && ! string . IsNullOrEmpty ( mergedOptions . Authority ) )
533494 {
@@ -582,8 +543,6 @@ internal static void ParseAuthorityIfNecessary(MergedOptions mergedOptions, IdWe
582543 mergedOptions . Instance = mergedOptions . PreserveAuthority ? mergedOptions . Authority ! : authoritySpan . Slice ( 0 , indexTenant ) . ToString ( ) ;
583544 mergedOptions . TenantId = mergedOptions . PreserveAuthority ? null : authoritySpan . Slice ( indexTenant + 1 , indexEndOfTenant - indexTenant - 1 ) . ToString ( ) ;
584545 }
585-
586- mergedOptions . _authorityParsed = true ;
587546 }
588547 }
589548
@@ -593,7 +552,6 @@ internal static void UpdateMergedOptionsFromJwtBearerOptions(JwtBearerOptions jw
593552 if ( string . IsNullOrEmpty ( mergedOptions . Authority ) && ! string . IsNullOrEmpty ( jwtBearerOptions . Authority ) )
594553 {
595554 mergedOptions . Authority = jwtBearerOptions . Authority ;
596- mergedOptions . AuthorityExplicitlyConfigured = true ;
597555 }
598556 }
599557#endif
0 commit comments