102102#import " MSALSignoutParameters.h"
103103#import " MSALPublicClientApplication+SingleAccount.h"
104104#import " MSALDeviceInfoProvider.h"
105+ #import " MSIDCurrentRequestTelemetry.h"
105106
106107@interface MSALPublicClientApplication ()
107108{
@@ -750,8 +751,9 @@ - (void)acquireTokenSilentWithParameters:(MSALSilentTokenParameters *)parameters
750751 }
751752
752753 BOOL shouldValidate = _validateAuthority;
754+ BOOL isDeveloperKnownAuthority = [self shouldExcludeValidationForAuthority: requestAuthority];
753755
754- if (shouldValidate && [ self shouldExcludeValidationForAuthority: requestAuthority] )
756+ if (shouldValidate && isDeveloperKnownAuthority )
755757 {
756758 shouldValidate = NO ;
757759 }
@@ -776,6 +778,8 @@ - (void)acquireTokenSilentWithParameters:(MSALSilentTokenParameters *)parameters
776778 return ;
777779 }
778780
781+ requestAuthority.isDeveloperKnown = isDeveloperKnownAuthority;
782+
779783 NSError *msidError = nil ;
780784
781785 MSIDRequestType requestType = [self requestType ];
@@ -810,6 +814,10 @@ - (void)acquireTokenSilentWithParameters:(MSALSilentTokenParameters *)parameters
810814 msidParams.providedAuthority = providedAuthority;
811815 msidParams.instanceAware = self.internalConfig .multipleCloudsSupported ;
812816 msidParams.keychainAccessGroup = self.internalConfig .cacheConfig .keychainSharingGroup ;
817+ msidParams.currentRequestTelemetry = [MSIDCurrentRequestTelemetry new ];
818+ msidParams.currentRequestTelemetry .schemaVersion = 2 ;
819+ msidParams.currentRequestTelemetry .apiId = [msidParams.telemetryApiId integerValue ];
820+ msidParams.currentRequestTelemetry .forceRefresh = parameters.forceRefresh ;
813821
814822 MSID_LOG_WITH_CTX_PII (MSIDLogLevelInfo, msidParams,
815823 @" -[MSALPublicClientApplication acquireTokenSilentForScopes:%@ \n "
@@ -830,19 +838,15 @@ - (void)acquireTokenSilentWithParameters:(MSALSilentTokenParameters *)parameters
830838 parameters.claimsRequest );
831839
832840 // Return early if account is in signed out state
833- MSALAccountsProvider *accountsProvider = [[MSALAccountsProvider alloc ] initWithTokenCache: self .tokenCache
834- accountMetadataCache: self .accountMetadataCache
835- clientId: self .internalConfig.clientId
836- externalAccountProvider: self .externalAccountHandler];
837841 NSError *signInStateError;
838- MSIDAccountMetadataState signInState = [accountsProvider signInStateForHomeAccountId: msidParams.accountIdentifier.homeAccountId
839- context: msidParams
840- error: &signInStateError];
842+ MSIDAccountMetadataState signInState = [self accountStateForParameters: msidParams error: &signInStateError];
841843
842- if (signInStateError) {
844+ if (signInStateError)
845+ {
843846 block (nil , signInStateError, msidParams);
844847 return ;
845848 }
849+
846850 if (signInState == MSIDAccountMetadataStateSignedOut)
847851 {
848852 NSError *interactionError = MSIDCreateError (MSIDErrorDomain, MSIDErrorInteractionRequired, @" Account is signed out, user interaction is required." , nil , nil , nil , msidParams.correlationId , nil , YES );
@@ -888,6 +892,25 @@ - (void)acquireTokenSilentWithParameters:(MSALSilentTokenParameters *)parameters
888892 }];
889893}
890894
895+ - (MSIDAccountMetadataState)accountStateForParameters : (MSIDRequestParameters *)msidParams error : (NSError **)signInStateError
896+ {
897+ if (!msidParams.accountIdentifier .homeAccountId )
898+ {
899+ return MSIDAccountMetadataStateUnknown;
900+ }
901+
902+ MSALAccountsProvider *accountsProvider = [[MSALAccountsProvider alloc ] initWithTokenCache: self .tokenCache
903+ accountMetadataCache: self .accountMetadataCache
904+ clientId: self .internalConfig.clientId
905+ externalAccountProvider: self .externalAccountHandler];
906+
907+ MSIDAccountMetadataState signInState = [accountsProvider signInStateForHomeAccountId: msidParams.accountIdentifier.homeAccountId
908+ context: msidParams
909+ error: signInStateError];
910+
911+ return signInState;
912+ }
913+
891914- (void )acquireTokenSilentForScopes : (NSArray <NSString *> *)scopes
892915 account : (MSALAccount *)account
893916 completionBlock : (MSALCompletionBlock)completionBlock
@@ -1014,6 +1037,8 @@ - (void)acquireTokenWithParameters:(MSALInteractiveTokenParameters *)parameters
10141037 return ;
10151038 }
10161039
1040+ requestAuthority.isDeveloperKnown = [self shouldExcludeValidationForAuthority: requestAuthority];
1041+
10171042 NSError *msidError = nil ;
10181043
10191044 MSIDBrokerInvocationOptions *brokerOptions = nil ;
@@ -1095,6 +1120,17 @@ - (void)acquireTokenWithParameters:(MSALInteractiveTokenParameters *)parameters
10951120 msidParams.claimsRequest = parameters.claimsRequest .msidClaimsRequest ;
10961121 msidParams.providedAuthority = requestAuthority;
10971122 msidParams.shouldValidateResultAccount = YES ;
1123+ msidParams.currentRequestTelemetry = [MSIDCurrentRequestTelemetry new ];
1124+ msidParams.currentRequestTelemetry .schemaVersion = 2 ;
1125+ msidParams.currentRequestTelemetry .apiId = [msidParams.telemetryApiId integerValue ];
1126+ msidParams.currentRequestTelemetry .forceRefresh = NO ;
1127+
1128+ MSIDAccountMetadataState signInState = [self accountStateForParameters: msidParams error: nil ];
1129+
1130+ if (signInState == MSIDAccountMetadataStateSignedOut && msidParams.promptType != MSIDPromptTypeConsent)
1131+ {
1132+ msidParams.promptType = MSIDPromptTypeLogin;
1133+ }
10981134
10991135 MSID_LOG_WITH_CTX_PII (MSIDLogLevelInfo, msidParams,
11001136 @" -[MSALPublicClientApplication acquireTokenWithParameters:%@ \n "
@@ -1395,9 +1431,6 @@ - (BOOL)shouldExcludeValidationForAuthority:(MSIDAuthority *)authority
13951431 for (MSALAuthority *knownAuthority in self.internalConfig .knownAuthorities )
13961432 {
13971433 if ([authority isKindOfClass: knownAuthority.msidAuthority.class]
1398- // Treat AAD authorities differently, since they should always succeed validation
1399- // Therefore, even if they are added to known authorities, still do validation
1400- && ![authority isKindOfClass: [MSIDAADAuthority class ]]
14011434 && [knownAuthority.url isEqual: authority.url])
14021435 {
14031436 return YES ;
@@ -1419,11 +1452,8 @@ + (NSOrderedSet *)defaultOIDCScopes
14191452
14201453- (MSIDRequestType)requestType
14211454{
1422- MSIDRequestType requestType = MSIDRequestLocalType;
1423-
1424- #if TARGET_OS_IPHONE
1425- requestType = MSIDRequestBrokeredType;
1426-
1455+ MSIDRequestType requestType = MSIDRequestBrokeredType;
1456+
14271457 if (MSALGlobalConfig.brokerAvailability == MSALBrokeredAvailabilityNone)
14281458 {
14291459 requestType = MSIDRequestLocalType;
@@ -1432,7 +1462,6 @@ - (MSIDRequestType)requestType
14321462 {
14331463 requestType = MSIDRequestLocalType;
14341464 }
1435- #endif
14361465
14371466 return requestType;
14381467}
0 commit comments