Skip to content

Commit

Permalink
Add more logs in getDeviceInfo flow due to an IcM (#1439)
Browse files Browse the repository at this point in the history
* Add more logs in getDeviceInfo flow due to an IcM

* Address Cr
  • Loading branch information
kaisong1990 committed Feb 4, 2022
1 parent e6e6afc commit 3749484
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
5 changes: 3 additions & 2 deletions MSAL/src/MSALPublicClientApplication.m
Expand Up @@ -1459,7 +1459,7 @@ - (void)signoutWithAccount:(nonnull MSALAccount *)account
- (void)getDeviceInformationWithParameters:(MSALParameters *)parameters
completionBlock:(MSALDeviceInformationCompletionBlock)completionBlock
{
MSID_LOG_WITH_CTX_PII(MSIDLogLevelInfo, nil, @"Querying device info");
MSID_LOG_WITH_CTX(MSIDLogLevelInfo, nil, @"Querying device info");

__auto_type block = ^(MSALDeviceInformation * _Nullable deviceInformation, NSError * _Nullable msidError)
{
Expand All @@ -1471,7 +1471,7 @@ - (void)getDeviceInformationWithParameters:(MSALParameters *)parameters
}
else
{
MSID_LOG_WITH_CTX_PII(MSIDLogLevelInfo, nil, @"Retrieved device info %@", deviceInformation);
MSID_LOG_WITH_CTX_PII(MSIDLogLevelInfo, nil, @"Retrieved device info %@", MSID_PII_LOG_MASKABLE(deviceInformation));
}

[MSALPublicClientApplication logOperation:@"getDeviceInformation" result:nil error:msalError context:nil];
Expand All @@ -1495,6 +1495,7 @@ - (void)getDeviceInformationWithParameters:(MSALParameters *)parameters

if (!requestParams)
{
MSID_LOG_WITH_CTX_PII(MSIDLogLevelError, nil, @"GetDeviceInfo: Error when creating requestParams: %@", requestParamsError);
block(nil, requestParamsError);
return;
}
Expand Down
14 changes: 11 additions & 3 deletions MSAL/src/instance/MSALDeviceInfoProvider.m
Expand Up @@ -53,12 +53,14 @@ - (void)deviceInfoWithRequestParameters:(MSIDRequestParameters *)requestParamete
{
[msalDeviceInfo addRegisteredDeviceMetadataInformation:deviceRegMetaDataInfo];
}


MSID_LOG_WITH_CTX_PII(MSIDLogLevelInfo, nil, @"GetDeviceInfo: Completing filling device info: %@, error: %@", MSID_PII_LOG_MASKABLE(msalDeviceInfo), MSID_PII_LOG_MASKABLE(error));
completionBlock(msalDeviceInfo, error);
};

if (![requestParameters shouldUseBroker])
{
MSID_LOG_WITH_CTX(MSIDLogLevelInfo, requestParameters, @"GetDeviceInfo: Should use broker decision: %i", NO);
NSError *error = MSIDCreateError(MSIDErrorDomain, MSIDErrorBrokerNotAvailable, @"Broker is not enabled for this operation. Please make sure you have enabled broker support for your application", nil, nil, nil, nil, nil, YES);
completionBlock(nil, error);
return;
Expand All @@ -69,7 +71,8 @@ - (void)deviceInfoWithRequestParameters:(MSIDRequestParameters *)requestParamete
{
canCallSSOExtension = [MSIDSSOExtensionGetDeviceInfoRequest canPerformRequest];
}


MSID_LOG_WITH_CTX(MSIDLogLevelInfo, requestParameters, @"GetDeviceInfo: Should call Sso Extension decision: %i", canCallSSOExtension);
if (!canCallSSOExtension)
{
MSID_LOG_WITH_CTX(MSIDLogLevelInfo, requestParameters, @"Broker is not present on this device. Defaulting to personal mode");
Expand All @@ -81,31 +84,36 @@ - (void)deviceInfoWithRequestParameters:(MSIDRequestParameters *)requestParamete
if (@available(iOS 13.0, macOS 10.15, *))
{
// We are here means canCallSSOExtension is TRUE
MSID_LOG_WITH_CTX(MSIDLogLevelVerbose, requestParameters, @"GetDeviceInfo: Creating Sso Extension request");
NSError *requestError;
MSIDSSOExtensionGetDeviceInfoRequest *ssoExtensionRequest = [[MSIDSSOExtensionGetDeviceInfoRequest alloc] initWithRequestParameters:requestParameters
error:&requestError];

if (!ssoExtensionRequest)
{
MSID_LOG_WITH_CTX_PII(MSIDLogLevelError, requestParameters, @"GetDeviceInfo: Get error when creating ssoExtensionRequest: %@", MSID_PII_LOG_MASKABLE(requestError));
completionBlock(nil, requestError);
return;
}

if (![self setCurrentSSOExtensionRequest:ssoExtensionRequest])
{
MSID_LOG_WITH_CTX(MSIDLogLevelError, requestParameters, @"GetDeviceInfo: Cannot start Sso Extension as another is in progress");
NSError *error = MSIDCreateError(MSIDErrorDomain, MSIDErrorInternal, @"Trying to start a get accounts request while one is already executing", nil, nil, nil, nil, nil, YES);
completionBlock(nil, error);
return;
}

MSID_LOG_WITH_CTX_PII(MSIDLogLevelInfo, requestParameters, @"GetDeviceInfo: Invoking Sso Extension with ssoExtensionRequest: %@", MSID_PII_LOG_MASKABLE(ssoExtensionRequest));
[ssoExtensionRequest executeRequestWithCompletion:^(MSIDDeviceInfo * _Nullable deviceInfo, NSError * _Nullable error)
{
MSID_LOG_WITH_CTX_PII(MSIDLogLevelInfo, requestParameters, @"GetDeviceInfo: Receiving results from Sso Extension with device info: %@, error: %@", MSID_PII_LOG_MASKABLE(deviceInfo), MSID_PII_LOG_MASKABLE(error));
[self copyAndClearCurrentSSOExtensionRequest];

if (!deviceInfo)
{
// We are returing registration details irrespective of failures due to SSO extension request as registration details must have for few clients
// Once we identify and fix the intermittent SSO extension issue then we should return either deviceInfo or error
MSID_LOG_WITH_CTX_PII(MSIDLogLevelError, nil, @"GetDeviceInfo: Error getting device info: %@", MSID_PII_LOG_MASKABLE(error));
fillDeviceInfoCompletionBlock(nil, error);
return;
}
Expand Down

0 comments on commit 3749484

Please sign in to comment.