88using System . Threading ;
99using System . Threading . Tasks ;
1010using Microsoft . Identity . Client . ApiConfig . Parameters ;
11+ using Microsoft . Identity . Client . Core ;
12+ using Microsoft . Identity . Client . Internal . Requests . Silent ;
1113using Microsoft . Identity . Client . OAuth2 ;
1214using Microsoft . Identity . Client . WsTrust ;
1315
@@ -20,6 +22,7 @@ internal class IntegratedWindowsAuthRequest : RequestBase
2022 {
2123 private readonly CommonNonInteractiveHandler _commonNonInteractiveHandler ;
2224 private readonly AcquireTokenByIntegratedWindowsAuthParameters _integratedWindowsAuthParameters ;
25+ private readonly Lazy < ISilentAuthRequestStrategy > _brokerStrategyLazy ;
2326
2427 public IntegratedWindowsAuthRequest (
2528 IServiceBundle serviceBundle ,
@@ -31,10 +34,29 @@ public IntegratedWindowsAuthRequest(
3134 _commonNonInteractiveHandler = new CommonNonInteractiveHandler (
3235 authenticationRequestParameters . RequestContext ,
3336 serviceBundle ) ;
37+
38+ var silentParameters = new AcquireTokenSilentParameters ( ) ;
39+ var silentRequest = new SilentRequest ( ServiceBundle , authenticationRequestParameters , silentParameters ) ;
40+ _brokerStrategyLazy = new Lazy < ISilentAuthRequestStrategy > ( ( ) => new BrokerSilentStrategy ( silentRequest ,
41+ serviceBundle ,
42+ authenticationRequestParameters ,
43+ silentParameters ,
44+ serviceBundle . PlatformProxy . CreateBroker (
45+ serviceBundle . Config , null ) ) ) ;
3446 }
3547
3648 protected override async Task < AuthenticationResult > ExecuteAsync ( CancellationToken cancellationToken )
3749 {
50+ bool isBrokerConfigured = AuthenticationRequestParameters . AppConfig . IsBrokerEnabled &&
51+ ServiceBundle . PlatformProxy . CanBrokerSupportSilentAuth ( ) ;
52+
53+ if ( isBrokerConfigured )
54+ {
55+ AuthenticationRequestParameters . RequestContext . Logger . Info ( "IWA called with broker. Routing to broker default user sign in" ) ;
56+ AuthenticationRequestParameters . Account = PublicClientApplication . OperatingSystemAccount ;
57+ return await _brokerStrategyLazy . Value . ExecuteAsync ( cancellationToken ) . ConfigureAwait ( false ) ;
58+ }
59+
3860 await ResolveAuthorityAsync ( ) . ConfigureAwait ( false ) ;
3961 await UpdateUsernameAsync ( ) . ConfigureAwait ( false ) ;
4062 var userAssertion = await FetchAssertionFromWsTrustAsync ( ) . ConfigureAwait ( false ) ;
0 commit comments