From 0e39cc2b4372be491cdbb73a515f343e113ad7ae Mon Sep 17 00:00:00 2001 From: YONG ZENG Date: Thu, 28 Jul 2016 23:39:18 -0700 Subject: [PATCH 01/92] Apply telemetry interface to existing code to generate useful events --- ADAL/ADAL.xcodeproj/project.pbxproj | 50 ++++++++++ ADAL/src/ADAuthenticationParameters.m | 2 +- ADAL/src/ADInstanceDiscovery.h | 2 + ADAL/src/ADInstanceDiscovery.m | 7 +- ADAL/src/cache/ADTokenCacheAccessor.h | 7 +- ADAL/src/cache/ADTokenCacheAccessor.m | 53 ++++++++-- .../src/request/ADAcquireTokenSilentHandler.h | 2 + .../src/request/ADAcquireTokenSilentHandler.m | 19 +++- .../ADAuthenticationRequest+AcquireToken.m | 59 +++++++++-- .../request/ADAuthenticationRequest+Broker.m | 11 ++- .../ADAuthenticationRequest+WebRequest.m | 31 +++++- ADAL/src/request/ADAuthenticationRequest.h | 2 + ADAL/src/request/ADAuthenticationRequest.m | 14 +++ ADAL/src/request/ADWebAuthRequest.m | 3 +- ADAL/src/request/ADWebRequest.h | 5 +- ADAL/src/request/ADWebRequest.m | 35 +++++++ ADAL/src/telemetry/ADAPIEvent.h | 41 ++++++++ ADAL/src/telemetry/ADAPIEvent.m | 98 +++++++++++++++++++ ADAL/src/telemetry/ADBrokerEvent.h | 30 ++++++ ADAL/src/telemetry/ADBrokerEvent.m | 33 +++++++ ADAL/src/telemetry/ADCacheEvent.h | 28 ++++++ ADAL/src/telemetry/ADCacheEvent.m | 28 ++++++ ADAL/src/telemetry/ADDefaultEvent.m | 49 ++++++++-- ADAL/src/telemetry/ADHttpEvent.h | 35 +++++++ ADAL/src/telemetry/ADHttpEvent.m | 74 ++++++++++++++ ADAL/src/telemetry/ADUIEvent.h | 30 ++++++ ADAL/src/telemetry/ADUIEvent.m | 33 +++++++ ADAL/tests/ADInstanceDiscoveryTests.m | 4 + ADAL/tests/ADTelemetryTests.m | 7 +- 29 files changed, 751 insertions(+), 41 deletions(-) create mode 100644 ADAL/src/telemetry/ADAPIEvent.h create mode 100644 ADAL/src/telemetry/ADAPIEvent.m create mode 100644 ADAL/src/telemetry/ADBrokerEvent.h create mode 100644 ADAL/src/telemetry/ADBrokerEvent.m create mode 100644 ADAL/src/telemetry/ADCacheEvent.h create mode 100644 ADAL/src/telemetry/ADCacheEvent.m create mode 100644 ADAL/src/telemetry/ADHttpEvent.h create mode 100644 ADAL/src/telemetry/ADHttpEvent.m create mode 100644 ADAL/src/telemetry/ADUIEvent.h create mode 100644 ADAL/src/telemetry/ADUIEvent.m diff --git a/ADAL/ADAL.xcodeproj/project.pbxproj b/ADAL/ADAL.xcodeproj/project.pbxproj index 287f492a5..0c85c1ee6 100755 --- a/ADAL/ADAL.xcodeproj/project.pbxproj +++ b/ADAL/ADAL.xcodeproj/project.pbxproj @@ -40,6 +40,21 @@ 600401C01D3868B20020EAAB /* ADAggregatedDispatcher.m in Sources */ = {isa = PBXBuildFile; fileRef = 600401B51D37658C0020EAAB /* ADAggregatedDispatcher.m */; }; 600401C21D39A18E0020EAAB /* ADDefaultDispatcher.h in Headers */ = {isa = PBXBuildFile; fileRef = 600401C11D39A18E0020EAAB /* ADDefaultDispatcher.h */; }; 600401C41D3D58D50020EAAB /* ADAggregatedDispatcher.h in Headers */ = {isa = PBXBuildFile; fileRef = 600401C31D3D58D50020EAAB /* ADAggregatedDispatcher.h */; }; + 6010EDE41D47B1AC00B62072 /* ADAPIEvent.h in Headers */ = {isa = PBXBuildFile; fileRef = 6010EDE31D47B1AC00B62072 /* ADAPIEvent.h */; }; + 6010EDE61D47B21600B62072 /* ADAPIEvent.m in Sources */ = {isa = PBXBuildFile; fileRef = 6010EDE51D47B21600B62072 /* ADAPIEvent.m */; }; + 6010EDE71D47B21600B62072 /* ADAPIEvent.m in Sources */ = {isa = PBXBuildFile; fileRef = 6010EDE51D47B21600B62072 /* ADAPIEvent.m */; }; + 6010EDE91D47B26300B62072 /* ADUIEvent.h in Headers */ = {isa = PBXBuildFile; fileRef = 6010EDE81D47B26300B62072 /* ADUIEvent.h */; }; + 6010EDEB1D47B27400B62072 /* ADUIEvent.m in Sources */ = {isa = PBXBuildFile; fileRef = 6010EDEA1D47B27400B62072 /* ADUIEvent.m */; }; + 6010EDEC1D47B27400B62072 /* ADUIEvent.m in Sources */ = {isa = PBXBuildFile; fileRef = 6010EDEA1D47B27400B62072 /* ADUIEvent.m */; }; + 6010EDEE1D47B29500B62072 /* ADHttpEvent.h in Headers */ = {isa = PBXBuildFile; fileRef = 6010EDED1D47B29500B62072 /* ADHttpEvent.h */; }; + 6010EDF01D47B2A600B62072 /* ADHttpEvent.m in Sources */ = {isa = PBXBuildFile; fileRef = 6010EDEF1D47B2A600B62072 /* ADHttpEvent.m */; }; + 6010EDF11D47B2A600B62072 /* ADHttpEvent.m in Sources */ = {isa = PBXBuildFile; fileRef = 6010EDEF1D47B2A600B62072 /* ADHttpEvent.m */; }; + 6010EDF31D47B2BD00B62072 /* ADCacheEvent.h in Headers */ = {isa = PBXBuildFile; fileRef = 6010EDF21D47B2BD00B62072 /* ADCacheEvent.h */; }; + 6010EDF51D47B2CE00B62072 /* ADCacheEvent.m in Sources */ = {isa = PBXBuildFile; fileRef = 6010EDF41D47B2CE00B62072 /* ADCacheEvent.m */; }; + 6010EDF61D47B2CE00B62072 /* ADCacheEvent.m in Sources */ = {isa = PBXBuildFile; fileRef = 6010EDF41D47B2CE00B62072 /* ADCacheEvent.m */; }; + 6010EDF81D47B2E300B62072 /* ADBrokerEvent.h in Headers */ = {isa = PBXBuildFile; fileRef = 6010EDF71D47B2E300B62072 /* ADBrokerEvent.h */; }; + 6010EDFA1D47B2F300B62072 /* ADBrokerEvent.m in Sources */ = {isa = PBXBuildFile; fileRef = 6010EDF91D47B2F300B62072 /* ADBrokerEvent.m */; }; + 6010EDFB1D47B2F300B62072 /* ADBrokerEvent.m in Sources */ = {isa = PBXBuildFile; fileRef = 6010EDF91D47B2F300B62072 /* ADBrokerEvent.m */; }; 601BEE311C6DAA86004AA8C1 /* ADTestAuthenticationViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 601BEE301C6DAA86004AA8C1 /* ADTestAuthenticationViewController.m */; }; 601BEE321C6DAA86004AA8C1 /* ADTestAuthenticationViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 601BEE301C6DAA86004AA8C1 /* ADTestAuthenticationViewController.m */; }; 601BEE341C6DCB0B004AA8C1 /* ADWebAuthControllerTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 601BEE331C6DCB0B004AA8C1 /* ADWebAuthControllerTests.m */; }; @@ -433,6 +448,16 @@ 600401BC1D377E9F0020EAAB /* ADDefaultDispatcher.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ADDefaultDispatcher.m; sourceTree = ""; }; 600401C11D39A18E0020EAAB /* ADDefaultDispatcher.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ADDefaultDispatcher.h; sourceTree = ""; }; 600401C31D3D58D50020EAAB /* ADAggregatedDispatcher.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ADAggregatedDispatcher.h; sourceTree = ""; }; + 6010EDE31D47B1AC00B62072 /* ADAPIEvent.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ADAPIEvent.h; sourceTree = ""; }; + 6010EDE51D47B21600B62072 /* ADAPIEvent.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ADAPIEvent.m; sourceTree = ""; }; + 6010EDE81D47B26300B62072 /* ADUIEvent.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ADUIEvent.h; sourceTree = ""; }; + 6010EDEA1D47B27400B62072 /* ADUIEvent.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ADUIEvent.m; sourceTree = ""; }; + 6010EDED1D47B29500B62072 /* ADHttpEvent.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ADHttpEvent.h; sourceTree = ""; }; + 6010EDEF1D47B2A600B62072 /* ADHttpEvent.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ADHttpEvent.m; sourceTree = ""; }; + 6010EDF21D47B2BD00B62072 /* ADCacheEvent.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ADCacheEvent.h; sourceTree = ""; }; + 6010EDF41D47B2CE00B62072 /* ADCacheEvent.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ADCacheEvent.m; sourceTree = ""; }; + 6010EDF71D47B2E300B62072 /* ADBrokerEvent.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ADBrokerEvent.h; sourceTree = ""; }; + 6010EDF91D47B2F300B62072 /* ADBrokerEvent.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ADBrokerEvent.m; sourceTree = ""; }; 601BEE2F1C6D9CCE004AA8C1 /* ADTestAuthenticationViewController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ADTestAuthenticationViewController.h; sourceTree = ""; }; 601BEE301C6DAA86004AA8C1 /* ADTestAuthenticationViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ADTestAuthenticationViewController.m; sourceTree = ""; }; 601BEE331C6DCB0B004AA8C1 /* ADWebAuthControllerTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ADWebAuthControllerTests.m; sourceTree = ""; }; @@ -683,6 +708,16 @@ 600401B71D3766F80020EAAB /* ADEventInterface.h */, 600401A81D3428770020EAAB /* ADDefaultEvent.h */, 600401AA1D3443D30020EAAB /* ADDefaultEvent.m */, + 6010EDE31D47B1AC00B62072 /* ADAPIEvent.h */, + 6010EDE51D47B21600B62072 /* ADAPIEvent.m */, + 6010EDE81D47B26300B62072 /* ADUIEvent.h */, + 6010EDEA1D47B27400B62072 /* ADUIEvent.m */, + 6010EDED1D47B29500B62072 /* ADHttpEvent.h */, + 6010EDEF1D47B2A600B62072 /* ADHttpEvent.m */, + 6010EDF21D47B2BD00B62072 /* ADCacheEvent.h */, + 6010EDF41D47B2CE00B62072 /* ADCacheEvent.m */, + 6010EDF71D47B2E300B62072 /* ADBrokerEvent.h */, + 6010EDF91D47B2F300B62072 /* ADBrokerEvent.m */, ); path = telemetry; sourceTree = ""; @@ -1177,17 +1212,20 @@ 9453C41C1C586456006B9E79 /* ADClientMetrics.h in Headers */, 9453C4381C586476006B9E79 /* ADNTLMHandler.h in Headers */, 9453C4641C58707B006B9E79 /* ADCredentialCollectionController.h in Headers */, + 6010EDEE1D47B29500B62072 /* ADHttpEvent.h in Headers */, 94DD18D81C5AC8DE00F80C62 /* ADUserIdentifier.h in Headers */, 9453C46A1C5870F5006B9E79 /* ADNTLMUIPrompt.h in Headers */, 600401A71D3426250020EAAB /* ADTelemetry+Internal.h in Headers */, 600401B61D37658C0020EAAB /* ADAggregatedDispatcher.m in Headers */, 9453C42E1C58646D006B9E79 /* ADAuthenticationRequest+Broker.h in Headers */, + 6010EDF31D47B2BD00B62072 /* ADCacheEvent.h in Headers */, 94DD18D11C5AC8DE00F80C62 /* ADAuthenticationError.h in Headers */, 600401C21D39A18E0020EAAB /* ADDefaultDispatcher.h in Headers */, 600401A91D3428770020EAAB /* ADDefaultEvent.h in Headers */, 9453C43E1C58647E006B9E79 /* ADHelpers.h in Headers */, 9453C4211C586462006B9E79 /* ADTokenCache+Internal.h in Headers */, 9453C44C1C586485006B9E79 /* ADPkeyAuthHelper.h in Headers */, + 6010EDE41D47B1AC00B62072 /* ADAPIEvent.h in Headers */, 9453C4421C58647E006B9E79 /* NSDictionary+ADExtensions.h in Headers */, 9453C43C1C58647E006B9E79 /* ADALFrameworkUtils.h in Headers */, 9453C4341C58646D006B9E79 /* ADWebResponse.h in Headers */, @@ -1197,12 +1235,14 @@ 9453C4321C58646D006B9E79 /* ADWebRequest.h in Headers */, 9453C4301C58646D006B9E79 /* ADAuthenticationRequest+WebRequest.h in Headers */, 9453C4241C586462006B9E79 /* ADTokenCacheItem+Internal.h in Headers */, + 6010EDE91D47B26300B62072 /* ADUIEvent.h in Headers */, 94DD18D41C5AC8DE00F80C62 /* ADAuthenticationSettings.h in Headers */, 94DD18CF1C5AC8DE00F80C62 /* ADAL.h in Headers */, 94DD18DA1C5AC8DE00F80C62 /* ADWebAuthController.h in Headers */, 9453C4161C586456006B9E79 /* ADOAuth2Constants.h in Headers */, 94DD18D91C5AC8DE00F80C62 /* ADUserInformation.h in Headers */, 9453C4281C58646D006B9E79 /* ADAuthenticationRequest.h in Headers */, + 6010EDF81D47B2E300B62072 /* ADBrokerEvent.h in Headers */, 9453C4061C586456006B9E79 /* ADAL_Internal.h in Headers */, 9453C4441C58647E006B9E79 /* NSString+ADHelperMethods.h in Headers */, 9453C4361C586476006B9E79 /* ADCustomHeaderHandler.h in Headers */, @@ -1405,6 +1445,7 @@ D6F0951B1CDC2BC300D28FC2 /* ADWebAuthRequest.m in Sources */, 9453C4691C58709D006B9E79 /* ADNTLMUIPrompt.m in Sources */, 8B7E6FC81856A1E8000DC3C8 /* ADOAuth2Constants.m in Sources */, + 6010EDEB1D47B27400B62072 /* ADUIEvent.m in Sources */, 9453C3931C5820E3006B9E79 /* ADWebRequest.m in Sources */, 9453C3451C57FC2A006B9E79 /* ADTokenCacheKey.m in Sources */, 9453C3701C580157006B9E79 /* NSString+ADHelperMethods.m in Sources */, @@ -1429,6 +1470,7 @@ 9453C35B1C580143006B9E79 /* ADRegistrationInformation.m in Sources */, 9453C36D1C580157006B9E79 /* ADHelpers.m in Sources */, 8BB8346218074CFA007F9F0D /* ADAuthenticationParameters.m in Sources */, + 6010EDF51D47B2CE00B62072 /* ADCacheEvent.m in Sources */, 946818A61C59B7F100CA0378 /* ADWebAuthController.m in Sources */, 9453C3221C57FBCB006B9E79 /* UIAlertView+Additions.m in Sources */, 9453C37D1C5801CB006B9E79 /* ADBrokerKeyHelper.m in Sources */, @@ -1437,6 +1479,7 @@ D610015E1D39A5620087AB81 /* ADKeychainUtil.m in Sources */, 9453C3711C580157006B9E79 /* NSURL+ADExtensions.m in Sources */, D6FB3E3C1B30D3630032F883 /* ADUserIdentifier.m in Sources */, + 6010EDF01D47B2A600B62072 /* ADHttpEvent.m in Sources */, 600401A41D3421480020EAAB /* ADTelemetry.m in Sources */, 9453C3721C580157006B9E79 /* NSUUID+ADExtensions.m in Sources */, 9424B6821CDD1B2B00729698 /* ADTokenCacheAccessor.m in Sources */, @@ -1444,11 +1487,13 @@ 9453C3921C5820E3006B9E79 /* ADAuthenticationRequest+WebRequest.m in Sources */, 8B92DB70181B2335004AAB0E /* ADLogger.m in Sources */, 9453C3901C5820E3006B9E79 /* ADAuthenticationRequest+AcquireToken.m in Sources */, + 6010EDE61D47B21600B62072 /* ADAPIEvent.m in Sources */, 9453C3941C5820E3006B9E79 /* ADWebResponse.m in Sources */, 8B0DA7DE182AD01100CF5E1E /* ADAuthenticationResult+Internal.m in Sources */, 600401BD1D377E9F0020EAAB /* ADDefaultDispatcher.m in Sources */, 8B5989511811A3DB00744AEE /* ADAuthenticationError.m in Sources */, D6E43A6A1B04026D000F5BE2 /* ADAuthenticationContext+Internal.m in Sources */, + 6010EDFA1D47B2F300B62072 /* ADBrokerEvent.m in Sources */, 9453C3421C57FC2A006B9E79 /* ADTokenCache.m in Sources */, 9453C4761C58750C006B9E79 /* ADBrokerHelper.m in Sources */, 9453C39C1C5826F2006B9E79 /* ADCustomHeaderHandler.m in Sources */, @@ -1505,7 +1550,9 @@ files = ( 600401C01D3868B20020EAAB /* ADAggregatedDispatcher.m in Sources */, 9453C4231C586462006B9E79 /* ADTokenCacheItem.m in Sources */, + 6010EDF11D47B2A600B62072 /* ADHttpEvent.m in Sources */, 94DD18CA1C5A00BC00F80C62 /* ADAuthenticationViewController.m in Sources */, + 6010EDE71D47B21600B62072 /* ADAPIEvent.m in Sources */, 946818A71C59B7F200CA0378 /* ADWebAuthController.m in Sources */, 9453C4071C586456006B9E79 /* ADAuthenticationContext.m in Sources */, D68040351D22F686007A61AC /* ADWebAuthResponse.m in Sources */, @@ -1527,6 +1574,7 @@ 9453C4141C586456006B9E79 /* ADLogger.m in Sources */, 9453C41B1C586456006B9E79 /* ADClientMetrics.m in Sources */, D68040301D21C4EB007A61AC /* ADWorkPlaceJoinUtil.m in Sources */, + 6010EDFB1D47B2F300B62072 /* ADBrokerEvent.m in Sources */, 9453C43D1C58647E006B9E79 /* ADALFrameworkUtils.m in Sources */, 9453C4371C586476006B9E79 /* ADCustomHeaderHandler.m in Sources */, 9453C4271C586462006B9E79 /* ADTokenCacheKey.m in Sources */, @@ -1545,7 +1593,9 @@ 9453C4131C586456006B9E79 /* ADInstanceDiscovery.m in Sources */, 9453C4181C586456006B9E79 /* ADUserInformation.m in Sources */, 9424B6841CDD39E400729698 /* ADTokenCacheAccessor.m in Sources */, + 6010EDEC1D47B27400B62072 /* ADUIEvent.m in Sources */, 9453C4331C58646D006B9E79 /* ADWebRequest.m in Sources */, + 6010EDF61D47B2CE00B62072 /* ADCacheEvent.m in Sources */, 9453C4351C58646D006B9E79 /* ADWebResponse.m in Sources */, 9453C4171C586456006B9E79 /* ADOAuth2Constants.m in Sources */, 9453C4101C586456006B9E79 /* ADAuthenticationResult.m in Sources */, diff --git a/ADAL/src/ADAuthenticationParameters.m b/ADAL/src/ADAuthenticationParameters.m index daa8f5523..b80e58919 100644 --- a/ADAL/src/ADAuthenticationParameters.m +++ b/ADAL/src/ADAuthenticationParameters.m @@ -90,7 +90,7 @@ + (void)parametersFromResourceUrl:(NSURL*)resourceUrl return; } - ADWebRequest* request = [[ADWebRequest alloc] initWithURL:resourceUrl correlationId:nil]; + ADWebRequest* request = [[ADWebRequest alloc] initWithURL:resourceUrl correlationId:nil telemetryRequestId:nil]; [request setIsGetRequest:YES]; AD_LOG_VERBOSE_F(@"Starting authorization challenge request", nil, @"Resource: %@", resourceUrl); diff --git a/ADAL/src/ADInstanceDiscovery.h b/ADAL/src/ADInstanceDiscovery.h index 5aa4122b9..d4ba46c88 100644 --- a/ADAL/src/ADInstanceDiscovery.h +++ b/ADAL/src/ADInstanceDiscovery.h @@ -48,6 +48,7 @@ typedef void(^ADDiscoveryCallback)(BOOL validated, ADAuthenticationError* error) @param completionBlock: the block to be called when the result is achieved.*/ - (void)validateAuthority:(NSString *)authority correlationId:(NSUUID *)correlationId + telemetryRequestId:(NSString*)telemetryRequestId completionBlock:(ADDiscoveryCallback) completionBlock; /*! Takes the string and makes it canonical URL, e.g. lowercase with @@ -65,6 +66,7 @@ typedef void(^ADDiscoveryCallback)(BOOL validated, ADAuthenticationError* error) host:(NSString *)authorityHost trustedAuthority:(NSString *)trustedAuthority correlationId:(NSUUID *)correlationId + telemetryRequestId:(NSString*)telemetryRequestId completionBlock:(ADDiscoveryCallback)completionBlock; @end diff --git a/ADAL/src/ADInstanceDiscovery.m b/ADAL/src/ADInstanceDiscovery.m index 3b98b6d75..6f4b7fead 100644 --- a/ADAL/src/ADInstanceDiscovery.m +++ b/ADAL/src/ADInstanceDiscovery.m @@ -141,6 +141,7 @@ - (NSString*)extractHost:(NSString *)authority - (void)validateAuthority:(NSString *)authority correlationId:(NSUUID *)correlationId + telemetryRequestId:(NSString*)telemetryRequestId completionBlock:(ADDiscoveryCallback)completionBlock; { API_ENTRY; @@ -175,6 +176,7 @@ - (void)validateAuthority:(NSString *)authority host:authorityHost trustedAuthority:sTrustedAuthority correlationId:correlationId + telemetryRequestId:telemetryRequestId completionBlock:completionBlock]; } @@ -276,6 +278,7 @@ - (void)requestValidationOfAuthority:(NSString *)authority host:(NSString *)authorityHost trustedAuthority:(NSString *)trustedAuthority correlationId:(NSUUID *)correlationId + telemetryRequestId:(NSString*)telemetryRequestId completionBlock:(ADDiscoveryCallback)completionBlock { THROW_ON_NIL_ARGUMENT(completionBlock); @@ -292,7 +295,9 @@ - (void)requestValidationOfAuthority:(NSString *)authority NSString* endPoint = [NSString stringWithFormat:@"%@/%@?%@", trustedAuthority, OAUTH2_INSTANCE_DISCOVERY_SUFFIX, [request_data adURLFormEncode]]; AD_LOG_VERBOSE(@"Authority Validation Request", correlationId, endPoint); - ADWebRequest *webRequest = [[ADWebRequest alloc] initWithURL:[NSURL URLWithString:endPoint] correlationId:correlationId]; + ADWebRequest *webRequest = [[ADWebRequest alloc] initWithURL:[NSURL URLWithString:endPoint] + correlationId:correlationId + telemetryRequestId:telemetryRequestId]; [webRequest setIsGetRequest:YES]; [webRequest.headers setObject:@"application/json" forKey:@"Accept"]; diff --git a/ADAL/src/cache/ADTokenCacheAccessor.h b/ADAL/src/cache/ADTokenCacheAccessor.h index 20b134ff1..8b0c259d8 100644 --- a/ADAL/src/cache/ADTokenCacheAccessor.h +++ b/ADAL/src/cache/ADTokenCacheAccessor.h @@ -44,6 +44,7 @@ resource:(NSString *)resource clientId:(NSString *)clientId correlationId:(NSUUID *)correlationId + telemetryRequestId:(NSString*)telemetryRequestId error:(ADAuthenticationError * __autoreleasing *)error; /*! @@ -53,6 +54,7 @@ - (ADTokenCacheItem *)getMRRTItemForUser:(ADUserIdentifier *)identifier clientId:(NSString *)clientId correlationId:(NSUUID *)correlationId + telemetryRequestId:(NSString*)telemetryRequestId error:(ADAuthenticationError * __autoreleasing *)error; /*! @@ -62,6 +64,7 @@ - (ADTokenCacheItem *)getFRTItemForUser:(ADUserIdentifier *)identifier familyId:(NSString *)familyId correlationId:(NSUUID *)correlationId + telemetryRequestId:(NSString*)telemetryRequestId error:(ADAuthenticationError * __autoreleasing *)error; /*! @@ -71,6 +74,7 @@ - (ADTokenCacheItem*)getADFSUserTokenForResource:(NSString *)resource clientId:(NSString *)clientId correlationId:(NSUUID *)correlationId + telemetryRequestId:(NSString*)telemetryRequestId error:(ADAuthenticationError * __autoreleasing *)error; /*! @@ -83,6 +87,7 @@ - (void)updateCacheToResult:(ADAuthenticationResult *)result cacheItem:(ADTokenCacheItem *)cacheItem refreshToken:(NSString *)refreshToken - correlationId:(NSUUID *)correlationId; + correlationId:(NSUUID *)correlationId + telemetryRequestId:(NSString*)telemetryRequestId; @end diff --git a/ADAL/src/cache/ADTokenCacheAccessor.m b/ADAL/src/cache/ADTokenCacheAccessor.m index 4bf29addb..450954348 100644 --- a/ADAL/src/cache/ADTokenCacheAccessor.m +++ b/ADAL/src/cache/ADTokenCacheAccessor.m @@ -27,6 +27,9 @@ #import "ADAuthenticationContext+Internal.h" #import "ADTokenCacheItem+Internal.h" #import "ADUserInformation.h" +#import "ADTelemetry.h" +#import "ADTelemetry+Internal.h" +#import "ADCacheEvent.h" @implementation ADTokenCacheAccessor @@ -66,6 +69,7 @@ - (ADTokenCacheItem *)getItemForUser:(ADUserIdentifier *)identifier resource:(NSString *)resource clientId:(NSString *)clientId correlationId:(NSUUID *)correlationId + telemetryRequestId:(NSString*)telemetryRequestId error:(ADAuthenticationError * __autoreleasing *)error { ADTokenCacheKey* key = [ADTokenCacheKey keyWithAuthority:_authority @@ -77,10 +81,18 @@ - (ADTokenCacheItem *)getItemForUser:(ADUserIdentifier *)identifier return nil; } - return [_dataSource getItemWithKey:key + [[ADTelemetry getInstance] startEvent:telemetryRequestId eventName:@"token_cache_lookup"]; + + ADTokenCacheItem* item = [_dataSource getItemWithKey:key userId:identifier.userId correlationId:correlationId error:error]; + + ADCacheEvent* event = [[ADCacheEvent alloc] initWithName:@"token_cache_lookup"]; + [[ADTelemetry getInstance] stopEvent:telemetryRequestId event:event]; + SAFE_ARC_RELEASE(event); + + return item; } /*! @@ -92,9 +104,10 @@ - (ADTokenCacheItem *)getATRTItemForUser:(ADUserIdentifier *)identifier resource:(NSString *)resource clientId:(NSString *)clientId correlationId:(NSUUID *)correlationId + telemetryRequestId:(NSString*)telemetryRequestId error:(ADAuthenticationError * __autoreleasing *)error { - return [self getItemForUser:identifier resource:resource clientId:clientId correlationId:correlationId error:error]; + return [self getItemForUser:identifier resource:resource clientId:clientId correlationId:correlationId telemetryRequestId:telemetryRequestId error:error]; } /*! @@ -104,9 +117,10 @@ - (ADTokenCacheItem *)getATRTItemForUser:(ADUserIdentifier *)identifier - (ADTokenCacheItem *)getMRRTItemForUser:(ADUserIdentifier *)identifier clientId:(NSString *)clientId correlationId:(NSUUID *)correlationId + telemetryRequestId:(NSString*)telemetryRequestId error:(ADAuthenticationError * __autoreleasing *)error { - return [self getItemForUser:identifier resource:nil clientId:clientId correlationId:correlationId error:error]; + return [self getItemForUser:identifier resource:nil clientId:clientId correlationId:correlationId telemetryRequestId:telemetryRequestId error:error]; } /*! @@ -116,16 +130,18 @@ - (ADTokenCacheItem *)getMRRTItemForUser:(ADUserIdentifier *)identifier - (ADTokenCacheItem *)getFRTItemForUser:(ADUserIdentifier *)identifier familyId:(NSString *)familyId correlationId:(NSUUID *)correlationId + telemetryRequestId:(NSString*)telemetryRequestId error:(ADAuthenticationError * __autoreleasing *)error { NSString* fociClientId = [ADTokenCacheAccessor familyClientId:familyId]; - return [self getItemForUser:identifier resource:nil clientId:fociClientId correlationId:correlationId error:error]; + return [self getItemForUser:identifier resource:nil clientId:fociClientId correlationId:correlationId telemetryRequestId:telemetryRequestId error:error]; } - (ADTokenCacheItem*)getADFSUserTokenForResource:(NSString *)resource clientId:(NSString *)clientId correlationId:(NSUUID *)correlationId + telemetryRequestId:(NSString*)telemetryRequestId error:(ADAuthenticationError * __autoreleasing *)error { // ADFS fix: When talking to ADFS directly we can get ATs and RTs (but not MRRTs or FRTs) without @@ -141,7 +157,15 @@ - (ADTokenCacheItem*)getADFSUserTokenForResource:(NSString *)resource return nil; } - return [_dataSource getItemWithKey:key userId:@"" correlationId:correlationId error:error]; + [[ADTelemetry getInstance] startEvent:telemetryRequestId eventName:@"token_cache_lookup"]; + + ADTokenCacheItem* item = [_dataSource getItemWithKey:key userId:@"" correlationId:correlationId error:error]; + + ADCacheEvent* event = [[ADCacheEvent alloc] initWithName:@"token_cache_lookup"]; + [[ADTelemetry getInstance] stopEvent:telemetryRequestId event:event]; + SAFE_ARC_RELEASE(event); + + return item; } @@ -151,6 +175,7 @@ - (void)updateCacheToResult:(ADAuthenticationResult *)result cacheItem:(ADTokenCacheItem *)cacheItem refreshToken:(NSString *)refreshToken correlationId:(NSUUID *)correlationId + telemetryRequestId:(NSString*)telemetryRequestId { if(!result) @@ -173,7 +198,8 @@ - (void)updateCacheToResult:(ADAuthenticationResult *)result [self updateCacheToItem:item MRRT:[result multiResourceRefreshToken] - correlationId:correlationId]; + correlationId:correlationId + telemetryRequestId:telemetryRequestId]; return; } @@ -191,13 +217,17 @@ - (void)updateCacheToResult:(ADAuthenticationResult *)result [self removeItemFromCache:cacheItem refreshToken:refreshToken correlationId:correlationId + telemetryRequestId:telemetryRequestId error:result.error]; } - (void)updateCacheToItem:(ADTokenCacheItem *)cacheItem MRRT:(BOOL)isMRRT correlationId:(NSUUID *)correlationId + telemetryRequestId:(NSString*)telemetryRequestId { + [[ADTelemetry getInstance] startEvent:telemetryRequestId eventName:@"token_cache_write"]; + NSString* savedRefreshToken = cacheItem.refreshToken; if (isMRRT) { @@ -232,11 +262,16 @@ - (void)updateCacheToItem:(ADTokenCacheItem *)cacheItem AD_LOG_VERBOSE_F(@"Token cache store", correlationId, @"Storing access token for resource: %@", cacheItem.resource); [_dataSource addOrUpdateItem:cacheItem correlationId:correlationId error:nil]; cacheItem.refreshToken = savedRefreshToken;//Restore for the result + + ADCacheEvent* event = [[ADCacheEvent alloc] initWithName:@"token_cache_write"]; + [[ADTelemetry getInstance] stopEvent:telemetryRequestId event:event]; + SAFE_ARC_RELEASE(event); } - (void)removeItemFromCache:(ADTokenCacheItem *)cacheItem refreshToken:(NSString *)refreshToken correlationId:(NSUUID *)correlationId + telemetryRequestId:(NSString*)telemetryRequestId error:(ADAuthenticationError *)error { if (!cacheItem && !refreshToken) @@ -244,6 +279,8 @@ - (void)removeItemFromCache:(ADTokenCacheItem *)cacheItem return; } + [[ADTelemetry getInstance] startEvent:telemetryRequestId eventName:@"token_cache_delete_token"]; + BOOL removed = NO; //The refresh token didn't work. We need to tombstone this refresh item in the cache. ADTokenCacheKey* exactKey = [cacheItem extractKey:nil]; @@ -283,6 +320,10 @@ - (void)removeItemFromCache:(ADTokenCacheItem *)cacheItem } } } + + ADCacheEvent* event = [[ADCacheEvent alloc] initWithName:@"token_cache_delete_token"]; + [[ADTelemetry getInstance] stopEvent:telemetryRequestId event:event]; + SAFE_ARC_RELEASE(event); } @end diff --git a/ADAL/src/request/ADAcquireTokenSilentHandler.h b/ADAL/src/request/ADAcquireTokenSilentHandler.h index ce797aa58..058482087 100644 --- a/ADAL/src/request/ADAcquireTokenSilentHandler.h +++ b/ADAL/src/request/ADAcquireTokenSilentHandler.h @@ -34,6 +34,7 @@ NSString* _redirectUri; ADUserIdentifier* _identifier; NSUUID* _correlationId; + NSString* _telemetryRequestId; ADTokenCacheAccessor* _tokenCache; ADTokenCacheItem* _mrrtItem; @@ -55,6 +56,7 @@ correlationId:(NSUUID *)correlationId tokenCache:(ADTokenCacheAccessor *)tokenCache extendedLifetime:(BOOL)extendedLifetime + telemetryRequestId:(NSString*)telemetryRequestId completionBlock:(ADAuthenticationCallback)completionBlock; @end diff --git a/ADAL/src/request/ADAcquireTokenSilentHandler.m b/ADAL/src/request/ADAcquireTokenSilentHandler.m index f04f6b231..56b83aec5 100644 --- a/ADAL/src/request/ADAcquireTokenSilentHandler.m +++ b/ADAL/src/request/ADAcquireTokenSilentHandler.m @@ -43,6 +43,7 @@ + (void)acquireTokenSilentForAuthority:(NSString *)authority correlationId:(NSUUID *)correlationId tokenCache:(ADTokenCacheAccessor *)tokenCache extendedLifetime:(BOOL)extendedLifetime + telemetryRequestId:(NSString*)telemetryRequestId completionBlock:(ADAuthenticationCallback)completionBlock { ADAcquireTokenSilentHandler* handler = [ADAcquireTokenSilentHandler new]; @@ -64,6 +65,8 @@ + (void)acquireTokenSilentForAuthority:(NSString *)authority SAFE_ARC_RETAIN(tokenCache); handler->_correlationId = correlationId; SAFE_ARC_RETAIN(correlationId); + handler->_telemetryRequestId = telemetryRequestId; + SAFE_ARC_RETAIN(telemetryRequestId); [handler getAccessToken:^(ADAuthenticationResult *result) { @@ -109,6 +112,9 @@ - (void)dealloc SAFE_ARC_RELEASE(_correlationId); _correlationId = nil; + SAFE_ARC_RELEASE(_telemetryRequestId); + _telemetryRequestId = nil; + SAFE_ARC_RELEASE(_tokenCache); _tokenCache = nil; @@ -167,7 +173,8 @@ - (void)acquireTokenByRefreshToken:(NSString*)refreshToken ADWebAuthRequest* webReq = [[ADWebAuthRequest alloc] initWithURL:[NSURL URLWithString:[_authority stringByAppendingString:OAUTH2_TOKEN_SUFFIX]] - correlationId:_correlationId]; + correlationId:_correlationId + telemetryRequestId:_telemetryRequestId]; [webReq setRequestDictionary:request_data]; AD_LOG_INFO_F(@"Attempting to acquire an access token from refresh token", nil, @"clientId: '%@'; resource: '%@';", _clientId, _resource); [webReq sendRequest:^(NSDictionary *response) @@ -187,7 +194,8 @@ - (void)acquireTokenByRefreshToken:(NSString*)refreshToken [_tokenCache updateCacheToResult:result cacheItem:resultItem refreshToken:refreshToken - correlationId:_correlationId]; + correlationId:_correlationId + telemetryRequestId:_telemetryRequestId]; } result = [ADAuthenticationContext updateResult:result toUser:_identifier];//Verify the user (just in case) // @@ -292,6 +300,7 @@ - (void)getAccessToken:(ADAuthenticationCallback)completionBlock resource:_resource clientId:_clientId correlationId:_correlationId + telemetryRequestId:_telemetryRequestId error:&error]; // If some error ocurred during the cache lookup then we need to fail out right away. if (!item && error) @@ -304,7 +313,7 @@ - (void)getAccessToken:(ADAuthenticationCallback)completionBlock // and we need to check the unknown user ADFS token as well if (!item) { - item = [_tokenCache getADFSUserTokenForResource:_resource clientId:_clientId correlationId:_correlationId error:&error]; + item = [_tokenCache getADFSUserTokenForResource:_resource clientId:_clientId correlationId:_correlationId telemetryRequestId:_telemetryRequestId error:&error]; if (!item && error) { completionBlock([ADAuthenticationResult resultFromError:error correlationId:_correlationId]); @@ -386,7 +395,7 @@ - (void)tryMRRT:(ADAuthenticationCallback)completionBlock // If we don't have an item yet see if we can pull one out of the cache if (!_mrrtItem) { - _mrrtItem = [_tokenCache getMRRTItemForUser:_identifier clientId:_clientId correlationId:_correlationId error:&error]; + _mrrtItem = [_tokenCache getMRRTItemForUser:_identifier clientId:_clientId correlationId:_correlationId telemetryRequestId:_telemetryRequestId error:&error]; if (!_mrrtItem && error) { completionBlock([ADAuthenticationResult resultFromError:error correlationId:_correlationId]); @@ -447,7 +456,7 @@ - (void)tryFRT:(NSString*)familyId completionBlock:(ADAuthenticationCallback)com _attemptedFRT = YES; ADAuthenticationError* error = nil; - ADTokenCacheItem* frtItem = [_tokenCache getFRTItemForUser:_identifier familyId:familyId correlationId:_correlationId error:&error]; + ADTokenCacheItem* frtItem = [_tokenCache getFRTItemForUser:_identifier familyId:familyId correlationId:_correlationId telemetryRequestId:_telemetryRequestId error:&error]; if (!frtItem && error) { completionBlock([ADAuthenticationResult resultFromError:error correlationId:_correlationId]); diff --git a/ADAL/src/request/ADAuthenticationRequest+AcquireToken.m b/ADAL/src/request/ADAuthenticationRequest+AcquireToken.m index dc1c443dd..d1616de4d 100644 --- a/ADAL/src/request/ADAuthenticationRequest+AcquireToken.m +++ b/ADAL/src/request/ADAuthenticationRequest+AcquireToken.m @@ -29,6 +29,9 @@ #import "ADUserIdentifier.h" #import "ADTokenCacheKey.h" #import "ADAcquireTokenSilentHandler.h" +#import "ADTelemetry.h" +#import "ADTelemetry+Internal.h" +#import "ADAPIEvent.h" @implementation ADAuthenticationRequest (AcquireToken) @@ -41,6 +44,17 @@ - (void)acquireToken:(ADAuthenticationCallback)completionBlock AD_REQUEST_CHECK_ARGUMENT(_resource); [self ensureRequest]; + [[ADTelemetry getInstance] startEvent:[self telemetryRequestId] eventName:@"acauire_token_call"]; + ADAuthenticationCallback requestCompletion = ^void(ADAuthenticationResult *result) + { + ADAPIEvent* event = [[ADAPIEvent alloc] initWithName:@"acauire_token_call"]; + [self fillTelemetryForAcquireToken:event result:result]; + [[ADTelemetry getInstance] stopEvent:[self telemetryRequestId] event:event]; + SAFE_ARC_RELEASE(event); + + completionBlock(result); + }; + NSString* log = [NSString stringWithFormat:@"acquireToken (authority = %@, resource = %@, clientId = %@, idtype = %@)", _context.authority, _resource, _clientId, [_identifier typeAsString]]; AD_LOG_INFO_F(log, _correlationId, @"userId = %@", _identifier.userId); @@ -53,7 +67,7 @@ - (void)acquireToken:(ADAuthenticationCallback)completionBlock errorDetails:@"Interactive authentication requests must originate from the main thread" correlationId:_correlationId]; - completionBlock([ADAuthenticationResult resultFromError:error]); + requestCompletion([ADAuthenticationResult resultFromError:error]); return; } @@ -64,28 +78,35 @@ - (void)acquireToken:(ADAuthenticationCallback)completionBlock protocolCode:nil errorDetails:ADRedirectUriInvalidError correlationId:_correlationId]; - completionBlock([ADAuthenticationResult resultFromError:error correlationId:_correlationId]); + requestCompletion([ADAuthenticationResult resultFromError:error correlationId:_correlationId]); return; } if (!_context.validateAuthority) { - [self validatedAcquireToken:completionBlock]; + [self validatedAcquireToken:requestCompletion]; return; } + [[ADTelemetry getInstance] startEvent:[self telemetryRequestId] eventName:@"authority_validation"]; [[ADInstanceDiscovery sharedInstance] validateAuthority:_context.authority correlationId:_correlationId + telemetryRequestId:_telemetryRequestId completionBlock:^(BOOL validated, ADAuthenticationError *error) { - (void)validated; + ADAPIEvent* event = [[ADAPIEvent alloc] initWithName:@"authority_validation"]; + [event setAuthorityValidationStatus:validated ? @"YES" : @"NO"]; + [event setAuthority:_context.authority]; + [[ADTelemetry getInstance] stopEvent:[self telemetryRequestId] event:event]; + SAFE_ARC_RELEASE(event); + if (error) { - completionBlock([ADAuthenticationResult resultFromError:error correlationId:_correlationId]); + requestCompletion([ADAuthenticationResult resultFromError:error correlationId:_correlationId]); } else { - [self validatedAcquireToken:completionBlock]; + [self validatedAcquireToken:requestCompletion]; } }]; @@ -105,6 +126,7 @@ - (void)validatedAcquireToken:(ADAuthenticationCallback)completionBlock correlationId:_correlationId tokenCache:_tokenCache extendedLifetime:_context.extendedLifetimeEnabled + telemetryRequestId:_telemetryRequestId completionBlock:^(ADAuthenticationResult *result) { if ([ADAuthenticationContext isFinalResult:result]) @@ -184,8 +206,13 @@ - (void)requestToken:(ADAuthenticationCallback)completionBlock __block BOOL silentRequest = _allowSilent; // Get the code first: + [[ADTelemetry getInstance] startEvent:[self telemetryRequestId] eventName:@"authorization_code"]; [self requestCode:^(NSString * code, ADAuthenticationError *error) { + ADAPIEvent* event = [[ADAPIEvent alloc] initWithName:@"authorization_code"]; + [[ADTelemetry getInstance] stopEvent:[self telemetryRequestId] event:event]; + SAFE_ARC_RELEASE(event); + if (error) { if (silentRequest) @@ -208,12 +235,17 @@ - (void)requestToken:(ADAuthenticationCallback)completionBlock } else { + [[ADTelemetry getInstance] startEvent:[self telemetryRequestId] eventName:@"token_grant"]; [self requestTokenByCode:code completionBlock:^(ADAuthenticationResult *result) { + ADAPIEvent* event = [[ADAPIEvent alloc] initWithName:@"token_grant"]; + [[ADTelemetry getInstance] stopEvent:[self telemetryRequestId] event:event]; + SAFE_ARC_RELEASE(event); + if (AD_SUCCEEDED == result.status) { - [_tokenCache updateCacheToResult:result cacheItem:nil refreshToken:nil correlationId:_correlationId]; + [_tokenCache updateCacheToResult:result cacheItem:nil refreshToken:nil correlationId:_correlationId telemetryRequestId:_telemetryRequestId]; result = [ADAuthenticationContext updateResult:result toUser:_identifier]; } completionBlock(result); @@ -247,5 +279,18 @@ - (void)requestTokenByCode:(NSString *)code completion:completionBlock]; } +- (void)fillTelemetryForAcquireToken:(ADAPIEvent*)event + result:(ADAuthenticationResult*)result +{ + [event setCorrelationId:_correlationId]; + [event setUserId:[_identifier userId]]; + [event setClientId:_clientId]; + [event setResultStatus:[result status]]; + [event setIsExtendedLifeTimeToken:[result extendedLifeTimeToken]? @"YES":@"NO"]; + [event setErrorCode:[NSString stringWithFormat:@"%ld",(long)[result.error code]]]; + [event setErrorDomain:[result.error domain]]; + [event setProtocolCode:[[result error] protocolCode]]; + [event setErrorDescription:[[result error] errorDetails]]; +} @end diff --git a/ADAL/src/request/ADAuthenticationRequest+Broker.m b/ADAL/src/request/ADAuthenticationRequest+Broker.m index d662f8099..2880dc39e 100644 --- a/ADAL/src/request/ADAuthenticationRequest+Broker.m +++ b/ADAL/src/request/ADAuthenticationRequest+Broker.m @@ -35,6 +35,9 @@ #import "ADUserInformation.h" #import "ADWebAuthController+Internal.h" #import "ADAuthenticationResult.h" +#import "ADTelemetry.h" +#import "ADTelemetry+Internal.h" +#import "ADBrokerEvent.h" #if TARGET_OS_IPHONE #import "ADKeychainTokenCache+Internal.h" @@ -152,7 +155,7 @@ + (void)internalHandleBrokerResponse:(NSURL *)response ADTokenCacheAccessor* cache = [[ADTokenCacheAccessor alloc] initWithDataSource:[ADKeychainTokenCache defaultKeychainCache] authority:result.tokenCacheItem.authority]; - [cache updateCacheToResult:result cacheItem:nil refreshToken:nil correlationId:nil]; + [cache updateCacheToResult:result cacheItem:nil refreshToken:nil correlationId:nil telemetryRequestId:nil]; NSString* userId = [[[result tokenCacheItem] userInformation] userId]; [ADAuthenticationContext updateResult:result @@ -213,9 +216,15 @@ - (void)callBroker:(ADAuthenticationCallback)completionBlock return; } + [[ADTelemetry getInstance] startEvent:[self telemetryRequestId] eventName:@"launch_broker"]; + void(^requestCompletion)(ADAuthenticationResult* result) = ^void(ADAuthenticationResult* result) { [self releaseUserInterationLock]; // Release the lock when completion block is called. + + ADBrokerEvent* event = [[ADBrokerEvent alloc] initWithName:@"launch_broker"]; + [[ADTelemetry getInstance] stopEvent:[self telemetryRequestId] event:event]; + completionBlock(result); }; diff --git a/ADAL/src/request/ADAuthenticationRequest+WebRequest.m b/ADAL/src/request/ADAuthenticationRequest+WebRequest.m index d7af6ae59..d04a0d3c2 100755 --- a/ADAL/src/request/ADAuthenticationRequest+WebRequest.m +++ b/ADAL/src/request/ADAuthenticationRequest+WebRequest.m @@ -37,6 +37,9 @@ #import "ADAuthenticationRequest.h" #import "ADTokenCacheItem+Internal.h" #import "ADWebAuthRequest.h" +#import "ADTelemetry.h" +#import "ADTelemetry+Internal.h" +#import "ADUIEvent.h" #import @@ -53,7 +56,9 @@ - (void)executeRequest:(NSDictionary *)request_data completion:(ADAuthenticationCallback)completionBlock { NSString* urlString = [_context.authority stringByAppendingString:OAUTH2_TOKEN_SUFFIX]; - ADWebAuthRequest* req = [[ADWebAuthRequest alloc] initWithURL:[NSURL URLWithString:urlString] correlationId:_correlationId]; + ADWebAuthRequest* req = [[ADWebAuthRequest alloc] initWithURL:[NSURL URLWithString:urlString] + correlationId:_correlationId + telemetryRequestId:_telemetryRequestId]; [req setRequestDictionary:request_data]; [req sendRequest:^(NSDictionary *response) { @@ -174,6 +179,16 @@ - (NSString*)generateQueryStringForRequestType:(NSString*)requestType - (void)launchWebView:(NSString*)startUrl completionBlock:(void (^)(ADAuthenticationError*, NSURL*))completionBlock { + [[ADTelemetry getInstance] startEvent:[self telemetryRequestId] eventName:@"launch_web_view"]; + void(^requestCompletion)(ADAuthenticationError *error, NSURL *end) = ^void(ADAuthenticationError *error, NSURL *end) + { + ADUIEvent* event = [[ADUIEvent alloc] initWithName:@"launch_web_view"]; + [self fillTelemetryUIEvent:event]; + [[ADTelemetry getInstance] stopEvent:[self telemetryRequestId] event:event]; + + completionBlock(error, end); + }; + [[ADWebAuthController sharedInstance] start:[NSURL URLWithString:startUrl] end:[NSURL URLWithString:_redirectUri] refreshCred:_refreshTokenCredential @@ -183,7 +198,7 @@ - (void)launchWebView:(NSString*)startUrl #endif webView:_context.webView correlationId:_correlationId - completion:completionBlock]; + completion:requestCompletion]; } //Requests an OAuth2 code to be used for obtaining a token: @@ -284,7 +299,9 @@ - (void)requestCode:(ADAuthorizationCodeCallback)completionBlock } NSURL* reqURL = [NSURL URLWithString:[_context.authority stringByAppendingString:OAUTH2_AUTHORIZE_SUFFIX]]; - ADWebAuthRequest* req = [[ADWebAuthRequest alloc] initWithURL:reqURL correlationId:_correlationId]; + ADWebAuthRequest* req = [[ADWebAuthRequest alloc] initWithURL:reqURL + correlationId:_correlationId + telemetryRequestId:_telemetryRequestId]; [req setIsGetRequest:YES]; [req setRequestDictionary:requestData]; [req sendRequest:^(NSDictionary * parameters) @@ -314,4 +331,12 @@ - (void)requestCode:(ADAuthorizationCodeCallback)completionBlock } } +- (void)fillTelemetryUIEvent:(ADUIEvent*)event +{ + if (_identifier && [_identifier isDisplayable] && ![NSString adIsStringNilOrBlank:_identifier.userId]) + { + [event setLoginHint:_identifier.userId]; + } +} + @end diff --git a/ADAL/src/request/ADAuthenticationRequest.h b/ADAL/src/request/ADAuthenticationRequest.h index 56fdf521c..c3bdba29a 100644 --- a/ADAL/src/request/ADAuthenticationRequest.h +++ b/ADAL/src/request/ADAuthenticationRequest.h @@ -71,6 +71,7 @@ NSUUID* _correlationId; NSString* _logComponent; + NSString* _telemetryRequestId; BOOL _requestStarted; BOOL _attemptedFRT; @@ -110,6 +111,7 @@ - (void)setSilent:(BOOL)silent; - (void)setCorrelationId:(NSUUID*)correlationId; - (NSUUID*)correlationId; +- (NSString*)telemetryRequestId; #if AD_BROKER - (NSString*)redirectUri; - (void)setRedirectUri:(NSString*)redirectUri; diff --git a/ADAL/src/request/ADAuthenticationRequest.m b/ADAL/src/request/ADAuthenticationRequest.m index c9aa51ece..8ac98c9c3 100644 --- a/ADAL/src/request/ADAuthenticationRequest.m +++ b/ADAL/src/request/ADAuthenticationRequest.m @@ -30,6 +30,8 @@ #import "NSDictionary+ADExtensions.h" #import "NSString+ADHelperMethods.h" #import "NSURL+ADExtensions.h" +#import "ADTelemetry.h" +#import "ADTelemetry+Internal.h" #if TARGET_OS_IPHONE #import "ADBrokerKeyHelper.h" @@ -138,6 +140,7 @@ - (void)dealloc SAFE_ARC_RELEASE(_queryParams); SAFE_ARC_RELEASE(_refreshTokenCredential); SAFE_ARC_RELEASE(_correlationId); + SAFE_ARC_RELEASE(_telemetryRequestId); SAFE_ARC_RELEASE(_underlyingError); SAFE_ARC_SUPER_DEALLOC(); @@ -302,6 +305,17 @@ - (NSUUID*)correlationId return _correlationId; } +- (NSString*)telemetryRequestId +{ + if (_telemetryRequestId == nil) + { + _telemetryRequestId = [[ADTelemetry getInstance] registerNewRequest]; + SAFE_ARC_RETAIN(_telemetryRequestId); + } + + return _telemetryRequestId; +} + - (BOOL)takeUserInterationLock { return !dispatch_semaphore_wait(sInteractionInProgress, DISPATCH_TIME_NOW); diff --git a/ADAL/src/request/ADWebAuthRequest.m b/ADAL/src/request/ADWebAuthRequest.m index 3989bdedd..0966c7934 100644 --- a/ADAL/src/request/ADWebAuthRequest.m +++ b/ADAL/src/request/ADWebAuthRequest.m @@ -39,8 +39,9 @@ @implementation ADWebAuthRequest - (id)initWithURL:(NSURL *)url correlationId:(NSUUID *)correlationId +telemetryRequestId:(NSString *)telemetryRequestId { - self = [super initWithURL:url correlationId:correlationId]; + self = [super initWithURL:url correlationId:correlationId telemetryRequestId:telemetryRequestId]; if (!self) { return nil; diff --git a/ADAL/src/request/ADWebRequest.h b/ADAL/src/request/ADWebRequest.h index 64b8071bb..b92a56fe3 100644 --- a/ADAL/src/request/ADWebRequest.h +++ b/ADAL/src/request/ADWebRequest.h @@ -43,6 +43,8 @@ BOOL _isGetRequest; + NSString* _telemetryRequestId; + void (^_completionHandler)( NSError *, ADWebResponse *); } @@ -54,7 +56,8 @@ @property (readonly) NSUUID* correlationId; - (id)initWithURL: (NSURL*)url - correlationId: (NSUUID*) correlationId; + correlationId: (NSUUID*)correlationId +telemetryRequestId: (NSString*)telemetryRequestId; - (void)send:( void (^)( NSError *, ADWebResponse *) )completionHandler; diff --git a/ADAL/src/request/ADWebRequest.m b/ADAL/src/request/ADWebRequest.m index 56d05e216..dc2a8f5f6 100644 --- a/ADAL/src/request/ADWebRequest.m +++ b/ADAL/src/request/ADWebRequest.m @@ -32,6 +32,9 @@ #import "ADHelpers.h" #import "ADLogger+Internal.h" #import "ADURLProtocol.h" +#import "ADTelemetry.h" +#import "ADTelemetry+Internal.h" +#import "ADHttpEvent.h" @interface ADWebRequest () @@ -78,6 +81,7 @@ - (void)setBody:(NSData *)body - (id)initWithURL:(NSURL *)requestURL correlationId:(NSUUID *)correlationId +telemetryRequestId:(NSString *)telemetryRequestId { if (!(self = [super init])) { @@ -93,6 +97,9 @@ - (id)initWithURL:(NSURL *)requestURL _correlationId = correlationId; SAFE_ARC_RETAIN(_correlationId); + _telemetryRequestId = telemetryRequestId; + SAFE_ARC_RETAIN(_telemetryRequestId); + _operationQueue = [[NSOperationQueue alloc] init]; [_operationQueue setMaxConcurrentOperationCount:1]; @@ -121,6 +128,9 @@ - (void)dealloc SAFE_ARC_RELEASE(_correlationId); _correlationId = nil; + SAFE_ARC_RELEASE(_telemetryRequestId); + _telemetryRequestId = nil; + SAFE_ARC_RELEASE(_operationQueue); _operationQueue = nil; @@ -142,6 +152,7 @@ - (void)completeWithError:(NSError *)error andResponse:(ADWebResponse *)response SAFE_ARC_RELEASE(_connection); _connection = nil; + [self stopTelemetryEvent:error response:response]; _completionHandler(error, response); } @@ -170,6 +181,8 @@ - (void)resend - (void)send { + [[ADTelemetry getInstance] startEvent:_telemetryRequestId eventName:@"http_request"]; + [_requestHeaders addEntriesFromDictionary:[ADLogger adalId]]; //Correlation id: if (_correlationId) @@ -306,4 +319,26 @@ -(void)connection:(NSURLConnection *)connection didSendBodyData:(NSInteger)bytes } +- (void)stopTelemetryEvent:(NSError *)error + response:(ADWebResponse *)response +{ + ADHttpEvent* event = [[ADHttpEvent alloc] initWithName:@"http_request"]; + + [event setHttpMethod:_isGetRequest ? @"GET" : @"POST"]; + [event setHttpPath:[[_requestURL host] stringByAppendingPathComponent:[_requestURL path]]]; + [event setHttpRequestQueryParams:[_requestURL query]]; + if (error) + { + [event setHttpResponseCode:[NSString stringWithFormat: @"%ld", (long)[error code]]]; + } + else if (response) + { + [event setHttpResponseCode:[NSString stringWithFormat: @"%ld", (long)[response statusCode]]]; + } + + [[ADTelemetry getInstance] stopEvent:_telemetryRequestId event:event]; + SAFE_ARC_RELEASE(event); + +} + @end diff --git a/ADAL/src/telemetry/ADAPIEvent.h b/ADAL/src/telemetry/ADAPIEvent.h new file mode 100644 index 000000000..7b6e1a08d --- /dev/null +++ b/ADAL/src/telemetry/ADAPIEvent.h @@ -0,0 +1,41 @@ +// Copyright (c) Microsoft Corporation. +// All rights reserved. +// +// This code is licensed under the MIT License. +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files(the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and / or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions : +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE. + +#import "ADDefaultEvent.h" + +@interface ADAPIEvent : ADDefaultEvent + +- (void)setResultStatus:(ADAuthenticationResultStatus)status; +- (void)setCorrelationId:(NSUUID*)correlationId; +- (void)setUserId:(NSString*)userId; +- (void)setClientId:(NSString*)clientId; +- (void)setIsExtendedLifeTimeToken:(NSString*)isExtendedLifeToken; +- (void)setErrorCode:(NSString*)errorCode; +- (void)setProtocolCode:(NSString*)protocolCode; +- (void)setErrorDescription:(NSString*)errorDescription; +- (void)setErrorDomain:(NSString*)errorDomain; + +- (void)setAuthorityValidationStatus:(NSString*)status; +- (void)setAuthority:(NSString*)authority; + +@end \ No newline at end of file diff --git a/ADAL/src/telemetry/ADAPIEvent.m b/ADAL/src/telemetry/ADAPIEvent.m new file mode 100644 index 000000000..92f6e1c4a --- /dev/null +++ b/ADAL/src/telemetry/ADAPIEvent.m @@ -0,0 +1,98 @@ +// Copyright (c) Microsoft Corporation. +// All rights reserved. +// +// This code is licensed under the MIT License. +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files(the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and / or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions : +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE. + +#import "ADAPIEvent.h" + +@implementation ADAPIEvent + +- (void)setResultStatus:(ADAuthenticationResultStatus)status +{ + NSString* statusStr = nil; + switch (status) { + case AD_SUCCEEDED: + statusStr = @"SUCCEEDED"; + break; + case AD_FAILED: + statusStr = @"FAILED"; + break; + case AD_USER_CANCELLED: + statusStr = @"USER_CANCELLED"; + break; + default: + statusStr = @"UNKNOWN"; + } + + [self setProperty:@"status" value:statusStr]; +} + +- (void)setCorrelationId:(NSUUID*)correlationId +{ + [self setProperty:@"correlation_id" value:[correlationId UUIDString]]; +} + +- (void)setUserId:(NSString*)userId; +{ + [self setProperty:@"user_id" value:[NSString stringWithFormat:@"%lu", (unsigned long)[userId hash]]]; +} + +- (void)setClientId:(NSString*)clientId +{ + [self setProperty:@"client_id" value:clientId]; +} + +- (void)setIsExtendedLifeTimeToken:(NSString*)isExtendedLifeToken +{ + [self setProperty:@"is_extended_life_time_token" value:isExtendedLifeToken]; +} + +- (void)setErrorCode:(NSString*)errorCode +{ + [self setProperty:@"error_code" value:errorCode]; +} + +- (void)setProtocolCode:(NSString*)protocolCode +{ + [self setProperty:@"protocol_code" value:protocolCode]; +} + +- (void)setErrorDescription:(NSString*)errorDescription +{ + [self setProperty:@"error_description" value:errorDescription]; +} + +- (void)setErrorDomain:(NSString*)errorDomain +{ + [self setProperty:@"error_domain" value:errorDomain]; +} + +- (void)setAuthorityValidationStatus:(NSString*)status +{ + [self setProperty:@"validation_status" value:status]; +} + +- (void)setAuthority:(NSString*)authority +{ + [self setProperty:@"authority" value:authority]; +} + +@end \ No newline at end of file diff --git a/ADAL/src/telemetry/ADBrokerEvent.h b/ADAL/src/telemetry/ADBrokerEvent.h new file mode 100644 index 000000000..4320a6056 --- /dev/null +++ b/ADAL/src/telemetry/ADBrokerEvent.h @@ -0,0 +1,30 @@ +// Copyright (c) Microsoft Corporation. +// All rights reserved. +// +// This code is licensed under the MIT License. +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files(the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and / or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions : +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE. + +#import "ADDefaultEvent.h" + +@interface ADBrokerEvent : ADDefaultEvent + +- (void)setBrokerAppVersion:(NSString*)version; + +@end \ No newline at end of file diff --git a/ADAL/src/telemetry/ADBrokerEvent.m b/ADAL/src/telemetry/ADBrokerEvent.m new file mode 100644 index 000000000..2237f8707 --- /dev/null +++ b/ADAL/src/telemetry/ADBrokerEvent.m @@ -0,0 +1,33 @@ +// Copyright (c) Microsoft Corporation. +// All rights reserved. +// +// This code is licensed under the MIT License. +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files(the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and / or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions : +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE. + +#import "ADBrokerEvent.h" + +@implementation ADBrokerEvent + +- (void)setBrokerAppVersion:(NSString*)version +{ + [self setProperty:@"broker_app_version" value:version]; +} + +@end \ No newline at end of file diff --git a/ADAL/src/telemetry/ADCacheEvent.h b/ADAL/src/telemetry/ADCacheEvent.h new file mode 100644 index 000000000..c5ea7a649 --- /dev/null +++ b/ADAL/src/telemetry/ADCacheEvent.h @@ -0,0 +1,28 @@ +// Copyright (c) Microsoft Corporation. +// All rights reserved. +// +// This code is licensed under the MIT License. +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files(the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and / or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions : +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE. + +#import "ADDefaultEvent.h" + +@interface ADCacheEvent : ADDefaultEvent + +@end \ No newline at end of file diff --git a/ADAL/src/telemetry/ADCacheEvent.m b/ADAL/src/telemetry/ADCacheEvent.m new file mode 100644 index 000000000..b12c728d4 --- /dev/null +++ b/ADAL/src/telemetry/ADCacheEvent.m @@ -0,0 +1,28 @@ +// Copyright (c) Microsoft Corporation. +// All rights reserved. +// +// This code is licensed under the MIT License. +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files(the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and / or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions : +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE. + +#import "ADCacheEvent.h" + +@implementation ADCacheEvent + +@end \ No newline at end of file diff --git a/ADAL/src/telemetry/ADDefaultEvent.m b/ADAL/src/telemetry/ADDefaultEvent.m index 27c583092..c1e0fe82f 100644 --- a/ADAL/src/telemetry/ADDefaultEvent.m +++ b/ADAL/src/telemetry/ADDefaultEvent.m @@ -24,6 +24,11 @@ #import "ADDefaultEvent.h" #import "ADEventInterface.h" +#if !TARGET_OS_IPHONE +#include +#include +#endif + @implementation ADDefaultEvent @synthesize propertyMap = _propertyMap; @@ -118,17 +123,20 @@ - (NSArray*)defaultParameters #if TARGET_OS_IPHONE //iOS: NSString* deviceId = [[[UIDevice currentDevice] identifierForVendor] UUIDString]; - NSString* deviceName = [[UIDevice currentDevice] name]; - SET_IF_NOT_NIL(s_defaultParameters, @"device_id", [[deviceId dataUsingEncoding:NSUTF8StringEncoding] base64EncodedStringWithOptions:0]); - SET_IF_NOT_NIL(s_defaultParameters, @"device_name", [[deviceName dataUsingEncoding:NSUTF8StringEncoding] base64EncodedStringWithOptions:0]); - - SET_IF_NOT_NIL(s_defaultParameters, @"application_name", [[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleDisplayName"]); - SET_IF_NOT_NIL(s_defaultParameters, @"sdk_id", @"iOS"); + NSString* applicationName = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleDisplayName"]; + NSString* sdkId = @"iOS"; #else - SET_IF_NOT_NIL(s_defaultParameters, @"application_name", [[NSProcessInfo processInfo] processName]); - SET_IF_NOT_NIL(s_defaultParameters, @"sdk_id", @"OSX"); + CFStringRef macSerialNumber = nil; + CopySerialNumber(&macSerialNumber); + NSString* deviceId = CFBridgingRelease(macSerialNumber); + SAFE_ARC_AUTORELEASE(deviceId); + NSString* applicationName = [[NSProcessInfo processInfo] processName]; + NSString* sdkId = @"OSX"; #endif + SET_IF_NOT_NIL(s_defaultParameters, @"device_id", ([NSString stringWithFormat:@"%lu", (unsigned long)[deviceId hash]])); + SET_IF_NOT_NIL(s_defaultParameters, @"application_name", applicationName); + SET_IF_NOT_NIL(s_defaultParameters, @"sdk_id", sdkId); SET_IF_NOT_NIL(s_defaultParameters, @"application_version", [[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleVersion"]); SET_IF_NOT_NIL(s_defaultParameters, @"sdk_version", ADAL_VERSION_NSSTRING); @@ -150,5 +158,30 @@ - (void)dealloc SAFE_ARC_SUPER_DEALLOC(); } +#if !TARGET_OS_IPHONE +// Returns the serial number as a CFString. +// It is the caller's responsibility to release the returned CFString when done with it. +void CopySerialNumber(CFStringRef *serialNumber) +{ + if (serialNumber != NULL) { + *serialNumber = NULL; + + io_service_t platformExpert = IOServiceGetMatchingService(kIOMasterPortDefault, + IOServiceMatching("IOPlatformExpertDevice")); + + if (platformExpert) { + CFTypeRef serialNumberAsCFString = + IORegistryEntryCreateCFProperty(platformExpert, + CFSTR(kIOPlatformSerialNumberKey), + kCFAllocatorDefault, 0); + if (serialNumberAsCFString) { + *serialNumber = serialNumberAsCFString; + } + + IOObjectRelease(platformExpert); + } + } +} +#endif @end \ No newline at end of file diff --git a/ADAL/src/telemetry/ADHttpEvent.h b/ADAL/src/telemetry/ADHttpEvent.h new file mode 100644 index 000000000..5c8a870c1 --- /dev/null +++ b/ADAL/src/telemetry/ADHttpEvent.h @@ -0,0 +1,35 @@ +// Copyright (c) Microsoft Corporation. +// All rights reserved. +// +// This code is licensed under the MIT License. +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files(the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and / or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions : +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE. + +#import "ADDefaultEvent.h" + +@interface ADHttpEvent : ADDefaultEvent + +- (void)setHttpMethod:(NSString*)method; +- (void)setHttpPath:(NSString*)path; +- (void)setHttpResponseCode:(NSString*)code; +- (void)setHttpResponseMethod:(NSString*)method; +- (void)setHttpRequestQueryParams:(NSString*)params; +- (void)setHttpUserAgent:(NSString*)userAgent; + +@end \ No newline at end of file diff --git a/ADAL/src/telemetry/ADHttpEvent.m b/ADAL/src/telemetry/ADHttpEvent.m new file mode 100644 index 000000000..840ec7dd5 --- /dev/null +++ b/ADAL/src/telemetry/ADHttpEvent.m @@ -0,0 +1,74 @@ +// Copyright (c) Microsoft Corporation. +// All rights reserved. +// +// This code is licensed under the MIT License. +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files(the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and / or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions : +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE. + +#import "ADHttpEvent.h" + +@implementation ADHttpEvent + +- (void)setHttpMethod:(NSString*)method +{ + [self setProperty:@"http_method" value:method]; +} + +- (void)setHttpPath:(NSString*)path +{ + [self setProperty:@"http_path" value:[self scrubTenantFromUrl:path]]; +} + +- (void)setHttpResponseCode:(NSString*)code +{ + [self setProperty:@"http_response_code" value:code]; +} + +- (void)setHttpResponseMethod:(NSString*)method +{ + [self setProperty:@"http_response_method" value:method]; +} + +- (void)setHttpRequestQueryParams:(NSString*)params +{ + [self setProperty:@"request_query_params" value:params]; +} + +- (void)setHttpUserAgent:(NSString*)userAgent +{ + [self setProperty:@"user_agent" value:userAgent]; +} + +- (NSString*)scrubTenantFromUrl:(NSString*)url +{ + //Scrub the tenant domain from the url + //E.g., "https://login.windows.net/omercantest.onmicrosoft.com" + //will become "https://login.windows.net/*.onmicrosoft.com" + NSRegularExpression* regex = [NSRegularExpression regularExpressionWithPattern: @"/[^/.]+.onmicrosoft.com" + options: NSRegularExpressionCaseInsensitive + error: nil]; + + NSString* scrubbedUrl = [regex stringByReplacingMatchesInString:url + options:0 + range:NSMakeRange(0, [url length]) + withTemplate:@"/*.onmicrosoft.com"]; + return scrubbedUrl; +} + +@end \ No newline at end of file diff --git a/ADAL/src/telemetry/ADUIEvent.h b/ADAL/src/telemetry/ADUIEvent.h new file mode 100644 index 000000000..0c5f3adda --- /dev/null +++ b/ADAL/src/telemetry/ADUIEvent.h @@ -0,0 +1,30 @@ +// Copyright (c) Microsoft Corporation. +// All rights reserved. +// +// This code is licensed under the MIT License. +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files(the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and / or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions : +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE. + +#import "ADDefaultEvent.h" + +@interface ADUIEvent : ADDefaultEvent + +- (void)setLoginHint:(NSString*)hint; + +@end \ No newline at end of file diff --git a/ADAL/src/telemetry/ADUIEvent.m b/ADAL/src/telemetry/ADUIEvent.m new file mode 100644 index 000000000..206a46abd --- /dev/null +++ b/ADAL/src/telemetry/ADUIEvent.m @@ -0,0 +1,33 @@ +// Copyright (c) Microsoft Corporation. +// All rights reserved. +// +// This code is licensed under the MIT License. +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files(the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and / or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions : +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE. + +#import "ADUIEvent.h" + +@implementation ADUIEvent + +- (void)setLoginHint:(NSString*)hint +{ + [self setProperty:@"login_hint" value:[NSString stringWithFormat:@"%lu", (unsigned long)[hint hash]]]; +} + +@end \ No newline at end of file diff --git a/ADAL/tests/ADInstanceDiscoveryTests.m b/ADAL/tests/ADInstanceDiscoveryTests.m index 50a5a47c2..08a299614 100644 --- a/ADAL/tests/ADInstanceDiscoveryTests.m +++ b/ADAL/tests/ADInstanceDiscoveryTests.m @@ -165,6 +165,7 @@ -(void) testValidateAuthorityError ADInstanceDiscovery* discovery = [[ADInstanceDiscovery alloc] init]; [discovery validateAuthority:testCase correlationId:correlationId + telemetryRequestId:nil completionBlock:^(BOOL validated, ADAuthenticationError *error) { XCTAssertFalse(validated, @"\"%@\" should come back invalid.", testCase); @@ -234,6 +235,7 @@ - (void)testNormalFlow [discovery validateAuthority:@"https://login.windows-ppe.net/common" correlationId:correlationId + telemetryRequestId:nil completionBlock:^(BOOL validated, ADAuthenticationError * error) { XCTAssertTrue(validated); @@ -258,6 +260,7 @@ - (void)testNonValidatedAuthority [discovery validateAuthority:@"https://MyFakeAuthority.microsoft.com/contoso.com" correlationId:correlationId + telemetryRequestId:nil completionBlock:^(BOOL validated, ADAuthenticationError * error) { XCTAssertFalse(validated); @@ -285,6 +288,7 @@ - (void)testUnreachableServer host:@"https://login.windows.cn" trustedAuthority:@"https://SomeValidURLButNotExistentInTheNet.com" correlationId:[NSUUID UUID] + telemetryRequestId:nil completionBlock:^(BOOL validated, ADAuthenticationError *error) { XCTAssertFalse(validated); diff --git a/ADAL/tests/ADTelemetryTests.m b/ADAL/tests/ADTelemetryTests.m index 978c1a964..e1733e671 100644 --- a/ADAL/tests/ADTelemetryTests.m +++ b/ADAL/tests/ADTelemetryTests.m @@ -105,17 +105,12 @@ - (void)testDefaultEventProperties { propertyName:@"sdk_version"]); XCTAssertEqual([self getPropertyCount:[receivedEvents firstObject] propertyName:@"sdk_version"], 1); -#if TARGET_OS_IPHONE + XCTAssertNotNil([self getPropertyFromEvent:[receivedEvents firstObject] propertyName:@"device_id"]); XCTAssertEqual([self getPropertyCount:[receivedEvents firstObject] propertyName:@"device_id"], 1); - XCTAssertNotNil([self getPropertyFromEvent:[receivedEvents firstObject] - propertyName:@"device_name"]); - XCTAssertEqual([self getPropertyCount:[receivedEvents firstObject] - propertyName:@"device_name"], 1); -#endif // application_name, application_version are also default properties, // but they are not available in unit test framework, so we omit them here From 99a9ba21396e411c26fb62f17f256b45f0c23346 Mon Sep 17 00:00:00 2001 From: YONG ZENG Date: Fri, 29 Jul 2016 15:03:24 -0700 Subject: [PATCH 02/92] use bundle id as application name for telemetry --- ADAL/src/telemetry/ADDefaultEvent.m | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ADAL/src/telemetry/ADDefaultEvent.m b/ADAL/src/telemetry/ADDefaultEvent.m index c1e0fe82f..b78eb48b8 100644 --- a/ADAL/src/telemetry/ADDefaultEvent.m +++ b/ADAL/src/telemetry/ADDefaultEvent.m @@ -123,7 +123,7 @@ - (NSArray*)defaultParameters #if TARGET_OS_IPHONE //iOS: NSString* deviceId = [[[UIDevice currentDevice] identifierForVendor] UUIDString]; - NSString* applicationName = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleDisplayName"]; + NSString* applicationName = [[NSBundle mainBundle] bundleIdentifier]; NSString* sdkId = @"iOS"; #else CFStringRef macSerialNumber = nil; From e1bf905fcfd7cc6037df71e70c623ca4f6413c2e Mon Sep 17 00:00:00 2001 From: YONG ZENG Date: Tue, 2 Aug 2016 17:55:57 -0700 Subject: [PATCH 03/92] rename getInstance to sharedInstance for ADTelemetry; passing in ADAuthenticationRequest as a parameter which contains both correlation id and telemetry request id. --- ADAL/src/ADInstanceDiscovery.h | 6 +- ADAL/src/ADInstanceDiscovery.m | 35 +++--- ADAL/src/cache/ADTokenCacheAccessor.h | 15 +-- ADAL/src/cache/ADTokenCacheAccessor.m | 84 ++++++------- .../src/request/ADAcquireTokenSilentHandler.h | 6 +- .../src/request/ADAcquireTokenSilentHandler.m | 58 ++++----- .../ADAuthenticationRequest+AcquireToken.m | 24 ++-- .../request/ADAuthenticationRequest+Broker.m | 6 +- .../ADAuthenticationRequest+WebRequest.m | 4 +- ADAL/src/request/ADAuthenticationRequest.m | 2 +- ADAL/src/request/ADWebRequest.m | 4 +- ADAL/src/telemetry/ADTelemetry.h | 2 +- ADAL/src/telemetry/ADTelemetry.m | 2 +- ADAL/tests/ADInstanceDiscoveryTests.m | 15 +-- ADAL/tests/ADTelemetryTests.m | 110 +++++++++--------- 15 files changed, 165 insertions(+), 208 deletions(-) diff --git a/ADAL/src/ADInstanceDiscovery.h b/ADAL/src/ADInstanceDiscovery.h index d4ba46c88..4b3e47ffa 100644 --- a/ADAL/src/ADInstanceDiscovery.h +++ b/ADAL/src/ADInstanceDiscovery.h @@ -47,8 +47,7 @@ typedef void(^ADDiscoveryCallback)(BOOL validated, ADAuthenticationError* error) of calling support to track unexpected failures. This parameter may be null, in which case the method will generate a new UUID. @param completionBlock: the block to be called when the result is achieved.*/ - (void)validateAuthority:(NSString *)authority - correlationId:(NSUUID *)correlationId - telemetryRequestId:(NSString*)telemetryRequestId + request:(ADAuthenticationRequest*)request completionBlock:(ADDiscoveryCallback) completionBlock; /*! Takes the string and makes it canonical URL, e.g. lowercase with @@ -65,8 +64,7 @@ typedef void(^ADDiscoveryCallback)(BOOL validated, ADAuthenticationError* error) - (void)requestValidationOfAuthority:(NSString *)authority host:(NSString *)authorityHost trustedAuthority:(NSString *)trustedAuthority - correlationId:(NSUUID *)correlationId - telemetryRequestId:(NSString*)telemetryRequestId + request:(ADAuthenticationRequest*)request completionBlock:(ADDiscoveryCallback)completionBlock; @end diff --git a/ADAL/src/ADInstanceDiscovery.m b/ADAL/src/ADInstanceDiscovery.m index 6f4b7fead..e781f86f1 100644 --- a/ADAL/src/ADInstanceDiscovery.m +++ b/ADAL/src/ADInstanceDiscovery.m @@ -140,24 +140,19 @@ - (NSString*)extractHost:(NSString *)authority } - (void)validateAuthority:(NSString *)authority - correlationId:(NSUUID *)correlationId - telemetryRequestId:(NSString*)telemetryRequestId + request:(ADAuthenticationRequest*)request completionBlock:(ADDiscoveryCallback)completionBlock; { API_ENTRY; THROW_ON_NIL_ARGUMENT(completionBlock); - if (!correlationId) - { - correlationId = [NSUUID UUID];//Create one if not passed. - } - NSString* message = [NSString stringWithFormat:@"Attempting to validate the authority: %@; CorrelationId: %@", authority, [correlationId UUIDString]]; - AD_LOG_VERBOSE(@"Instance discovery", correlationId, message); + NSString* message = [NSString stringWithFormat:@"Attempting to validate the authority: %@; CorrelationId: %@", authority, [[request correlationId] UUIDString]]; + AD_LOG_VERBOSE(@"Instance discovery", [request correlationId], message); authority = [authority lowercaseString]; ADAuthenticationError* error = nil; - NSString* authorityHost = [self extractHost:authority correlationId:correlationId error:&error]; + NSString* authorityHost = [self extractHost:authority correlationId:[request correlationId] error:&error]; if (!authorityHost) { completionBlock(NO, error); @@ -175,8 +170,7 @@ - (void)validateAuthority:(NSString *)authority [self requestValidationOfAuthority:authority host:authorityHost trustedAuthority:sTrustedAuthority - correlationId:correlationId - telemetryRequestId:telemetryRequestId + request:request completionBlock:completionBlock]; } @@ -277,12 +271,11 @@ - (ADAuthenticationError *)processWebReponse:(ADWebResponse *)webResponse - (void)requestValidationOfAuthority:(NSString *)authority host:(NSString *)authorityHost trustedAuthority:(NSString *)trustedAuthority - correlationId:(NSUUID *)correlationId - telemetryRequestId:(NSString*)telemetryRequestId + request:(ADAuthenticationRequest*)request completionBlock:(ADDiscoveryCallback)completionBlock { THROW_ON_NIL_ARGUMENT(completionBlock); - THROW_ON_NIL_ARGUMENT(correlationId);//Should be set by the caller + THROW_ON_NIL_ARGUMENT([request correlationId]);//Should be set by the caller //All attempts to complete are done. Now try to validate the authorization ednpoint: NSString* authorizationEndpoint = [authority stringByAppendingString:OAUTH2_AUTHORIZE_SUFFIX]; @@ -294,10 +287,10 @@ - (void)requestValidationOfAuthority:(NSString *)authority NSString* endPoint = [NSString stringWithFormat:@"%@/%@?%@", trustedAuthority, OAUTH2_INSTANCE_DISCOVERY_SUFFIX, [request_data adURLFormEncode]]; - AD_LOG_VERBOSE(@"Authority Validation Request", correlationId, endPoint); + AD_LOG_VERBOSE(@"Authority Validation Request", [request correlationId], endPoint); ADWebRequest *webRequest = [[ADWebRequest alloc] initWithURL:[NSURL URLWithString:endPoint] - correlationId:correlationId - telemetryRequestId:telemetryRequestId]; + correlationId:[request correlationId] + telemetryRequestId:[request telemetryRequestId]]; [webRequest setIsGetRequest:YES]; [webRequest.headers setObject:@"application/json" forKey:@"Accept"]; @@ -310,22 +303,22 @@ - (void)requestValidationOfAuthority:(NSString *)authority ADAuthenticationError* adError = nil; if (error) { - AD_LOG_WARN(@"System error while making request.", correlationId, error.description); + AD_LOG_WARN(@"System error while making request.", [request correlationId], error.description); adError = [ADAuthenticationError errorFromNSError:error errorDetails:error.localizedDescription - correlationId:correlationId]; + correlationId:[request correlationId]]; } else { adError = [self processWebReponse:webResponse authorityHost:authorityHost - correlationId:correlationId]; + correlationId:[request correlationId]]; } NSString* errorDetails = [adError errorDetails]; [[ADClientMetrics getInstance] endClientMetricsRecord:endPoint startTime:startTime - correlationId:correlationId + correlationId:[request correlationId] errorDetails:errorDetails]; SAFE_ARC_RELEASE(startTime); diff --git a/ADAL/src/cache/ADTokenCacheAccessor.h b/ADAL/src/cache/ADTokenCacheAccessor.h index 8b0c259d8..8b2f395f6 100644 --- a/ADAL/src/cache/ADTokenCacheAccessor.h +++ b/ADAL/src/cache/ADTokenCacheAccessor.h @@ -43,8 +43,7 @@ - (ADTokenCacheItem *)getATRTItemForUser:(ADUserIdentifier *)identifier resource:(NSString *)resource clientId:(NSString *)clientId - correlationId:(NSUUID *)correlationId - telemetryRequestId:(NSString*)telemetryRequestId + request:(ADAuthenticationRequest*)request error:(ADAuthenticationError * __autoreleasing *)error; /*! @@ -53,8 +52,7 @@ */ - (ADTokenCacheItem *)getMRRTItemForUser:(ADUserIdentifier *)identifier clientId:(NSString *)clientId - correlationId:(NSUUID *)correlationId - telemetryRequestId:(NSString*)telemetryRequestId + request:(ADAuthenticationRequest*)request error:(ADAuthenticationError * __autoreleasing *)error; /*! @@ -63,8 +61,7 @@ */ - (ADTokenCacheItem *)getFRTItemForUser:(ADUserIdentifier *)identifier familyId:(NSString *)familyId - correlationId:(NSUUID *)correlationId - telemetryRequestId:(NSString*)telemetryRequestId + request:(ADAuthenticationRequest*)request error:(ADAuthenticationError * __autoreleasing *)error; /*! @@ -73,8 +70,7 @@ */ - (ADTokenCacheItem*)getADFSUserTokenForResource:(NSString *)resource clientId:(NSString *)clientId - correlationId:(NSUUID *)correlationId - telemetryRequestId:(NSString*)telemetryRequestId + request:(ADAuthenticationRequest*)request error:(ADAuthenticationError * __autoreleasing *)error; /*! @@ -87,7 +83,6 @@ - (void)updateCacheToResult:(ADAuthenticationResult *)result cacheItem:(ADTokenCacheItem *)cacheItem refreshToken:(NSString *)refreshToken - correlationId:(NSUUID *)correlationId - telemetryRequestId:(NSString*)telemetryRequestId; + request:(ADAuthenticationRequest*)request; @end diff --git a/ADAL/src/cache/ADTokenCacheAccessor.m b/ADAL/src/cache/ADTokenCacheAccessor.m index 450954348..ecf14d303 100644 --- a/ADAL/src/cache/ADTokenCacheAccessor.m +++ b/ADAL/src/cache/ADTokenCacheAccessor.m @@ -68,8 +68,7 @@ - (id)initWithDataSource:(id)dataSource - (ADTokenCacheItem *)getItemForUser:(ADUserIdentifier *)identifier resource:(NSString *)resource clientId:(NSString *)clientId - correlationId:(NSUUID *)correlationId - telemetryRequestId:(NSString*)telemetryRequestId + request:(ADAuthenticationRequest*)request error:(ADAuthenticationError * __autoreleasing *)error { ADTokenCacheKey* key = [ADTokenCacheKey keyWithAuthority:_authority @@ -81,15 +80,15 @@ - (ADTokenCacheItem *)getItemForUser:(ADUserIdentifier *)identifier return nil; } - [[ADTelemetry getInstance] startEvent:telemetryRequestId eventName:@"token_cache_lookup"]; + [[ADTelemetry sharedInstance] startEvent:[request telemetryRequestId] eventName:@"token_cache_lookup"]; ADTokenCacheItem* item = [_dataSource getItemWithKey:key userId:identifier.userId - correlationId:correlationId + correlationId:[request correlationId] error:error]; ADCacheEvent* event = [[ADCacheEvent alloc] initWithName:@"token_cache_lookup"]; - [[ADTelemetry getInstance] stopEvent:telemetryRequestId event:event]; + [[ADTelemetry sharedInstance] stopEvent:[request telemetryRequestId] event:event]; SAFE_ARC_RELEASE(event); return item; @@ -103,11 +102,10 @@ - (ADTokenCacheItem *)getItemForUser:(ADUserIdentifier *)identifier - (ADTokenCacheItem *)getATRTItemForUser:(ADUserIdentifier *)identifier resource:(NSString *)resource clientId:(NSString *)clientId - correlationId:(NSUUID *)correlationId - telemetryRequestId:(NSString*)telemetryRequestId + request:(ADAuthenticationRequest*)request error:(ADAuthenticationError * __autoreleasing *)error { - return [self getItemForUser:identifier resource:resource clientId:clientId correlationId:correlationId telemetryRequestId:telemetryRequestId error:error]; + return [self getItemForUser:identifier resource:resource clientId:clientId request:request error:error]; } /*! @@ -116,11 +114,10 @@ - (ADTokenCacheItem *)getATRTItemForUser:(ADUserIdentifier *)identifier */ - (ADTokenCacheItem *)getMRRTItemForUser:(ADUserIdentifier *)identifier clientId:(NSString *)clientId - correlationId:(NSUUID *)correlationId - telemetryRequestId:(NSString*)telemetryRequestId + request:(ADAuthenticationRequest*)request error:(ADAuthenticationError * __autoreleasing *)error { - return [self getItemForUser:identifier resource:nil clientId:clientId correlationId:correlationId telemetryRequestId:telemetryRequestId error:error]; + return [self getItemForUser:identifier resource:nil clientId:clientId request:request error:error]; } /*! @@ -129,19 +126,17 @@ - (ADTokenCacheItem *)getMRRTItemForUser:(ADUserIdentifier *)identifier */ - (ADTokenCacheItem *)getFRTItemForUser:(ADUserIdentifier *)identifier familyId:(NSString *)familyId - correlationId:(NSUUID *)correlationId - telemetryRequestId:(NSString*)telemetryRequestId + request:(ADAuthenticationRequest*)request error:(ADAuthenticationError * __autoreleasing *)error { NSString* fociClientId = [ADTokenCacheAccessor familyClientId:familyId]; - return [self getItemForUser:identifier resource:nil clientId:fociClientId correlationId:correlationId telemetryRequestId:telemetryRequestId error:error]; + return [self getItemForUser:identifier resource:nil clientId:fociClientId request:request error:error]; } - (ADTokenCacheItem*)getADFSUserTokenForResource:(NSString *)resource clientId:(NSString *)clientId - correlationId:(NSUUID *)correlationId - telemetryRequestId:(NSString*)telemetryRequestId + request:(ADAuthenticationRequest*)request error:(ADAuthenticationError * __autoreleasing *)error { // ADFS fix: When talking to ADFS directly we can get ATs and RTs (but not MRRTs or FRTs) without @@ -157,12 +152,12 @@ - (ADTokenCacheItem*)getADFSUserTokenForResource:(NSString *)resource return nil; } - [[ADTelemetry getInstance] startEvent:telemetryRequestId eventName:@"token_cache_lookup"]; + [[ADTelemetry sharedInstance] startEvent:[request telemetryRequestId] eventName:@"token_cache_lookup"]; - ADTokenCacheItem* item = [_dataSource getItemWithKey:key userId:@"" correlationId:correlationId error:error]; + ADTokenCacheItem* item = [_dataSource getItemWithKey:key userId:@"" correlationId:[request correlationId] error:error]; ADCacheEvent* event = [[ADCacheEvent alloc] initWithName:@"token_cache_lookup"]; - [[ADTelemetry getInstance] stopEvent:telemetryRequestId event:event]; + [[ADTelemetry sharedInstance] stopEvent:[request telemetryRequestId] event:event]; SAFE_ARC_RELEASE(event); return item; @@ -174,8 +169,7 @@ - (ADTokenCacheItem*)getADFSUserTokenForResource:(NSString *)resource - (void)updateCacheToResult:(ADAuthenticationResult *)result cacheItem:(ADTokenCacheItem *)cacheItem refreshToken:(NSString *)refreshToken - correlationId:(NSUUID *)correlationId - telemetryRequestId:(NSString*)telemetryRequestId + request:(ADAuthenticationRequest*)request { if(!result) @@ -192,14 +186,13 @@ - (void)updateCacheToResult:(ADAuthenticationResult *)result || ![ADAuthenticationContext handleNilOrEmptyAsResult:item argumentName:@"resource" authenticationResult:&result] || ![ADAuthenticationContext handleNilOrEmptyAsResult:item argumentName:@"accessToken" authenticationResult:&result]) { - AD_LOG_WARN(@"Told to update cache to an invalid token cache item", correlationId, nil); + AD_LOG_WARN(@"Told to update cache to an invalid token cache item", [request correlationId], nil); return; } [self updateCacheToItem:item MRRT:[result multiResourceRefreshToken] - correlationId:correlationId - telemetryRequestId:telemetryRequestId]; + request:request]; return; } @@ -216,22 +209,20 @@ - (void)updateCacheToResult:(ADAuthenticationResult *)result [self removeItemFromCache:cacheItem refreshToken:refreshToken - correlationId:correlationId - telemetryRequestId:telemetryRequestId + request:request error:result.error]; } - (void)updateCacheToItem:(ADTokenCacheItem *)cacheItem MRRT:(BOOL)isMRRT - correlationId:(NSUUID *)correlationId - telemetryRequestId:(NSString*)telemetryRequestId + request:(ADAuthenticationRequest*)request { - [[ADTelemetry getInstance] startEvent:telemetryRequestId eventName:@"token_cache_write"]; + [[ADTelemetry sharedInstance] startEvent:[request telemetryRequestId] eventName:@"token_cache_write"]; NSString* savedRefreshToken = cacheItem.refreshToken; if (isMRRT) { - AD_LOG_VERBOSE_F(@"Token cache store", correlationId, @"Storing multi-resource refresh token for authority: %@", _authority); + AD_LOG_VERBOSE_F(@"Token cache store", [request correlationId], @"Storing multi-resource refresh token for authority: %@", _authority); //If the server returned a multi-resource refresh token, we break //the item into two: one with the access token and no refresh token and @@ -243,7 +234,7 @@ - (void)updateCacheToItem:(ADTokenCacheItem *)cacheItem multiRefreshTokenItem.accessToken = nil; multiRefreshTokenItem.resource = nil; multiRefreshTokenItem.expiresOn = nil; - [_dataSource addOrUpdateItem:multiRefreshTokenItem correlationId:correlationId error:nil]; + [_dataSource addOrUpdateItem:multiRefreshTokenItem correlationId:[request correlationId] error:nil]; // If the item is also a Family Refesh Token (FRT) we update the FRT // as well so we have a guaranteed spot to look for the most recent FRT. @@ -253,25 +244,24 @@ - (void)updateCacheToItem:(ADTokenCacheItem *)cacheItem ADTokenCacheItem* frtItem = [multiRefreshTokenItem copy]; NSString* fociClientId = [ADTokenCacheAccessor familyClientId:familyId]; frtItem.clientId = fociClientId; - [_dataSource addOrUpdateItem:frtItem correlationId:correlationId error:nil]; + [_dataSource addOrUpdateItem:frtItem correlationId:[request correlationId] error:nil]; SAFE_ARC_RELEASE(frtItem); } SAFE_ARC_RELEASE(multiRefreshTokenItem); } - AD_LOG_VERBOSE_F(@"Token cache store", correlationId, @"Storing access token for resource: %@", cacheItem.resource); - [_dataSource addOrUpdateItem:cacheItem correlationId:correlationId error:nil]; + AD_LOG_VERBOSE_F(@"Token cache store", [request correlationId], @"Storing access token for resource: %@", cacheItem.resource); + [_dataSource addOrUpdateItem:cacheItem correlationId:[request correlationId] error:nil]; cacheItem.refreshToken = savedRefreshToken;//Restore for the result ADCacheEvent* event = [[ADCacheEvent alloc] initWithName:@"token_cache_write"]; - [[ADTelemetry getInstance] stopEvent:telemetryRequestId event:event]; + [[ADTelemetry sharedInstance] stopEvent:[request telemetryRequestId] event:event]; SAFE_ARC_RELEASE(event); } - (void)removeItemFromCache:(ADTokenCacheItem *)cacheItem refreshToken:(NSString *)refreshToken - correlationId:(NSUUID *)correlationId - telemetryRequestId:(NSString*)telemetryRequestId + request:(ADAuthenticationRequest*)request error:(ADAuthenticationError *)error { if (!cacheItem && !refreshToken) @@ -279,22 +269,22 @@ - (void)removeItemFromCache:(ADTokenCacheItem *)cacheItem return; } - [[ADTelemetry getInstance] startEvent:telemetryRequestId eventName:@"token_cache_delete_token"]; + [[ADTelemetry sharedInstance] startEvent:[request telemetryRequestId] eventName:@"token_cache_delete_token"]; BOOL removed = NO; //The refresh token didn't work. We need to tombstone this refresh item in the cache. ADTokenCacheKey* exactKey = [cacheItem extractKey:nil]; if (exactKey) { - ADTokenCacheItem* existing = [_dataSource getItemWithKey:exactKey userId:cacheItem.userInformation.userId correlationId:correlationId error:nil]; + ADTokenCacheItem* existing = [_dataSource getItemWithKey:exactKey userId:cacheItem.userInformation.userId correlationId:[request correlationId] error:nil]; if ([refreshToken isEqualToString:existing.refreshToken])//If still there, attempt to remove { - AD_LOG_VERBOSE_F(@"Token cache store", correlationId, @"Tombstoning cache for resource: %@", cacheItem.resource); + AD_LOG_VERBOSE_F(@"Token cache store", [request correlationId], @"Tombstoning cache for resource: %@", cacheItem.resource); //update tombstone property before update the tombstone in cache - [existing makeTombstone:@{ @"correlationId" : [correlationId UUIDString], + [existing makeTombstone:@{ @"correlationId" : [[request correlationId] UUIDString], @"errorDetails" : [error errorDetails], @"protocolCode" : [error protocolCode] }]; - [_dataSource addOrUpdateItem:existing correlationId:correlationId error:nil]; + [_dataSource addOrUpdateItem:existing correlationId:[request correlationId] error:nil]; removed = YES; } } @@ -308,21 +298,21 @@ - (void)removeItemFromCache:(ADTokenCacheItem *)cacheItem error:nil]; if (broadKey) { - ADTokenCacheItem* broadItem = [_dataSource getItemWithKey:broadKey userId:cacheItem.userInformation.userId correlationId:correlationId error:nil]; + ADTokenCacheItem* broadItem = [_dataSource getItemWithKey:broadKey userId:cacheItem.userInformation.userId correlationId:[request correlationId] error:nil]; if (broadItem && [refreshToken isEqualToString:broadItem.refreshToken])//Remove if still there { - AD_LOG_VERBOSE_F(@"Token cache store", correlationId, @"Tombstoning multi-resource refresh token for authority: %@", _authority); + AD_LOG_VERBOSE_F(@"Token cache store", [request correlationId], @"Tombstoning multi-resource refresh token for authority: %@", _authority); //update tombstone property before update the tombstone in cache - [broadItem makeTombstone:@{ @"correlationId" : [correlationId UUIDString], + [broadItem makeTombstone:@{ @"correlationId" : [[request correlationId] UUIDString], @"errorDetails" : [error errorDetails], @"protocolCode" : [error protocolCode] }]; - [_dataSource addOrUpdateItem:broadItem correlationId:correlationId error:nil]; + [_dataSource addOrUpdateItem:broadItem correlationId:[request correlationId] error:nil]; } } } ADCacheEvent* event = [[ADCacheEvent alloc] initWithName:@"token_cache_delete_token"]; - [[ADTelemetry getInstance] stopEvent:telemetryRequestId event:event]; + [[ADTelemetry sharedInstance] stopEvent:[request telemetryRequestId] event:event]; SAFE_ARC_RELEASE(event); } diff --git a/ADAL/src/request/ADAcquireTokenSilentHandler.h b/ADAL/src/request/ADAcquireTokenSilentHandler.h index 058482087..1389cc665 100644 --- a/ADAL/src/request/ADAcquireTokenSilentHandler.h +++ b/ADAL/src/request/ADAcquireTokenSilentHandler.h @@ -33,9 +33,8 @@ NSString* _clientId; NSString* _redirectUri; ADUserIdentifier* _identifier; - NSUUID* _correlationId; - NSString* _telemetryRequestId; ADTokenCacheAccessor* _tokenCache; + ADAuthenticationRequest* _request; ADTokenCacheItem* _mrrtItem; ADTokenCacheItem* _extendedLifetimeAccessTokenItem; //store valid AT in terms of ext_expires_in (if find any) @@ -53,10 +52,9 @@ clientId:(NSString *)clientId redirectUri:(NSString *)redirectUri identifier:(ADUserIdentifier *)identifier - correlationId:(NSUUID *)correlationId tokenCache:(ADTokenCacheAccessor *)tokenCache extendedLifetime:(BOOL)extendedLifetime - telemetryRequestId:(NSString*)telemetryRequestId + request:(ADAuthenticationRequest*)request completionBlock:(ADAuthenticationCallback)completionBlock; @end diff --git a/ADAL/src/request/ADAcquireTokenSilentHandler.m b/ADAL/src/request/ADAcquireTokenSilentHandler.m index 56b83aec5..437960ca0 100644 --- a/ADAL/src/request/ADAcquireTokenSilentHandler.m +++ b/ADAL/src/request/ADAcquireTokenSilentHandler.m @@ -40,10 +40,9 @@ + (void)acquireTokenSilentForAuthority:(NSString *)authority clientId:(NSString *)clientId redirectUri:(NSString *)redirectUri identifier:(ADUserIdentifier *)identifier - correlationId:(NSUUID *)correlationId tokenCache:(ADTokenCacheAccessor *)tokenCache extendedLifetime:(BOOL)extendedLifetime - telemetryRequestId:(NSString*)telemetryRequestId + request:(ADAuthenticationRequest*)request completionBlock:(ADAuthenticationCallback)completionBlock { ADAcquireTokenSilentHandler* handler = [ADAcquireTokenSilentHandler new]; @@ -63,10 +62,8 @@ + (void)acquireTokenSilentForAuthority:(NSString *)authority SAFE_ARC_RETAIN(identifier); handler->_tokenCache = tokenCache; SAFE_ARC_RETAIN(tokenCache); - handler->_correlationId = correlationId; - SAFE_ARC_RETAIN(correlationId); - handler->_telemetryRequestId = telemetryRequestId; - SAFE_ARC_RETAIN(telemetryRequestId); + handler->_request = request; + SAFE_ARC_RETAIN(request); [handler getAccessToken:^(ADAuthenticationResult *result) { @@ -80,11 +77,11 @@ + (void)acquireTokenSilentForAuthority:(NSString *)authority [ADLogger logToken:handler->_extendedLifetimeAccessTokenItem.accessToken tokenType:@"access token (extended lifetime)" expiresOn:handler->_extendedLifetimeAccessTokenItem.expiresOn - correlationId:handler->_correlationId]; + correlationId:[handler->_request correlationId]]; result = [ADAuthenticationResult resultFromTokenCacheItem:handler->_extendedLifetimeAccessTokenItem multiResourceRefreshToken:NO - correlationId:handler->_correlationId]; + correlationId:[handler->_request correlationId]]; [result setExtendedLifeTimeToken:YES]; } @@ -109,11 +106,8 @@ - (void)dealloc SAFE_ARC_RELEASE(_identifier); _identifier = nil; - SAFE_ARC_RELEASE(_correlationId); - _correlationId = nil; - - SAFE_ARC_RELEASE(_telemetryRequestId); - _telemetryRequestId = nil; + SAFE_ARC_RELEASE(_request); + _request = nil; SAFE_ARC_RELEASE(_tokenCache); _tokenCache = nil; @@ -139,9 +133,9 @@ - (void)acquireTokenByRefreshToken:(NSString*)refreshToken cacheItem:(ADTokenCacheItem*)cacheItem completionBlock:(ADAuthenticationCallback)completionBlock { - AD_LOG_VERBOSE_F(@"Attempting to acquire an access token from refresh token.", _correlationId, @"Resource: %@", _resource); + AD_LOG_VERBOSE_F(@"Attempting to acquire an access token from refresh token.", [_request correlationId], @"Resource: %@", _resource); - [ADLogger logToken:refreshToken tokenType:@"refresh token" expiresOn:nil correlationId:_correlationId]; + [ADLogger logToken:refreshToken tokenType:@"refresh token" expiresOn:nil correlationId:[_request correlationId]]; //Fill the data for the token refreshing: NSMutableDictionary *request_data = nil; @@ -173,8 +167,8 @@ - (void)acquireTokenByRefreshToken:(NSString*)refreshToken ADWebAuthRequest* webReq = [[ADWebAuthRequest alloc] initWithURL:[NSURL URLWithString:[_authority stringByAppendingString:OAUTH2_TOKEN_SUFFIX]] - correlationId:_correlationId - telemetryRequestId:_telemetryRequestId]; + correlationId:[_request correlationId] + telemetryRequestId:[_request telemetryRequestId]]; [webReq setRequestDictionary:request_data]; AD_LOG_INFO_F(@"Attempting to acquire an access token from refresh token", nil, @"clientId: '%@'; resource: '%@';", _clientId, _resource); [webReq sendRequest:^(NSDictionary *response) @@ -188,14 +182,13 @@ - (void)acquireTokenByRefreshToken:(NSString*)refreshToken resultItem.authority = _authority; - ADAuthenticationResult *result = [resultItem processTokenResponse:response fromRefresh:YES requestCorrelationId:_correlationId]; + ADAuthenticationResult *result = [resultItem processTokenResponse:response fromRefresh:YES requestCorrelationId:[_request correlationId]]; if (cacheItem)//The request came from the cache item, update it: { [_tokenCache updateCacheToResult:result cacheItem:resultItem refreshToken:refreshToken - correlationId:_correlationId - telemetryRequestId:_telemetryRequestId]; + request:_request]; } result = [ADAuthenticationContext updateResult:result toUser:_identifier];//Verify the user (just in case) // @@ -272,7 +265,7 @@ - (void)acquireTokenWithItem:(ADTokenCacheItem *)item msg = [NSString stringWithFormat:@"Acquire Token with Refresh Token %@.", resultStatus]; } - AD_LOG_INFO_F(msg, _correlationId, @"clientId: '%@'; resource: '%@';", _clientId, _resource); + AD_LOG_INFO_F(msg, [_request correlationId], @"clientId: '%@'; resource: '%@';", _clientId, _resource); if ([ADAuthenticationContext isFinalResult:result]) { @@ -299,13 +292,12 @@ - (void)getAccessToken:(ADAuthenticationCallback)completionBlock ADTokenCacheItem* item = [_tokenCache getATRTItemForUser:_identifier resource:_resource clientId:_clientId - correlationId:_correlationId - telemetryRequestId:_telemetryRequestId + request:_request error:&error]; // If some error ocurred during the cache lookup then we need to fail out right away. if (!item && error) { - completionBlock([ADAuthenticationResult resultFromError:error correlationId:_correlationId]); + completionBlock([ADAuthenticationResult resultFromError:error correlationId:[_request correlationId]]); return; } @@ -313,10 +305,10 @@ - (void)getAccessToken:(ADAuthenticationCallback)completionBlock // and we need to check the unknown user ADFS token as well if (!item) { - item = [_tokenCache getADFSUserTokenForResource:_resource clientId:_clientId correlationId:_correlationId telemetryRequestId:_telemetryRequestId error:&error]; + item = [_tokenCache getADFSUserTokenForResource:_resource clientId:_clientId request:_request error:&error]; if (!item && error) { - completionBlock([ADAuthenticationResult resultFromError:error correlationId:_correlationId]); + completionBlock([ADAuthenticationResult resultFromError:error correlationId:[_request correlationId]]); return; } @@ -332,8 +324,8 @@ - (void)getAccessToken:(ADAuthenticationCallback)completionBlock // If we have a good (non-expired) access token then return it right away if (item.accessToken && !item.isExpired) { - [ADLogger logToken:item.accessToken tokenType:@"access token" expiresOn:item.expiresOn correlationId:_correlationId]; - ADAuthenticationResult* result = [ADAuthenticationResult resultFromTokenCacheItem:item multiResourceRefreshToken:NO correlationId:_correlationId]; + [ADLogger logToken:item.accessToken tokenType:@"access token" expiresOn:item.expiresOn correlationId:[_request correlationId]]; + ADAuthenticationResult* result = [ADAuthenticationResult resultFromTokenCacheItem:item multiResourceRefreshToken:NO correlationId:[_request correlationId]]; completionBlock(result); return; } @@ -358,7 +350,7 @@ - (void)tryRT:(ADTokenCacheItem*)item completionBlock:(ADAuthenticationCallback) if (!item.isExtendedLifetimeValid && ![_tokenCache.dataSource removeItem:item error:&error] && error) { // If we failed to remove the item with an error, then return that error right away - completionBlock([ADAuthenticationResult resultFromError:error correlationId:_correlationId]); + completionBlock([ADAuthenticationResult resultFromError:error correlationId:[_request correlationId]]); return; } @@ -395,10 +387,10 @@ - (void)tryMRRT:(ADAuthenticationCallback)completionBlock // If we don't have an item yet see if we can pull one out of the cache if (!_mrrtItem) { - _mrrtItem = [_tokenCache getMRRTItemForUser:_identifier clientId:_clientId correlationId:_correlationId telemetryRequestId:_telemetryRequestId error:&error]; + _mrrtItem = [_tokenCache getMRRTItemForUser:_identifier clientId:_clientId request:_request error:&error]; if (!_mrrtItem && error) { - completionBlock([ADAuthenticationResult resultFromError:error correlationId:_correlationId]); + completionBlock([ADAuthenticationResult resultFromError:error correlationId:[_request correlationId]]); return; } } @@ -456,10 +448,10 @@ - (void)tryFRT:(NSString*)familyId completionBlock:(ADAuthenticationCallback)com _attemptedFRT = YES; ADAuthenticationError* error = nil; - ADTokenCacheItem* frtItem = [_tokenCache getFRTItemForUser:_identifier familyId:familyId correlationId:_correlationId telemetryRequestId:_telemetryRequestId error:&error]; + ADTokenCacheItem* frtItem = [_tokenCache getFRTItemForUser:_identifier familyId:familyId request:_request error:&error]; if (!frtItem && error) { - completionBlock([ADAuthenticationResult resultFromError:error correlationId:_correlationId]); + completionBlock([ADAuthenticationResult resultFromError:error correlationId:[_request correlationId]]); return; } diff --git a/ADAL/src/request/ADAuthenticationRequest+AcquireToken.m b/ADAL/src/request/ADAuthenticationRequest+AcquireToken.m index d1616de4d..a43c533c9 100644 --- a/ADAL/src/request/ADAuthenticationRequest+AcquireToken.m +++ b/ADAL/src/request/ADAuthenticationRequest+AcquireToken.m @@ -44,12 +44,12 @@ - (void)acquireToken:(ADAuthenticationCallback)completionBlock AD_REQUEST_CHECK_ARGUMENT(_resource); [self ensureRequest]; - [[ADTelemetry getInstance] startEvent:[self telemetryRequestId] eventName:@"acauire_token_call"]; + [[ADTelemetry sharedInstance] startEvent:[self telemetryRequestId] eventName:@"acauire_token_call"]; ADAuthenticationCallback requestCompletion = ^void(ADAuthenticationResult *result) { ADAPIEvent* event = [[ADAPIEvent alloc] initWithName:@"acauire_token_call"]; [self fillTelemetryForAcquireToken:event result:result]; - [[ADTelemetry getInstance] stopEvent:[self telemetryRequestId] event:event]; + [[ADTelemetry sharedInstance] stopEvent:[self telemetryRequestId] event:event]; SAFE_ARC_RELEASE(event); completionBlock(result); @@ -88,16 +88,15 @@ - (void)acquireToken:(ADAuthenticationCallback)completionBlock return; } - [[ADTelemetry getInstance] startEvent:[self telemetryRequestId] eventName:@"authority_validation"]; + [[ADTelemetry sharedInstance] startEvent:[self telemetryRequestId] eventName:@"authority_validation"]; [[ADInstanceDiscovery sharedInstance] validateAuthority:_context.authority - correlationId:_correlationId - telemetryRequestId:_telemetryRequestId + request:self completionBlock:^(BOOL validated, ADAuthenticationError *error) { ADAPIEvent* event = [[ADAPIEvent alloc] initWithName:@"authority_validation"]; [event setAuthorityValidationStatus:validated ? @"YES" : @"NO"]; [event setAuthority:_context.authority]; - [[ADTelemetry getInstance] stopEvent:[self telemetryRequestId] event:event]; + [[ADTelemetry sharedInstance] stopEvent:[self telemetryRequestId] event:event]; SAFE_ARC_RELEASE(event); if (error) @@ -123,10 +122,9 @@ - (void)validatedAcquireToken:(ADAuthenticationCallback)completionBlock clientId:_clientId redirectUri:_redirectUri identifier:_identifier - correlationId:_correlationId tokenCache:_tokenCache extendedLifetime:_context.extendedLifetimeEnabled - telemetryRequestId:_telemetryRequestId + request:self completionBlock:^(ADAuthenticationResult *result) { if ([ADAuthenticationContext isFinalResult:result]) @@ -206,11 +204,11 @@ - (void)requestToken:(ADAuthenticationCallback)completionBlock __block BOOL silentRequest = _allowSilent; // Get the code first: - [[ADTelemetry getInstance] startEvent:[self telemetryRequestId] eventName:@"authorization_code"]; + [[ADTelemetry sharedInstance] startEvent:[self telemetryRequestId] eventName:@"authorization_code"]; [self requestCode:^(NSString * code, ADAuthenticationError *error) { ADAPIEvent* event = [[ADAPIEvent alloc] initWithName:@"authorization_code"]; - [[ADTelemetry getInstance] stopEvent:[self telemetryRequestId] event:event]; + [[ADTelemetry sharedInstance] stopEvent:[self telemetryRequestId] event:event]; SAFE_ARC_RELEASE(event); if (error) @@ -235,17 +233,17 @@ - (void)requestToken:(ADAuthenticationCallback)completionBlock } else { - [[ADTelemetry getInstance] startEvent:[self telemetryRequestId] eventName:@"token_grant"]; + [[ADTelemetry sharedInstance] startEvent:[self telemetryRequestId] eventName:@"token_grant"]; [self requestTokenByCode:code completionBlock:^(ADAuthenticationResult *result) { ADAPIEvent* event = [[ADAPIEvent alloc] initWithName:@"token_grant"]; - [[ADTelemetry getInstance] stopEvent:[self telemetryRequestId] event:event]; + [[ADTelemetry sharedInstance] stopEvent:[self telemetryRequestId] event:event]; SAFE_ARC_RELEASE(event); if (AD_SUCCEEDED == result.status) { - [_tokenCache updateCacheToResult:result cacheItem:nil refreshToken:nil correlationId:_correlationId telemetryRequestId:_telemetryRequestId]; + [_tokenCache updateCacheToResult:result cacheItem:nil refreshToken:nil request:self]; result = [ADAuthenticationContext updateResult:result toUser:_identifier]; } completionBlock(result); diff --git a/ADAL/src/request/ADAuthenticationRequest+Broker.m b/ADAL/src/request/ADAuthenticationRequest+Broker.m index 2880dc39e..53b16d3cd 100644 --- a/ADAL/src/request/ADAuthenticationRequest+Broker.m +++ b/ADAL/src/request/ADAuthenticationRequest+Broker.m @@ -155,7 +155,7 @@ + (void)internalHandleBrokerResponse:(NSURL *)response ADTokenCacheAccessor* cache = [[ADTokenCacheAccessor alloc] initWithDataSource:[ADKeychainTokenCache defaultKeychainCache] authority:result.tokenCacheItem.authority]; - [cache updateCacheToResult:result cacheItem:nil refreshToken:nil correlationId:nil telemetryRequestId:nil]; + [cache updateCacheToResult:result cacheItem:nil refreshToken:nil request:nil]; NSString* userId = [[[result tokenCacheItem] userInformation] userId]; [ADAuthenticationContext updateResult:result @@ -216,14 +216,14 @@ - (void)callBroker:(ADAuthenticationCallback)completionBlock return; } - [[ADTelemetry getInstance] startEvent:[self telemetryRequestId] eventName:@"launch_broker"]; + [[ADTelemetry sharedInstance] startEvent:[self telemetryRequestId] eventName:@"launch_broker"]; void(^requestCompletion)(ADAuthenticationResult* result) = ^void(ADAuthenticationResult* result) { [self releaseUserInterationLock]; // Release the lock when completion block is called. ADBrokerEvent* event = [[ADBrokerEvent alloc] initWithName:@"launch_broker"]; - [[ADTelemetry getInstance] stopEvent:[self telemetryRequestId] event:event]; + [[ADTelemetry sharedInstance] stopEvent:[self telemetryRequestId] event:event]; completionBlock(result); }; diff --git a/ADAL/src/request/ADAuthenticationRequest+WebRequest.m b/ADAL/src/request/ADAuthenticationRequest+WebRequest.m index d04a0d3c2..c653392ca 100755 --- a/ADAL/src/request/ADAuthenticationRequest+WebRequest.m +++ b/ADAL/src/request/ADAuthenticationRequest+WebRequest.m @@ -179,12 +179,12 @@ - (NSString*)generateQueryStringForRequestType:(NSString*)requestType - (void)launchWebView:(NSString*)startUrl completionBlock:(void (^)(ADAuthenticationError*, NSURL*))completionBlock { - [[ADTelemetry getInstance] startEvent:[self telemetryRequestId] eventName:@"launch_web_view"]; + [[ADTelemetry sharedInstance] startEvent:[self telemetryRequestId] eventName:@"launch_web_view"]; void(^requestCompletion)(ADAuthenticationError *error, NSURL *end) = ^void(ADAuthenticationError *error, NSURL *end) { ADUIEvent* event = [[ADUIEvent alloc] initWithName:@"launch_web_view"]; [self fillTelemetryUIEvent:event]; - [[ADTelemetry getInstance] stopEvent:[self telemetryRequestId] event:event]; + [[ADTelemetry sharedInstance] stopEvent:[self telemetryRequestId] event:event]; completionBlock(error, end); }; diff --git a/ADAL/src/request/ADAuthenticationRequest.m b/ADAL/src/request/ADAuthenticationRequest.m index 8ac98c9c3..5182026ad 100644 --- a/ADAL/src/request/ADAuthenticationRequest.m +++ b/ADAL/src/request/ADAuthenticationRequest.m @@ -309,7 +309,7 @@ - (NSString*)telemetryRequestId { if (_telemetryRequestId == nil) { - _telemetryRequestId = [[ADTelemetry getInstance] registerNewRequest]; + _telemetryRequestId = [[ADTelemetry sharedInstance] registerNewRequest]; SAFE_ARC_RETAIN(_telemetryRequestId); } diff --git a/ADAL/src/request/ADWebRequest.m b/ADAL/src/request/ADWebRequest.m index dc2a8f5f6..be63073e7 100644 --- a/ADAL/src/request/ADWebRequest.m +++ b/ADAL/src/request/ADWebRequest.m @@ -181,7 +181,7 @@ - (void)resend - (void)send { - [[ADTelemetry getInstance] startEvent:_telemetryRequestId eventName:@"http_request"]; + [[ADTelemetry sharedInstance] startEvent:_telemetryRequestId eventName:@"http_request"]; [_requestHeaders addEntriesFromDictionary:[ADLogger adalId]]; //Correlation id: @@ -336,7 +336,7 @@ - (void)stopTelemetryEvent:(NSError *)error [event setHttpResponseCode:[NSString stringWithFormat: @"%ld", (long)[response statusCode]]]; } - [[ADTelemetry getInstance] stopEvent:_telemetryRequestId event:event]; + [[ADTelemetry sharedInstance] stopEvent:_telemetryRequestId event:event]; SAFE_ARC_RELEASE(event); } diff --git a/ADAL/src/telemetry/ADTelemetry.h b/ADAL/src/telemetry/ADTelemetry.h index 2c07708a5..2a90e53ec 100644 --- a/ADAL/src/telemetry/ADTelemetry.h +++ b/ADAL/src/telemetry/ADTelemetry.h @@ -58,7 +58,7 @@ /*! Get a singleton instance of ADTelemetry. */ -+ (ADTelemetry*)getInstance; ++ (ADTelemetry*)sharedInstance; /*! Register a telemetry dispatcher for receiving telemetry events. diff --git a/ADAL/src/telemetry/ADTelemetry.m b/ADAL/src/telemetry/ADTelemetry.m index cf6f1ec1b..f9ccd02d6 100644 --- a/ADAL/src/telemetry/ADTelemetry.m +++ b/ADAL/src/telemetry/ADTelemetry.m @@ -48,7 +48,7 @@ -(id) initInternal return self; } -+ (ADTelemetry*)getInstance ++ (ADTelemetry*)sharedInstance { static dispatch_once_t once; static ADTelemetry* singleton = nil; diff --git a/ADAL/tests/ADInstanceDiscoveryTests.m b/ADAL/tests/ADInstanceDiscoveryTests.m index 08a299614..c3856b8a5 100644 --- a/ADAL/tests/ADInstanceDiscoveryTests.m +++ b/ADAL/tests/ADInstanceDiscoveryTests.m @@ -158,14 +158,12 @@ -(void) testValidateAuthorityError NSArray* cases = @[@"http://invalidscheme.com", @"https://Invalid URL 2305 8 -0238460-820-386"]; - NSUUID* correlationId = [NSUUID UUID]; for (NSString* testCase in cases) { ADInstanceDiscovery* discovery = [[ADInstanceDiscovery alloc] init]; [discovery validateAuthority:testCase - correlationId:correlationId - telemetryRequestId:nil + request:nil completionBlock:^(BOOL validated, ADAuthenticationError *error) { XCTAssertFalse(validated, @"\"%@\" should come back invalid.", testCase); @@ -229,13 +227,11 @@ - (void)testCanonicalizeAuthority - (void)testNormalFlow { ADInstanceDiscovery* discovery = [[ADInstanceDiscovery alloc] init]; - NSUUID* correlationId = [NSUUID UUID]; [ADTestURLConnection addResponse:[ADTestURLResponse responseValidAuthority:@"https://login.windows-ppe.net/common"]]; [discovery validateAuthority:@"https://login.windows-ppe.net/common" - correlationId:correlationId - telemetryRequestId:nil + request:[ADAuthenticationRequest new] completionBlock:^(BOOL validated, ADAuthenticationError * error) { XCTAssertTrue(validated); @@ -254,13 +250,11 @@ - (void)testNonValidatedAuthority { [self adSetLogTolerance:ADAL_LOG_LEVEL_ERROR]; ADInstanceDiscovery* discovery = [[ADInstanceDiscovery alloc] init]; - NSUUID* correlationId = [NSUUID UUID]; [ADTestURLConnection addResponse:[ADTestURLResponse responseInvalidAuthority:@"https://myfakeauthority.microsoft.com/contoso.com"]]; [discovery validateAuthority:@"https://MyFakeAuthority.microsoft.com/contoso.com" - correlationId:correlationId - telemetryRequestId:nil + request:[ADAuthenticationRequest new] completionBlock:^(BOOL validated, ADAuthenticationError * error) { XCTAssertFalse(validated); @@ -287,8 +281,7 @@ - (void)testUnreachableServer [discovery requestValidationOfAuthority:@"https://login.windows.cn/MSOpenTechBV.onmicrosoft.com" host:@"https://login.windows.cn" trustedAuthority:@"https://SomeValidURLButNotExistentInTheNet.com" - correlationId:[NSUUID UUID] - telemetryRequestId:nil + request:[ADAuthenticationRequest new] completionBlock:^(BOOL validated, ADAuthenticationError *error) { XCTAssertFalse(validated); diff --git a/ADAL/tests/ADTelemetryTests.m b/ADAL/tests/ADTelemetryTests.m index e1733e671..b4dff1dcd 100644 --- a/ADAL/tests/ADTelemetryTests.m +++ b/ADAL/tests/ADTelemetryTests.m @@ -81,15 +81,15 @@ - (void)testDefaultEventProperties { }]; // register the dispatcher - [[ADTelemetry getInstance] registerDispatcher:dispatcher aggregationRequired:NO]; + [[ADTelemetry sharedInstance] registerDispatcher:dispatcher aggregationRequired:NO]; // generate telemetry event - NSString* requestId = [[ADTelemetry getInstance] registerNewRequest]; - [[ADTelemetry getInstance] startEvent:requestId eventName:@"testEvent"]; - [[ADTelemetry getInstance] stopEvent:requestId + NSString* requestId = [[ADTelemetry sharedInstance] registerNewRequest]; + [[ADTelemetry sharedInstance] startEvent:requestId eventName:@"testEvent"]; + [[ADTelemetry sharedInstance] stopEvent:requestId event:[[ADDefaultEvent alloc] initWithName:@"testEvent"]]; - [[ADTelemetry getInstance] flush]; + [[ADTelemetry sharedInstance] flush]; // there should be 1 telemetry event recorded as we only generated one above XCTAssertEqual([receivedEvents count], 1); @@ -128,22 +128,22 @@ - (void)testSequentialEvents { }]; // register the dispatcher - [[ADTelemetry getInstance] registerDispatcher:dispatcher aggregationRequired:NO]; + [[ADTelemetry sharedInstance] registerDispatcher:dispatcher aggregationRequired:NO]; // generate telemetry event 1 - NSString* requestId = [[ADTelemetry getInstance] registerNewRequest]; - [[ADTelemetry getInstance] startEvent:requestId eventName:@"testEvent1"]; - [[ADTelemetry getInstance] stopEvent:requestId + NSString* requestId = [[ADTelemetry sharedInstance] registerNewRequest]; + [[ADTelemetry sharedInstance] startEvent:requestId eventName:@"testEvent1"]; + [[ADTelemetry sharedInstance] stopEvent:requestId event:[[ADDefaultEvent alloc] initWithName:@"testEvent1"]]; // generate telemetry event 2 - [[ADTelemetry getInstance] startEvent:requestId eventName:@"testEvent2"]; + [[ADTelemetry sharedInstance] startEvent:requestId eventName:@"testEvent2"]; ADDefaultEvent* event2 = [[ADDefaultEvent alloc] initWithName:@"testEvent2"]; [event2 setProperty:@"customized_property" value:@"customized_value"]; - [[ADTelemetry getInstance] stopEvent:requestId + [[ADTelemetry sharedInstance] stopEvent:requestId event:event2]; - [[ADTelemetry getInstance] flush]; + [[ADTelemetry sharedInstance] flush]; // there should be 2 telemetry events recorded as we generated two XCTAssertEqual([receivedEvents count], 2); @@ -198,22 +198,22 @@ - (void)testSequentialEventsWithAggregation { }]; // register the dispatcher with aggregation - [[ADTelemetry getInstance] registerDispatcher:dispatcher aggregationRequired:YES]; + [[ADTelemetry sharedInstance] registerDispatcher:dispatcher aggregationRequired:YES]; // generate telemetry event 1 - NSString* requestId = [[ADTelemetry getInstance] registerNewRequest]; - [[ADTelemetry getInstance] startEvent:requestId eventName:@"testEvent1"]; - [[ADTelemetry getInstance] stopEvent:requestId + NSString* requestId = [[ADTelemetry sharedInstance] registerNewRequest]; + [[ADTelemetry sharedInstance] startEvent:requestId eventName:@"testEvent1"]; + [[ADTelemetry sharedInstance] stopEvent:requestId event:[[ADDefaultEvent alloc] initWithName:@"testEvent1"]]; // generate telemetry event 2 - [[ADTelemetry getInstance] startEvent:requestId eventName:@"testEvent2"]; + [[ADTelemetry sharedInstance] startEvent:requestId eventName:@"testEvent2"]; ADDefaultEvent* event2 = [[ADDefaultEvent alloc] initWithName:@"testEvent2"]; [event2 setProperty:@"customized_property" value:@"customized_value"]; - [[ADTelemetry getInstance] stopEvent:requestId + [[ADTelemetry sharedInstance] stopEvent:requestId event:event2]; - [[ADTelemetry getInstance] flush]; + [[ADTelemetry sharedInstance] flush]; // there should be 1 telemetry event recorded as aggregation flag is on XCTAssertEqual([receivedEvents count], 1); @@ -246,22 +246,22 @@ - (void)testNestedEvents { }]; // register the dispatcher - [[ADTelemetry getInstance] registerDispatcher:dispatcher aggregationRequired:NO]; + [[ADTelemetry sharedInstance] registerDispatcher:dispatcher aggregationRequired:NO]; // generate telemetry event1 nested with event2 - NSString* requestId = [[ADTelemetry getInstance] registerNewRequest]; - [[ADTelemetry getInstance] startEvent:requestId eventName:@"testEvent1"]; + NSString* requestId = [[ADTelemetry sharedInstance] registerNewRequest]; + [[ADTelemetry sharedInstance] startEvent:requestId eventName:@"testEvent1"]; - [[ADTelemetry getInstance] startEvent:requestId eventName:@"testEvent2"]; + [[ADTelemetry sharedInstance] startEvent:requestId eventName:@"testEvent2"]; ADDefaultEvent* event2 = [[ADDefaultEvent alloc] initWithName:@"testEvent2"]; [event2 setProperty:@"customized_property" value:@"customized_value"]; - [[ADTelemetry getInstance] stopEvent:requestId + [[ADTelemetry sharedInstance] stopEvent:requestId event:event2]; - [[ADTelemetry getInstance] stopEvent:requestId + [[ADTelemetry sharedInstance] stopEvent:requestId event:[[ADDefaultEvent alloc] initWithName:@"testEvent1"]]; - [[ADTelemetry getInstance] flush]; + [[ADTelemetry sharedInstance] flush]; // there should be 2 telemetry events recorded as we generated two XCTAssertEqual([receivedEvents count], 2); @@ -319,22 +319,22 @@ - (void)testNestedEventsWithAggregation { }]; // register the dispatcher with aggregation - [[ADTelemetry getInstance] registerDispatcher:dispatcher aggregationRequired:YES]; + [[ADTelemetry sharedInstance] registerDispatcher:dispatcher aggregationRequired:YES]; // generate telemetry event1 nested with event2 - NSString* requestId = [[ADTelemetry getInstance] registerNewRequest]; - [[ADTelemetry getInstance] startEvent:requestId eventName:@"testEvent1"]; + NSString* requestId = [[ADTelemetry sharedInstance] registerNewRequest]; + [[ADTelemetry sharedInstance] startEvent:requestId eventName:@"testEvent1"]; - [[ADTelemetry getInstance] startEvent:requestId eventName:@"testEvent2"]; + [[ADTelemetry sharedInstance] startEvent:requestId eventName:@"testEvent2"]; ADDefaultEvent* event2 = [[ADDefaultEvent alloc] initWithName:@"testEvent2"]; [event2 setProperty:@"customized_property" value:@"customized_value"]; - [[ADTelemetry getInstance] stopEvent:requestId + [[ADTelemetry sharedInstance] stopEvent:requestId event:event2]; - [[ADTelemetry getInstance] stopEvent:requestId + [[ADTelemetry sharedInstance] stopEvent:requestId event:[[ADDefaultEvent alloc] initWithName:@"testEvent1"]]; - [[ADTelemetry getInstance] flush]; + [[ADTelemetry sharedInstance] flush]; // there should be 1 telemetry event recorded as aggregation flag is ON XCTAssertEqual([receivedEvents count], 1); @@ -365,29 +365,29 @@ - (void)testComplexEvents { }]; // register the dispatcher - [[ADTelemetry getInstance] registerDispatcher:dispatcher aggregationRequired:NO]; + [[ADTelemetry sharedInstance] registerDispatcher:dispatcher aggregationRequired:NO]; // generate telemetry event1 nested with event2 - NSString* requestId = [[ADTelemetry getInstance] registerNewRequest]; - [[ADTelemetry getInstance] startEvent:requestId eventName:@"testEvent1"]; + NSString* requestId = [[ADTelemetry sharedInstance] registerNewRequest]; + [[ADTelemetry sharedInstance] startEvent:requestId eventName:@"testEvent1"]; - [[ADTelemetry getInstance] startEvent:requestId eventName:@"testEvent2"]; + [[ADTelemetry sharedInstance] startEvent:requestId eventName:@"testEvent2"]; - [[ADTelemetry getInstance] startEvent:requestId eventName:@"testEvent3"]; - [[ADTelemetry getInstance] stopEvent:requestId + [[ADTelemetry sharedInstance] startEvent:requestId eventName:@"testEvent3"]; + [[ADTelemetry sharedInstance] stopEvent:requestId event:[[ADDefaultEvent alloc] initWithName:@"testEvent3"]]; - [[ADTelemetry getInstance] stopEvent:requestId + [[ADTelemetry sharedInstance] stopEvent:requestId event:[[ADDefaultEvent alloc] initWithName:@"testEvent2"]]; - [[ADTelemetry getInstance] stopEvent:requestId + [[ADTelemetry sharedInstance] stopEvent:requestId event:[[ADDefaultEvent alloc] initWithName:@"testEvent1"]]; - [[ADTelemetry getInstance] startEvent:requestId eventName:@"testEvent4"]; - [[ADTelemetry getInstance] stopEvent:requestId + [[ADTelemetry sharedInstance] startEvent:requestId eventName:@"testEvent4"]; + [[ADTelemetry sharedInstance] stopEvent:requestId event:[[ADDefaultEvent alloc] initWithName:@"testEvent4"]]; - [[ADTelemetry getInstance] flush]; + [[ADTelemetry sharedInstance] flush]; // there should be 4 telemetry events recorded as we generated four XCTAssertEqual([receivedEvents count], 4); @@ -469,29 +469,29 @@ - (void)testComplexEventsWithAggregation { }]; // register the dispatcher - [[ADTelemetry getInstance] registerDispatcher:dispatcher aggregationRequired:YES]; + [[ADTelemetry sharedInstance] registerDispatcher:dispatcher aggregationRequired:YES]; // generate telemetry event1 nested with event2 - NSString* requestId = [[ADTelemetry getInstance] registerNewRequest]; - [[ADTelemetry getInstance] startEvent:requestId eventName:@"testEvent1"]; + NSString* requestId = [[ADTelemetry sharedInstance] registerNewRequest]; + [[ADTelemetry sharedInstance] startEvent:requestId eventName:@"testEvent1"]; - [[ADTelemetry getInstance] startEvent:requestId eventName:@"testEvent2"]; + [[ADTelemetry sharedInstance] startEvent:requestId eventName:@"testEvent2"]; - [[ADTelemetry getInstance] startEvent:requestId eventName:@"testEvent3"]; - [[ADTelemetry getInstance] stopEvent:requestId + [[ADTelemetry sharedInstance] startEvent:requestId eventName:@"testEvent3"]; + [[ADTelemetry sharedInstance] stopEvent:requestId event:[[ADDefaultEvent alloc] initWithName:@"testEvent3"]]; - [[ADTelemetry getInstance] stopEvent:requestId + [[ADTelemetry sharedInstance] stopEvent:requestId event:[[ADDefaultEvent alloc] initWithName:@"testEvent2"]]; - [[ADTelemetry getInstance] stopEvent:requestId + [[ADTelemetry sharedInstance] stopEvent:requestId event:[[ADDefaultEvent alloc] initWithName:@"testEvent1"]]; - [[ADTelemetry getInstance] startEvent:requestId eventName:@"testEvent4"]; - [[ADTelemetry getInstance] stopEvent:requestId + [[ADTelemetry sharedInstance] startEvent:requestId eventName:@"testEvent4"]; + [[ADTelemetry sharedInstance] stopEvent:requestId event:[[ADDefaultEvent alloc] initWithName:@"testEvent4"]]; - [[ADTelemetry getInstance] flush]; + [[ADTelemetry sharedInstance] flush]; // there should be 1 telemetry events recorded as aggregation flag is ON XCTAssertEqual([receivedEvents count], 1); From c68d3ae8c927ed395c803376af8599befb80d3ed Mon Sep 17 00:00:00 2001 From: YONG ZENG Date: Thu, 4 Aug 2016 09:29:15 -0700 Subject: [PATCH 04/92] Refactor by adding ADRequestParameters class --- ADAL/ADAL.xcodeproj/project.pbxproj | 10 ++ ADAL/src/ADAuthenticationContext+Internal.h | 2 +- ADAL/src/ADAuthenticationContext.m | 13 +- ADAL/src/ADAuthenticationParameters.m | 2 +- ADAL/src/ADInstanceDiscovery.h | 4 +- ADAL/src/ADInstanceDiscovery.m | 27 ++-- ADAL/src/ADRequestParameters.h | 57 ++++++++ ADAL/src/ADRequestParameters.m | 101 ++++++++++++++ ADAL/src/cache/ADTokenCacheAccessor.h | 10 +- ADAL/src/cache/ADTokenCacheAccessor.m | 74 +++++----- .../src/request/ADAcquireTokenSilentHandler.h | 19 +-- .../src/request/ADAcquireTokenSilentHandler.m | 132 +++++++----------- ...ADAuthenticationRequest+AcquireAssertion.m | 10 +- .../ADAuthenticationRequest+AcquireToken.m | 61 ++++---- .../request/ADAuthenticationRequest+Broker.m | 62 ++++---- .../ADAuthenticationRequest+WebRequest.m | 48 +++---- ADAL/src/request/ADAuthenticationRequest.h | 15 +- ADAL/src/request/ADAuthenticationRequest.m | 59 +++----- ADAL/src/request/ADWebAuthRequest.m | 5 +- ADAL/src/request/ADWebRequest.h | 3 +- ADAL/src/request/ADWebRequest.m | 7 +- ADAL/src/telemetry/ADTelemetry+Internal.h | 2 + ADAL/src/telemetry/ADTelemetry.h | 5 - ADAL/src/telemetry/ADTelemetry.m | 22 +-- ADAL/tests/ADInstanceDiscoveryTests.m | 16 ++- 25 files changed, 427 insertions(+), 339 deletions(-) create mode 100644 ADAL/src/ADRequestParameters.h create mode 100644 ADAL/src/ADRequestParameters.m diff --git a/ADAL/ADAL.xcodeproj/project.pbxproj b/ADAL/ADAL.xcodeproj/project.pbxproj index 0c85c1ee6..4737e27b9 100755 --- a/ADAL/ADAL.xcodeproj/project.pbxproj +++ b/ADAL/ADAL.xcodeproj/project.pbxproj @@ -60,6 +60,9 @@ 601BEE341C6DCB0B004AA8C1 /* ADWebAuthControllerTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 601BEE331C6DCB0B004AA8C1 /* ADWebAuthControllerTests.m */; }; 601BEE351C6DCB0B004AA8C1 /* ADWebAuthControllerTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 601BEE331C6DCB0B004AA8C1 /* ADWebAuthControllerTests.m */; }; 6071B5E41C14C0B0006F6CC2 /* ADTestURLConnection.m in Sources */ = {isa = PBXBuildFile; fileRef = 6071B5E31C14C0B0006F6CC2 /* ADTestURLConnection.m */; }; + 60D2F3FF1D524F7A008725D9 /* ADRequestParameters.h in Headers */ = {isa = PBXBuildFile; fileRef = 60D2F3FE1D524F7A008725D9 /* ADRequestParameters.h */; }; + 60D2F4011D531F16008725D9 /* ADRequestParameters.m in Sources */ = {isa = PBXBuildFile; fileRef = 60D2F4001D531F16008725D9 /* ADRequestParameters.m */; }; + 60D2F4021D531F16008725D9 /* ADRequestParameters.m in Sources */ = {isa = PBXBuildFile; fileRef = 60D2F4001D531F16008725D9 /* ADRequestParameters.m */; }; 8B0965AE17F25770002BDFB8 /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 8B0965AD17F25770002BDFB8 /* Foundation.framework */; }; 8B0965BC17F25770002BDFB8 /* XCTest.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 8B0965BB17F25770002BDFB8 /* XCTest.framework */; }; 8B0965BD17F25770002BDFB8 /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 8B0965AD17F25770002BDFB8 /* Foundation.framework */; }; @@ -463,6 +466,8 @@ 601BEE331C6DCB0B004AA8C1 /* ADWebAuthControllerTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ADWebAuthControllerTests.m; sourceTree = ""; }; 6071B5E21C14C0B0006F6CC2 /* ADTestURLConnection.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ADTestURLConnection.h; sourceTree = ""; }; 6071B5E31C14C0B0006F6CC2 /* ADTestURLConnection.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ADTestURLConnection.m; sourceTree = ""; }; + 60D2F3FE1D524F7A008725D9 /* ADRequestParameters.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ADRequestParameters.h; sourceTree = ""; }; + 60D2F4001D531F16008725D9 /* ADRequestParameters.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ADRequestParameters.m; sourceTree = ""; }; 8B0965AA17F25770002BDFB8 /* libADALiOS.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = libADALiOS.a; sourceTree = BUILT_PRODUCTS_DIR; }; 8B0965AD17F25770002BDFB8 /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = System/Library/Frameworks/Foundation.framework; sourceTree = SDKROOT; }; 8B0965BA17F25770002BDFB8 /* ADALiOSTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = ADALiOSTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; @@ -788,6 +793,8 @@ 97A522481A1A752D001D77CE /* ADClientMetrics.m */, 97A522511A1A89C4001D77CE /* ADClientMetrics.h */, D6FB3E3B1B30D3630032F883 /* ADUserIdentifier.m */, + 60D2F3FE1D524F7A008725D9 /* ADRequestParameters.h */, + 60D2F4001D531F16008725D9 /* ADRequestParameters.m */, 9453C3771C58017F006B9E79 /* broker */, 9453C3181C57FB91006B9E79 /* cache */, 9453C37F1C5820B1006B9E79 /* request */, @@ -1204,6 +1211,7 @@ D68040331D22F686007A61AC /* ADWebAuthResponse.h in Headers */, 9453C44A1C586485006B9E79 /* ADRegistrationInformation.h in Headers */, 9453C4261C586462006B9E79 /* ADTokenCacheKey.h in Headers */, + 60D2F3FF1D524F7A008725D9 /* ADRequestParameters.h in Headers */, 94DD18D21C5AC8DE00F80C62 /* ADAuthenticationParameters.h in Headers */, 9453C4081C586456006B9E79 /* ADAuthenticationContext+Internal.h in Headers */, 9453C42A1C58646D006B9E79 /* ADAuthenticationRequest+AcquireAssertion.h in Headers */, @@ -1470,6 +1478,7 @@ 9453C35B1C580143006B9E79 /* ADRegistrationInformation.m in Sources */, 9453C36D1C580157006B9E79 /* ADHelpers.m in Sources */, 8BB8346218074CFA007F9F0D /* ADAuthenticationParameters.m in Sources */, + 60D2F4011D531F16008725D9 /* ADRequestParameters.m in Sources */, 6010EDF51D47B2CE00B62072 /* ADCacheEvent.m in Sources */, 946818A61C59B7F100CA0378 /* ADWebAuthController.m in Sources */, 9453C3221C57FBCB006B9E79 /* UIAlertView+Additions.m in Sources */, @@ -1598,6 +1607,7 @@ 6010EDF61D47B2CE00B62072 /* ADCacheEvent.m in Sources */, 9453C4351C58646D006B9E79 /* ADWebResponse.m in Sources */, 9453C4171C586456006B9E79 /* ADOAuth2Constants.m in Sources */, + 60D2F4021D531F16008725D9 /* ADRequestParameters.m in Sources */, 9453C4101C586456006B9E79 /* ADAuthenticationResult.m in Sources */, 9453C4091C586456006B9E79 /* ADAuthenticationContext+Internal.m in Sources */, D6F0951C1CDC2BC300D28FC2 /* ADWebAuthRequest.m in Sources */, diff --git a/ADAL/src/ADAuthenticationContext+Internal.h b/ADAL/src/ADAuthenticationContext+Internal.h index 85a92ce99..5ab51e159 100644 --- a/ADAL/src/ADAuthenticationContext+Internal.h +++ b/ADAL/src/ADAuthenticationContext+Internal.h @@ -32,7 +32,7 @@ } #define CHECK_FOR_NIL(_val) \ - if (!_val) { completionBlock([ADAuthenticationResult resultFromError:[ADAuthenticationError unexpectedInternalError:@"" #_val " is nil!" correlationId:_correlationId]]); return; } + if (!_val) { completionBlock([ADAuthenticationResult resultFromError:[ADAuthenticationError unexpectedInternalError:@"" #_val " is nil!" correlationId:[_requestParams correlationId]]]); return; } #import "ADAL_Internal.h" diff --git a/ADAL/src/ADAuthenticationContext.m b/ADAL/src/ADAuthenticationContext.m index 44b7ee13a..f88055fc8 100755 --- a/ADAL/src/ADAuthenticationContext.m +++ b/ADAL/src/ADAuthenticationContext.m @@ -24,6 +24,7 @@ #import "ADAuthenticationSettings.h" #import "ADInstanceDiscovery.h" #import "ADTokenCache+Internal.h" +#import "ADRequestParameters.h" #if TARGET_OS_IPHONE #import "ADKeychainTokenCache+Internal.h" #endif @@ -170,10 +171,16 @@ - (ADAuthenticationRequest*)requestWithRedirectString:(NSString*)redirectUri { ADAuthenticationError* error = nil; + ADRequestParameters* requestParams = [[ADRequestParameters alloc] init]; + [requestParams setAuthority:_authority]; + [requestParams setResource:resource]; + [requestParams setClientId:clientId]; + [requestParams setRedirectUri:redirectUri]; + [requestParams setTokenCache:_tokenCacheStore]; + [requestParams setExtendedLifetime:_extendedLifetimeEnabled]; + ADAuthenticationRequest* request = [ADAuthenticationRequest requestWithContext:self - redirectUri:redirectUri - clientId:clientId - resource:resource + requestParams:requestParams error:&error]; if (!request) diff --git a/ADAL/src/ADAuthenticationParameters.m b/ADAL/src/ADAuthenticationParameters.m index b80e58919..acd9b9638 100644 --- a/ADAL/src/ADAuthenticationParameters.m +++ b/ADAL/src/ADAuthenticationParameters.m @@ -90,7 +90,7 @@ + (void)parametersFromResourceUrl:(NSURL*)resourceUrl return; } - ADWebRequest* request = [[ADWebRequest alloc] initWithURL:resourceUrl correlationId:nil telemetryRequestId:nil]; + ADWebRequest* request = [[ADWebRequest alloc] initWithURL:resourceUrl requestParams:nil]; [request setIsGetRequest:YES]; AD_LOG_VERBOSE_F(@"Starting authorization challenge request", nil, @"Resource: %@", resourceUrl); diff --git a/ADAL/src/ADInstanceDiscovery.h b/ADAL/src/ADInstanceDiscovery.h index 4b3e47ffa..d7ee7f255 100644 --- a/ADAL/src/ADInstanceDiscovery.h +++ b/ADAL/src/ADInstanceDiscovery.h @@ -47,7 +47,7 @@ typedef void(^ADDiscoveryCallback)(BOOL validated, ADAuthenticationError* error) of calling support to track unexpected failures. This parameter may be null, in which case the method will generate a new UUID. @param completionBlock: the block to be called when the result is achieved.*/ - (void)validateAuthority:(NSString *)authority - request:(ADAuthenticationRequest*)request + requestParams:(ADRequestParameters*)requestParams completionBlock:(ADDiscoveryCallback) completionBlock; /*! Takes the string and makes it canonical URL, e.g. lowercase with @@ -64,7 +64,7 @@ typedef void(^ADDiscoveryCallback)(BOOL validated, ADAuthenticationError* error) - (void)requestValidationOfAuthority:(NSString *)authority host:(NSString *)authorityHost trustedAuthority:(NSString *)trustedAuthority - request:(ADAuthenticationRequest*)request + requestParams:(ADRequestParameters*)requestParams completionBlock:(ADDiscoveryCallback)completionBlock; @end diff --git a/ADAL/src/ADInstanceDiscovery.m b/ADAL/src/ADInstanceDiscovery.m index e781f86f1..b6a3416a3 100644 --- a/ADAL/src/ADInstanceDiscovery.m +++ b/ADAL/src/ADInstanceDiscovery.m @@ -140,19 +140,19 @@ - (NSString*)extractHost:(NSString *)authority } - (void)validateAuthority:(NSString *)authority - request:(ADAuthenticationRequest*)request + requestParams:(ADRequestParameters*)requestParams completionBlock:(ADDiscoveryCallback)completionBlock; { API_ENTRY; THROW_ON_NIL_ARGUMENT(completionBlock); - NSString* message = [NSString stringWithFormat:@"Attempting to validate the authority: %@; CorrelationId: %@", authority, [[request correlationId] UUIDString]]; - AD_LOG_VERBOSE(@"Instance discovery", [request correlationId], message); + NSString* message = [NSString stringWithFormat:@"Attempting to validate the authority: %@; CorrelationId: %@", authority, [[requestParams correlationId] UUIDString]]; + AD_LOG_VERBOSE(@"Instance discovery", [requestParams correlationId], message); authority = [authority lowercaseString]; ADAuthenticationError* error = nil; - NSString* authorityHost = [self extractHost:authority correlationId:[request correlationId] error:&error]; + NSString* authorityHost = [self extractHost:authority correlationId:[requestParams correlationId] error:&error]; if (!authorityHost) { completionBlock(NO, error); @@ -170,7 +170,7 @@ - (void)validateAuthority:(NSString *)authority [self requestValidationOfAuthority:authority host:authorityHost trustedAuthority:sTrustedAuthority - request:request + requestParams:requestParams completionBlock:completionBlock]; } @@ -271,11 +271,11 @@ - (ADAuthenticationError *)processWebReponse:(ADWebResponse *)webResponse - (void)requestValidationOfAuthority:(NSString *)authority host:(NSString *)authorityHost trustedAuthority:(NSString *)trustedAuthority - request:(ADAuthenticationRequest*)request + requestParams:(ADRequestParameters*)requestParams completionBlock:(ADDiscoveryCallback)completionBlock { THROW_ON_NIL_ARGUMENT(completionBlock); - THROW_ON_NIL_ARGUMENT([request correlationId]);//Should be set by the caller + THROW_ON_NIL_ARGUMENT([requestParams correlationId]);//Should be set by the caller //All attempts to complete are done. Now try to validate the authorization ednpoint: NSString* authorizationEndpoint = [authority stringByAppendingString:OAUTH2_AUTHORIZE_SUFFIX]; @@ -287,10 +287,9 @@ - (void)requestValidationOfAuthority:(NSString *)authority NSString* endPoint = [NSString stringWithFormat:@"%@/%@?%@", trustedAuthority, OAUTH2_INSTANCE_DISCOVERY_SUFFIX, [request_data adURLFormEncode]]; - AD_LOG_VERBOSE(@"Authority Validation Request", [request correlationId], endPoint); + AD_LOG_VERBOSE(@"Authority Validation Request", [requestParams correlationId], endPoint); ADWebRequest *webRequest = [[ADWebRequest alloc] initWithURL:[NSURL URLWithString:endPoint] - correlationId:[request correlationId] - telemetryRequestId:[request telemetryRequestId]]; + requestParams:requestParams]; [webRequest setIsGetRequest:YES]; [webRequest.headers setObject:@"application/json" forKey:@"Accept"]; @@ -303,22 +302,22 @@ - (void)requestValidationOfAuthority:(NSString *)authority ADAuthenticationError* adError = nil; if (error) { - AD_LOG_WARN(@"System error while making request.", [request correlationId], error.description); + AD_LOG_WARN(@"System error while making request.", [requestParams correlationId], error.description); adError = [ADAuthenticationError errorFromNSError:error errorDetails:error.localizedDescription - correlationId:[request correlationId]]; + correlationId:[requestParams correlationId]]; } else { adError = [self processWebReponse:webResponse authorityHost:authorityHost - correlationId:[request correlationId]]; + correlationId:[requestParams correlationId]]; } NSString* errorDetails = [adError errorDetails]; [[ADClientMetrics getInstance] endClientMetricsRecord:endPoint startTime:startTime - correlationId:[request correlationId] + correlationId:[requestParams correlationId] errorDetails:errorDetails]; SAFE_ARC_RELEASE(startTime); diff --git a/ADAL/src/ADRequestParameters.h b/ADAL/src/ADRequestParameters.h new file mode 100644 index 000000000..16d3a8ff9 --- /dev/null +++ b/ADAL/src/ADRequestParameters.h @@ -0,0 +1,57 @@ +// Copyright (c) Microsoft Corporation. +// All rights reserved. +// +// This code is licensed under the MIT License. +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files(the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and / or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions : +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE. + +@interface ADRequestParameters : NSObject +{ + NSString* _authority; + NSString* _resource; + NSString* _clientId; + NSString* _redirectUri; + ADUserIdentifier* _identifier; + ADTokenCacheAccessor* _tokenCache; + BOOL _extendedLifetime; + NSUUID* _correlationId; + NSString* _telemetryRequestId; +} + +@property (retain, nonatomic) NSString* authority; +@property (retain, nonatomic) NSString* resource; +@property (retain, nonatomic) NSString* clientId; +@property (retain, nonatomic) NSString* redirectUri; +@property (retain, nonatomic) ADUserIdentifier* identifier; +@property (retain, nonatomic) ADTokenCacheAccessor* tokenCache; +@property BOOL extendedLifetime; +@property (retain, nonatomic) NSUUID* correlationId; +@property (retain, nonatomic) NSString* telemetryRequestId; + +- (id)initWithAuthority:(NSString *)authorityParam + resource:(NSString *)resourceParam + clientId:(NSString *)clientIdParam + redirectUri:(NSString *)redirectUriParam + identifier:(ADUserIdentifier *)identifierParam + tokenCache:(ADTokenCacheAccessor *)tokenCacheParam + extendedLifetime:(BOOL)extendedLifetimeParam + correlationId:(NSUUID *)correlationIdParam + telemetryRequestId:(NSString *)telemetryRequestIdParam; + +@end diff --git a/ADAL/src/ADRequestParameters.m b/ADAL/src/ADRequestParameters.m new file mode 100644 index 000000000..e0070718f --- /dev/null +++ b/ADAL/src/ADRequestParameters.m @@ -0,0 +1,101 @@ +// Copyright (c) Microsoft Corporation. +// All rights reserved. +// +// This code is licensed under the MIT License. +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files(the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and / or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions : +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE. + +#import "ADRequestParameters.h" + +@implementation ADRequestParameters + +@synthesize authority = _authority; +@synthesize resource = _resource; +@synthesize clientId = _clientId; +@synthesize redirectUri = _redirectUri; +@synthesize identifier = _identifier; +@synthesize tokenCache = _tokenCache; +@synthesize extendedLifetime = _extendedLifetime; +@synthesize correlationId = _correlationId; +@synthesize telemetryRequestId = _telemetryRequestId; + +- (id)initWithAuthority:(NSString *)authority + resource:(NSString *)resource + clientId:(NSString *)clientId + redirectUri:(NSString *)redirectUri + identifier:(ADUserIdentifier *)identifier + tokenCache:(ADTokenCacheAccessor *)tokenCache + extendedLifetime:(BOOL)extendedLifetime + correlationId:(NSUUID *)correlationId + telemetryRequestId:(NSString *)telemetryRequestId +{ + if (!(self = [super init])) + { + return nil; + } + + [self setAuthority:authority]; + [self setResource:resource]; + [self setClientId:clientId]; + [self setRedirectUri:redirectUri]; + [self setIdentifier:identifier]; + [self setTokenCache:tokenCache]; + [self setExtendedLifetime:extendedLifetime]; + [self setCorrelationId:correlationId]; + [self setTelemetryRequestId:telemetryRequestId]; + + return self; +} + +- (void)setResource:(NSString *)resource +{ + SAFE_ARC_RELEASE(_resource); + _resource = [resource adTrimmedString]; + SAFE_ARC_RETAIN(_resource); +} + +- (void)setClientId:(NSString *)clientId +{ + SAFE_ARC_RELEASE(_clientId); + _clientId = [clientId adTrimmedString]; + SAFE_ARC_RETAIN(_clientId); +} + +- (void)setRedirectUri:(NSString *)redirectUri +{ + SAFE_ARC_RELEASE(_redirectUri); + _redirectUri = [redirectUri adTrimmedString]; + SAFE_ARC_RETAIN(_redirectUri); +} + +- (void)dealloc +{ + self.authority = nil; + self.resource = nil; + self.clientId = nil; + self.redirectUri = nil; + self.identifier = nil; + self.tokenCache = nil; + self.correlationId = nil; + self.telemetryRequestId = nil; + + SAFE_ARC_SUPER_DEALLOC(); +} + +@end \ No newline at end of file diff --git a/ADAL/src/cache/ADTokenCacheAccessor.h b/ADAL/src/cache/ADTokenCacheAccessor.h index 8b2f395f6..8a9229f8d 100644 --- a/ADAL/src/cache/ADTokenCacheAccessor.h +++ b/ADAL/src/cache/ADTokenCacheAccessor.h @@ -43,7 +43,7 @@ - (ADTokenCacheItem *)getATRTItemForUser:(ADUserIdentifier *)identifier resource:(NSString *)resource clientId:(NSString *)clientId - request:(ADAuthenticationRequest*)request + requestParams:(ADRequestParameters*)requestParams error:(ADAuthenticationError * __autoreleasing *)error; /*! @@ -52,7 +52,7 @@ */ - (ADTokenCacheItem *)getMRRTItemForUser:(ADUserIdentifier *)identifier clientId:(NSString *)clientId - request:(ADAuthenticationRequest*)request + requestParams:(ADRequestParameters*)requestParams error:(ADAuthenticationError * __autoreleasing *)error; /*! @@ -61,7 +61,7 @@ */ - (ADTokenCacheItem *)getFRTItemForUser:(ADUserIdentifier *)identifier familyId:(NSString *)familyId - request:(ADAuthenticationRequest*)request + requestParams:(ADRequestParameters*)requestParams error:(ADAuthenticationError * __autoreleasing *)error; /*! @@ -70,7 +70,7 @@ */ - (ADTokenCacheItem*)getADFSUserTokenForResource:(NSString *)resource clientId:(NSString *)clientId - request:(ADAuthenticationRequest*)request + requestParams:(ADRequestParameters*)requestParams error:(ADAuthenticationError * __autoreleasing *)error; /*! @@ -83,6 +83,6 @@ - (void)updateCacheToResult:(ADAuthenticationResult *)result cacheItem:(ADTokenCacheItem *)cacheItem refreshToken:(NSString *)refreshToken - request:(ADAuthenticationRequest*)request; + requestParams:(ADRequestParameters*)requestParams; @end diff --git a/ADAL/src/cache/ADTokenCacheAccessor.m b/ADAL/src/cache/ADTokenCacheAccessor.m index ecf14d303..436f3e2f1 100644 --- a/ADAL/src/cache/ADTokenCacheAccessor.m +++ b/ADAL/src/cache/ADTokenCacheAccessor.m @@ -68,7 +68,7 @@ - (id)initWithDataSource:(id)dataSource - (ADTokenCacheItem *)getItemForUser:(ADUserIdentifier *)identifier resource:(NSString *)resource clientId:(NSString *)clientId - request:(ADAuthenticationRequest*)request + requestParams:(ADRequestParameters*)requestParams error:(ADAuthenticationError * __autoreleasing *)error { ADTokenCacheKey* key = [ADTokenCacheKey keyWithAuthority:_authority @@ -80,15 +80,15 @@ - (ADTokenCacheItem *)getItemForUser:(ADUserIdentifier *)identifier return nil; } - [[ADTelemetry sharedInstance] startEvent:[request telemetryRequestId] eventName:@"token_cache_lookup"]; + [[ADTelemetry sharedInstance] startEvent:[requestParams telemetryRequestId] eventName:@"token_cache_lookup"]; ADTokenCacheItem* item = [_dataSource getItemWithKey:key userId:identifier.userId - correlationId:[request correlationId] + correlationId:[requestParams correlationId] error:error]; ADCacheEvent* event = [[ADCacheEvent alloc] initWithName:@"token_cache_lookup"]; - [[ADTelemetry sharedInstance] stopEvent:[request telemetryRequestId] event:event]; + [[ADTelemetry sharedInstance] stopEvent:[requestParams telemetryRequestId] event:event]; SAFE_ARC_RELEASE(event); return item; @@ -102,10 +102,10 @@ - (ADTokenCacheItem *)getItemForUser:(ADUserIdentifier *)identifier - (ADTokenCacheItem *)getATRTItemForUser:(ADUserIdentifier *)identifier resource:(NSString *)resource clientId:(NSString *)clientId - request:(ADAuthenticationRequest*)request + requestParams:(ADRequestParameters*)requestParams error:(ADAuthenticationError * __autoreleasing *)error { - return [self getItemForUser:identifier resource:resource clientId:clientId request:request error:error]; + return [self getItemForUser:identifier resource:resource clientId:clientId requestParams:requestParams error:error]; } /*! @@ -114,10 +114,10 @@ - (ADTokenCacheItem *)getATRTItemForUser:(ADUserIdentifier *)identifier */ - (ADTokenCacheItem *)getMRRTItemForUser:(ADUserIdentifier *)identifier clientId:(NSString *)clientId - request:(ADAuthenticationRequest*)request + requestParams:(ADRequestParameters*)requestParams error:(ADAuthenticationError * __autoreleasing *)error { - return [self getItemForUser:identifier resource:nil clientId:clientId request:request error:error]; + return [self getItemForUser:identifier resource:nil clientId:clientId requestParams:requestParams error:error]; } /*! @@ -126,17 +126,17 @@ - (ADTokenCacheItem *)getMRRTItemForUser:(ADUserIdentifier *)identifier */ - (ADTokenCacheItem *)getFRTItemForUser:(ADUserIdentifier *)identifier familyId:(NSString *)familyId - request:(ADAuthenticationRequest*)request + requestParams:(ADRequestParameters*)requestParams error:(ADAuthenticationError * __autoreleasing *)error { NSString* fociClientId = [ADTokenCacheAccessor familyClientId:familyId]; - return [self getItemForUser:identifier resource:nil clientId:fociClientId request:request error:error]; + return [self getItemForUser:identifier resource:nil clientId:fociClientId requestParams:requestParams error:error]; } - (ADTokenCacheItem*)getADFSUserTokenForResource:(NSString *)resource clientId:(NSString *)clientId - request:(ADAuthenticationRequest*)request + requestParams:(ADRequestParameters*)requestParams error:(ADAuthenticationError * __autoreleasing *)error { // ADFS fix: When talking to ADFS directly we can get ATs and RTs (but not MRRTs or FRTs) without @@ -152,12 +152,12 @@ - (ADTokenCacheItem*)getADFSUserTokenForResource:(NSString *)resource return nil; } - [[ADTelemetry sharedInstance] startEvent:[request telemetryRequestId] eventName:@"token_cache_lookup"]; + [[ADTelemetry sharedInstance] startEvent:[requestParams telemetryRequestId] eventName:@"token_cache_lookup"]; - ADTokenCacheItem* item = [_dataSource getItemWithKey:key userId:@"" correlationId:[request correlationId] error:error]; + ADTokenCacheItem* item = [_dataSource getItemWithKey:key userId:@"" correlationId:[requestParams correlationId] error:error]; ADCacheEvent* event = [[ADCacheEvent alloc] initWithName:@"token_cache_lookup"]; - [[ADTelemetry sharedInstance] stopEvent:[request telemetryRequestId] event:event]; + [[ADTelemetry sharedInstance] stopEvent:[requestParams telemetryRequestId] event:event]; SAFE_ARC_RELEASE(event); return item; @@ -169,7 +169,7 @@ - (ADTokenCacheItem*)getADFSUserTokenForResource:(NSString *)resource - (void)updateCacheToResult:(ADAuthenticationResult *)result cacheItem:(ADTokenCacheItem *)cacheItem refreshToken:(NSString *)refreshToken - request:(ADAuthenticationRequest*)request + requestParams:(ADRequestParameters*)requestParams { if(!result) @@ -186,13 +186,13 @@ - (void)updateCacheToResult:(ADAuthenticationResult *)result || ![ADAuthenticationContext handleNilOrEmptyAsResult:item argumentName:@"resource" authenticationResult:&result] || ![ADAuthenticationContext handleNilOrEmptyAsResult:item argumentName:@"accessToken" authenticationResult:&result]) { - AD_LOG_WARN(@"Told to update cache to an invalid token cache item", [request correlationId], nil); + AD_LOG_WARN(@"Told to update cache to an invalid token cache item", [requestParams correlationId], nil); return; } [self updateCacheToItem:item MRRT:[result multiResourceRefreshToken] - request:request]; + requestParams:requestParams]; return; } @@ -209,20 +209,20 @@ - (void)updateCacheToResult:(ADAuthenticationResult *)result [self removeItemFromCache:cacheItem refreshToken:refreshToken - request:request + requestParams:requestParams error:result.error]; } - (void)updateCacheToItem:(ADTokenCacheItem *)cacheItem MRRT:(BOOL)isMRRT - request:(ADAuthenticationRequest*)request + requestParams:(ADRequestParameters*)requestParams { - [[ADTelemetry sharedInstance] startEvent:[request telemetryRequestId] eventName:@"token_cache_write"]; + [[ADTelemetry sharedInstance] startEvent:[requestParams telemetryRequestId] eventName:@"token_cache_write"]; NSString* savedRefreshToken = cacheItem.refreshToken; if (isMRRT) { - AD_LOG_VERBOSE_F(@"Token cache store", [request correlationId], @"Storing multi-resource refresh token for authority: %@", _authority); + AD_LOG_VERBOSE_F(@"Token cache store", [requestParams correlationId], @"Storing multi-resource refresh token for authority: %@", _authority); //If the server returned a multi-resource refresh token, we break //the item into two: one with the access token and no refresh token and @@ -234,7 +234,7 @@ - (void)updateCacheToItem:(ADTokenCacheItem *)cacheItem multiRefreshTokenItem.accessToken = nil; multiRefreshTokenItem.resource = nil; multiRefreshTokenItem.expiresOn = nil; - [_dataSource addOrUpdateItem:multiRefreshTokenItem correlationId:[request correlationId] error:nil]; + [_dataSource addOrUpdateItem:multiRefreshTokenItem correlationId:[requestParams correlationId] error:nil]; // If the item is also a Family Refesh Token (FRT) we update the FRT // as well so we have a guaranteed spot to look for the most recent FRT. @@ -244,24 +244,24 @@ - (void)updateCacheToItem:(ADTokenCacheItem *)cacheItem ADTokenCacheItem* frtItem = [multiRefreshTokenItem copy]; NSString* fociClientId = [ADTokenCacheAccessor familyClientId:familyId]; frtItem.clientId = fociClientId; - [_dataSource addOrUpdateItem:frtItem correlationId:[request correlationId] error:nil]; + [_dataSource addOrUpdateItem:frtItem correlationId:[requestParams correlationId] error:nil]; SAFE_ARC_RELEASE(frtItem); } SAFE_ARC_RELEASE(multiRefreshTokenItem); } - AD_LOG_VERBOSE_F(@"Token cache store", [request correlationId], @"Storing access token for resource: %@", cacheItem.resource); - [_dataSource addOrUpdateItem:cacheItem correlationId:[request correlationId] error:nil]; + AD_LOG_VERBOSE_F(@"Token cache store", [requestParams correlationId], @"Storing access token for resource: %@", cacheItem.resource); + [_dataSource addOrUpdateItem:cacheItem correlationId:[requestParams correlationId] error:nil]; cacheItem.refreshToken = savedRefreshToken;//Restore for the result ADCacheEvent* event = [[ADCacheEvent alloc] initWithName:@"token_cache_write"]; - [[ADTelemetry sharedInstance] stopEvent:[request telemetryRequestId] event:event]; + [[ADTelemetry sharedInstance] stopEvent:[requestParams telemetryRequestId] event:event]; SAFE_ARC_RELEASE(event); } - (void)removeItemFromCache:(ADTokenCacheItem *)cacheItem refreshToken:(NSString *)refreshToken - request:(ADAuthenticationRequest*)request + requestParams:(ADRequestParameters*)requestParams error:(ADAuthenticationError *)error { if (!cacheItem && !refreshToken) @@ -269,22 +269,22 @@ - (void)removeItemFromCache:(ADTokenCacheItem *)cacheItem return; } - [[ADTelemetry sharedInstance] startEvent:[request telemetryRequestId] eventName:@"token_cache_delete_token"]; + [[ADTelemetry sharedInstance] startEvent:[requestParams telemetryRequestId] eventName:@"token_cache_delete_token"]; BOOL removed = NO; //The refresh token didn't work. We need to tombstone this refresh item in the cache. ADTokenCacheKey* exactKey = [cacheItem extractKey:nil]; if (exactKey) { - ADTokenCacheItem* existing = [_dataSource getItemWithKey:exactKey userId:cacheItem.userInformation.userId correlationId:[request correlationId] error:nil]; + ADTokenCacheItem* existing = [_dataSource getItemWithKey:exactKey userId:cacheItem.userInformation.userId correlationId:[requestParams correlationId] error:nil]; if ([refreshToken isEqualToString:existing.refreshToken])//If still there, attempt to remove { - AD_LOG_VERBOSE_F(@"Token cache store", [request correlationId], @"Tombstoning cache for resource: %@", cacheItem.resource); + AD_LOG_VERBOSE_F(@"Token cache store", [requestParams correlationId], @"Tombstoning cache for resource: %@", cacheItem.resource); //update tombstone property before update the tombstone in cache - [existing makeTombstone:@{ @"correlationId" : [[request correlationId] UUIDString], + [existing makeTombstone:@{ @"correlationId" : [[requestParams correlationId] UUIDString], @"errorDetails" : [error errorDetails], @"protocolCode" : [error protocolCode] }]; - [_dataSource addOrUpdateItem:existing correlationId:[request correlationId] error:nil]; + [_dataSource addOrUpdateItem:existing correlationId:[requestParams correlationId] error:nil]; removed = YES; } } @@ -298,21 +298,21 @@ - (void)removeItemFromCache:(ADTokenCacheItem *)cacheItem error:nil]; if (broadKey) { - ADTokenCacheItem* broadItem = [_dataSource getItemWithKey:broadKey userId:cacheItem.userInformation.userId correlationId:[request correlationId] error:nil]; + ADTokenCacheItem* broadItem = [_dataSource getItemWithKey:broadKey userId:cacheItem.userInformation.userId correlationId:[requestParams correlationId] error:nil]; if (broadItem && [refreshToken isEqualToString:broadItem.refreshToken])//Remove if still there { - AD_LOG_VERBOSE_F(@"Token cache store", [request correlationId], @"Tombstoning multi-resource refresh token for authority: %@", _authority); + AD_LOG_VERBOSE_F(@"Token cache store", [requestParams correlationId], @"Tombstoning multi-resource refresh token for authority: %@", _authority); //update tombstone property before update the tombstone in cache - [broadItem makeTombstone:@{ @"correlationId" : [[request correlationId] UUIDString], + [broadItem makeTombstone:@{ @"correlationId" : [[requestParams correlationId] UUIDString], @"errorDetails" : [error errorDetails], @"protocolCode" : [error protocolCode] }]; - [_dataSource addOrUpdateItem:broadItem correlationId:[request correlationId] error:nil]; + [_dataSource addOrUpdateItem:broadItem correlationId:[requestParams correlationId] error:nil]; } } } ADCacheEvent* event = [[ADCacheEvent alloc] initWithName:@"token_cache_delete_token"]; - [[ADTelemetry sharedInstance] stopEvent:[request telemetryRequestId] event:event]; + [[ADTelemetry sharedInstance] stopEvent:[requestParams telemetryRequestId] event:event]; SAFE_ARC_RELEASE(event); } diff --git a/ADAL/src/request/ADAcquireTokenSilentHandler.h b/ADAL/src/request/ADAcquireTokenSilentHandler.h index 1389cc665..45b610661 100644 --- a/ADAL/src/request/ADAcquireTokenSilentHandler.h +++ b/ADAL/src/request/ADAcquireTokenSilentHandler.h @@ -28,13 +28,7 @@ @interface ADAcquireTokenSilentHandler : NSObject { - NSString* _authority; - NSString* _resource; - NSString* _clientId; - NSString* _redirectUri; - ADUserIdentifier* _identifier; - ADTokenCacheAccessor* _tokenCache; - ADAuthenticationRequest* _request; + ADRequestParameters* _requestParams; ADTokenCacheItem* _mrrtItem; ADTokenCacheItem* _extendedLifetimeAccessTokenItem; //store valid AT in terms of ext_expires_in (if find any) @@ -47,14 +41,7 @@ BOOL _attemptedFRT; } -+ (void)acquireTokenSilentForAuthority:(NSString *)authority - resource:(NSString *)resource - clientId:(NSString *)clientId - redirectUri:(NSString *)redirectUri - identifier:(ADUserIdentifier *)identifier - tokenCache:(ADTokenCacheAccessor *)tokenCache - extendedLifetime:(BOOL)extendedLifetime - request:(ADAuthenticationRequest*)request - completionBlock:(ADAuthenticationCallback)completionBlock; ++ (void)acquireTokenSilentForRequestParams:(ADRequestParameters*)requestParams + completionBlock:(ADAuthenticationCallback)completionBlock; @end diff --git a/ADAL/src/request/ADAcquireTokenSilentHandler.m b/ADAL/src/request/ADAcquireTokenSilentHandler.m index 437960ca0..1f98ef6d4 100644 --- a/ADAL/src/request/ADAcquireTokenSilentHandler.m +++ b/ADAL/src/request/ADAcquireTokenSilentHandler.m @@ -35,14 +35,7 @@ @implementation ADAcquireTokenSilentHandler -+ (void)acquireTokenSilentForAuthority:(NSString *)authority - resource:(NSString *)resource - clientId:(NSString *)clientId - redirectUri:(NSString *)redirectUri - identifier:(ADUserIdentifier *)identifier - tokenCache:(ADTokenCacheAccessor *)tokenCache - extendedLifetime:(BOOL)extendedLifetime - request:(ADAuthenticationRequest*)request ++ (void)acquireTokenSilentForRequestParams:(ADRequestParameters*)requestParams completionBlock:(ADAuthenticationCallback)completionBlock { ADAcquireTokenSilentHandler* handler = [ADAcquireTokenSilentHandler new]; @@ -50,25 +43,13 @@ + (void)acquireTokenSilentForAuthority:(NSString *)authority // As this is an internal class these properties should all be set by the // authentication request, which created copies of them. - handler->_authority = authority; - SAFE_ARC_RETAIN(authority); - handler->_resource = resource; - SAFE_ARC_RETAIN(resource); - handler->_clientId = clientId; - SAFE_ARC_RETAIN(clientId); - handler->_redirectUri = redirectUri; - SAFE_ARC_RETAIN(redirectUri); - handler->_identifier = identifier; - SAFE_ARC_RETAIN(identifier); - handler->_tokenCache = tokenCache; - SAFE_ARC_RETAIN(tokenCache); - handler->_request = request; - SAFE_ARC_RETAIN(request); + handler->_requestParams = requestParams; + SAFE_ARC_RETAIN(requestParams); [handler getAccessToken:^(ADAuthenticationResult *result) { // Logic for returning extended lifetime token - if (extendedLifetime && [handler isServerUnavailable:result] && handler->_extendedLifetimeAccessTokenItem) + if ([requestParams extendedLifetime] && [handler isServerUnavailable:result] && handler->_extendedLifetimeAccessTokenItem) { handler->_extendedLifetimeAccessTokenItem.expiresOn = [handler->_extendedLifetimeAccessTokenItem.additionalServer valueForKey:@"ext_expires_on"]; @@ -77,11 +58,11 @@ + (void)acquireTokenSilentForAuthority:(NSString *)authority [ADLogger logToken:handler->_extendedLifetimeAccessTokenItem.accessToken tokenType:@"access token (extended lifetime)" expiresOn:handler->_extendedLifetimeAccessTokenItem.expiresOn - correlationId:[handler->_request correlationId]]; + correlationId:[handler->_requestParams correlationId]]; result = [ADAuthenticationResult resultFromTokenCacheItem:handler->_extendedLifetimeAccessTokenItem multiResourceRefreshToken:NO - correlationId:[handler->_request correlationId]]; + correlationId:[handler->_requestParams correlationId]]; [result setExtendedLifeTimeToken:YES]; } @@ -91,26 +72,8 @@ + (void)acquireTokenSilentForAuthority:(NSString *)authority - (void)dealloc { - SAFE_ARC_RELEASE(_authority); - _authority = nil; - - SAFE_ARC_RELEASE(_resource); - _resource = nil; - - SAFE_ARC_RELEASE(_clientId); - _clientId = nil; - - SAFE_ARC_RELEASE(_redirectUri); - _redirectUri = nil; - - SAFE_ARC_RELEASE(_identifier); - _identifier = nil; - - SAFE_ARC_RELEASE(_request); - _request = nil; - - SAFE_ARC_RELEASE(_tokenCache); - _tokenCache = nil; + SAFE_ARC_RELEASE(_requestParams); + _requestParams = nil; SAFE_ARC_RELEASE(_mrrtItem); _mrrtItem = nil; @@ -133,9 +96,9 @@ - (void)acquireTokenByRefreshToken:(NSString*)refreshToken cacheItem:(ADTokenCacheItem*)cacheItem completionBlock:(ADAuthenticationCallback)completionBlock { - AD_LOG_VERBOSE_F(@"Attempting to acquire an access token from refresh token.", [_request correlationId], @"Resource: %@", _resource); + AD_LOG_VERBOSE_F(@"Attempting to acquire an access token from refresh token.", [_requestParams correlationId], @"Resource: %@", [_requestParams resource]); - [ADLogger logToken:refreshToken tokenType:@"refresh token" expiresOn:nil correlationId:[_request correlationId]]; + [ADLogger logToken:refreshToken tokenType:@"refresh token" expiresOn:nil correlationId:[_requestParams correlationId]]; //Fill the data for the token refreshing: NSMutableDictionary *request_data = nil; @@ -143,8 +106,8 @@ - (void)acquireTokenByRefreshToken:(NSString*)refreshToken { NSString* jwtToken = [self createAccessTokenRequestJWTUsingRT:cacheItem]; request_data = [NSMutableDictionary dictionaryWithObjectsAndKeys: - _redirectUri, @"redirect_uri", - _clientId, @"client_id", + [_requestParams redirectUri], @"redirect_uri", + [_requestParams clientId], @"client_id", @"2.0", @"windows_api_version", @"urn:ietf:params:oauth:grant-type:jwt-bearer", OAUTH2_GRANT_TYPE, jwtToken, @"request", @@ -156,41 +119,40 @@ - (void)acquireTokenByRefreshToken:(NSString*)refreshToken request_data = [NSMutableDictionary dictionaryWithObjectsAndKeys: OAUTH2_REFRESH_TOKEN, OAUTH2_GRANT_TYPE, refreshToken, OAUTH2_REFRESH_TOKEN, - _clientId, OAUTH2_CLIENT_ID, + [_requestParams clientId], OAUTH2_CLIENT_ID, nil]; } - if (![NSString adIsStringNilOrBlank:_resource]) + if (![NSString adIsStringNilOrBlank:[_requestParams resource]]) { - [request_data setObject:_resource forKey:OAUTH2_RESOURCE]; + [request_data setObject:[_requestParams resource] forKey:OAUTH2_RESOURCE]; } ADWebAuthRequest* webReq = - [[ADWebAuthRequest alloc] initWithURL:[NSURL URLWithString:[_authority stringByAppendingString:OAUTH2_TOKEN_SUFFIX]] - correlationId:[_request correlationId] - telemetryRequestId:[_request telemetryRequestId]]; + [[ADWebAuthRequest alloc] initWithURL:[NSURL URLWithString:[[_requestParams authority] stringByAppendingString:OAUTH2_TOKEN_SUFFIX]] + requestParams:_requestParams]; [webReq setRequestDictionary:request_data]; - AD_LOG_INFO_F(@"Attempting to acquire an access token from refresh token", nil, @"clientId: '%@'; resource: '%@';", _clientId, _resource); + AD_LOG_INFO_F(@"Attempting to acquire an access token from refresh token", nil, @"clientId: '%@'; resource: '%@';", [_requestParams clientId], [_requestParams resource]); [webReq sendRequest:^(NSDictionary *response) { ADTokenCacheItem* resultItem = (cacheItem) ? cacheItem : [ADTokenCacheItem new]; //Always ensure that the cache item has all of these set, especially in the broad token case, where the passed item //may have empty "resource" property: - resultItem.resource = _resource; - resultItem.clientId = _clientId; - resultItem.authority = _authority; + resultItem.resource = [_requestParams resource]; + resultItem.clientId = [_requestParams clientId]; + resultItem.authority = [_requestParams authority]; - ADAuthenticationResult *result = [resultItem processTokenResponse:response fromRefresh:YES requestCorrelationId:[_request correlationId]]; + ADAuthenticationResult *result = [resultItem processTokenResponse:response fromRefresh:YES requestCorrelationId:[_requestParams correlationId]]; if (cacheItem)//The request came from the cache item, update it: { - [_tokenCache updateCacheToResult:result - cacheItem:resultItem - refreshToken:refreshToken - request:_request]; + [[_requestParams tokenCache] updateCacheToResult:result + cacheItem:resultItem + refreshToken:refreshToken + requestParams:_requestParams]; } - result = [ADAuthenticationContext updateResult:result toUser:_identifier];//Verify the user (just in case) + result = [ADAuthenticationContext updateResult:result toUser:[_requestParams identifier]];//Verify the user (just in case) // if (!cacheItem) { @@ -214,15 +176,15 @@ - (NSString*)createAccessTokenRequestJWTUsingRT:(ADTokenCacheItem*)cacheItem NSInteger iat = round([[NSDate date] timeIntervalSince1970]); NSDictionary *payload = @{ - @"resource" : _resource, - @"client_id" : _clientId, + @"resource" : [_requestParams resource], + @"client_id" : [_requestParams clientId], @"refresh_token" : cacheItem.refreshToken, @"iat" : [NSNumber numberWithInteger:iat], @"nbf" : [NSNumber numberWithInteger:iat], @"exp" : [NSNumber numberWithInteger:iat], @"scope" : @"openid", @"grant_type" : grantType, - @"aud" : _authority + @"aud" : [_requestParams authority] }; NSString* returnValue = [ADHelpers createSignedJWTUsingKeyDerivation:header @@ -265,7 +227,7 @@ - (void)acquireTokenWithItem:(ADTokenCacheItem *)item msg = [NSString stringWithFormat:@"Acquire Token with Refresh Token %@.", resultStatus]; } - AD_LOG_INFO_F(msg, [_request correlationId], @"clientId: '%@'; resource: '%@';", _clientId, _resource); + AD_LOG_INFO_F(msg, [_requestParams correlationId], @"clientId: '%@'; resource: '%@';", [_requestParams clientId], [_requestParams resource]); if ([ADAuthenticationContext isFinalResult:result]) { @@ -289,15 +251,15 @@ - (void)getAccessToken:(ADAuthenticationCallback)completionBlock THROW_ON_NIL_ARGUMENT(completionBlock); ADAuthenticationError* error = nil; - ADTokenCacheItem* item = [_tokenCache getATRTItemForUser:_identifier - resource:_resource - clientId:_clientId - request:_request - error:&error]; + ADTokenCacheItem* item = [[_requestParams tokenCache] getATRTItemForUser:[_requestParams identifier] + resource:[_requestParams resource] + clientId:[_requestParams clientId] + requestParams:_requestParams + error:&error]; // If some error ocurred during the cache lookup then we need to fail out right away. if (!item && error) { - completionBlock([ADAuthenticationResult resultFromError:error correlationId:[_request correlationId]]); + completionBlock([ADAuthenticationResult resultFromError:error correlationId:[_requestParams correlationId]]); return; } @@ -305,10 +267,10 @@ - (void)getAccessToken:(ADAuthenticationCallback)completionBlock // and we need to check the unknown user ADFS token as well if (!item) { - item = [_tokenCache getADFSUserTokenForResource:_resource clientId:_clientId request:_request error:&error]; + item = [[_requestParams tokenCache] getADFSUserTokenForResource:[_requestParams resource] clientId:[_requestParams clientId] requestParams:_requestParams error:&error]; if (!item && error) { - completionBlock([ADAuthenticationResult resultFromError:error correlationId:[_request correlationId]]); + completionBlock([ADAuthenticationResult resultFromError:error correlationId:[_requestParams correlationId]]); return; } @@ -324,8 +286,8 @@ - (void)getAccessToken:(ADAuthenticationCallback)completionBlock // If we have a good (non-expired) access token then return it right away if (item.accessToken && !item.isExpired) { - [ADLogger logToken:item.accessToken tokenType:@"access token" expiresOn:item.expiresOn correlationId:[_request correlationId]]; - ADAuthenticationResult* result = [ADAuthenticationResult resultFromTokenCacheItem:item multiResourceRefreshToken:NO correlationId:[_request correlationId]]; + [ADLogger logToken:item.accessToken tokenType:@"access token" expiresOn:item.expiresOn correlationId:[_requestParams correlationId]]; + ADAuthenticationResult* result = [ADAuthenticationResult resultFromTokenCacheItem:item multiResourceRefreshToken:NO correlationId:[_requestParams correlationId]]; completionBlock(result); return; } @@ -347,10 +309,10 @@ - (void)tryRT:(ADTokenCacheItem*)item completionBlock:(ADAuthenticationCallback) if (!item.refreshToken) { // There's nothing usable in this cache item if extended lifetime also expires, delete it. - if (!item.isExtendedLifetimeValid && ![_tokenCache.dataSource removeItem:item error:&error] && error) + if (!item.isExtendedLifetimeValid && ![[_requestParams tokenCache].dataSource removeItem:item error:&error] && error) { // If we failed to remove the item with an error, then return that error right away - completionBlock([ADAuthenticationResult resultFromError:error correlationId:[_request correlationId]]); + completionBlock([ADAuthenticationResult resultFromError:error correlationId:[_requestParams correlationId]]); return; } @@ -387,10 +349,10 @@ - (void)tryMRRT:(ADAuthenticationCallback)completionBlock // If we don't have an item yet see if we can pull one out of the cache if (!_mrrtItem) { - _mrrtItem = [_tokenCache getMRRTItemForUser:_identifier clientId:_clientId request:_request error:&error]; + _mrrtItem = [[_requestParams tokenCache] getMRRTItemForUser:[_requestParams identifier] clientId:[_requestParams clientId] requestParams:_requestParams error:&error]; if (!_mrrtItem && error) { - completionBlock([ADAuthenticationResult resultFromError:error correlationId:[_request correlationId]]); + completionBlock([ADAuthenticationResult resultFromError:error correlationId:[_requestParams correlationId]]); return; } } @@ -448,10 +410,10 @@ - (void)tryFRT:(NSString*)familyId completionBlock:(ADAuthenticationCallback)com _attemptedFRT = YES; ADAuthenticationError* error = nil; - ADTokenCacheItem* frtItem = [_tokenCache getFRTItemForUser:_identifier familyId:familyId request:_request error:&error]; + ADTokenCacheItem* frtItem = [[_requestParams tokenCache] getFRTItemForUser:[_requestParams identifier] familyId:familyId requestParams:_requestParams error:&error]; if (!frtItem && error) { - completionBlock([ADAuthenticationResult resultFromError:error correlationId:[_request correlationId]]); + completionBlock([ADAuthenticationResult resultFromError:error correlationId:[_requestParams correlationId]]); return; } diff --git a/ADAL/src/request/ADAuthenticationRequest+AcquireAssertion.m b/ADAL/src/request/ADAuthenticationRequest+AcquireAssertion.m index b6158c357..3b65f16ea 100644 --- a/ADAL/src/request/ADAuthenticationRequest+AcquireAssertion.m +++ b/ADAL/src/request/ADAuthenticationRequest+AcquireAssertion.m @@ -49,7 +49,7 @@ - (NSString*)assertionTypeString - (void)requestTokenByAssertion:(ADAuthenticationCallback)completionBlock { [self ensureRequest]; - AD_LOG_INFO_F(@"Requesting token from SAML Assertion", _correlationId, @"resource: %@, clientId: %@", _resource, _clientId); + AD_LOG_INFO_F(@"Requesting token from SAML Assertion", [_requestParams correlationId], @"resource: %@, clientId: %@", [_requestParams resource], [_requestParams clientId]); NSData *encodeData = [_samlAssertion dataUsingEncoding:NSUTF8StringEncoding]; NSString *base64String = [encodeData base64EncodedStringWithOptions:0]; @@ -58,16 +58,16 @@ - (void)requestTokenByAssertion:(ADAuthenticationCallback)completionBlock if (!assertionType) { ADAuthenticationError* error = [ADAuthenticationError invalidArgumentError:@"Unrecognized assertion type." - correlationId:_correlationId]; - completionBlock([ADAuthenticationResult resultFromError:error correlationId:_correlationId]); + correlationId:[_requestParams correlationId]]; + completionBlock([ADAuthenticationResult resultFromError:error correlationId:[_requestParams correlationId]]); return; } NSMutableDictionary *request_data = [NSMutableDictionary dictionaryWithObjectsAndKeys: assertionType, OAUTH2_GRANT_TYPE, base64String, OAUTH2_ASSERTION, - _clientId, OAUTH2_CLIENT_ID, - _resource, OAUTH2_RESOURCE, + [_requestParams clientId], OAUTH2_CLIENT_ID, + [_requestParams resource], OAUTH2_RESOURCE, OAUTH2_SCOPE_OPENID_VALUE, OAUTH2_SCOPE, nil]; [self executeRequest:request_data diff --git a/ADAL/src/request/ADAuthenticationRequest+AcquireToken.m b/ADAL/src/request/ADAuthenticationRequest+AcquireToken.m index a43c533c9..ca5dbe190 100644 --- a/ADAL/src/request/ADAuthenticationRequest+AcquireToken.m +++ b/ADAL/src/request/ADAuthenticationRequest+AcquireToken.m @@ -41,7 +41,7 @@ @implementation ADAuthenticationRequest (AcquireToken) - (void)acquireToken:(ADAuthenticationCallback)completionBlock { THROW_ON_NIL_ARGUMENT(completionBlock); - AD_REQUEST_CHECK_ARGUMENT(_resource); + AD_REQUEST_CHECK_ARGUMENT([_requestParams resource]); [self ensureRequest]; [[ADTelemetry sharedInstance] startEvent:[self telemetryRequestId] eventName:@"acauire_token_call"]; @@ -51,13 +51,15 @@ - (void)acquireToken:(ADAuthenticationCallback)completionBlock [self fillTelemetryForAcquireToken:event result:result]; [[ADTelemetry sharedInstance] stopEvent:[self telemetryRequestId] event:event]; SAFE_ARC_RELEASE(event); + //flush all events in the end of the acquireToken call + [[ADTelemetry sharedInstance] flush]; completionBlock(result); }; NSString* log = [NSString stringWithFormat:@"acquireToken (authority = %@, resource = %@, clientId = %@, idtype = %@)", - _context.authority, _resource, _clientId, [_identifier typeAsString]]; - AD_LOG_INFO_F(log, _correlationId, @"userId = %@", _identifier.userId); + [_requestParams authority], [_requestParams resource], [_requestParams clientId], [[_requestParams identifier] typeAsString]]; + AD_LOG_INFO_F(log, [_requestParams correlationId], @"userId = %@", [_requestParams identifier].userId); if (!_silent && ![NSThread isMainThread]) { @@ -65,20 +67,20 @@ - (void)acquireToken:(ADAuthenticationCallback)completionBlock [ADAuthenticationError errorFromAuthenticationError:AD_ERROR_UI_NOT_ON_MAIN_THREAD protocolCode:nil errorDetails:@"Interactive authentication requests must originate from the main thread" - correlationId:_correlationId]; + correlationId:[_requestParams correlationId]]; requestCompletion([ADAuthenticationResult resultFromError:error]); return; } - if (!_silent && _context.credentialsType == AD_CREDENTIALS_AUTO && ![ADAuthenticationRequest validBrokerRedirectUri:_redirectUri]) + if (!_silent && _context.credentialsType == AD_CREDENTIALS_AUTO && ![ADAuthenticationRequest validBrokerRedirectUri:[_requestParams redirectUri]]) { ADAuthenticationError* error = [ADAuthenticationError errorFromAuthenticationError:AD_ERROR_TOKENBROKER_INVALID_REDIRECT_URI protocolCode:nil errorDetails:ADRedirectUriInvalidError - correlationId:_correlationId]; - requestCompletion([ADAuthenticationResult resultFromError:error correlationId:_correlationId]); + correlationId:[_requestParams correlationId]]; + requestCompletion([ADAuthenticationResult resultFromError:error correlationId:[_requestParams correlationId]]); return; } @@ -90,7 +92,7 @@ - (void)acquireToken:(ADAuthenticationCallback)completionBlock [[ADTelemetry sharedInstance] startEvent:[self telemetryRequestId] eventName:@"authority_validation"]; [[ADInstanceDiscovery sharedInstance] validateAuthority:_context.authority - request:self + requestParams:_requestParams completionBlock:^(BOOL validated, ADAuthenticationError *error) { ADAPIEvent* event = [[ADAPIEvent alloc] initWithName:@"authority_validation"]; @@ -101,7 +103,7 @@ - (void)acquireToken:(ADAuthenticationCallback)completionBlock if (error) { - requestCompletion([ADAuthenticationResult resultFromError:error correlationId:_correlationId]); + requestCompletion([ADAuthenticationResult resultFromError:error correlationId:[_requestParams correlationId]]); } else { @@ -117,15 +119,8 @@ - (void)validatedAcquireToken:(ADAuthenticationCallback)completionBlock if (![ADAuthenticationContext isForcedAuthorization:_promptBehavior] && [_context hasCacheStore]) { - [ADAcquireTokenSilentHandler acquireTokenSilentForAuthority:_context.authority - resource:_resource - clientId:_clientId - redirectUri:_redirectUri - identifier:_identifier - tokenCache:_tokenCache - extendedLifetime:_context.extendedLifetimeEnabled - request:self - completionBlock:^(ADAuthenticationResult *result) + [ADAcquireTokenSilentHandler acquireTokenSilentForRequestParams:_requestParams + completionBlock:^(ADAuthenticationResult *result) { if ([ADAuthenticationContext isFinalResult:result]) { @@ -166,9 +161,9 @@ - (void)requestToken:(ADAuthenticationCallback)completionBlock protocolCode:nil errorDetails:ADCredentialsNeeded userInfo:underlyingError - correlationId:_correlationId]; + correlationId:[_requestParams correlationId]]; - ADAuthenticationResult* result = [ADAuthenticationResult resultFromError:error correlationId:_correlationId]; + ADAuthenticationResult* result = [ADAuthenticationResult resultFromError:error correlationId:[_requestParams correlationId]]; completionBlock(result); return; } @@ -185,8 +180,8 @@ - (void)requestToken:(ADAuthenticationCallback)completionBlock [ADAuthenticationError errorFromAuthenticationError:AD_ERROR_UI_NOT_SUPPORTED_IN_APP_EXTENSION protocolCode:nil errorDetails:ADInteractionNotSupportedInExtension - correlationId:_correlationId]; - ADAuthenticationResult* result = [ADAuthenticationResult resultFromError:error correlationId:_correlationId]; + correlationId:[_requestParams correlationId]]; + ADAuthenticationResult* result = [ADAuthenticationResult resultFromError:error correlationId:[_requestParams correlationId]]; completionBlock(result); return; } @@ -220,8 +215,8 @@ - (void)requestToken:(ADAuthenticationCallback)completionBlock return; } - ADAuthenticationResult* result = (AD_ERROR_UI_USER_CANCEL == error.code) ? [ADAuthenticationResult resultFromCancellation:_correlationId] - : [ADAuthenticationResult resultFromError:error correlationId:_correlationId]; + ADAuthenticationResult* result = (AD_ERROR_UI_USER_CANCEL == error.code) ? [ADAuthenticationResult resultFromCancellation:[_requestParams correlationId]] + : [ADAuthenticationResult resultFromError:error correlationId:[_requestParams correlationId]]; completionBlock(result); } else @@ -243,8 +238,8 @@ - (void)requestToken:(ADAuthenticationCallback)completionBlock if (AD_SUCCEEDED == result.status) { - [_tokenCache updateCacheToResult:result cacheItem:nil refreshToken:nil request:self]; - result = [ADAuthenticationContext updateResult:result toUser:_identifier]; + [[_requestParams tokenCache] updateCacheToResult:result cacheItem:nil refreshToken:nil requestParams:_requestParams]; + result = [ADAuthenticationContext updateResult:result toUser:[_requestParams identifier]]; } completionBlock(result); }]; @@ -257,16 +252,16 @@ - (void)requestToken:(ADAuthenticationCallback)completionBlock - (void)requestTokenByCode:(NSString *)code completionBlock:(ADAuthenticationCallback)completionBlock { - HANDLE_ARGUMENT(code, _correlationId); + HANDLE_ARGUMENT(code, [_requestParams correlationId]); [self ensureRequest]; - AD_LOG_VERBOSE_F(@"Requesting token from authorization code.", _correlationId, @"Requesting token by authorization code for resource: %@", _resource); + AD_LOG_VERBOSE_F(@"Requesting token from authorization code.", [_requestParams correlationId], @"Requesting token by authorization code for resource: %@", [_requestParams resource]); //Fill the data for the token refreshing: NSMutableDictionary *request_data = [NSMutableDictionary dictionaryWithObjectsAndKeys: OAUTH2_AUTHORIZATION_CODE, OAUTH2_GRANT_TYPE, code, OAUTH2_CODE, - _clientId, OAUTH2_CLIENT_ID, - _redirectUri, OAUTH2_REDIRECT_URI, + [_requestParams clientId], OAUTH2_CLIENT_ID, + [_requestParams redirectUri], OAUTH2_REDIRECT_URI, nil]; if(![NSString adIsStringNilOrBlank:_scope]) { @@ -280,9 +275,9 @@ - (void)requestTokenByCode:(NSString *)code - (void)fillTelemetryForAcquireToken:(ADAPIEvent*)event result:(ADAuthenticationResult*)result { - [event setCorrelationId:_correlationId]; - [event setUserId:[_identifier userId]]; - [event setClientId:_clientId]; + [event setCorrelationId:[_requestParams correlationId]]; + [event setUserId:[[_requestParams identifier] userId]]; + [event setClientId:[_requestParams clientId]]; [event setResultStatus:[result status]]; [event setIsExtendedLifeTimeToken:[result extendedLifeTimeToken]? @"YES":@"NO"]; [event setErrorCode:[NSString stringWithFormat:@"%ld",(long)[result.error code]]]; diff --git a/ADAL/src/request/ADAuthenticationRequest+Broker.m b/ADAL/src/request/ADAuthenticationRequest+Broker.m index 53b16d3cd..be5dea4b0 100644 --- a/ADAL/src/request/ADAuthenticationRequest+Broker.m +++ b/ADAL/src/request/ADAuthenticationRequest+Broker.m @@ -155,7 +155,7 @@ + (void)internalHandleBrokerResponse:(NSURL *)response ADTokenCacheAccessor* cache = [[ADTokenCacheAccessor alloc] initWithDataSource:[ADKeychainTokenCache defaultKeychainCache] authority:result.tokenCacheItem.authority]; - [cache updateCacheToResult:result cacheItem:nil refreshToken:nil request:nil]; + [cache updateCacheToResult:result cacheItem:nil refreshToken:nil requestParams:nil]; NSString* userId = [[[result tokenCacheItem] userInformation] userId]; [ADAuthenticationContext updateResult:result @@ -188,19 +188,19 @@ - (BOOL)canUseBroker - (void)callBroker:(ADAuthenticationCallback)completionBlock { - CHECK_FOR_NIL(_context.authority); - CHECK_FOR_NIL(_resource); - CHECK_FOR_NIL(_clientId); - CHECK_FOR_NIL(_correlationId); + CHECK_FOR_NIL([_requestParams authority]); + CHECK_FOR_NIL([_requestParams resource]); + CHECK_FOR_NIL([_requestParams clientId]); + CHECK_FOR_NIL([_requestParams correlationId]); ADAuthenticationError* error = nil; - if(![ADAuthenticationRequest validBrokerRedirectUri:_redirectUri]) + if(![ADAuthenticationRequest validBrokerRedirectUri:[_requestParams redirectUri]]) { error = [ADAuthenticationError errorFromAuthenticationError:AD_ERROR_TOKENBROKER_INVALID_REDIRECT_URI protocolCode:nil errorDetails:ADRedirectUriInvalidError - correlationId:_correlationId]; - completionBlock([ADAuthenticationResult resultFromError:error correlationId:_correlationId]); + correlationId:[_requestParams correlationId]]; + completionBlock([ADAuthenticationResult resultFromError:error correlationId:[_requestParams correlationId]]); return; } @@ -211,8 +211,8 @@ - (void)callBroker:(ADAuthenticationCallback)completionBlock ADAuthenticationError* error = [ADAuthenticationError errorFromAuthenticationError:AD_ERROR_UI_MULTLIPLE_INTERACTIVE_REQUESTS protocolCode:nil errorDetails:message - correlationId:_correlationId]; - completionBlock([ADAuthenticationResult resultFromError:error correlationId:_correlationId]); + correlationId:[_requestParams correlationId]]; + completionBlock([ADAuthenticationResult resultFromError:error correlationId:[_requestParams correlationId]]); return; } @@ -228,14 +228,14 @@ - (void)callBroker:(ADAuthenticationCallback)completionBlock completionBlock(result); }; - AD_LOG_INFO(@"Invoking broker for authentication", _correlationId, nil); + AD_LOG_INFO(@"Invoking broker for authentication", [_requestParams correlationId], nil); #if TARGET_OS_IPHONE // Broker Message Encryption ADBrokerKeyHelper* brokerHelper = [[ADBrokerKeyHelper alloc] init]; NSData* key = [brokerHelper getBrokerKey:&error]; if (!key) { - ADAuthenticationError* adError = [ADAuthenticationError unexpectedInternalError:@"Unable to retrieve broker key." correlationId:_correlationId]; - completionBlock([ADAuthenticationResult resultFromError:adError correlationId:_correlationId]); + ADAuthenticationError* adError = [ADAuthenticationError unexpectedInternalError:@"Unable to retrieve broker key." correlationId:[_requestParams correlationId]]; + completionBlock([ADAuthenticationResult resultFromError:adError correlationId:[_requestParams correlationId]]); return; } @@ -248,14 +248,14 @@ - (void)callBroker:(ADAuthenticationCallback)completionBlock CHECK_FOR_NIL(adalVersion); NSDictionary* queryDictionary = @{ - @"authority": _context.authority, - @"resource" : _resource, - @"client_id": _clientId, - @"redirect_uri": _redirectUri, - @"username_type": _identifier ? [_identifier typeAsString] : @"", - @"username": _identifier.userId ? _identifier.userId : @"", + @"authority": [_requestParams authority], + @"resource" : [_requestParams resource], + @"client_id": [_requestParams clientId], + @"redirect_uri": [_requestParams redirectUri], + @"username_type": [_requestParams identifier] ? [[_requestParams identifier] typeAsString] : @"", + @"username": [_requestParams identifier].userId ? [_requestParams identifier].userId : @"", @"force" : _promptBehavior == AD_FORCE_PROMPT ? @"YES" : @"NO", - @"correlation_id": _correlationId, + @"correlation_id": [_requestParams correlationId], #if TARGET_OS_IPHONE // Broker Message Encryption @"broker_key": base64UrlKey, #endif // TARGET_OS_IPHONE Broker Message Encryption @@ -270,16 +270,16 @@ - (void)callBroker:(ADAuthenticationCallback)completionBlock - (void)handleBrokerFromWebiewResponse:(NSString*)urlString completionBlock:(ADAuthenticationCallback)completionBlock { - CHECK_FOR_NIL(_resource); + CHECK_FOR_NIL([_requestParams resource]); ADAuthenticationError* error = nil; - if(![ADAuthenticationRequest validBrokerRedirectUri:_redirectUri]) + if(![ADAuthenticationRequest validBrokerRedirectUri:[_requestParams redirectUri]]) { error = [ADAuthenticationError errorFromAuthenticationError:AD_ERROR_TOKENBROKER_INVALID_REDIRECT_URI protocolCode:nil errorDetails:ADRedirectUriInvalidError - correlationId:_correlationId]; - completionBlock([ADAuthenticationResult resultFromError:error correlationId:_correlationId]); + correlationId:[_requestParams correlationId]]; + completionBlock([ADAuthenticationResult resultFromError:error correlationId:[_requestParams correlationId]]); return; } @@ -292,7 +292,7 @@ - (void)handleBrokerFromWebiewResponse:(NSString*)urlString #endif // TARGET_OS_IPHONE Broker Message Encryption NSString* adalVersion = [ADLogger getAdalVersion]; - NSString* correlationIdStr = [_correlationId UUIDString]; + NSString* correlationIdStr = [[_requestParams correlationId] UUIDString]; NSString* authority = _context.authority; CHECK_FOR_NIL(adalVersion); @@ -301,12 +301,12 @@ - (void)handleBrokerFromWebiewResponse:(NSString*)urlString NSString* query = [[NSURL URLWithString:urlString] query]; NSMutableDictionary* urlParams = [[NSDictionary adURLFormDecode:query] mutableCopy]; - [urlParams addEntriesFromDictionary:@{@"authority": _context.authority, - @"resource" : _resource, - @"client_id": _clientId, - @"redirect_uri": _redirectUri, - @"username_type": _identifier ? [_identifier typeAsString] : @"", - @"username": _identifier.userId ? _identifier.userId : @"", + [urlParams addEntriesFromDictionary:@{@"authority": [_requestParams authority], + @"resource" : [_requestParams resource], + @"client_id": [_requestParams clientId], + @"redirect_uri": [_requestParams redirectUri], + @"username_type": [_requestParams identifier] ? [[_requestParams identifier] typeAsString] : @"", + @"username": [_requestParams identifier].userId ? [_requestParams identifier].userId : @"", @"correlation_id": correlationIdStr, #if TARGET_OS_IPHONE // Broker Message Encryption @"broker_key": base64UrlKey, diff --git a/ADAL/src/request/ADAuthenticationRequest+WebRequest.m b/ADAL/src/request/ADAuthenticationRequest+WebRequest.m index c653392ca..bed298849 100755 --- a/ADAL/src/request/ADAuthenticationRequest+WebRequest.m +++ b/ADAL/src/request/ADAuthenticationRequest+WebRequest.m @@ -57,19 +57,18 @@ - (void)executeRequest:(NSDictionary *)request_data { NSString* urlString = [_context.authority stringByAppendingString:OAUTH2_TOKEN_SUFFIX]; ADWebAuthRequest* req = [[ADWebAuthRequest alloc] initWithURL:[NSURL URLWithString:urlString] - correlationId:_correlationId - telemetryRequestId:_telemetryRequestId]; + requestParams:_requestParams]; [req setRequestDictionary:request_data]; [req sendRequest:^(NSDictionary *response) { //Prefill the known elements in the item. These can be overridden by the response: ADTokenCacheItem* item = [ADTokenCacheItem new]; - item.resource = _resource; - item.clientId = _clientId; + item.resource = [_requestParams resource]; + item.clientId = [_requestParams clientId]; item.authority = _context.authority; ADAuthenticationResult* result = [item processTokenResponse:response fromRefresh:NO - requestCorrelationId:_correlationId]; + requestCorrelationId:[_requestParams correlationId]]; SAFE_ARC_RELEASE(item); completionBlock(result); }]; @@ -87,7 +86,7 @@ - (BOOL)takeExclusionLockWithCallback: (ADAuthorizationCodeCallback) completionB ADAuthenticationError* error = [ADAuthenticationError errorFromAuthenticationError:AD_ERROR_UI_MULTLIPLE_INTERACTIVE_REQUESTS protocolCode:nil errorDetails:message - correlationId:_correlationId]; + correlationId:[_requestParams correlationId]]; completionBlock(nil, error); return NO; } @@ -114,18 +113,18 @@ - (BOOL)verifyStateFromDictionary: (NSDictionary*) dictionary if (![NSString adIsStringNilOrBlank:authorizationServer] && ![NSString adIsStringNilOrBlank:resource]) { - AD_LOG_VERBOSE_F(@"State", _correlationId, @"The authorization server returned the following state: %@", state); + AD_LOG_VERBOSE_F(@"State", [_requestParams correlationId], @"The authorization server returned the following state: %@", state); return YES; } } - AD_LOG_WARN_F(@"State error", _correlationId, @"Missing or invalid state returned: %@", state); + AD_LOG_WARN_F(@"State error", [_requestParams correlationId], @"Missing or invalid state returned: %@", state); return NO; } // Encodes the state parameter for a protocol message - (NSString *)encodeProtocolState { - return [[[NSMutableDictionary dictionaryWithObjectsAndKeys:_context.authority, @"a", _resource, @"r", _scope, @"s", nil] + return [[[NSMutableDictionary dictionaryWithObjectsAndKeys:[_requestParams authority], @"a", [_requestParams resource], @"r", _scope, @"s", nil] adURLFormEncode] adBase64UrlEncode]; } @@ -138,16 +137,16 @@ - (NSString*)generateQueryStringForRequestType:(NSString*)requestType NSMutableString* startUrl = [NSMutableString stringWithFormat:@"%@?%@=%@&%@=%@&%@=%@&%@=%@&%@=%@", [_context.authority stringByAppendingString:OAUTH2_AUTHORIZE_SUFFIX], OAUTH2_RESPONSE_TYPE, requestType, - OAUTH2_CLIENT_ID, [_clientId adUrlFormEncode], - OAUTH2_RESOURCE, [_resource adUrlFormEncode], - OAUTH2_REDIRECT_URI, [_redirectUri adUrlFormEncode], + OAUTH2_CLIENT_ID, [[_requestParams clientId] adUrlFormEncode], + OAUTH2_RESOURCE, [[_requestParams resource] adUrlFormEncode], + OAUTH2_REDIRECT_URI, [[_requestParams redirectUri] adUrlFormEncode], OAUTH2_STATE, state]; [startUrl appendFormat:@"&%@", [[ADLogger adalId] adURLFormEncode]]; - if (_identifier && [_identifier isDisplayable] && ![NSString adIsStringNilOrBlank:_identifier.userId]) + if ([_requestParams identifier] && [[_requestParams identifier] isDisplayable] && ![NSString adIsStringNilOrBlank:[_requestParams identifier].userId]) { - [startUrl appendFormat:@"&%@=%@", OAUTH2_LOGIN_HINT, [_identifier.userId adUrlFormEncode]]; + [startUrl appendFormat:@"&%@=%@", OAUTH2_LOGIN_HINT, [[_requestParams identifier].userId adUrlFormEncode]]; } NSString* promptParam = [ADAuthenticationContext getPromptParameter:_promptBehavior]; if (promptParam) @@ -190,14 +189,14 @@ - (void)launchWebView:(NSString*)startUrl }; [[ADWebAuthController sharedInstance] start:[NSURL URLWithString:startUrl] - end:[NSURL URLWithString:_redirectUri] + end:[NSURL URLWithString:[_requestParams redirectUri]] refreshCred:_refreshTokenCredential #if TARGET_OS_IPHONE parent:_context.parentController fullScreen:[ADAuthenticationSettings sharedInstance].enableFullScreen #endif webView:_context.webView - correlationId:_correlationId + correlationId:[_requestParams correlationId] completion:requestCompletion]; } @@ -207,7 +206,7 @@ - (void)requestCode:(ADAuthorizationCodeCallback)completionBlock THROW_ON_NIL_ARGUMENT(completionBlock); [self ensureRequest]; - AD_LOG_VERBOSE_F(@"Requesting authorization code.", _correlationId, @"Requesting authorization code for resource: %@", _resource); + AD_LOG_VERBOSE_F(@"Requesting authorization code.", [_requestParams correlationId], @"Requesting authorization code for resource: %@", [_requestParams resource]); if (![self takeExclusionLockWithCallback:completionBlock]) { return; @@ -267,7 +266,7 @@ - (void)requestCode:(ADAuthorizationCodeCallback)completionBlock error = [ADAuthenticationError errorFromAuthenticationError:AD_ERROR_SERVER_AUTHORIZATION_CODE protocolCode:nil errorDetails:@"The authorization server did not return a valid authorization code." - correlationId:_correlationId]; + correlationId:[_requestParams correlationId]]; } } } @@ -287,9 +286,9 @@ - (void)requestCode:(ADAuthorizationCodeCallback)completionBlock { NSMutableDictionary* requestData = nil; requestData = [NSMutableDictionary dictionaryWithObjectsAndKeys: - _clientId, OAUTH2_CLIENT_ID, - _redirectUri, OAUTH2_REDIRECT_URI, - _resource, OAUTH2_RESOURCE, + [_requestParams clientId], OAUTH2_CLIENT_ID, + [_requestParams redirectUri], OAUTH2_REDIRECT_URI, + [_requestParams resource], OAUTH2_RESOURCE, OAUTH2_CODE, OAUTH2_RESPONSE_TYPE, @"1", @"nux", nil]; @@ -300,8 +299,7 @@ - (void)requestCode:(ADAuthorizationCodeCallback)completionBlock NSURL* reqURL = [NSURL URLWithString:[_context.authority stringByAppendingString:OAUTH2_AUTHORIZE_SUFFIX]]; ADWebAuthRequest* req = [[ADWebAuthRequest alloc] initWithURL:reqURL - correlationId:_correlationId - telemetryRequestId:_telemetryRequestId]; + requestParams:_requestParams]; [req setIsGetRequest:YES]; [req setRequestDictionary:requestData]; [req sendRequest:^(NSDictionary * parameters) @@ -333,9 +331,9 @@ - (void)requestCode:(ADAuthorizationCodeCallback)completionBlock - (void)fillTelemetryUIEvent:(ADUIEvent*)event { - if (_identifier && [_identifier isDisplayable] && ![NSString adIsStringNilOrBlank:_identifier.userId]) + if ([_requestParams identifier] && [[_requestParams identifier] isDisplayable] && ![NSString adIsStringNilOrBlank:[_requestParams identifier].userId]) { - [event setLoginHint:_identifier.userId]; + [event setLoginHint:[_requestParams identifier].userId]; } } diff --git a/ADAL/src/request/ADAuthenticationRequest.h b/ADAL/src/request/ADAuthenticationRequest.h index c3bdba29a..a47e56878 100644 --- a/ADAL/src/request/ADAuthenticationRequest.h +++ b/ADAL/src/request/ADAuthenticationRequest.h @@ -24,6 +24,7 @@ #import #import "ADAuthenticationContext.h" +#import "ADRequestParameters.h" @class ADUserIdentifier; @class ADTokenCacheAccessor; @@ -48,16 +49,10 @@ { @protected ADAuthenticationContext* _context; - NSString* _clientId; - NSString* _redirectUri; - ADTokenCacheAccessor* _tokenCache; - - ADUserIdentifier* _identifier; + ADRequestParameters* _requestParams; ADPromptBehavior _promptBehavior; - NSString* _resource; - NSString* _scope; NSString* _queryParams; @@ -69,9 +64,7 @@ BOOL _silent; BOOL _allowSilent; - NSUUID* _correlationId; NSString* _logComponent; - NSString* _telemetryRequestId; BOOL _requestStarted; BOOL _attemptedFRT; @@ -90,9 +83,7 @@ // The default constructor. All of the parameters are mandatory + (ADAuthenticationRequest*)requestWithContext:(ADAuthenticationContext*)context - redirectUri:(NSString*)redirectUri - clientId:(NSString*)clientId - resource:(NSString*)resource + requestParams:(ADRequestParameters*)requestParams error:(ADAuthenticationError* __autoreleasing *)error; // This message is sent before any stage of processing is done, it marks all the fields as un-editable and grabs the diff --git a/ADAL/src/request/ADAuthenticationRequest.m b/ADAL/src/request/ADAuthenticationRequest.m index 5182026ad..8b7a6b473 100644 --- a/ADAL/src/request/ADAuthenticationRequest.m +++ b/ADAL/src/request/ADAuthenticationRequest.m @@ -87,39 +87,30 @@ + (ADAuthenticationRequest *)requestWithContext:(ADAuthenticationContext *)conte } + (ADAuthenticationRequest*)requestWithContext:(ADAuthenticationContext*)context - redirectUri:(NSString*)redirectUri - clientId:(NSString*)clientId - resource:(NSString*)resource + requestParams:(ADRequestParameters*)requestParams error:(ADAuthenticationError* __autoreleasing *)error { ERROR_RETURN_IF_NIL(context); - ERROR_RETURN_IF_NIL(clientId); + ERROR_RETURN_IF_NIL([requestParams clientId]); - ADAuthenticationRequest *request = [[ADAuthenticationRequest alloc] initWithContext:context redirectUri:redirectUri clientId:clientId resource:resource]; + ADAuthenticationRequest *request = [[ADAuthenticationRequest alloc] initWithContext:context requestParams:requestParams]; SAFE_ARC_AUTORELEASE(request); return request; } - (id)initWithContext:(ADAuthenticationContext*)context - redirectUri:(NSString*)redirectUri - clientId:(NSString*)clientId - resource:(NSString*)resource + requestParams:(ADRequestParameters*)requestParams { RETURN_IF_NIL(context); - RETURN_IF_NIL(clientId); + RETURN_IF_NIL([requestParams clientId]); if (!(self = [super init])) return nil; SAFE_ARC_RETAIN(context); _context = context; - _tokenCache = context.tokenCacheStore; - _redirectUri = [redirectUri adTrimmedString]; - SAFE_ARC_RETAIN(_redirectUri); - _clientId = [clientId adTrimmedString]; - SAFE_ARC_RETAIN(_clientId); - _resource = [resource adTrimmedString]; - SAFE_ARC_RETAIN(_resource); + SAFE_ARC_RETAIN(requestParams); + _requestParams = requestParams; _promptBehavior = AD_PROMPT_AUTO; @@ -132,15 +123,10 @@ - (id)initWithContext:(ADAuthenticationContext*)context - (void)dealloc { SAFE_ARC_RELEASE(_context); - SAFE_ARC_RELEASE(_clientId); - SAFE_ARC_RELEASE(_redirectUri); - SAFE_ARC_RELEASE(_identifier); - SAFE_ARC_RELEASE(_resource); + SAFE_ARC_RELEASE(_requestParams); SAFE_ARC_RELEASE(_scope); SAFE_ARC_RELEASE(_queryParams); SAFE_ARC_RELEASE(_refreshTokenCredential); - SAFE_ARC_RELEASE(_correlationId); - SAFE_ARC_RELEASE(_telemetryRequestId); SAFE_ARC_RELEASE(_underlyingError); SAFE_ARC_SUPER_DEALLOC(); @@ -179,13 +165,11 @@ - (void)setExtraQueryParameters:(NSString *)queryParams - (void)setUserIdentifier:(ADUserIdentifier *)identifier { CHECK_REQUEST_STARTED; - if (_identifier == identifier) + if ([_requestParams identifier] == identifier) { return; } - SAFE_ARC_RELEASE(_identifier); - _identifier = identifier; - SAFE_ARC_RETAIN(_identifier); + [_requestParams setIdentifier:identifier]; } - (void)setUserId:(NSString *)userId @@ -209,13 +193,11 @@ - (void)setSilent:(BOOL)silent - (void)setCorrelationId:(NSUUID*)correlationId { CHECK_REQUEST_STARTED; - if (_correlationId == correlationId) + if ([_requestParams correlationId] == correlationId) { return; } - SAFE_ARC_RELEASE(_correlationId); - _correlationId = correlationId; - SAFE_ARC_RETAIN(_correlationId); + [_requestParams setCorrelationId:correlationId]; } #if AD_BROKER @@ -288,32 +270,29 @@ - (void)ensureRequest - (NSUUID*)correlationId { - if (_correlationId == nil) + if ([_requestParams correlationId] == nil) { //if correlationId is set in context, use it //if not, generate one if ([_context correlationId]) { - _correlationId = [_context correlationId]; - SAFE_ARC_RETAIN(_correlationId); + [_requestParams setCorrelationId:[_context correlationId]]; } else { - _correlationId = [NSUUID UUID]; - SAFE_ARC_RETAIN(_correlationId); + [_requestParams setCorrelationId:[NSUUID UUID]]; } } - return _correlationId; + return [_requestParams correlationId]; } - (NSString*)telemetryRequestId { - if (_telemetryRequestId == nil) + if ([_requestParams telemetryRequestId] == nil) { - _telemetryRequestId = [[ADTelemetry sharedInstance] registerNewRequest]; - SAFE_ARC_RETAIN(_telemetryRequestId); + [_requestParams setTelemetryRequestId:[[ADTelemetry sharedInstance] registerNewRequest]]; } - return _telemetryRequestId; + return [_requestParams telemetryRequestId]; } - (BOOL)takeUserInterationLock diff --git a/ADAL/src/request/ADWebAuthRequest.m b/ADAL/src/request/ADWebAuthRequest.m index 0966c7934..aaaac18b6 100644 --- a/ADAL/src/request/ADWebAuthRequest.m +++ b/ADAL/src/request/ADWebAuthRequest.m @@ -38,10 +38,9 @@ @implementation ADWebAuthRequest @synthesize handledPkeyAuthChallenge = _handledPkeyAuthChallenge; - (id)initWithURL:(NSURL *)url - correlationId:(NSUUID *)correlationId -telemetryRequestId:(NSString *)telemetryRequestId + requestParams:(ADRequestParameters*)requestParams { - self = [super initWithURL:url correlationId:correlationId telemetryRequestId:telemetryRequestId]; + self = [super initWithURL:url requestParams:requestParams]; if (!self) { return nil; diff --git a/ADAL/src/request/ADWebRequest.h b/ADAL/src/request/ADWebRequest.h index b92a56fe3..c050e3faa 100644 --- a/ADAL/src/request/ADWebRequest.h +++ b/ADAL/src/request/ADWebRequest.h @@ -56,8 +56,7 @@ @property (readonly) NSUUID* correlationId; - (id)initWithURL: (NSURL*)url - correlationId: (NSUUID*)correlationId -telemetryRequestId: (NSString*)telemetryRequestId; + requestParams:(ADRequestParameters*)requestParams; - (void)send:( void (^)( NSError *, ADWebResponse *) )completionHandler; diff --git a/ADAL/src/request/ADWebRequest.m b/ADAL/src/request/ADWebRequest.m index be63073e7..c09aa2470 100644 --- a/ADAL/src/request/ADWebRequest.m +++ b/ADAL/src/request/ADWebRequest.m @@ -80,8 +80,7 @@ - (void)setBody:(NSData *)body #pragma mark - Initialization - (id)initWithURL:(NSURL *)requestURL - correlationId:(NSUUID *)correlationId -telemetryRequestId:(NSString *)telemetryRequestId + requestParams:(ADRequestParameters*)requestParams { if (!(self = [super init])) { @@ -94,10 +93,10 @@ - (id)initWithURL:(NSURL *)requestURL // Default timeout for ADWebRequest is 30 seconds _timeout = [[ADAuthenticationSettings sharedInstance] requestTimeOut]; - _correlationId = correlationId; + _correlationId = [requestParams correlationId]; SAFE_ARC_RETAIN(_correlationId); - _telemetryRequestId = telemetryRequestId; + _telemetryRequestId = [requestParams telemetryRequestId]; SAFE_ARC_RETAIN(_telemetryRequestId); _operationQueue = [[NSOperationQueue alloc] init]; diff --git a/ADAL/src/telemetry/ADTelemetry+Internal.h b/ADAL/src/telemetry/ADTelemetry+Internal.h index f070062d8..2ca3c6a67 100644 --- a/ADAL/src/telemetry/ADTelemetry+Internal.h +++ b/ADAL/src/telemetry/ADTelemetry+Internal.h @@ -36,4 +36,6 @@ - (void)dispatchEventNow:(NSString*)requestId event:(id)event; +- (void)flush; + @end \ No newline at end of file diff --git a/ADAL/src/telemetry/ADTelemetry.h b/ADAL/src/telemetry/ADTelemetry.h index 2a90e53ec..59e2f50e1 100644 --- a/ADAL/src/telemetry/ADTelemetry.h +++ b/ADAL/src/telemetry/ADTelemetry.h @@ -69,9 +69,4 @@ - (void)registerDispatcher:(id)dispatcher aggregationRequired:(BOOL)aggregationRequired; -/*! - Flush all cached telemetry events to the registered dispatcher. - */ -- (void)flush; - @end \ No newline at end of file diff --git a/ADAL/src/telemetry/ADTelemetry.m b/ADAL/src/telemetry/ADTelemetry.m index f9ccd02d6..f526330fb 100644 --- a/ADAL/src/telemetry/ADTelemetry.m +++ b/ADAL/src/telemetry/ADTelemetry.m @@ -78,17 +78,6 @@ - (void)registerDispatcher:(id)dispatcher } } -- (void)flush -{ - @synchronized(self) - { - if (_dispatcher) - { - [_dispatcher flush]; - } - } -} - - (void)dealloc { SAFE_ARC_RELEASE(_dispatcher); @@ -178,4 +167,15 @@ - (NSString*)getPropertyFromEvent:(id)event return nil; } +- (void)flush +{ + @synchronized(self) + { + if (_dispatcher) + { + [_dispatcher flush]; + } + } +} + @end \ No newline at end of file diff --git a/ADAL/tests/ADInstanceDiscoveryTests.m b/ADAL/tests/ADInstanceDiscoveryTests.m index c3856b8a5..59ff7d636 100644 --- a/ADAL/tests/ADInstanceDiscoveryTests.m +++ b/ADAL/tests/ADInstanceDiscoveryTests.m @@ -163,7 +163,7 @@ -(void) testValidateAuthorityError { ADInstanceDiscovery* discovery = [[ADInstanceDiscovery alloc] init]; [discovery validateAuthority:testCase - request:nil + requestParams:nil completionBlock:^(BOOL validated, ADAuthenticationError *error) { XCTAssertFalse(validated, @"\"%@\" should come back invalid.", testCase); @@ -229,9 +229,11 @@ - (void)testNormalFlow ADInstanceDiscovery* discovery = [[ADInstanceDiscovery alloc] init]; [ADTestURLConnection addResponse:[ADTestURLResponse responseValidAuthority:@"https://login.windows-ppe.net/common"]]; + ADRequestParameters* requestParams = [ADRequestParameters new]; + [requestParams setCorrelationId:[NSUUID UUID]]; [discovery validateAuthority:@"https://login.windows-ppe.net/common" - request:[ADAuthenticationRequest new] + requestParams:requestParams completionBlock:^(BOOL validated, ADAuthenticationError * error) { XCTAssertTrue(validated); @@ -243,6 +245,7 @@ - (void)testNormalFlow TEST_WAIT; XCTAssertTrue([[discovery validatedAuthorities] containsObject:@"https://login.windows-ppe.net"]); SAFE_ARC_RELEASE(discovery); + SAFE_ARC_RELEASE(requestParams); } //Ensures that an invalid authority is not approved @@ -250,11 +253,13 @@ - (void)testNonValidatedAuthority { [self adSetLogTolerance:ADAL_LOG_LEVEL_ERROR]; ADInstanceDiscovery* discovery = [[ADInstanceDiscovery alloc] init]; + ADRequestParameters* requestParams = [ADRequestParameters new]; + [requestParams setCorrelationId:[NSUUID UUID]]; [ADTestURLConnection addResponse:[ADTestURLResponse responseInvalidAuthority:@"https://myfakeauthority.microsoft.com/contoso.com"]]; [discovery validateAuthority:@"https://MyFakeAuthority.microsoft.com/contoso.com" - request:[ADAuthenticationRequest new] + requestParams:requestParams completionBlock:^(BOOL validated, ADAuthenticationError * error) { XCTAssertFalse(validated); @@ -271,6 +276,8 @@ - (void)testUnreachableServer { [self adSetLogTolerance:ADAL_LOG_LEVEL_ERROR]; ADInstanceDiscovery* discovery = [[ADInstanceDiscovery alloc] init]; + ADRequestParameters* requestParams = [ADRequestParameters new]; + [requestParams setCorrelationId:[NSUUID UUID]]; NSURL* requestURL = [NSURL URLWithString:@"https://SomeValidURLButNotExistentInTheNet.com/common/discovery/instance?api-version=1.0&authorization_endpoint=https://login.windows.cn/MSOpenTechBV.onmicrosoft.com/oauth2/authorize&x-client-Ver=" ADAL_VERSION_STRING]; NSError* responseError = [NSError errorWithDomain:NSURLErrorDomain code:NSURLErrorCannotFindHost userInfo:nil]; @@ -281,7 +288,7 @@ - (void)testUnreachableServer [discovery requestValidationOfAuthority:@"https://login.windows.cn/MSOpenTechBV.onmicrosoft.com" host:@"https://login.windows.cn" trustedAuthority:@"https://SomeValidURLButNotExistentInTheNet.com" - request:[ADAuthenticationRequest new] + requestParams:requestParams completionBlock:^(BOOL validated, ADAuthenticationError *error) { XCTAssertFalse(validated); @@ -294,6 +301,7 @@ - (void)testUnreachableServer TEST_WAIT; SAFE_ARC_RELEASE(discovery); + SAFE_ARC_RELEASE(requestParams); } @end From 6f7c93b0c463975cb95bcfaf35708a65c1b6ffba Mon Sep 17 00:00:00 2001 From: YONG ZENG Date: Thu, 4 Aug 2016 10:51:23 -0700 Subject: [PATCH 05/92] comment fix and indent fix --- ADAL/src/ADRequestParameters.h | 18 +++++++++--------- ADAL/src/cache/ADTokenCacheAccessor.m | 6 +++--- ADAL/src/request/ADAcquireTokenSilentHandler.m | 2 +- ADAL/src/request/ADAuthenticationRequest.h | 2 +- ADAL/tests/ADInstanceDiscoveryTests.m | 8 +++++--- 5 files changed, 19 insertions(+), 17 deletions(-) diff --git a/ADAL/src/ADRequestParameters.h b/ADAL/src/ADRequestParameters.h index 16d3a8ff9..25bdb1534 100644 --- a/ADAL/src/ADRequestParameters.h +++ b/ADAL/src/ADRequestParameters.h @@ -44,14 +44,14 @@ @property (retain, nonatomic) NSUUID* correlationId; @property (retain, nonatomic) NSString* telemetryRequestId; -- (id)initWithAuthority:(NSString *)authorityParam - resource:(NSString *)resourceParam - clientId:(NSString *)clientIdParam - redirectUri:(NSString *)redirectUriParam - identifier:(ADUserIdentifier *)identifierParam - tokenCache:(ADTokenCacheAccessor *)tokenCacheParam - extendedLifetime:(BOOL)extendedLifetimeParam - correlationId:(NSUUID *)correlationIdParam - telemetryRequestId:(NSString *)telemetryRequestIdParam; +- (id)initWithAuthority:(NSString *)authority + resource:(NSString *)resource + clientId:(NSString *)clientId + redirectUri:(NSString *)redirectUri + identifier:(ADUserIdentifier *)identifier + tokenCache:(ADTokenCacheAccessor *)tokenCache + extendedLifetime:(BOOL)extendedLifetime + correlationId:(NSUUID *)correlationId + telemetryRequestId:(NSString *)telemetryRequestId; @end diff --git a/ADAL/src/cache/ADTokenCacheAccessor.m b/ADAL/src/cache/ADTokenCacheAccessor.m index 436f3e2f1..845b7b8f6 100644 --- a/ADAL/src/cache/ADTokenCacheAccessor.m +++ b/ADAL/src/cache/ADTokenCacheAccessor.m @@ -83,9 +83,9 @@ - (ADTokenCacheItem *)getItemForUser:(ADUserIdentifier *)identifier [[ADTelemetry sharedInstance] startEvent:[requestParams telemetryRequestId] eventName:@"token_cache_lookup"]; ADTokenCacheItem* item = [_dataSource getItemWithKey:key - userId:identifier.userId - correlationId:[requestParams correlationId] - error:error]; + userId:identifier.userId + correlationId:[requestParams correlationId] + error:error]; ADCacheEvent* event = [[ADCacheEvent alloc] initWithName:@"token_cache_lookup"]; [[ADTelemetry sharedInstance] stopEvent:[requestParams telemetryRequestId] event:event]; diff --git a/ADAL/src/request/ADAcquireTokenSilentHandler.m b/ADAL/src/request/ADAcquireTokenSilentHandler.m index 1f98ef6d4..95ced1831 100644 --- a/ADAL/src/request/ADAcquireTokenSilentHandler.m +++ b/ADAL/src/request/ADAcquireTokenSilentHandler.m @@ -36,7 +36,7 @@ @implementation ADAcquireTokenSilentHandler + (void)acquireTokenSilentForRequestParams:(ADRequestParameters*)requestParams - completionBlock:(ADAuthenticationCallback)completionBlock + completionBlock:(ADAuthenticationCallback)completionBlock { ADAcquireTokenSilentHandler* handler = [ADAcquireTokenSilentHandler new]; diff --git a/ADAL/src/request/ADAuthenticationRequest.h b/ADAL/src/request/ADAuthenticationRequest.h index a47e56878..2774046ed 100644 --- a/ADAL/src/request/ADAuthenticationRequest.h +++ b/ADAL/src/request/ADAuthenticationRequest.h @@ -81,7 +81,7 @@ + (ADAuthenticationRequest *)requestWithAuthority:(NSString *)authority; + (ADAuthenticationRequest *)requestWithContext:(ADAuthenticationContext *)context; -// The default constructor. All of the parameters are mandatory +// The default constructor. For requestParams, redirectUri, clientId and resource are mandatory + (ADAuthenticationRequest*)requestWithContext:(ADAuthenticationContext*)context requestParams:(ADRequestParameters*)requestParams error:(ADAuthenticationError* __autoreleasing *)error; diff --git a/ADAL/tests/ADInstanceDiscoveryTests.m b/ADAL/tests/ADInstanceDiscoveryTests.m index 59ff7d636..f7308e734 100644 --- a/ADAL/tests/ADInstanceDiscoveryTests.m +++ b/ADAL/tests/ADInstanceDiscoveryTests.m @@ -158,12 +158,14 @@ -(void) testValidateAuthorityError NSArray* cases = @[@"http://invalidscheme.com", @"https://Invalid URL 2305 8 -0238460-820-386"]; + ADRequestParameters* requestParams = [ADRequestParameters new]; + [requestParams setCorrelationId:[NSUUID UUID]]; for (NSString* testCase in cases) { ADInstanceDiscovery* discovery = [[ADInstanceDiscovery alloc] init]; [discovery validateAuthority:testCase - requestParams:nil + requestParams:requestParams completionBlock:^(BOOL validated, ADAuthenticationError *error) { XCTAssertFalse(validated, @"\"%@\" should come back invalid.", testCase); @@ -227,11 +229,11 @@ - (void)testCanonicalizeAuthority - (void)testNormalFlow { ADInstanceDiscovery* discovery = [[ADInstanceDiscovery alloc] init]; - - [ADTestURLConnection addResponse:[ADTestURLResponse responseValidAuthority:@"https://login.windows-ppe.net/common"]]; ADRequestParameters* requestParams = [ADRequestParameters new]; [requestParams setCorrelationId:[NSUUID UUID]]; + [ADTestURLConnection addResponse:[ADTestURLResponse responseValidAuthority:@"https://login.windows-ppe.net/common"]]; + [discovery validateAuthority:@"https://login.windows-ppe.net/common" requestParams:requestParams completionBlock:^(BOOL validated, ADAuthenticationError * error) From f449868be5cad8281f6922505603b76115ceb773 Mon Sep 17 00:00:00 2001 From: YONG ZENG Date: Thu, 4 Aug 2016 11:26:54 -0700 Subject: [PATCH 06/92] add "Telemetry" to event names --- ADAL/ADAL.xcodeproj/project.pbxproj | 128 +++++++++--------- ADAL/src/cache/ADTokenCacheAccessor.m | 10 +- .../ADAuthenticationRequest+AcquireToken.m | 12 +- .../request/ADAuthenticationRequest+Broker.m | 4 +- .../ADAuthenticationRequest+WebRequest.m | 6 +- ADAL/src/request/ADWebRequest.m | 4 +- ADAL/src/telemetry/ADAggregatedDispatcher.m | 4 +- ADAL/src/telemetry/ADDefaultDispatcher.h | 2 +- ADAL/src/telemetry/ADDefaultDispatcher.m | 6 +- ADAL/src/telemetry/ADTelemetry+Internal.h | 6 +- ADAL/src/telemetry/ADTelemetry.m | 8 +- .../{ADAPIEvent.h => ADTelemetryAPIEvent.h} | 4 +- .../{ADAPIEvent.m => ADTelemetryAPIEvent.m} | 4 +- ...BrokerEvent.h => ADTelemetryBrokerEvent.h} | 4 +- ...BrokerEvent.m => ADTelemetryBrokerEvent.m} | 4 +- ...ADCacheEvent.h => ADTelemetryCacheEvent.h} | 4 +- ...ADCacheEvent.m => ADTelemetryCacheEvent.m} | 4 +- ...faultEvent.h => ADTelemetryDefaultEvent.h} | 4 +- ...faultEvent.m => ADTelemetryDefaultEvent.m} | 6 +- ...nterface.h => ADTelemetryEventInterface.h} | 2 +- .../{ADHttpEvent.h => ADTelemetryHttpEvent.h} | 4 +- .../{ADHttpEvent.m => ADTelemetryHttpEvent.m} | 4 +- .../{ADUIEvent.h => ADTelemetryUIEvent.h} | 4 +- .../{ADUIEvent.m => ADTelemetryUIEvent.m} | 4 +- ADAL/tests/ADTelemetryTests.m | 36 ++--- 25 files changed, 139 insertions(+), 139 deletions(-) rename ADAL/src/telemetry/{ADAPIEvent.h => ADTelemetryAPIEvent.h} (94%) rename ADAL/src/telemetry/{ADAPIEvent.m => ADTelemetryAPIEvent.m} (97%) rename ADAL/src/telemetry/{ADBrokerEvent.h => ADTelemetryBrokerEvent.h} (92%) rename ADAL/src/telemetry/{ADBrokerEvent.m => ADTelemetryBrokerEvent.m} (94%) rename ADAL/src/telemetry/{ADCacheEvent.h => ADTelemetryCacheEvent.h} (92%) rename ADAL/src/telemetry/{ADCacheEvent.m => ADTelemetryCacheEvent.m} (94%) rename ADAL/src/telemetry/{ADDefaultEvent.h => ADTelemetryDefaultEvent.h} (91%) rename ADAL/src/telemetry/{ADDefaultEvent.m => ADTelemetryDefaultEvent.m} (97%) rename ADAL/src/telemetry/{ADEventInterface.h => ADTelemetryEventInterface.h} (96%) rename ADAL/src/telemetry/{ADHttpEvent.h => ADTelemetryHttpEvent.h} (93%) rename ADAL/src/telemetry/{ADHttpEvent.m => ADTelemetryHttpEvent.m} (97%) rename ADAL/src/telemetry/{ADUIEvent.h => ADTelemetryUIEvent.h} (93%) rename ADAL/src/telemetry/{ADUIEvent.m => ADTelemetryUIEvent.m} (95%) diff --git a/ADAL/ADAL.xcodeproj/project.pbxproj b/ADAL/ADAL.xcodeproj/project.pbxproj index 4737e27b9..d43b82a3d 100755 --- a/ADAL/ADAL.xcodeproj/project.pbxproj +++ b/ADAL/ADAL.xcodeproj/project.pbxproj @@ -26,13 +26,13 @@ 600401A41D3421480020EAAB /* ADTelemetry.m in Sources */ = {isa = PBXBuildFile; fileRef = 600401A31D3421480020EAAB /* ADTelemetry.m */; }; 600401A51D3421480020EAAB /* ADTelemetry.m in Sources */ = {isa = PBXBuildFile; fileRef = 600401A31D3421480020EAAB /* ADTelemetry.m */; }; 600401A71D3426250020EAAB /* ADTelemetry+Internal.h in Headers */ = {isa = PBXBuildFile; fileRef = 600401A61D3426250020EAAB /* ADTelemetry+Internal.h */; }; - 600401A91D3428770020EAAB /* ADDefaultEvent.h in Headers */ = {isa = PBXBuildFile; fileRef = 600401A81D3428770020EAAB /* ADDefaultEvent.h */; }; - 600401AB1D3443D30020EAAB /* ADDefaultEvent.m in Sources */ = {isa = PBXBuildFile; fileRef = 600401AA1D3443D30020EAAB /* ADDefaultEvent.m */; }; - 600401AC1D3443D30020EAAB /* ADDefaultEvent.m in Sources */ = {isa = PBXBuildFile; fileRef = 600401AA1D3443D30020EAAB /* ADDefaultEvent.m */; }; + 600401A91D3428770020EAAB /* ADTelemetryDefaultEvent.h in Headers */ = {isa = PBXBuildFile; fileRef = 600401A81D3428770020EAAB /* ADTelemetryDefaultEvent.h */; }; + 600401AB1D3443D30020EAAB /* ADTelemetryDefaultEvent.m in Sources */ = {isa = PBXBuildFile; fileRef = 600401AA1D3443D30020EAAB /* ADTelemetryDefaultEvent.m */; }; + 600401AC1D3443D30020EAAB /* ADTelemetryDefaultEvent.m in Sources */ = {isa = PBXBuildFile; fileRef = 600401AA1D3443D30020EAAB /* ADTelemetryDefaultEvent.m */; }; 600401B11D3578C30020EAAB /* ADTelemetryTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 600401B01D3578C30020EAAB /* ADTelemetryTests.m */; }; 600401B21D3578C30020EAAB /* ADTelemetryTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 600401B01D3578C30020EAAB /* ADTelemetryTests.m */; }; 600401B61D37658C0020EAAB /* ADAggregatedDispatcher.m in Headers */ = {isa = PBXBuildFile; fileRef = 600401B51D37658C0020EAAB /* ADAggregatedDispatcher.m */; }; - 600401B81D3766F80020EAAB /* ADEventInterface.h in Headers */ = {isa = PBXBuildFile; fileRef = 600401B71D3766F80020EAAB /* ADEventInterface.h */; }; + 600401B81D3766F80020EAAB /* ADTelemetryEventInterface.h in Headers */ = {isa = PBXBuildFile; fileRef = 600401B71D3766F80020EAAB /* ADTelemetryEventInterface.h */; }; 600401B91D377ACC0020EAAB /* ADAggregatedDispatcher.m in Sources */ = {isa = PBXBuildFile; fileRef = 600401B51D37658C0020EAAB /* ADAggregatedDispatcher.m */; }; 600401BD1D377E9F0020EAAB /* ADDefaultDispatcher.m in Sources */ = {isa = PBXBuildFile; fileRef = 600401BC1D377E9F0020EAAB /* ADDefaultDispatcher.m */; }; 600401BE1D377E9F0020EAAB /* ADDefaultDispatcher.m in Sources */ = {isa = PBXBuildFile; fileRef = 600401BC1D377E9F0020EAAB /* ADDefaultDispatcher.m */; }; @@ -40,21 +40,21 @@ 600401C01D3868B20020EAAB /* ADAggregatedDispatcher.m in Sources */ = {isa = PBXBuildFile; fileRef = 600401B51D37658C0020EAAB /* ADAggregatedDispatcher.m */; }; 600401C21D39A18E0020EAAB /* ADDefaultDispatcher.h in Headers */ = {isa = PBXBuildFile; fileRef = 600401C11D39A18E0020EAAB /* ADDefaultDispatcher.h */; }; 600401C41D3D58D50020EAAB /* ADAggregatedDispatcher.h in Headers */ = {isa = PBXBuildFile; fileRef = 600401C31D3D58D50020EAAB /* ADAggregatedDispatcher.h */; }; - 6010EDE41D47B1AC00B62072 /* ADAPIEvent.h in Headers */ = {isa = PBXBuildFile; fileRef = 6010EDE31D47B1AC00B62072 /* ADAPIEvent.h */; }; - 6010EDE61D47B21600B62072 /* ADAPIEvent.m in Sources */ = {isa = PBXBuildFile; fileRef = 6010EDE51D47B21600B62072 /* ADAPIEvent.m */; }; - 6010EDE71D47B21600B62072 /* ADAPIEvent.m in Sources */ = {isa = PBXBuildFile; fileRef = 6010EDE51D47B21600B62072 /* ADAPIEvent.m */; }; - 6010EDE91D47B26300B62072 /* ADUIEvent.h in Headers */ = {isa = PBXBuildFile; fileRef = 6010EDE81D47B26300B62072 /* ADUIEvent.h */; }; - 6010EDEB1D47B27400B62072 /* ADUIEvent.m in Sources */ = {isa = PBXBuildFile; fileRef = 6010EDEA1D47B27400B62072 /* ADUIEvent.m */; }; - 6010EDEC1D47B27400B62072 /* ADUIEvent.m in Sources */ = {isa = PBXBuildFile; fileRef = 6010EDEA1D47B27400B62072 /* ADUIEvent.m */; }; - 6010EDEE1D47B29500B62072 /* ADHttpEvent.h in Headers */ = {isa = PBXBuildFile; fileRef = 6010EDED1D47B29500B62072 /* ADHttpEvent.h */; }; - 6010EDF01D47B2A600B62072 /* ADHttpEvent.m in Sources */ = {isa = PBXBuildFile; fileRef = 6010EDEF1D47B2A600B62072 /* ADHttpEvent.m */; }; - 6010EDF11D47B2A600B62072 /* ADHttpEvent.m in Sources */ = {isa = PBXBuildFile; fileRef = 6010EDEF1D47B2A600B62072 /* ADHttpEvent.m */; }; - 6010EDF31D47B2BD00B62072 /* ADCacheEvent.h in Headers */ = {isa = PBXBuildFile; fileRef = 6010EDF21D47B2BD00B62072 /* ADCacheEvent.h */; }; - 6010EDF51D47B2CE00B62072 /* ADCacheEvent.m in Sources */ = {isa = PBXBuildFile; fileRef = 6010EDF41D47B2CE00B62072 /* ADCacheEvent.m */; }; - 6010EDF61D47B2CE00B62072 /* ADCacheEvent.m in Sources */ = {isa = PBXBuildFile; fileRef = 6010EDF41D47B2CE00B62072 /* ADCacheEvent.m */; }; - 6010EDF81D47B2E300B62072 /* ADBrokerEvent.h in Headers */ = {isa = PBXBuildFile; fileRef = 6010EDF71D47B2E300B62072 /* ADBrokerEvent.h */; }; - 6010EDFA1D47B2F300B62072 /* ADBrokerEvent.m in Sources */ = {isa = PBXBuildFile; fileRef = 6010EDF91D47B2F300B62072 /* ADBrokerEvent.m */; }; - 6010EDFB1D47B2F300B62072 /* ADBrokerEvent.m in Sources */ = {isa = PBXBuildFile; fileRef = 6010EDF91D47B2F300B62072 /* ADBrokerEvent.m */; }; + 6010EDE41D47B1AC00B62072 /* ADTelemetryAPIEvent.h in Headers */ = {isa = PBXBuildFile; fileRef = 6010EDE31D47B1AC00B62072 /* ADTelemetryAPIEvent.h */; }; + 6010EDE61D47B21600B62072 /* ADTelemetryAPIEvent.m in Sources */ = {isa = PBXBuildFile; fileRef = 6010EDE51D47B21600B62072 /* ADTelemetryAPIEvent.m */; }; + 6010EDE71D47B21600B62072 /* ADTelemetryAPIEvent.m in Sources */ = {isa = PBXBuildFile; fileRef = 6010EDE51D47B21600B62072 /* ADTelemetryAPIEvent.m */; }; + 6010EDE91D47B26300B62072 /* ADTelemetryUIEvent.h in Headers */ = {isa = PBXBuildFile; fileRef = 6010EDE81D47B26300B62072 /* ADTelemetryUIEvent.h */; }; + 6010EDEB1D47B27400B62072 /* ADTelemetryUIEvent.m in Sources */ = {isa = PBXBuildFile; fileRef = 6010EDEA1D47B27400B62072 /* ADTelemetryUIEvent.m */; }; + 6010EDEC1D47B27400B62072 /* ADTelemetryUIEvent.m in Sources */ = {isa = PBXBuildFile; fileRef = 6010EDEA1D47B27400B62072 /* ADTelemetryUIEvent.m */; }; + 6010EDEE1D47B29500B62072 /* ADTelemetryHttpEvent.h in Headers */ = {isa = PBXBuildFile; fileRef = 6010EDED1D47B29500B62072 /* ADTelemetryHttpEvent.h */; }; + 6010EDF01D47B2A600B62072 /* ADTelemetryHttpEvent.m in Sources */ = {isa = PBXBuildFile; fileRef = 6010EDEF1D47B2A600B62072 /* ADTelemetryHttpEvent.m */; }; + 6010EDF11D47B2A600B62072 /* ADTelemetryHttpEvent.m in Sources */ = {isa = PBXBuildFile; fileRef = 6010EDEF1D47B2A600B62072 /* ADTelemetryHttpEvent.m */; }; + 6010EDF31D47B2BD00B62072 /* ADTelemetryCacheEvent.h in Headers */ = {isa = PBXBuildFile; fileRef = 6010EDF21D47B2BD00B62072 /* ADTelemetryCacheEvent.h */; }; + 6010EDF51D47B2CE00B62072 /* ADTelemetryCacheEvent.m in Sources */ = {isa = PBXBuildFile; fileRef = 6010EDF41D47B2CE00B62072 /* ADTelemetryCacheEvent.m */; }; + 6010EDF61D47B2CE00B62072 /* ADTelemetryCacheEvent.m in Sources */ = {isa = PBXBuildFile; fileRef = 6010EDF41D47B2CE00B62072 /* ADTelemetryCacheEvent.m */; }; + 6010EDF81D47B2E300B62072 /* ADTelemetryBrokerEvent.h in Headers */ = {isa = PBXBuildFile; fileRef = 6010EDF71D47B2E300B62072 /* ADTelemetryBrokerEvent.h */; }; + 6010EDFA1D47B2F300B62072 /* ADTelemetryBrokerEvent.m in Sources */ = {isa = PBXBuildFile; fileRef = 6010EDF91D47B2F300B62072 /* ADTelemetryBrokerEvent.m */; }; + 6010EDFB1D47B2F300B62072 /* ADTelemetryBrokerEvent.m in Sources */ = {isa = PBXBuildFile; fileRef = 6010EDF91D47B2F300B62072 /* ADTelemetryBrokerEvent.m */; }; 601BEE311C6DAA86004AA8C1 /* ADTestAuthenticationViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 601BEE301C6DAA86004AA8C1 /* ADTestAuthenticationViewController.m */; }; 601BEE321C6DAA86004AA8C1 /* ADTestAuthenticationViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 601BEE301C6DAA86004AA8C1 /* ADTestAuthenticationViewController.m */; }; 601BEE341C6DCB0B004AA8C1 /* ADWebAuthControllerTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 601BEE331C6DCB0B004AA8C1 /* ADWebAuthControllerTests.m */; }; @@ -443,24 +443,24 @@ 6004019F1D340B760020EAAB /* ADTelemetry.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ADTelemetry.h; sourceTree = ""; }; 600401A31D3421480020EAAB /* ADTelemetry.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ADTelemetry.m; sourceTree = ""; }; 600401A61D3426250020EAAB /* ADTelemetry+Internal.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "ADTelemetry+Internal.h"; sourceTree = ""; }; - 600401A81D3428770020EAAB /* ADDefaultEvent.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ADDefaultEvent.h; sourceTree = ""; }; - 600401AA1D3443D30020EAAB /* ADDefaultEvent.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ADDefaultEvent.m; sourceTree = ""; }; + 600401A81D3428770020EAAB /* ADTelemetryDefaultEvent.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ADTelemetryDefaultEvent.h; sourceTree = ""; }; + 600401AA1D3443D30020EAAB /* ADTelemetryDefaultEvent.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ADTelemetryDefaultEvent.m; sourceTree = ""; }; 600401B01D3578C30020EAAB /* ADTelemetryTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ADTelemetryTests.m; sourceTree = ""; }; 600401B51D37658C0020EAAB /* ADAggregatedDispatcher.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ADAggregatedDispatcher.m; sourceTree = ""; }; - 600401B71D3766F80020EAAB /* ADEventInterface.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ADEventInterface.h; sourceTree = ""; }; + 600401B71D3766F80020EAAB /* ADTelemetryEventInterface.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ADTelemetryEventInterface.h; sourceTree = ""; }; 600401BC1D377E9F0020EAAB /* ADDefaultDispatcher.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ADDefaultDispatcher.m; sourceTree = ""; }; 600401C11D39A18E0020EAAB /* ADDefaultDispatcher.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ADDefaultDispatcher.h; sourceTree = ""; }; 600401C31D3D58D50020EAAB /* ADAggregatedDispatcher.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ADAggregatedDispatcher.h; sourceTree = ""; }; - 6010EDE31D47B1AC00B62072 /* ADAPIEvent.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ADAPIEvent.h; sourceTree = ""; }; - 6010EDE51D47B21600B62072 /* ADAPIEvent.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ADAPIEvent.m; sourceTree = ""; }; - 6010EDE81D47B26300B62072 /* ADUIEvent.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ADUIEvent.h; sourceTree = ""; }; - 6010EDEA1D47B27400B62072 /* ADUIEvent.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ADUIEvent.m; sourceTree = ""; }; - 6010EDED1D47B29500B62072 /* ADHttpEvent.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ADHttpEvent.h; sourceTree = ""; }; - 6010EDEF1D47B2A600B62072 /* ADHttpEvent.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ADHttpEvent.m; sourceTree = ""; }; - 6010EDF21D47B2BD00B62072 /* ADCacheEvent.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ADCacheEvent.h; sourceTree = ""; }; - 6010EDF41D47B2CE00B62072 /* ADCacheEvent.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ADCacheEvent.m; sourceTree = ""; }; - 6010EDF71D47B2E300B62072 /* ADBrokerEvent.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ADBrokerEvent.h; sourceTree = ""; }; - 6010EDF91D47B2F300B62072 /* ADBrokerEvent.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ADBrokerEvent.m; sourceTree = ""; }; + 6010EDE31D47B1AC00B62072 /* ADTelemetryAPIEvent.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ADTelemetryAPIEvent.h; sourceTree = ""; }; + 6010EDE51D47B21600B62072 /* ADTelemetryAPIEvent.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ADTelemetryAPIEvent.m; sourceTree = ""; }; + 6010EDE81D47B26300B62072 /* ADTelemetryUIEvent.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ADTelemetryUIEvent.h; sourceTree = ""; }; + 6010EDEA1D47B27400B62072 /* ADTelemetryUIEvent.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ADTelemetryUIEvent.m; sourceTree = ""; }; + 6010EDED1D47B29500B62072 /* ADTelemetryHttpEvent.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ADTelemetryHttpEvent.h; sourceTree = ""; }; + 6010EDEF1D47B2A600B62072 /* ADTelemetryHttpEvent.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ADTelemetryHttpEvent.m; sourceTree = ""; }; + 6010EDF21D47B2BD00B62072 /* ADTelemetryCacheEvent.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ADTelemetryCacheEvent.h; sourceTree = ""; }; + 6010EDF41D47B2CE00B62072 /* ADTelemetryCacheEvent.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ADTelemetryCacheEvent.m; sourceTree = ""; }; + 6010EDF71D47B2E300B62072 /* ADTelemetryBrokerEvent.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ADTelemetryBrokerEvent.h; sourceTree = ""; }; + 6010EDF91D47B2F300B62072 /* ADTelemetryBrokerEvent.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ADTelemetryBrokerEvent.m; sourceTree = ""; }; 601BEE2F1C6D9CCE004AA8C1 /* ADTestAuthenticationViewController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ADTestAuthenticationViewController.h; sourceTree = ""; }; 601BEE301C6DAA86004AA8C1 /* ADTestAuthenticationViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ADTestAuthenticationViewController.m; sourceTree = ""; }; 601BEE331C6DCB0B004AA8C1 /* ADWebAuthControllerTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ADWebAuthControllerTests.m; sourceTree = ""; }; @@ -710,19 +710,19 @@ 600401BC1D377E9F0020EAAB /* ADDefaultDispatcher.m */, 600401C31D3D58D50020EAAB /* ADAggregatedDispatcher.h */, 600401B51D37658C0020EAAB /* ADAggregatedDispatcher.m */, - 600401B71D3766F80020EAAB /* ADEventInterface.h */, - 600401A81D3428770020EAAB /* ADDefaultEvent.h */, - 600401AA1D3443D30020EAAB /* ADDefaultEvent.m */, - 6010EDE31D47B1AC00B62072 /* ADAPIEvent.h */, - 6010EDE51D47B21600B62072 /* ADAPIEvent.m */, - 6010EDE81D47B26300B62072 /* ADUIEvent.h */, - 6010EDEA1D47B27400B62072 /* ADUIEvent.m */, - 6010EDED1D47B29500B62072 /* ADHttpEvent.h */, - 6010EDEF1D47B2A600B62072 /* ADHttpEvent.m */, - 6010EDF21D47B2BD00B62072 /* ADCacheEvent.h */, - 6010EDF41D47B2CE00B62072 /* ADCacheEvent.m */, - 6010EDF71D47B2E300B62072 /* ADBrokerEvent.h */, - 6010EDF91D47B2F300B62072 /* ADBrokerEvent.m */, + 600401B71D3766F80020EAAB /* ADTelemetryEventInterface.h */, + 600401A81D3428770020EAAB /* ADTelemetryDefaultEvent.h */, + 600401AA1D3443D30020EAAB /* ADTelemetryDefaultEvent.m */, + 6010EDE31D47B1AC00B62072 /* ADTelemetryAPIEvent.h */, + 6010EDE51D47B21600B62072 /* ADTelemetryAPIEvent.m */, + 6010EDE81D47B26300B62072 /* ADTelemetryUIEvent.h */, + 6010EDEA1D47B27400B62072 /* ADTelemetryUIEvent.m */, + 6010EDED1D47B29500B62072 /* ADTelemetryHttpEvent.h */, + 6010EDEF1D47B2A600B62072 /* ADTelemetryHttpEvent.m */, + 6010EDF21D47B2BD00B62072 /* ADTelemetryCacheEvent.h */, + 6010EDF41D47B2CE00B62072 /* ADTelemetryCacheEvent.m */, + 6010EDF71D47B2E300B62072 /* ADTelemetryBrokerEvent.h */, + 6010EDF91D47B2F300B62072 /* ADTelemetryBrokerEvent.m */, ); path = telemetry; sourceTree = ""; @@ -1204,7 +1204,7 @@ 9453C4151C586456006B9E79 /* ADLogger+Internal.h in Headers */, 94E0FD8E1C59614B00CD707B /* ADTokenCache.h in Headers */, 94DD18D01C5AC8DE00F80C62 /* ADAuthenticationContext.h in Headers */, - 600401B81D3766F80020EAAB /* ADEventInterface.h in Headers */, + 600401B81D3766F80020EAAB /* ADTelemetryEventInterface.h in Headers */, 9453C4121C586456006B9E79 /* ADInstanceDiscovery.h in Headers */, 9453C43A1C586476006B9E79 /* ADURLProtocol.h in Headers */, 9453C4221C586462006B9E79 /* ADTokenCacheAccessor.h in Headers */, @@ -1220,20 +1220,20 @@ 9453C41C1C586456006B9E79 /* ADClientMetrics.h in Headers */, 9453C4381C586476006B9E79 /* ADNTLMHandler.h in Headers */, 9453C4641C58707B006B9E79 /* ADCredentialCollectionController.h in Headers */, - 6010EDEE1D47B29500B62072 /* ADHttpEvent.h in Headers */, + 6010EDEE1D47B29500B62072 /* ADTelemetryHttpEvent.h in Headers */, 94DD18D81C5AC8DE00F80C62 /* ADUserIdentifier.h in Headers */, 9453C46A1C5870F5006B9E79 /* ADNTLMUIPrompt.h in Headers */, 600401A71D3426250020EAAB /* ADTelemetry+Internal.h in Headers */, 600401B61D37658C0020EAAB /* ADAggregatedDispatcher.m in Headers */, 9453C42E1C58646D006B9E79 /* ADAuthenticationRequest+Broker.h in Headers */, - 6010EDF31D47B2BD00B62072 /* ADCacheEvent.h in Headers */, + 6010EDF31D47B2BD00B62072 /* ADTelemetryCacheEvent.h in Headers */, 94DD18D11C5AC8DE00F80C62 /* ADAuthenticationError.h in Headers */, 600401C21D39A18E0020EAAB /* ADDefaultDispatcher.h in Headers */, - 600401A91D3428770020EAAB /* ADDefaultEvent.h in Headers */, + 600401A91D3428770020EAAB /* ADTelemetryDefaultEvent.h in Headers */, 9453C43E1C58647E006B9E79 /* ADHelpers.h in Headers */, 9453C4211C586462006B9E79 /* ADTokenCache+Internal.h in Headers */, 9453C44C1C586485006B9E79 /* ADPkeyAuthHelper.h in Headers */, - 6010EDE41D47B1AC00B62072 /* ADAPIEvent.h in Headers */, + 6010EDE41D47B1AC00B62072 /* ADTelemetryAPIEvent.h in Headers */, 9453C4421C58647E006B9E79 /* NSDictionary+ADExtensions.h in Headers */, 9453C43C1C58647E006B9E79 /* ADALFrameworkUtils.h in Headers */, 9453C4341C58646D006B9E79 /* ADWebResponse.h in Headers */, @@ -1243,14 +1243,14 @@ 9453C4321C58646D006B9E79 /* ADWebRequest.h in Headers */, 9453C4301C58646D006B9E79 /* ADAuthenticationRequest+WebRequest.h in Headers */, 9453C4241C586462006B9E79 /* ADTokenCacheItem+Internal.h in Headers */, - 6010EDE91D47B26300B62072 /* ADUIEvent.h in Headers */, + 6010EDE91D47B26300B62072 /* ADTelemetryUIEvent.h in Headers */, 94DD18D41C5AC8DE00F80C62 /* ADAuthenticationSettings.h in Headers */, 94DD18CF1C5AC8DE00F80C62 /* ADAL.h in Headers */, 94DD18DA1C5AC8DE00F80C62 /* ADWebAuthController.h in Headers */, 9453C4161C586456006B9E79 /* ADOAuth2Constants.h in Headers */, 94DD18D91C5AC8DE00F80C62 /* ADUserInformation.h in Headers */, 9453C4281C58646D006B9E79 /* ADAuthenticationRequest.h in Headers */, - 6010EDF81D47B2E300B62072 /* ADBrokerEvent.h in Headers */, + 6010EDF81D47B2E300B62072 /* ADTelemetryBrokerEvent.h in Headers */, 9453C4061C586456006B9E79 /* ADAL_Internal.h in Headers */, 9453C4441C58647E006B9E79 /* NSString+ADHelperMethods.h in Headers */, 9453C4361C586476006B9E79 /* ADCustomHeaderHandler.h in Headers */, @@ -1453,11 +1453,11 @@ D6F0951B1CDC2BC300D28FC2 /* ADWebAuthRequest.m in Sources */, 9453C4691C58709D006B9E79 /* ADNTLMUIPrompt.m in Sources */, 8B7E6FC81856A1E8000DC3C8 /* ADOAuth2Constants.m in Sources */, - 6010EDEB1D47B27400B62072 /* ADUIEvent.m in Sources */, + 6010EDEB1D47B27400B62072 /* ADTelemetryUIEvent.m in Sources */, 9453C3931C5820E3006B9E79 /* ADWebRequest.m in Sources */, 9453C3451C57FC2A006B9E79 /* ADTokenCacheKey.m in Sources */, 9453C3701C580157006B9E79 /* NSString+ADHelperMethods.m in Sources */, - 600401AB1D3443D30020EAAB /* ADDefaultEvent.m in Sources */, + 600401AB1D3443D30020EAAB /* ADTelemetryDefaultEvent.m in Sources */, 9453C39E1C5826F2006B9E79 /* ADURLProtocol.m in Sources */, D68040341D22F686007A61AC /* ADWebAuthResponse.m in Sources */, 9453C35D1C580143006B9E79 /* ADWorkPlaceJoinUtil.m in Sources */, @@ -1479,7 +1479,7 @@ 9453C36D1C580157006B9E79 /* ADHelpers.m in Sources */, 8BB8346218074CFA007F9F0D /* ADAuthenticationParameters.m in Sources */, 60D2F4011D531F16008725D9 /* ADRequestParameters.m in Sources */, - 6010EDF51D47B2CE00B62072 /* ADCacheEvent.m in Sources */, + 6010EDF51D47B2CE00B62072 /* ADTelemetryCacheEvent.m in Sources */, 946818A61C59B7F100CA0378 /* ADWebAuthController.m in Sources */, 9453C3221C57FBCB006B9E79 /* UIAlertView+Additions.m in Sources */, 9453C37D1C5801CB006B9E79 /* ADBrokerKeyHelper.m in Sources */, @@ -1488,7 +1488,7 @@ D610015E1D39A5620087AB81 /* ADKeychainUtil.m in Sources */, 9453C3711C580157006B9E79 /* NSURL+ADExtensions.m in Sources */, D6FB3E3C1B30D3630032F883 /* ADUserIdentifier.m in Sources */, - 6010EDF01D47B2A600B62072 /* ADHttpEvent.m in Sources */, + 6010EDF01D47B2A600B62072 /* ADTelemetryHttpEvent.m in Sources */, 600401A41D3421480020EAAB /* ADTelemetry.m in Sources */, 9453C3721C580157006B9E79 /* NSUUID+ADExtensions.m in Sources */, 9424B6821CDD1B2B00729698 /* ADTokenCacheAccessor.m in Sources */, @@ -1496,13 +1496,13 @@ 9453C3921C5820E3006B9E79 /* ADAuthenticationRequest+WebRequest.m in Sources */, 8B92DB70181B2335004AAB0E /* ADLogger.m in Sources */, 9453C3901C5820E3006B9E79 /* ADAuthenticationRequest+AcquireToken.m in Sources */, - 6010EDE61D47B21600B62072 /* ADAPIEvent.m in Sources */, + 6010EDE61D47B21600B62072 /* ADTelemetryAPIEvent.m in Sources */, 9453C3941C5820E3006B9E79 /* ADWebResponse.m in Sources */, 8B0DA7DE182AD01100CF5E1E /* ADAuthenticationResult+Internal.m in Sources */, 600401BD1D377E9F0020EAAB /* ADDefaultDispatcher.m in Sources */, 8B5989511811A3DB00744AEE /* ADAuthenticationError.m in Sources */, D6E43A6A1B04026D000F5BE2 /* ADAuthenticationContext+Internal.m in Sources */, - 6010EDFA1D47B2F300B62072 /* ADBrokerEvent.m in Sources */, + 6010EDFA1D47B2F300B62072 /* ADTelemetryBrokerEvent.m in Sources */, 9453C3421C57FC2A006B9E79 /* ADTokenCache.m in Sources */, 9453C4761C58750C006B9E79 /* ADBrokerHelper.m in Sources */, 9453C39C1C5826F2006B9E79 /* ADCustomHeaderHandler.m in Sources */, @@ -1559,9 +1559,9 @@ files = ( 600401C01D3868B20020EAAB /* ADAggregatedDispatcher.m in Sources */, 9453C4231C586462006B9E79 /* ADTokenCacheItem.m in Sources */, - 6010EDF11D47B2A600B62072 /* ADHttpEvent.m in Sources */, + 6010EDF11D47B2A600B62072 /* ADTelemetryHttpEvent.m in Sources */, 94DD18CA1C5A00BC00F80C62 /* ADAuthenticationViewController.m in Sources */, - 6010EDE71D47B21600B62072 /* ADAPIEvent.m in Sources */, + 6010EDE71D47B21600B62072 /* ADTelemetryAPIEvent.m in Sources */, 946818A71C59B7F200CA0378 /* ADWebAuthController.m in Sources */, 9453C4071C586456006B9E79 /* ADAuthenticationContext.m in Sources */, D68040351D22F686007A61AC /* ADWebAuthResponse.m in Sources */, @@ -1583,13 +1583,13 @@ 9453C4141C586456006B9E79 /* ADLogger.m in Sources */, 9453C41B1C586456006B9E79 /* ADClientMetrics.m in Sources */, D68040301D21C4EB007A61AC /* ADWorkPlaceJoinUtil.m in Sources */, - 6010EDFB1D47B2F300B62072 /* ADBrokerEvent.m in Sources */, + 6010EDFB1D47B2F300B62072 /* ADTelemetryBrokerEvent.m in Sources */, 9453C43D1C58647E006B9E79 /* ADALFrameworkUtils.m in Sources */, 9453C4371C586476006B9E79 /* ADCustomHeaderHandler.m in Sources */, 9453C4271C586462006B9E79 /* ADTokenCacheKey.m in Sources */, 9453C44D1C586485006B9E79 /* ADPkeyAuthHelper.m in Sources */, 9453C4741C5874FB006B9E79 /* ADBrokerHelper.m in Sources */, - 600401AC1D3443D30020EAAB /* ADDefaultEvent.m in Sources */, + 600401AC1D3443D30020EAAB /* ADTelemetryDefaultEvent.m in Sources */, 600401BE1D377E9F0020EAAB /* ADDefaultDispatcher.m in Sources */, 9453C43B1C586476006B9E79 /* ADURLProtocol.m in Sources */, 9453C42D1C58646D006B9E79 /* ADAuthenticationRequest+AcquireToken.m in Sources */, @@ -1602,9 +1602,9 @@ 9453C4131C586456006B9E79 /* ADInstanceDiscovery.m in Sources */, 9453C4181C586456006B9E79 /* ADUserInformation.m in Sources */, 9424B6841CDD39E400729698 /* ADTokenCacheAccessor.m in Sources */, - 6010EDEC1D47B27400B62072 /* ADUIEvent.m in Sources */, + 6010EDEC1D47B27400B62072 /* ADTelemetryUIEvent.m in Sources */, 9453C4331C58646D006B9E79 /* ADWebRequest.m in Sources */, - 6010EDF61D47B2CE00B62072 /* ADCacheEvent.m in Sources */, + 6010EDF61D47B2CE00B62072 /* ADTelemetryCacheEvent.m in Sources */, 9453C4351C58646D006B9E79 /* ADWebResponse.m in Sources */, 9453C4171C586456006B9E79 /* ADOAuth2Constants.m in Sources */, 60D2F4021D531F16008725D9 /* ADRequestParameters.m in Sources */, diff --git a/ADAL/src/cache/ADTokenCacheAccessor.m b/ADAL/src/cache/ADTokenCacheAccessor.m index 845b7b8f6..1ff77d1c2 100644 --- a/ADAL/src/cache/ADTokenCacheAccessor.m +++ b/ADAL/src/cache/ADTokenCacheAccessor.m @@ -29,7 +29,7 @@ #import "ADUserInformation.h" #import "ADTelemetry.h" #import "ADTelemetry+Internal.h" -#import "ADCacheEvent.h" +#import "ADTelemetryCacheEvent.h" @implementation ADTokenCacheAccessor @@ -87,7 +87,7 @@ - (ADTokenCacheItem *)getItemForUser:(ADUserIdentifier *)identifier correlationId:[requestParams correlationId] error:error]; - ADCacheEvent* event = [[ADCacheEvent alloc] initWithName:@"token_cache_lookup"]; + ADTelemetryCacheEvent* event = [[ADTelemetryCacheEvent alloc] initWithName:@"token_cache_lookup"]; [[ADTelemetry sharedInstance] stopEvent:[requestParams telemetryRequestId] event:event]; SAFE_ARC_RELEASE(event); @@ -156,7 +156,7 @@ - (ADTokenCacheItem*)getADFSUserTokenForResource:(NSString *)resource ADTokenCacheItem* item = [_dataSource getItemWithKey:key userId:@"" correlationId:[requestParams correlationId] error:error]; - ADCacheEvent* event = [[ADCacheEvent alloc] initWithName:@"token_cache_lookup"]; + ADTelemetryCacheEvent* event = [[ADTelemetryCacheEvent alloc] initWithName:@"token_cache_lookup"]; [[ADTelemetry sharedInstance] stopEvent:[requestParams telemetryRequestId] event:event]; SAFE_ARC_RELEASE(event); @@ -254,7 +254,7 @@ - (void)updateCacheToItem:(ADTokenCacheItem *)cacheItem [_dataSource addOrUpdateItem:cacheItem correlationId:[requestParams correlationId] error:nil]; cacheItem.refreshToken = savedRefreshToken;//Restore for the result - ADCacheEvent* event = [[ADCacheEvent alloc] initWithName:@"token_cache_write"]; + ADTelemetryCacheEvent* event = [[ADTelemetryCacheEvent alloc] initWithName:@"token_cache_write"]; [[ADTelemetry sharedInstance] stopEvent:[requestParams telemetryRequestId] event:event]; SAFE_ARC_RELEASE(event); } @@ -311,7 +311,7 @@ - (void)removeItemFromCache:(ADTokenCacheItem *)cacheItem } } - ADCacheEvent* event = [[ADCacheEvent alloc] initWithName:@"token_cache_delete_token"]; + ADTelemetryCacheEvent* event = [[ADTelemetryCacheEvent alloc] initWithName:@"token_cache_delete_token"]; [[ADTelemetry sharedInstance] stopEvent:[requestParams telemetryRequestId] event:event]; SAFE_ARC_RELEASE(event); } diff --git a/ADAL/src/request/ADAuthenticationRequest+AcquireToken.m b/ADAL/src/request/ADAuthenticationRequest+AcquireToken.m index ca5dbe190..472c57478 100644 --- a/ADAL/src/request/ADAuthenticationRequest+AcquireToken.m +++ b/ADAL/src/request/ADAuthenticationRequest+AcquireToken.m @@ -31,7 +31,7 @@ #import "ADAcquireTokenSilentHandler.h" #import "ADTelemetry.h" #import "ADTelemetry+Internal.h" -#import "ADAPIEvent.h" +#import "ADTelemetryAPIEvent.h" @implementation ADAuthenticationRequest (AcquireToken) @@ -47,7 +47,7 @@ - (void)acquireToken:(ADAuthenticationCallback)completionBlock [[ADTelemetry sharedInstance] startEvent:[self telemetryRequestId] eventName:@"acauire_token_call"]; ADAuthenticationCallback requestCompletion = ^void(ADAuthenticationResult *result) { - ADAPIEvent* event = [[ADAPIEvent alloc] initWithName:@"acauire_token_call"]; + ADTelemetryAPIEvent* event = [[ADTelemetryAPIEvent alloc] initWithName:@"acauire_token_call"]; [self fillTelemetryForAcquireToken:event result:result]; [[ADTelemetry sharedInstance] stopEvent:[self telemetryRequestId] event:event]; SAFE_ARC_RELEASE(event); @@ -95,7 +95,7 @@ - (void)acquireToken:(ADAuthenticationCallback)completionBlock requestParams:_requestParams completionBlock:^(BOOL validated, ADAuthenticationError *error) { - ADAPIEvent* event = [[ADAPIEvent alloc] initWithName:@"authority_validation"]; + ADTelemetryAPIEvent* event = [[ADTelemetryAPIEvent alloc] initWithName:@"authority_validation"]; [event setAuthorityValidationStatus:validated ? @"YES" : @"NO"]; [event setAuthority:_context.authority]; [[ADTelemetry sharedInstance] stopEvent:[self telemetryRequestId] event:event]; @@ -202,7 +202,7 @@ - (void)requestToken:(ADAuthenticationCallback)completionBlock [[ADTelemetry sharedInstance] startEvent:[self telemetryRequestId] eventName:@"authorization_code"]; [self requestCode:^(NSString * code, ADAuthenticationError *error) { - ADAPIEvent* event = [[ADAPIEvent alloc] initWithName:@"authorization_code"]; + ADTelemetryAPIEvent* event = [[ADTelemetryAPIEvent alloc] initWithName:@"authorization_code"]; [[ADTelemetry sharedInstance] stopEvent:[self telemetryRequestId] event:event]; SAFE_ARC_RELEASE(event); @@ -232,7 +232,7 @@ - (void)requestToken:(ADAuthenticationCallback)completionBlock [self requestTokenByCode:code completionBlock:^(ADAuthenticationResult *result) { - ADAPIEvent* event = [[ADAPIEvent alloc] initWithName:@"token_grant"]; + ADTelemetryAPIEvent* event = [[ADTelemetryAPIEvent alloc] initWithName:@"token_grant"]; [[ADTelemetry sharedInstance] stopEvent:[self telemetryRequestId] event:event]; SAFE_ARC_RELEASE(event); @@ -272,7 +272,7 @@ - (void)requestTokenByCode:(NSString *)code completion:completionBlock]; } -- (void)fillTelemetryForAcquireToken:(ADAPIEvent*)event +- (void)fillTelemetryForAcquireToken:(ADTelemetryAPIEvent*)event result:(ADAuthenticationResult*)result { [event setCorrelationId:[_requestParams correlationId]]; diff --git a/ADAL/src/request/ADAuthenticationRequest+Broker.m b/ADAL/src/request/ADAuthenticationRequest+Broker.m index be5dea4b0..33234d5b5 100644 --- a/ADAL/src/request/ADAuthenticationRequest+Broker.m +++ b/ADAL/src/request/ADAuthenticationRequest+Broker.m @@ -37,7 +37,7 @@ #import "ADAuthenticationResult.h" #import "ADTelemetry.h" #import "ADTelemetry+Internal.h" -#import "ADBrokerEvent.h" +#import "ADTelemetryBrokerEvent.h" #if TARGET_OS_IPHONE #import "ADKeychainTokenCache+Internal.h" @@ -222,7 +222,7 @@ - (void)callBroker:(ADAuthenticationCallback)completionBlock { [self releaseUserInterationLock]; // Release the lock when completion block is called. - ADBrokerEvent* event = [[ADBrokerEvent alloc] initWithName:@"launch_broker"]; + ADTelemetryBrokerEvent* event = [[ADTelemetryBrokerEvent alloc] initWithName:@"launch_broker"]; [[ADTelemetry sharedInstance] stopEvent:[self telemetryRequestId] event:event]; completionBlock(result); diff --git a/ADAL/src/request/ADAuthenticationRequest+WebRequest.m b/ADAL/src/request/ADAuthenticationRequest+WebRequest.m index bed298849..52ca05724 100755 --- a/ADAL/src/request/ADAuthenticationRequest+WebRequest.m +++ b/ADAL/src/request/ADAuthenticationRequest+WebRequest.m @@ -39,7 +39,7 @@ #import "ADWebAuthRequest.h" #import "ADTelemetry.h" #import "ADTelemetry+Internal.h" -#import "ADUIEvent.h" +#import "ADTelemetryUIEvent.h" #import @@ -181,7 +181,7 @@ - (void)launchWebView:(NSString*)startUrl [[ADTelemetry sharedInstance] startEvent:[self telemetryRequestId] eventName:@"launch_web_view"]; void(^requestCompletion)(ADAuthenticationError *error, NSURL *end) = ^void(ADAuthenticationError *error, NSURL *end) { - ADUIEvent* event = [[ADUIEvent alloc] initWithName:@"launch_web_view"]; + ADTelemetryUIEvent* event = [[ADTelemetryUIEvent alloc] initWithName:@"launch_web_view"]; [self fillTelemetryUIEvent:event]; [[ADTelemetry sharedInstance] stopEvent:[self telemetryRequestId] event:event]; @@ -329,7 +329,7 @@ - (void)requestCode:(ADAuthorizationCodeCallback)completionBlock } } -- (void)fillTelemetryUIEvent:(ADUIEvent*)event +- (void)fillTelemetryUIEvent:(ADTelemetryUIEvent*)event { if ([_requestParams identifier] && [[_requestParams identifier] isDisplayable] && ![NSString adIsStringNilOrBlank:[_requestParams identifier].userId]) { diff --git a/ADAL/src/request/ADWebRequest.m b/ADAL/src/request/ADWebRequest.m index c09aa2470..93f12b951 100644 --- a/ADAL/src/request/ADWebRequest.m +++ b/ADAL/src/request/ADWebRequest.m @@ -34,7 +34,7 @@ #import "ADURLProtocol.h" #import "ADTelemetry.h" #import "ADTelemetry+Internal.h" -#import "ADHttpEvent.h" +#import "ADTelemetryHttpEvent.h" @interface ADWebRequest () @@ -321,7 +321,7 @@ -(void)connection:(NSURLConnection *)connection didSendBodyData:(NSInteger)bytes - (void)stopTelemetryEvent:(NSError *)error response:(ADWebResponse *)response { - ADHttpEvent* event = [[ADHttpEvent alloc] initWithName:@"http_request"]; + ADTelemetryHttpEvent* event = [[ADTelemetryHttpEvent alloc] initWithName:@"http_request"]; [event setHttpMethod:_isGetRequest ? @"GET" : @"POST"]; [event setHttpPath:[[_requestURL host] stringByAppendingPathComponent:[_requestURL path]]]; diff --git a/ADAL/src/telemetry/ADAggregatedDispatcher.m b/ADAL/src/telemetry/ADAggregatedDispatcher.m index 9cf6701c5..5254c4c4e 100644 --- a/ADAL/src/telemetry/ADAggregatedDispatcher.m +++ b/ADAL/src/telemetry/ADAggregatedDispatcher.m @@ -22,7 +22,7 @@ // THE SOFTWARE. #import "ADTelemetry.h" -#import "ADEventInterface.h" +#import "ADTelemetryEventInterface.h" #import "ADAggregatedDispatcher.h" @implementation ADAggregatedDispatcher @@ -53,7 +53,7 @@ - (void)flush NSArray* events = [objectsToBeDispatched objectForKey:requestId]; NSMutableArray* aggregatedEvent = [NSMutableArray new]; - for (id event in events) + for (id event in events) { NSArray* properties = [event getProperties]; diff --git a/ADAL/src/telemetry/ADDefaultDispatcher.h b/ADAL/src/telemetry/ADDefaultDispatcher.h index 1ef273e91..5db71bfe7 100644 --- a/ADAL/src/telemetry/ADDefaultDispatcher.h +++ b/ADAL/src/telemetry/ADDefaultDispatcher.h @@ -31,7 +31,7 @@ - (id)initWithDispatcher:(id)dispatcher; - (void)receive:(NSString *)requestId - event:(id)event; + event:(id)event; - (void)flush; diff --git a/ADAL/src/telemetry/ADDefaultDispatcher.m b/ADAL/src/telemetry/ADDefaultDispatcher.m index 75d63b4d7..50946a2a2 100644 --- a/ADAL/src/telemetry/ADDefaultDispatcher.m +++ b/ADAL/src/telemetry/ADDefaultDispatcher.m @@ -22,7 +22,7 @@ // THE SOFTWARE. #import "ADTelemetry.h" -#import "ADEventInterface.h" +#import "ADTelemetryEventInterface.h" #import "ADDefaultDispatcher.h" @implementation ADDefaultDispatcher @@ -59,7 +59,7 @@ - (void)flush { NSArray* events = [objectsToBeDispatched objectForKey:requestId]; - for (id event in events) + for (id event in events) { NSArray* properties = [event getProperties]; if (properties) @@ -73,7 +73,7 @@ - (void)flush } - (void)receive:(NSString *)requestId - event:(id)event + event:(id)event { if ([NSString adIsStringNilOrBlank:requestId] || !event) { diff --git a/ADAL/src/telemetry/ADTelemetry+Internal.h b/ADAL/src/telemetry/ADTelemetry+Internal.h index 2ca3c6a67..54557ea25 100644 --- a/ADAL/src/telemetry/ADTelemetry+Internal.h +++ b/ADAL/src/telemetry/ADTelemetry+Internal.h @@ -21,7 +21,7 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN // THE SOFTWARE. -#import "ADEventInterface.h" +#import "ADTelemetryEventInterface.h" @interface ADTelemetry (Internal) @@ -31,10 +31,10 @@ eventName:(NSString*)eventName; - (void)stopEvent:(NSString*)requestId - event:(id)event; + event:(id)event; - (void)dispatchEventNow:(NSString*)requestId - event:(id)event; + event:(id)event; - (void)flush; diff --git a/ADAL/src/telemetry/ADTelemetry.m b/ADAL/src/telemetry/ADTelemetry.m index f526330fb..f20d75ab3 100644 --- a/ADAL/src/telemetry/ADTelemetry.m +++ b/ADAL/src/telemetry/ADTelemetry.m @@ -23,7 +23,7 @@ #import "ADTelemetry.h" #import "ADTelemetry+Internal.h" -#import "ADEventInterface.h" +#import "ADTelemetryEventInterface.h" #import "ADDefaultDispatcher.h" #import "ADAggregatedDispatcher.h" @@ -111,7 +111,7 @@ - (void)startEvent:(NSString*)requestId } - (void)stopEvent:(NSString*)requestId - event:(id)event + event:(id)event { NSString* eventName = [self getPropertyFromEvent:event propertyName:@"event_name"]; @@ -136,7 +136,7 @@ - (void)stopEvent:(NSString*)requestId } - (void)dispatchEventNow:(NSString*)requestId - event:(id)event + event:(id)event { @synchronized(self)//Guard against thread-unsafe callback and modification of _dispatcher after the check { @@ -153,7 +153,7 @@ - (NSString*)getEventTrackingKey:(NSString*)requestId return [NSString stringWithFormat:@"%@%@%@", requestId, s_delimiter, eventName]; } -- (NSString*)getPropertyFromEvent:(id)event +- (NSString*)getPropertyFromEvent:(id)event propertyName:(NSString*)propertyName { NSArray* properties = [event getProperties]; diff --git a/ADAL/src/telemetry/ADAPIEvent.h b/ADAL/src/telemetry/ADTelemetryAPIEvent.h similarity index 94% rename from ADAL/src/telemetry/ADAPIEvent.h rename to ADAL/src/telemetry/ADTelemetryAPIEvent.h index 7b6e1a08d..c88a1c280 100644 --- a/ADAL/src/telemetry/ADAPIEvent.h +++ b/ADAL/src/telemetry/ADTelemetryAPIEvent.h @@ -21,9 +21,9 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN // THE SOFTWARE. -#import "ADDefaultEvent.h" +#import "ADTelemetryDefaultEvent.h" -@interface ADAPIEvent : ADDefaultEvent +@interface ADTelemetryAPIEvent : ADTelemetryDefaultEvent - (void)setResultStatus:(ADAuthenticationResultStatus)status; - (void)setCorrelationId:(NSUUID*)correlationId; diff --git a/ADAL/src/telemetry/ADAPIEvent.m b/ADAL/src/telemetry/ADTelemetryAPIEvent.m similarity index 97% rename from ADAL/src/telemetry/ADAPIEvent.m rename to ADAL/src/telemetry/ADTelemetryAPIEvent.m index 92f6e1c4a..048a0edb4 100644 --- a/ADAL/src/telemetry/ADAPIEvent.m +++ b/ADAL/src/telemetry/ADTelemetryAPIEvent.m @@ -21,9 +21,9 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN // THE SOFTWARE. -#import "ADAPIEvent.h" +#import "ADTelemetryAPIEvent.h" -@implementation ADAPIEvent +@implementation ADTelemetryAPIEvent - (void)setResultStatus:(ADAuthenticationResultStatus)status { diff --git a/ADAL/src/telemetry/ADBrokerEvent.h b/ADAL/src/telemetry/ADTelemetryBrokerEvent.h similarity index 92% rename from ADAL/src/telemetry/ADBrokerEvent.h rename to ADAL/src/telemetry/ADTelemetryBrokerEvent.h index 4320a6056..fb0725985 100644 --- a/ADAL/src/telemetry/ADBrokerEvent.h +++ b/ADAL/src/telemetry/ADTelemetryBrokerEvent.h @@ -21,9 +21,9 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN // THE SOFTWARE. -#import "ADDefaultEvent.h" +#import "ADTelemetryDefaultEvent.h" -@interface ADBrokerEvent : ADDefaultEvent +@interface ADTelemetryBrokerEvent : ADTelemetryDefaultEvent - (void)setBrokerAppVersion:(NSString*)version; diff --git a/ADAL/src/telemetry/ADBrokerEvent.m b/ADAL/src/telemetry/ADTelemetryBrokerEvent.m similarity index 94% rename from ADAL/src/telemetry/ADBrokerEvent.m rename to ADAL/src/telemetry/ADTelemetryBrokerEvent.m index 2237f8707..0846790b9 100644 --- a/ADAL/src/telemetry/ADBrokerEvent.m +++ b/ADAL/src/telemetry/ADTelemetryBrokerEvent.m @@ -21,9 +21,9 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN // THE SOFTWARE. -#import "ADBrokerEvent.h" +#import "ADTelemetryBrokerEvent.h" -@implementation ADBrokerEvent +@implementation ADTelemetryBrokerEvent - (void)setBrokerAppVersion:(NSString*)version { diff --git a/ADAL/src/telemetry/ADCacheEvent.h b/ADAL/src/telemetry/ADTelemetryCacheEvent.h similarity index 92% rename from ADAL/src/telemetry/ADCacheEvent.h rename to ADAL/src/telemetry/ADTelemetryCacheEvent.h index c5ea7a649..1cb6c7641 100644 --- a/ADAL/src/telemetry/ADCacheEvent.h +++ b/ADAL/src/telemetry/ADTelemetryCacheEvent.h @@ -21,8 +21,8 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN // THE SOFTWARE. -#import "ADDefaultEvent.h" +#import "ADTelemetryDefaultEvent.h" -@interface ADCacheEvent : ADDefaultEvent +@interface ADTelemetryCacheEvent : ADTelemetryDefaultEvent @end \ No newline at end of file diff --git a/ADAL/src/telemetry/ADCacheEvent.m b/ADAL/src/telemetry/ADTelemetryCacheEvent.m similarity index 94% rename from ADAL/src/telemetry/ADCacheEvent.m rename to ADAL/src/telemetry/ADTelemetryCacheEvent.m index b12c728d4..422b7b935 100644 --- a/ADAL/src/telemetry/ADCacheEvent.m +++ b/ADAL/src/telemetry/ADTelemetryCacheEvent.m @@ -21,8 +21,8 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN // THE SOFTWARE. -#import "ADCacheEvent.h" +#import "ADTelemetryCacheEvent.h" -@implementation ADCacheEvent +@implementation ADTelemetryCacheEvent @end \ No newline at end of file diff --git a/ADAL/src/telemetry/ADDefaultEvent.h b/ADAL/src/telemetry/ADTelemetryDefaultEvent.h similarity index 91% rename from ADAL/src/telemetry/ADDefaultEvent.h rename to ADAL/src/telemetry/ADTelemetryDefaultEvent.h index 675385f3f..5a6fa45a8 100644 --- a/ADAL/src/telemetry/ADDefaultEvent.h +++ b/ADAL/src/telemetry/ADTelemetryDefaultEvent.h @@ -21,9 +21,9 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN // THE SOFTWARE. -#import "ADEventInterface.h" +#import "ADTelemetryEventInterface.h" -@interface ADDefaultEvent : NSObject +@interface ADTelemetryDefaultEvent : NSObject { NSMutableArray* _propertyMap; } diff --git a/ADAL/src/telemetry/ADDefaultEvent.m b/ADAL/src/telemetry/ADTelemetryDefaultEvent.m similarity index 97% rename from ADAL/src/telemetry/ADDefaultEvent.m rename to ADAL/src/telemetry/ADTelemetryDefaultEvent.m index b78eb48b8..7dbaecf3a 100644 --- a/ADAL/src/telemetry/ADDefaultEvent.m +++ b/ADAL/src/telemetry/ADTelemetryDefaultEvent.m @@ -21,15 +21,15 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN // THE SOFTWARE. -#import "ADDefaultEvent.h" -#import "ADEventInterface.h" +#import "ADTelemetryDefaultEvent.h" +#import "ADTelemetryEventInterface.h" #if !TARGET_OS_IPHONE #include #include #endif -@implementation ADDefaultEvent +@implementation ADTelemetryDefaultEvent @synthesize propertyMap = _propertyMap; diff --git a/ADAL/src/telemetry/ADEventInterface.h b/ADAL/src/telemetry/ADTelemetryEventInterface.h similarity index 96% rename from ADAL/src/telemetry/ADEventInterface.h rename to ADAL/src/telemetry/ADTelemetryEventInterface.h index 521741df6..248edb54f 100644 --- a/ADAL/src/telemetry/ADEventInterface.h +++ b/ADAL/src/telemetry/ADTelemetryEventInterface.h @@ -21,7 +21,7 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN // THE SOFTWARE. -@protocol ADEventInterface +@protocol ADTelemetryEventInterface @property (readonly) NSMutableArray* propertyMap; diff --git a/ADAL/src/telemetry/ADHttpEvent.h b/ADAL/src/telemetry/ADTelemetryHttpEvent.h similarity index 93% rename from ADAL/src/telemetry/ADHttpEvent.h rename to ADAL/src/telemetry/ADTelemetryHttpEvent.h index 5c8a870c1..068c63db2 100644 --- a/ADAL/src/telemetry/ADHttpEvent.h +++ b/ADAL/src/telemetry/ADTelemetryHttpEvent.h @@ -21,9 +21,9 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN // THE SOFTWARE. -#import "ADDefaultEvent.h" +#import "ADTelemetryDefaultEvent.h" -@interface ADHttpEvent : ADDefaultEvent +@interface ADTelemetryHttpEvent : ADTelemetryDefaultEvent - (void)setHttpMethod:(NSString*)method; - (void)setHttpPath:(NSString*)path; diff --git a/ADAL/src/telemetry/ADHttpEvent.m b/ADAL/src/telemetry/ADTelemetryHttpEvent.m similarity index 97% rename from ADAL/src/telemetry/ADHttpEvent.m rename to ADAL/src/telemetry/ADTelemetryHttpEvent.m index 840ec7dd5..b152ac8aa 100644 --- a/ADAL/src/telemetry/ADHttpEvent.m +++ b/ADAL/src/telemetry/ADTelemetryHttpEvent.m @@ -21,9 +21,9 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN // THE SOFTWARE. -#import "ADHttpEvent.h" +#import "ADTelemetryHttpEvent.h" -@implementation ADHttpEvent +@implementation ADTelemetryHttpEvent - (void)setHttpMethod:(NSString*)method { diff --git a/ADAL/src/telemetry/ADUIEvent.h b/ADAL/src/telemetry/ADTelemetryUIEvent.h similarity index 93% rename from ADAL/src/telemetry/ADUIEvent.h rename to ADAL/src/telemetry/ADTelemetryUIEvent.h index 0c5f3adda..1cd2cec01 100644 --- a/ADAL/src/telemetry/ADUIEvent.h +++ b/ADAL/src/telemetry/ADTelemetryUIEvent.h @@ -21,9 +21,9 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN // THE SOFTWARE. -#import "ADDefaultEvent.h" +#import "ADTelemetryDefaultEvent.h" -@interface ADUIEvent : ADDefaultEvent +@interface ADTelemetryUIEvent : ADTelemetryDefaultEvent - (void)setLoginHint:(NSString*)hint; diff --git a/ADAL/src/telemetry/ADUIEvent.m b/ADAL/src/telemetry/ADTelemetryUIEvent.m similarity index 95% rename from ADAL/src/telemetry/ADUIEvent.m rename to ADAL/src/telemetry/ADTelemetryUIEvent.m index 206a46abd..91ca18c00 100644 --- a/ADAL/src/telemetry/ADUIEvent.m +++ b/ADAL/src/telemetry/ADTelemetryUIEvent.m @@ -21,9 +21,9 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN // THE SOFTWARE. -#import "ADUIEvent.h" +#import "ADTelemetryUIEvent.h" -@implementation ADUIEvent +@implementation ADTelemetryUIEvent - (void)setLoginHint:(NSString*)hint { diff --git a/ADAL/tests/ADTelemetryTests.m b/ADAL/tests/ADTelemetryTests.m index b4dff1dcd..36d4a47e8 100644 --- a/ADAL/tests/ADTelemetryTests.m +++ b/ADAL/tests/ADTelemetryTests.m @@ -24,7 +24,7 @@ #import #import "ADTelemetry.h" #import "ADTelemetry+Internal.h" -#import "ADDefaultEvent.h" +#import "ADTelemetryDefaultEvent.h" typedef void(^TestCallback)(NSArray* event); @@ -87,7 +87,7 @@ - (void)testDefaultEventProperties { NSString* requestId = [[ADTelemetry sharedInstance] registerNewRequest]; [[ADTelemetry sharedInstance] startEvent:requestId eventName:@"testEvent"]; [[ADTelemetry sharedInstance] stopEvent:requestId - event:[[ADDefaultEvent alloc] initWithName:@"testEvent"]]; + event:[[ADTelemetryDefaultEvent alloc] initWithName:@"testEvent"]]; [[ADTelemetry sharedInstance] flush]; @@ -134,11 +134,11 @@ - (void)testSequentialEvents { NSString* requestId = [[ADTelemetry sharedInstance] registerNewRequest]; [[ADTelemetry sharedInstance] startEvent:requestId eventName:@"testEvent1"]; [[ADTelemetry sharedInstance] stopEvent:requestId - event:[[ADDefaultEvent alloc] initWithName:@"testEvent1"]]; + event:[[ADTelemetryDefaultEvent alloc] initWithName:@"testEvent1"]]; // generate telemetry event 2 [[ADTelemetry sharedInstance] startEvent:requestId eventName:@"testEvent2"]; - ADDefaultEvent* event2 = [[ADDefaultEvent alloc] initWithName:@"testEvent2"]; + ADTelemetryDefaultEvent* event2 = [[ADTelemetryDefaultEvent alloc] initWithName:@"testEvent2"]; [event2 setProperty:@"customized_property" value:@"customized_value"]; [[ADTelemetry sharedInstance] stopEvent:requestId event:event2]; @@ -204,11 +204,11 @@ - (void)testSequentialEventsWithAggregation { NSString* requestId = [[ADTelemetry sharedInstance] registerNewRequest]; [[ADTelemetry sharedInstance] startEvent:requestId eventName:@"testEvent1"]; [[ADTelemetry sharedInstance] stopEvent:requestId - event:[[ADDefaultEvent alloc] initWithName:@"testEvent1"]]; + event:[[ADTelemetryDefaultEvent alloc] initWithName:@"testEvent1"]]; // generate telemetry event 2 [[ADTelemetry sharedInstance] startEvent:requestId eventName:@"testEvent2"]; - ADDefaultEvent* event2 = [[ADDefaultEvent alloc] initWithName:@"testEvent2"]; + ADTelemetryDefaultEvent* event2 = [[ADTelemetryDefaultEvent alloc] initWithName:@"testEvent2"]; [event2 setProperty:@"customized_property" value:@"customized_value"]; [[ADTelemetry sharedInstance] stopEvent:requestId event:event2]; @@ -253,13 +253,13 @@ - (void)testNestedEvents { [[ADTelemetry sharedInstance] startEvent:requestId eventName:@"testEvent1"]; [[ADTelemetry sharedInstance] startEvent:requestId eventName:@"testEvent2"]; - ADDefaultEvent* event2 = [[ADDefaultEvent alloc] initWithName:@"testEvent2"]; + ADTelemetryDefaultEvent* event2 = [[ADTelemetryDefaultEvent alloc] initWithName:@"testEvent2"]; [event2 setProperty:@"customized_property" value:@"customized_value"]; [[ADTelemetry sharedInstance] stopEvent:requestId event:event2]; [[ADTelemetry sharedInstance] stopEvent:requestId - event:[[ADDefaultEvent alloc] initWithName:@"testEvent1"]]; + event:[[ADTelemetryDefaultEvent alloc] initWithName:@"testEvent1"]]; [[ADTelemetry sharedInstance] flush]; @@ -326,13 +326,13 @@ - (void)testNestedEventsWithAggregation { [[ADTelemetry sharedInstance] startEvent:requestId eventName:@"testEvent1"]; [[ADTelemetry sharedInstance] startEvent:requestId eventName:@"testEvent2"]; - ADDefaultEvent* event2 = [[ADDefaultEvent alloc] initWithName:@"testEvent2"]; + ADTelemetryDefaultEvent* event2 = [[ADTelemetryDefaultEvent alloc] initWithName:@"testEvent2"]; [event2 setProperty:@"customized_property" value:@"customized_value"]; [[ADTelemetry sharedInstance] stopEvent:requestId event:event2]; [[ADTelemetry sharedInstance] stopEvent:requestId - event:[[ADDefaultEvent alloc] initWithName:@"testEvent1"]]; + event:[[ADTelemetryDefaultEvent alloc] initWithName:@"testEvent1"]]; [[ADTelemetry sharedInstance] flush]; @@ -375,17 +375,17 @@ - (void)testComplexEvents { [[ADTelemetry sharedInstance] startEvent:requestId eventName:@"testEvent3"]; [[ADTelemetry sharedInstance] stopEvent:requestId - event:[[ADDefaultEvent alloc] initWithName:@"testEvent3"]]; + event:[[ADTelemetryDefaultEvent alloc] initWithName:@"testEvent3"]]; [[ADTelemetry sharedInstance] stopEvent:requestId - event:[[ADDefaultEvent alloc] initWithName:@"testEvent2"]]; + event:[[ADTelemetryDefaultEvent alloc] initWithName:@"testEvent2"]]; [[ADTelemetry sharedInstance] stopEvent:requestId - event:[[ADDefaultEvent alloc] initWithName:@"testEvent1"]]; + event:[[ADTelemetryDefaultEvent alloc] initWithName:@"testEvent1"]]; [[ADTelemetry sharedInstance] startEvent:requestId eventName:@"testEvent4"]; [[ADTelemetry sharedInstance] stopEvent:requestId - event:[[ADDefaultEvent alloc] initWithName:@"testEvent4"]]; + event:[[ADTelemetryDefaultEvent alloc] initWithName:@"testEvent4"]]; [[ADTelemetry sharedInstance] flush]; @@ -479,17 +479,17 @@ - (void)testComplexEventsWithAggregation { [[ADTelemetry sharedInstance] startEvent:requestId eventName:@"testEvent3"]; [[ADTelemetry sharedInstance] stopEvent:requestId - event:[[ADDefaultEvent alloc] initWithName:@"testEvent3"]]; + event:[[ADTelemetryDefaultEvent alloc] initWithName:@"testEvent3"]]; [[ADTelemetry sharedInstance] stopEvent:requestId - event:[[ADDefaultEvent alloc] initWithName:@"testEvent2"]]; + event:[[ADTelemetryDefaultEvent alloc] initWithName:@"testEvent2"]]; [[ADTelemetry sharedInstance] stopEvent:requestId - event:[[ADDefaultEvent alloc] initWithName:@"testEvent1"]]; + event:[[ADTelemetryDefaultEvent alloc] initWithName:@"testEvent1"]]; [[ADTelemetry sharedInstance] startEvent:requestId eventName:@"testEvent4"]; [[ADTelemetry sharedInstance] stopEvent:requestId - event:[[ADDefaultEvent alloc] initWithName:@"testEvent4"]]; + event:[[ADTelemetryDefaultEvent alloc] initWithName:@"testEvent4"]]; [[ADTelemetry sharedInstance] flush]; From 647c5cd10752cb4b434da0597a58c8c002a956ba Mon Sep 17 00:00:00 2001 From: YONG ZENG Date: Fri, 5 Aug 2016 00:18:02 -0700 Subject: [PATCH 07/92] apply telemetry to more places --- ADAL/src/cache/ADTokenCacheAccessor.m | 71 ++++++++++++++----- .../src/request/ADAcquireTokenSilentHandler.m | 10 +++ .../ADAuthenticationRequest+AcquireToken.m | 21 +++++- .../request/ADAuthenticationRequest+Broker.m | 1 + ADAL/src/telemetry/ADTelemetryAPIEvent.h | 3 + ADAL/src/telemetry/ADTelemetryAPIEvent.m | 10 +++ ADAL/src/telemetry/ADTelemetryBrokerEvent.h | 1 + ADAL/src/telemetry/ADTelemetryBrokerEvent.m | 20 ++++++ ADAL/src/telemetry/ADTelemetryCacheEvent.h | 3 + ADAL/src/telemetry/ADTelemetryCacheEvent.m | 10 +++ 10 files changed, 131 insertions(+), 19 deletions(-) diff --git a/ADAL/src/cache/ADTokenCacheAccessor.m b/ADAL/src/cache/ADTokenCacheAccessor.m index 1ff77d1c2..2006d7b9d 100644 --- a/ADAL/src/cache/ADTokenCacheAccessor.m +++ b/ADAL/src/cache/ADTokenCacheAccessor.m @@ -80,18 +80,10 @@ - (ADTokenCacheItem *)getItemForUser:(ADUserIdentifier *)identifier return nil; } - [[ADTelemetry sharedInstance] startEvent:[requestParams telemetryRequestId] eventName:@"token_cache_lookup"]; - - ADTokenCacheItem* item = [_dataSource getItemWithKey:key - userId:identifier.userId - correlationId:[requestParams correlationId] - error:error]; - - ADTelemetryCacheEvent* event = [[ADTelemetryCacheEvent alloc] initWithName:@"token_cache_lookup"]; - [[ADTelemetry sharedInstance] stopEvent:[requestParams telemetryRequestId] event:event]; - SAFE_ARC_RELEASE(event); - - return item; + return [_dataSource getItemWithKey:key + userId:identifier.userId + correlationId:[requestParams correlationId] + error:error]; } /*! @@ -105,7 +97,17 @@ - (ADTokenCacheItem *)getATRTItemForUser:(ADUserIdentifier *)identifier requestParams:(ADRequestParameters*)requestParams error:(ADAuthenticationError * __autoreleasing *)error { - return [self getItemForUser:identifier resource:resource clientId:clientId requestParams:requestParams error:error]; + [[ADTelemetry sharedInstance] startEvent:[requestParams telemetryRequestId] eventName:@"token_cache_lookup"]; + + ADTokenCacheItem* item = [self getItemForUser:identifier resource:resource clientId:clientId requestParams:requestParams error:error]; + + ADTelemetryCacheEvent* event = [[ADTelemetryCacheEvent alloc] initWithName:@"token_cache_lookup"]; + [event setTokenType:@"access token/refresh token"]; + [event setStatus:item? @"succeeded" : @"failed"]; + [[ADTelemetry sharedInstance] stopEvent:[requestParams telemetryRequestId] event:event]; + SAFE_ARC_RELEASE(event); + + return item; } /*! @@ -117,7 +119,17 @@ - (ADTokenCacheItem *)getMRRTItemForUser:(ADUserIdentifier *)identifier requestParams:(ADRequestParameters*)requestParams error:(ADAuthenticationError * __autoreleasing *)error { - return [self getItemForUser:identifier resource:nil clientId:clientId requestParams:requestParams error:error]; + [[ADTelemetry sharedInstance] startEvent:[requestParams telemetryRequestId] eventName:@"token_cache_lookup"]; + + ADTokenCacheItem* item = [self getItemForUser:identifier resource:nil clientId:clientId requestParams:requestParams error:error]; + + ADTelemetryCacheEvent* event = [[ADTelemetryCacheEvent alloc] initWithName:@"token_cache_lookup"]; + [event setTokenType:@"multi-resource refresh token"]; + [event setStatus:item? @"succeeded" : @"failed"]; + [[ADTelemetry sharedInstance] stopEvent:[requestParams telemetryRequestId] event:event]; + SAFE_ARC_RELEASE(event); + + return item; } /*! @@ -129,9 +141,18 @@ - (ADTokenCacheItem *)getFRTItemForUser:(ADUserIdentifier *)identifier requestParams:(ADRequestParameters*)requestParams error:(ADAuthenticationError * __autoreleasing *)error { + [[ADTelemetry sharedInstance] startEvent:[requestParams telemetryRequestId] eventName:@"token_cache_lookup"]; + NSString* fociClientId = [ADTokenCacheAccessor familyClientId:familyId]; + ADTokenCacheItem* item = [self getItemForUser:identifier resource:nil clientId:fociClientId requestParams:requestParams error:error]; + + ADTelemetryCacheEvent* event = [[ADTelemetryCacheEvent alloc] initWithName:@"token_cache_lookup"]; + [event setTokenType:@"family refresh token"]; + [event setStatus:item? @"succeeded" : @"failed"]; + [[ADTelemetry sharedInstance] stopEvent:[requestParams telemetryRequestId] event:event]; + SAFE_ARC_RELEASE(event); - return [self getItemForUser:identifier resource:nil clientId:fociClientId requestParams:requestParams error:error]; + return item; } - (ADTokenCacheItem*)getADFSUserTokenForResource:(NSString *)resource @@ -157,6 +178,8 @@ - (ADTokenCacheItem*)getADFSUserTokenForResource:(NSString *)resource ADTokenCacheItem* item = [_dataSource getItemWithKey:key userId:@"" correlationId:[requestParams correlationId] error:error]; ADTelemetryCacheEvent* event = [[ADTelemetryCacheEvent alloc] initWithName:@"token_cache_lookup"]; + [event setTokenType:@"ADFS access token/refresh token"]; + [event setStatus:item? @"succeeded" : @"failed"]; [[ADTelemetry sharedInstance] stopEvent:[requestParams telemetryRequestId] event:event]; SAFE_ARC_RELEASE(event); @@ -217,12 +240,11 @@ - (void)updateCacheToItem:(ADTokenCacheItem *)cacheItem MRRT:(BOOL)isMRRT requestParams:(ADRequestParameters*)requestParams { - [[ADTelemetry sharedInstance] startEvent:[requestParams telemetryRequestId] eventName:@"token_cache_write"]; - NSString* savedRefreshToken = cacheItem.refreshToken; if (isMRRT) { AD_LOG_VERBOSE_F(@"Token cache store", [requestParams correlationId], @"Storing multi-resource refresh token for authority: %@", _authority); + [[ADTelemetry sharedInstance] startEvent:[requestParams telemetryRequestId] eventName:@"token_cache_write"]; //If the server returned a multi-resource refresh token, we break //the item into two: one with the access token and no refresh token and @@ -236,25 +258,40 @@ - (void)updateCacheToItem:(ADTokenCacheItem *)cacheItem multiRefreshTokenItem.expiresOn = nil; [_dataSource addOrUpdateItem:multiRefreshTokenItem correlationId:[requestParams correlationId] error:nil]; + ADTelemetryCacheEvent* event = [[ADTelemetryCacheEvent alloc] initWithName:@"token_cache_write"]; + [event setTokenType:@"multi-resource refresh token"]; + [[ADTelemetry sharedInstance] stopEvent:[requestParams telemetryRequestId] event:event]; + SAFE_ARC_RELEASE(event); + // If the item is also a Family Refesh Token (FRT) we update the FRT // as well so we have a guaranteed spot to look for the most recent FRT. NSString* familyId = cacheItem.familyId; if (familyId) { + [[ADTelemetry sharedInstance] startEvent:[requestParams telemetryRequestId] eventName:@"token_cache_write"]; + ADTokenCacheItem* frtItem = [multiRefreshTokenItem copy]; NSString* fociClientId = [ADTokenCacheAccessor familyClientId:familyId]; frtItem.clientId = fociClientId; [_dataSource addOrUpdateItem:frtItem correlationId:[requestParams correlationId] error:nil]; SAFE_ARC_RELEASE(frtItem); + + ADTelemetryCacheEvent* event = [[ADTelemetryCacheEvent alloc] initWithName:@"token_cache_write"]; + [event setTokenType:@"family refresh token"]; + [[ADTelemetry sharedInstance] stopEvent:[requestParams telemetryRequestId] event:event]; + SAFE_ARC_RELEASE(event); } SAFE_ARC_RELEASE(multiRefreshTokenItem); } AD_LOG_VERBOSE_F(@"Token cache store", [requestParams correlationId], @"Storing access token for resource: %@", cacheItem.resource); + [[ADTelemetry sharedInstance] startEvent:[requestParams telemetryRequestId] eventName:@"token_cache_write"]; + [_dataSource addOrUpdateItem:cacheItem correlationId:[requestParams correlationId] error:nil]; cacheItem.refreshToken = savedRefreshToken;//Restore for the result ADTelemetryCacheEvent* event = [[ADTelemetryCacheEvent alloc] initWithName:@"token_cache_write"]; + [event setTokenType:@"access token"]; [[ADTelemetry sharedInstance] stopEvent:[requestParams telemetryRequestId] event:event]; SAFE_ARC_RELEASE(event); } diff --git a/ADAL/src/request/ADAcquireTokenSilentHandler.m b/ADAL/src/request/ADAcquireTokenSilentHandler.m index 95ced1831..29f722f5b 100644 --- a/ADAL/src/request/ADAcquireTokenSilentHandler.m +++ b/ADAL/src/request/ADAcquireTokenSilentHandler.m @@ -32,6 +32,9 @@ #import "ADWebAuthRequest.h" #import "ADHelpers.h" #import "ADTokenCacheAccessor.h" +#import "ADTelemetry.h" +#import "ADTelemetry+Internal.h" +#import "ADTelemetryAPIEvent.h" @implementation ADAcquireTokenSilentHandler @@ -199,10 +202,17 @@ - (void)acquireTokenWithItem:(ADTokenCacheItem *)item completionBlock:(ADAuthenticationCallback)completionBlock fallback:(ADAuthenticationCallback)fallback { + [[ADTelemetry sharedInstance] startEvent:[_requestParams telemetryRequestId] eventName:@"token_grant"]; [self acquireTokenByRefreshToken:item.refreshToken cacheItem:item completionBlock:^(ADAuthenticationResult *result) { + ADTelemetryAPIEvent* event = [[ADTelemetryAPIEvent alloc] initWithName:@"token_grant"]; + [event setGrantType:@"by refresh token"]; + [event setResultStatus:[result status]]; + [[ADTelemetry sharedInstance] stopEvent:[_requestParams telemetryRequestId] event:event]; + SAFE_ARC_RELEASE(event); + NSString* resultStatus = @"Succeded"; if (result.status == AD_FAILED) diff --git a/ADAL/src/request/ADAuthenticationRequest+AcquireToken.m b/ADAL/src/request/ADAuthenticationRequest+AcquireToken.m index 472c57478..b9d6994da 100644 --- a/ADAL/src/request/ADAuthenticationRequest+AcquireToken.m +++ b/ADAL/src/request/ADAuthenticationRequest+AcquireToken.m @@ -119,9 +119,14 @@ - (void)validatedAcquireToken:(ADAuthenticationCallback)completionBlock if (![ADAuthenticationContext isForcedAuthorization:_promptBehavior] && [_context hasCacheStore]) { + [[ADTelemetry sharedInstance] startEvent:[self telemetryRequestId] eventName:@"acquire_token_silent"]; [ADAcquireTokenSilentHandler acquireTokenSilentForRequestParams:_requestParams completionBlock:^(ADAuthenticationResult *result) { + ADTelemetryAPIEvent* event = [[ADTelemetryAPIEvent alloc] initWithName:@"acquire_token_silent"]; + [[ADTelemetry sharedInstance] stopEvent:[self telemetryRequestId] event:event]; + SAFE_ARC_RELEASE(event); + if ([ADAuthenticationContext isFinalResult:result]) { completionBlock(result); @@ -203,8 +208,6 @@ - (void)requestToken:(ADAuthenticationCallback)completionBlock [self requestCode:^(NSString * code, ADAuthenticationError *error) { ADTelemetryAPIEvent* event = [[ADTelemetryAPIEvent alloc] initWithName:@"authorization_code"]; - [[ADTelemetry sharedInstance] stopEvent:[self telemetryRequestId] event:event]; - SAFE_ARC_RELEASE(event); if (error) { @@ -217,22 +220,34 @@ - (void)requestToken:(ADAuthenticationCallback)completionBlock ADAuthenticationResult* result = (AD_ERROR_UI_USER_CANCEL == error.code) ? [ADAuthenticationResult resultFromCancellation:[_requestParams correlationId]] : [ADAuthenticationResult resultFromError:error correlationId:[_requestParams correlationId]]; + + [event setAPIStatus:(AD_ERROR_UI_USER_CANCEL == error.code) ? @"canceled":@"failed"]; + [[ADTelemetry sharedInstance] stopEvent:[self telemetryRequestId] event:event]; + completionBlock(result); } else { if([code hasPrefix:@"msauth://"]) { + [event setAPIStatus:@"try to invoke broker from webview"]; + [[ADTelemetry sharedInstance] stopEvent:[self telemetryRequestId] event:event]; + [self handleBrokerFromWebiewResponse:code completionBlock:completionBlock]; } else { + [event setAPIStatus:@"succeeded"]; + [[ADTelemetry sharedInstance] stopEvent:[self telemetryRequestId] event:event]; + [[ADTelemetry sharedInstance] startEvent:[self telemetryRequestId] eventName:@"token_grant"]; [self requestTokenByCode:code completionBlock:^(ADAuthenticationResult *result) { ADTelemetryAPIEvent* event = [[ADTelemetryAPIEvent alloc] initWithName:@"token_grant"]; + [event setGrantType:@"by code"]; + [event setResultStatus:[result status]]; [[ADTelemetry sharedInstance] stopEvent:[self telemetryRequestId] event:event]; SAFE_ARC_RELEASE(event); @@ -245,6 +260,8 @@ - (void)requestToken:(ADAuthenticationCallback)completionBlock }]; } } + + SAFE_ARC_RELEASE(event); }]; } diff --git a/ADAL/src/request/ADAuthenticationRequest+Broker.m b/ADAL/src/request/ADAuthenticationRequest+Broker.m index 33234d5b5..865f21d44 100644 --- a/ADAL/src/request/ADAuthenticationRequest+Broker.m +++ b/ADAL/src/request/ADAuthenticationRequest+Broker.m @@ -223,6 +223,7 @@ - (void)callBroker:(ADAuthenticationCallback)completionBlock [self releaseUserInterationLock]; // Release the lock when completion block is called. ADTelemetryBrokerEvent* event = [[ADTelemetryBrokerEvent alloc] initWithName:@"launch_broker"]; + [event setResultStatus:[result status]]; [[ADTelemetry sharedInstance] stopEvent:[self telemetryRequestId] event:event]; completionBlock(result); diff --git a/ADAL/src/telemetry/ADTelemetryAPIEvent.h b/ADAL/src/telemetry/ADTelemetryAPIEvent.h index c88a1c280..aa06c095f 100644 --- a/ADAL/src/telemetry/ADTelemetryAPIEvent.h +++ b/ADAL/src/telemetry/ADTelemetryAPIEvent.h @@ -38,4 +38,7 @@ - (void)setAuthorityValidationStatus:(NSString*)status; - (void)setAuthority:(NSString*)authority; +- (void)setGrantType:(NSString*)grantType; +- (void)setAPIStatus:(NSString*)status; + @end \ No newline at end of file diff --git a/ADAL/src/telemetry/ADTelemetryAPIEvent.m b/ADAL/src/telemetry/ADTelemetryAPIEvent.m index 048a0edb4..c8d4b4188 100644 --- a/ADAL/src/telemetry/ADTelemetryAPIEvent.m +++ b/ADAL/src/telemetry/ADTelemetryAPIEvent.m @@ -95,4 +95,14 @@ - (void)setAuthority:(NSString*)authority [self setProperty:@"authority" value:authority]; } +- (void)setGrantType:(NSString*)grantType +{ + [self setProperty:@"grant_type" value:grantType]; +} + +- (void)setAPIStatus:(NSString*)status +{ + [self setProperty:@"api_status" value:status]; +} + @end \ No newline at end of file diff --git a/ADAL/src/telemetry/ADTelemetryBrokerEvent.h b/ADAL/src/telemetry/ADTelemetryBrokerEvent.h index fb0725985..575eb3440 100644 --- a/ADAL/src/telemetry/ADTelemetryBrokerEvent.h +++ b/ADAL/src/telemetry/ADTelemetryBrokerEvent.h @@ -26,5 +26,6 @@ @interface ADTelemetryBrokerEvent : ADTelemetryDefaultEvent - (void)setBrokerAppVersion:(NSString*)version; +- (void)setResultStatus:(ADAuthenticationResultStatus)status; @end \ No newline at end of file diff --git a/ADAL/src/telemetry/ADTelemetryBrokerEvent.m b/ADAL/src/telemetry/ADTelemetryBrokerEvent.m index 0846790b9..170375ee9 100644 --- a/ADAL/src/telemetry/ADTelemetryBrokerEvent.m +++ b/ADAL/src/telemetry/ADTelemetryBrokerEvent.m @@ -30,4 +30,24 @@ - (void)setBrokerAppVersion:(NSString*)version [self setProperty:@"broker_app_version" value:version]; } +- (void)setResultStatus:(ADAuthenticationResultStatus)status +{ + NSString* statusStr = nil; + switch (status) { + case AD_SUCCEEDED: + statusStr = @"SUCCEEDED"; + break; + case AD_FAILED: + statusStr = @"FAILED"; + break; + case AD_USER_CANCELLED: + statusStr = @"USER_CANCELLED"; + break; + default: + statusStr = @"UNKNOWN"; + } + + [self setProperty:@"status" value:statusStr]; +} + @end \ No newline at end of file diff --git a/ADAL/src/telemetry/ADTelemetryCacheEvent.h b/ADAL/src/telemetry/ADTelemetryCacheEvent.h index 1cb6c7641..50e4283c8 100644 --- a/ADAL/src/telemetry/ADTelemetryCacheEvent.h +++ b/ADAL/src/telemetry/ADTelemetryCacheEvent.h @@ -25,4 +25,7 @@ @interface ADTelemetryCacheEvent : ADTelemetryDefaultEvent +- (void)setTokenType:(NSString*)tokenType; +- (void)setStatus:(NSString*)status; + @end \ No newline at end of file diff --git a/ADAL/src/telemetry/ADTelemetryCacheEvent.m b/ADAL/src/telemetry/ADTelemetryCacheEvent.m index 422b7b935..dd4837d9f 100644 --- a/ADAL/src/telemetry/ADTelemetryCacheEvent.m +++ b/ADAL/src/telemetry/ADTelemetryCacheEvent.m @@ -25,4 +25,14 @@ @implementation ADTelemetryCacheEvent +- (void)setTokenType:(NSString*)tokenType +{ + [self setProperty:@"token_type" value:tokenType]; +} + +- (void)setStatus:(NSString*)status +{ + [self setProperty:@"status" value:status]; +} + @end \ No newline at end of file From 39687d80f2cd2ce58a06e53e66bbaf51b94b164e Mon Sep 17 00:00:00 2001 From: YONG ZENG Date: Mon, 8 Aug 2016 16:34:42 -0700 Subject: [PATCH 08/92] extract broker app version from broker response for telemetry --- ADAL/src/ADOAuth2Constants.h | 1 + ADAL/src/ADOAuth2Constants.m | 1 + .../request/ADAuthenticationRequest+Broker.m | 22 +++++++++++++++++- ADAL/src/request/ADWebRequest.m | 1 + ADAL/src/telemetry/ADTelemetryBrokerEvent.h | 2 ++ ADAL/src/telemetry/ADTelemetryBrokerEvent.m | 23 +++++++++++++++++++ ADAL/src/telemetry/ADTelemetryDefaultEvent.m | 10 ++++---- ADAL/src/telemetry/ADTelemetryHttpEvent.h | 1 + ADAL/src/telemetry/ADTelemetryHttpEvent.m | 5 ++++ ADAL/tests/ADTelemetryTests.m | 8 +++---- 10 files changed, 65 insertions(+), 9 deletions(-) diff --git a/ADAL/src/ADOAuth2Constants.h b/ADAL/src/ADOAuth2Constants.h index 4235f9253..33b6cb847 100644 --- a/ADAL/src/ADOAuth2Constants.h +++ b/ADAL/src/ADOAuth2Constants.h @@ -63,6 +63,7 @@ extern NSString *const ADAL_CLIENT_FAMILY_ID; extern NSString *const BROKER_MAX_PROTOCOL_VERSION; extern NSString *const BROKER_MESSAGE_VERSION; +extern NSString *const BROKER_APP_VERSION; extern NSString *const BROKER_RESPONSE_KEY; extern NSString *const BROKER_HASH_KEY; diff --git a/ADAL/src/ADOAuth2Constants.m b/ADAL/src/ADOAuth2Constants.m index 0f7bd358b..70ade4055 100644 --- a/ADAL/src/ADOAuth2Constants.m +++ b/ADAL/src/ADOAuth2Constants.m @@ -64,6 +64,7 @@ NSString *const BROKER_MAX_PROTOCOL_VERSION = @"max_protocol_ver"; NSString *const BROKER_MESSAGE_VERSION = @"msg_protocol_ver"; +NSString *const BROKER_APP_VERSION = @"x-broker-app-ver"; NSString *const BROKER_RESPONSE_KEY = @"response"; NSString *const BROKER_HASH_KEY = @"hash"; diff --git a/ADAL/src/request/ADAuthenticationRequest+Broker.m b/ADAL/src/request/ADAuthenticationRequest+Broker.m index 865f21d44..888147d6e 100644 --- a/ADAL/src/request/ADAuthenticationRequest+Broker.m +++ b/ADAL/src/request/ADAuthenticationRequest+Broker.m @@ -45,6 +45,9 @@ #import "ADBrokerNotificationManager.h" #endif // TARGET_OS_IPHONE +static NSString* s_brokerAppVersion = nil; +static NSString* s_brokerProtocolVersion = nil; + @implementation ADAuthenticationRequest (Broker) + (BOOL)validBrokerRedirectUri:(NSString*)url @@ -89,6 +92,8 @@ + (void)internalHandleBrokerResponse:(NSURL *)response NSDictionary* queryParamsMap = [NSDictionary adURLFormDecode:qp]; ADAuthenticationResult* result; + s_brokerAppVersion = [queryParamsMap valueForKey:BROKER_APP_VERSION]; + if([queryParamsMap valueForKey:OAUTH2_ERROR_DESCRIPTION]){ result = [ADAuthenticationResult resultFromBrokerResponse:queryParamsMap]; } @@ -101,6 +106,7 @@ + (void)internalHandleBrokerResponse:(NSURL *)response NSString* hash = [queryParamsMap valueForKey:BROKER_HASH_KEY]; NSString* encryptedBase64Response = [queryParamsMap valueForKey:BROKER_RESPONSE_KEY]; NSString* msgVer = [queryParamsMap valueForKey:BROKER_MESSAGE_VERSION]; + s_brokerProtocolVersion = msgVer; NSInteger protocolVersion = 1; NSUUID* correlationId = [queryParamsMap valueForKey:OAUTH2_CORRELATION_ID_RESPONSE] ? @@ -224,6 +230,8 @@ - (void)callBroker:(ADAuthenticationCallback)completionBlock ADTelemetryBrokerEvent* event = [[ADTelemetryBrokerEvent alloc] initWithName:@"launch_broker"]; [event setResultStatus:[result status]]; + [event setBrokerAppVersion:s_brokerAppVersion]; + [event setBrokerProtocolVersion:s_brokerProtocolVersion]; [[ADTelemetry sharedInstance] stopEvent:[self telemetryRequestId] event:event]; completionBlock(result); @@ -318,7 +326,19 @@ - (void)handleBrokerFromWebiewResponse:(NSString*)urlString if ([ADBrokerHelper canUseBroker]) { - [ADBrokerHelper invokeBroker:urlParams completionHandler:completionBlock]; + [[ADTelemetry sharedInstance] startEvent:[self telemetryRequestId] eventName:@"launch_broker"]; + void(^requestCompletion)(ADAuthenticationResult* result) = ^void(ADAuthenticationResult* result) + { + ADTelemetryBrokerEvent* event = [[ADTelemetryBrokerEvent alloc] initWithName:@"launch_broker"]; + [event setResultStatus:[result status]]; + [event setBrokerAppVersion:s_brokerAppVersion]; + [event setBrokerProtocolVersion:s_brokerProtocolVersion]; + [[ADTelemetry sharedInstance] stopEvent:[self telemetryRequestId] event:event]; + + completionBlock(result); + }; + + [ADBrokerHelper invokeBroker:urlParams completionHandler:requestCompletion]; } else { diff --git a/ADAL/src/request/ADWebRequest.m b/ADAL/src/request/ADWebRequest.m index 93f12b951..dd51b036c 100644 --- a/ADAL/src/request/ADWebRequest.m +++ b/ADAL/src/request/ADWebRequest.m @@ -329,6 +329,7 @@ - (void)stopTelemetryEvent:(NSError *)error if (error) { [event setHttpResponseCode:[NSString stringWithFormat: @"%ld", (long)[error code]]]; + [event setHttpErrorDomain:[error domain]]; } else if (response) { diff --git a/ADAL/src/telemetry/ADTelemetryBrokerEvent.h b/ADAL/src/telemetry/ADTelemetryBrokerEvent.h index 575eb3440..eb1fb1872 100644 --- a/ADAL/src/telemetry/ADTelemetryBrokerEvent.h +++ b/ADAL/src/telemetry/ADTelemetryBrokerEvent.h @@ -26,6 +26,8 @@ @interface ADTelemetryBrokerEvent : ADTelemetryDefaultEvent - (void)setBrokerAppVersion:(NSString*)version; +- (void)setBrokerProtocolVersion:(NSString*)version; - (void)setResultStatus:(ADAuthenticationResultStatus)status; +- (void)setBrokerApp:(NSString*)appName; @end \ No newline at end of file diff --git a/ADAL/src/telemetry/ADTelemetryBrokerEvent.m b/ADAL/src/telemetry/ADTelemetryBrokerEvent.m index 170375ee9..915740e03 100644 --- a/ADAL/src/telemetry/ADTelemetryBrokerEvent.m +++ b/ADAL/src/telemetry/ADTelemetryBrokerEvent.m @@ -25,11 +25,29 @@ @implementation ADTelemetryBrokerEvent +-(id) init +{ + self = [super init]; + if(self) + { + //this is the only broker for iOS + [self setBrokerApp:@"Azure Authenticator"]; + } + + return self; +} + + - (void)setBrokerAppVersion:(NSString*)version { [self setProperty:@"broker_app_version" value:version]; } +- (void)setBrokerProtocolVersion:(NSString*)version +{ + [self setProperty:@"broker_protocol_version" value:version]; +} + - (void)setResultStatus:(ADAuthenticationResultStatus)status { NSString* statusStr = nil; @@ -50,4 +68,9 @@ - (void)setResultStatus:(ADAuthenticationResultStatus)status [self setProperty:@"status" value:statusStr]; } +- (void)setBrokerApp:(NSString*)appName +{ + [self setProperty:@"broker_app" value:appName]; +} + @end \ No newline at end of file diff --git a/ADAL/src/telemetry/ADTelemetryDefaultEvent.m b/ADAL/src/telemetry/ADTelemetryDefaultEvent.m index 7dbaecf3a..d7fac8060 100644 --- a/ADAL/src/telemetry/ADTelemetryDefaultEvent.m +++ b/ADAL/src/telemetry/ADTelemetryDefaultEvent.m @@ -23,6 +23,7 @@ #import "ADTelemetryDefaultEvent.h" #import "ADTelemetryEventInterface.h" +#import "ADLogger.h" #if !TARGET_OS_IPHONE #include @@ -124,22 +125,23 @@ - (NSArray*)defaultParameters //iOS: NSString* deviceId = [[[UIDevice currentDevice] identifierForVendor] UUIDString]; NSString* applicationName = [[NSBundle mainBundle] bundleIdentifier]; - NSString* sdkId = @"iOS"; #else CFStringRef macSerialNumber = nil; CopySerialNumber(&macSerialNumber); NSString* deviceId = CFBridgingRelease(macSerialNumber); SAFE_ARC_AUTORELEASE(deviceId); NSString* applicationName = [[NSProcessInfo processInfo] processName]; - NSString* sdkId = @"OSX"; #endif SET_IF_NOT_NIL(s_defaultParameters, @"device_id", ([NSString stringWithFormat:@"%lu", (unsigned long)[deviceId hash]])); SET_IF_NOT_NIL(s_defaultParameters, @"application_name", applicationName); - SET_IF_NOT_NIL(s_defaultParameters, @"sdk_id", sdkId); SET_IF_NOT_NIL(s_defaultParameters, @"application_version", [[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleVersion"]); - SET_IF_NOT_NIL(s_defaultParameters, @"sdk_version", ADAL_VERSION_NSSTRING); + NSDictionary* adalId = [ADLogger adalId]; + for (NSString* key in adalId) + { + SET_IF_NOT_NIL(s_defaultParameters, key, [adalId objectForKey:key]); + } }); return s_defaultParameters; diff --git a/ADAL/src/telemetry/ADTelemetryHttpEvent.h b/ADAL/src/telemetry/ADTelemetryHttpEvent.h index 068c63db2..4009181dc 100644 --- a/ADAL/src/telemetry/ADTelemetryHttpEvent.h +++ b/ADAL/src/telemetry/ADTelemetryHttpEvent.h @@ -31,5 +31,6 @@ - (void)setHttpResponseMethod:(NSString*)method; - (void)setHttpRequestQueryParams:(NSString*)params; - (void)setHttpUserAgent:(NSString*)userAgent; +- (void)setHttpErrorDomain:(NSString*)errorDomain; @end \ No newline at end of file diff --git a/ADAL/src/telemetry/ADTelemetryHttpEvent.m b/ADAL/src/telemetry/ADTelemetryHttpEvent.m index b152ac8aa..aa5690b6f 100644 --- a/ADAL/src/telemetry/ADTelemetryHttpEvent.m +++ b/ADAL/src/telemetry/ADTelemetryHttpEvent.m @@ -55,6 +55,11 @@ - (void)setHttpUserAgent:(NSString*)userAgent [self setProperty:@"user_agent" value:userAgent]; } +- (void)setHttpErrorDomain:(NSString*)errorDomain +{ + [self setProperty:@"http_error_domain" value:errorDomain]; +} + - (NSString*)scrubTenantFromUrl:(NSString*)url { //Scrub the tenant domain from the url diff --git a/ADAL/tests/ADTelemetryTests.m b/ADAL/tests/ADTelemetryTests.m index 36d4a47e8..007c8c7f5 100644 --- a/ADAL/tests/ADTelemetryTests.m +++ b/ADAL/tests/ADTelemetryTests.m @@ -97,14 +97,14 @@ - (void)testDefaultEventProperties { // make sure the default properties are recorded in the telemetry event, // i.e. sdk_id, sdk_version, device_id, device_name XCTAssertNotNil([self getPropertyFromEvent:[receivedEvents firstObject] - propertyName:@"sdk_id"]); + propertyName:@"x-client-SKU"]); XCTAssertEqual([self getPropertyCount:[receivedEvents firstObject] - propertyName:@"sdk_id"], 1); + propertyName:@"x-client-SKU"], 1); XCTAssertNotNil([self getPropertyFromEvent:[receivedEvents firstObject] - propertyName:@"sdk_version"]); + propertyName:@"x-client-Ver"]); XCTAssertEqual([self getPropertyCount:[receivedEvents firstObject] - propertyName:@"sdk_version"], 1); + propertyName:@"x-client-Ver"], 1); XCTAssertNotNil([self getPropertyFromEvent:[receivedEvents firstObject] propertyName:@"device_id"]); From a92459906ae320eb441c47c6a0222cc5fff82006 Mon Sep 17 00:00:00 2001 From: YONG ZENG Date: Mon, 8 Aug 2016 22:09:09 -0700 Subject: [PATCH 09/92] fix the errors caused by the merge; fix a bug of over-releasing a variable --- ADAL.xcworkspace/contents.xcworkspacedata | 3 ++ ADAL/ADAL.xcodeproj/project.pbxproj | 41 +++++++++++++------- ADAL/src/telemetry/ADTelemetryDefaultEvent.m | 1 - 3 files changed, 31 insertions(+), 14 deletions(-) diff --git a/ADAL.xcworkspace/contents.xcworkspacedata b/ADAL.xcworkspace/contents.xcworkspacedata index f1cf7b876..3b62a971b 100644 --- a/ADAL.xcworkspace/contents.xcworkspacedata +++ b/ADAL.xcworkspace/contents.xcworkspacedata @@ -10,4 +10,7 @@ + + diff --git a/ADAL/ADAL.xcodeproj/project.pbxproj b/ADAL/ADAL.xcodeproj/project.pbxproj index ecce8efcd..7a0acb17f 100755 --- a/ADAL/ADAL.xcodeproj/project.pbxproj +++ b/ADAL/ADAL.xcodeproj/project.pbxproj @@ -25,40 +25,43 @@ 600401A51D3421480020EAAB /* ADTelemetry.m in Sources */ = {isa = PBXBuildFile; fileRef = 600401A31D3421480020EAAB /* ADTelemetry.m */; }; 600401A71D3426250020EAAB /* ADTelemetry+Internal.h in Headers */ = {isa = PBXBuildFile; fileRef = 600401A61D3426250020EAAB /* ADTelemetry+Internal.h */; }; 600401A91D3428770020EAAB /* ADTelemetryDefaultEvent.h in Headers */ = {isa = PBXBuildFile; fileRef = 600401A81D3428770020EAAB /* ADTelemetryDefaultEvent.h */; }; - 600401AB1D3443D30020EAAB /* ADTelemetryDefaultEvent.m in Sources */ = {isa = PBXBuildFile; fileRef = 600401AA1D3443D30020EAAB /* ADTelemetryDefaultEvent.m */; }; 600401AC1D3443D30020EAAB /* ADTelemetryDefaultEvent.m in Sources */ = {isa = PBXBuildFile; fileRef = 600401AA1D3443D30020EAAB /* ADTelemetryDefaultEvent.m */; }; 600401B11D3578C30020EAAB /* ADTelemetryTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 600401B01D3578C30020EAAB /* ADTelemetryTests.m */; }; 600401B21D3578C30020EAAB /* ADTelemetryTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 600401B01D3578C30020EAAB /* ADTelemetryTests.m */; }; 600401B61D37658C0020EAAB /* ADAggregatedDispatcher.m in Headers */ = {isa = PBXBuildFile; fileRef = 600401B51D37658C0020EAAB /* ADAggregatedDispatcher.m */; }; 600401B81D3766F80020EAAB /* ADTelemetryEventInterface.h in Headers */ = {isa = PBXBuildFile; fileRef = 600401B71D3766F80020EAAB /* ADTelemetryEventInterface.h */; }; - 600401B91D377ACC0020EAAB /* ADAggregatedDispatcher.m in Sources */ = {isa = PBXBuildFile; fileRef = 600401B51D37658C0020EAAB /* ADAggregatedDispatcher.m */; }; - 600401BD1D377E9F0020EAAB /* ADDefaultDispatcher.m in Sources */ = {isa = PBXBuildFile; fileRef = 600401BC1D377E9F0020EAAB /* ADDefaultDispatcher.m */; }; 600401BE1D377E9F0020EAAB /* ADDefaultDispatcher.m in Sources */ = {isa = PBXBuildFile; fileRef = 600401BC1D377E9F0020EAAB /* ADDefaultDispatcher.m */; }; 600401C01D3868B20020EAAB /* ADAggregatedDispatcher.m in Sources */ = {isa = PBXBuildFile; fileRef = 600401B51D37658C0020EAAB /* ADAggregatedDispatcher.m */; }; 600401C21D39A18E0020EAAB /* ADDefaultDispatcher.h in Headers */ = {isa = PBXBuildFile; fileRef = 600401C11D39A18E0020EAAB /* ADDefaultDispatcher.h */; }; 600401C41D3D58D50020EAAB /* ADAggregatedDispatcher.h in Headers */ = {isa = PBXBuildFile; fileRef = 600401C31D3D58D50020EAAB /* ADAggregatedDispatcher.h */; }; 6010EDE41D47B1AC00B62072 /* ADTelemetryAPIEvent.h in Headers */ = {isa = PBXBuildFile; fileRef = 6010EDE31D47B1AC00B62072 /* ADTelemetryAPIEvent.h */; }; - 6010EDE61D47B21600B62072 /* ADTelemetryAPIEvent.m in Sources */ = {isa = PBXBuildFile; fileRef = 6010EDE51D47B21600B62072 /* ADTelemetryAPIEvent.m */; }; 6010EDE71D47B21600B62072 /* ADTelemetryAPIEvent.m in Sources */ = {isa = PBXBuildFile; fileRef = 6010EDE51D47B21600B62072 /* ADTelemetryAPIEvent.m */; }; 6010EDE91D47B26300B62072 /* ADTelemetryUIEvent.h in Headers */ = {isa = PBXBuildFile; fileRef = 6010EDE81D47B26300B62072 /* ADTelemetryUIEvent.h */; }; - 6010EDEB1D47B27400B62072 /* ADTelemetryUIEvent.m in Sources */ = {isa = PBXBuildFile; fileRef = 6010EDEA1D47B27400B62072 /* ADTelemetryUIEvent.m */; }; 6010EDEC1D47B27400B62072 /* ADTelemetryUIEvent.m in Sources */ = {isa = PBXBuildFile; fileRef = 6010EDEA1D47B27400B62072 /* ADTelemetryUIEvent.m */; }; 6010EDEE1D47B29500B62072 /* ADTelemetryHttpEvent.h in Headers */ = {isa = PBXBuildFile; fileRef = 6010EDED1D47B29500B62072 /* ADTelemetryHttpEvent.h */; }; - 6010EDF01D47B2A600B62072 /* ADTelemetryHttpEvent.m in Sources */ = {isa = PBXBuildFile; fileRef = 6010EDEF1D47B2A600B62072 /* ADTelemetryHttpEvent.m */; }; 6010EDF11D47B2A600B62072 /* ADTelemetryHttpEvent.m in Sources */ = {isa = PBXBuildFile; fileRef = 6010EDEF1D47B2A600B62072 /* ADTelemetryHttpEvent.m */; }; 6010EDF31D47B2BD00B62072 /* ADTelemetryCacheEvent.h in Headers */ = {isa = PBXBuildFile; fileRef = 6010EDF21D47B2BD00B62072 /* ADTelemetryCacheEvent.h */; }; - 6010EDF51D47B2CE00B62072 /* ADTelemetryCacheEvent.m in Sources */ = {isa = PBXBuildFile; fileRef = 6010EDF41D47B2CE00B62072 /* ADTelemetryCacheEvent.m */; }; 6010EDF61D47B2CE00B62072 /* ADTelemetryCacheEvent.m in Sources */ = {isa = PBXBuildFile; fileRef = 6010EDF41D47B2CE00B62072 /* ADTelemetryCacheEvent.m */; }; 6010EDF81D47B2E300B62072 /* ADTelemetryBrokerEvent.h in Headers */ = {isa = PBXBuildFile; fileRef = 6010EDF71D47B2E300B62072 /* ADTelemetryBrokerEvent.h */; }; - 6010EDFA1D47B2F300B62072 /* ADTelemetryBrokerEvent.m in Sources */ = {isa = PBXBuildFile; fileRef = 6010EDF91D47B2F300B62072 /* ADTelemetryBrokerEvent.m */; }; 6010EDFB1D47B2F300B62072 /* ADTelemetryBrokerEvent.m in Sources */ = {isa = PBXBuildFile; fileRef = 6010EDF91D47B2F300B62072 /* ADTelemetryBrokerEvent.m */; }; 601BEE311C6DAA86004AA8C1 /* ADTestAuthenticationViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 601BEE301C6DAA86004AA8C1 /* ADTestAuthenticationViewController.m */; }; 601BEE321C6DAA86004AA8C1 /* ADTestAuthenticationViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 601BEE301C6DAA86004AA8C1 /* ADTestAuthenticationViewController.m */; }; 601BEE341C6DCB0B004AA8C1 /* ADWebAuthControllerTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 601BEE331C6DCB0B004AA8C1 /* ADWebAuthControllerTests.m */; }; 601BEE351C6DCB0B004AA8C1 /* ADWebAuthControllerTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 601BEE331C6DCB0B004AA8C1 /* ADWebAuthControllerTests.m */; }; + 603389271D595A920024A9BF /* ADRequestParameters.m in Sources */ = {isa = PBXBuildFile; fileRef = 60D2F4001D531F16008725D9 /* ADRequestParameters.m */; }; + 603389281D595AA70024A9BF /* ADTelemetryAPIEvent.m in Sources */ = {isa = PBXBuildFile; fileRef = 6010EDE51D47B21600B62072 /* ADTelemetryAPIEvent.m */; }; + 603389291D595AD50024A9BF /* ADTelemetryUIEvent.m in Sources */ = {isa = PBXBuildFile; fileRef = 6010EDEA1D47B27400B62072 /* ADTelemetryUIEvent.m */; }; + 6033892A1D595AD50024A9BF /* ADTelemetryHttpEvent.m in Sources */ = {isa = PBXBuildFile; fileRef = 6010EDEF1D47B2A600B62072 /* ADTelemetryHttpEvent.m */; }; + 6033892B1D595AD50024A9BF /* ADTelemetryCacheEvent.m in Sources */ = {isa = PBXBuildFile; fileRef = 6010EDF41D47B2CE00B62072 /* ADTelemetryCacheEvent.m */; }; + 6033892C1D595AD50024A9BF /* ADTelemetryBrokerEvent.m in Sources */ = {isa = PBXBuildFile; fileRef = 6010EDF91D47B2F300B62072 /* ADTelemetryBrokerEvent.m */; }; + 6033892D1D595AFF0024A9BF /* ADRequestParameters.m in Sources */ = {isa = PBXBuildFile; fileRef = 60D2F4001D531F16008725D9 /* ADRequestParameters.m */; }; + 6033892E1D595AFF0024A9BF /* ADTelemetryAPIEvent.m in Sources */ = {isa = PBXBuildFile; fileRef = 6010EDE51D47B21600B62072 /* ADTelemetryAPIEvent.m */; }; + 6033892F1D595AFF0024A9BF /* ADTelemetryUIEvent.m in Sources */ = {isa = PBXBuildFile; fileRef = 6010EDEA1D47B27400B62072 /* ADTelemetryUIEvent.m */; }; + 603389301D595AFF0024A9BF /* ADTelemetryHttpEvent.m in Sources */ = {isa = PBXBuildFile; fileRef = 6010EDEF1D47B2A600B62072 /* ADTelemetryHttpEvent.m */; }; + 603389311D595AFF0024A9BF /* ADTelemetryCacheEvent.m in Sources */ = {isa = PBXBuildFile; fileRef = 6010EDF41D47B2CE00B62072 /* ADTelemetryCacheEvent.m */; }; + 603389321D595AFF0024A9BF /* ADTelemetryBrokerEvent.m in Sources */ = {isa = PBXBuildFile; fileRef = 6010EDF91D47B2F300B62072 /* ADTelemetryBrokerEvent.m */; }; 6071B5E41C14C0B0006F6CC2 /* ADTestURLConnection.m in Sources */ = {isa = PBXBuildFile; fileRef = 6071B5E31C14C0B0006F6CC2 /* ADTestURLConnection.m */; }; 60D2F3FF1D524F7A008725D9 /* ADRequestParameters.h in Headers */ = {isa = PBXBuildFile; fileRef = 60D2F3FE1D524F7A008725D9 /* ADRequestParameters.h */; }; - 60D2F4011D531F16008725D9 /* ADRequestParameters.m in Sources */ = {isa = PBXBuildFile; fileRef = 60D2F4001D531F16008725D9 /* ADRequestParameters.m */; }; 60D2F4021D531F16008725D9 /* ADRequestParameters.m in Sources */ = {isa = PBXBuildFile; fileRef = 60D2F4001D531F16008725D9 /* ADRequestParameters.m */; }; 8B0965AE17F25770002BDFB8 /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 8B0965AD17F25770002BDFB8 /* Foundation.framework */; }; 8B0965BC17F25770002BDFB8 /* XCTest.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 8B0965BB17F25770002BDFB8 /* XCTest.framework */; }; @@ -412,11 +415,11 @@ D69A72191D4FF68300E91DB3 /* ADTelemetry.m in Sources */ = {isa = PBXBuildFile; fileRef = 600401A31D3421480020EAAB /* ADTelemetry.m */; }; D69A721A1D4FF68300E91DB3 /* ADDefaultDispatcher.m in Sources */ = {isa = PBXBuildFile; fileRef = 600401BC1D377E9F0020EAAB /* ADDefaultDispatcher.m */; }; D69A721B1D4FF68300E91DB3 /* ADAggregatedDispatcher.m in Sources */ = {isa = PBXBuildFile; fileRef = 600401B51D37658C0020EAAB /* ADAggregatedDispatcher.m */; }; - D69A721C1D4FF68300E91DB3 /* ADDefaultEvent.m in Sources */ = {isa = PBXBuildFile; fileRef = 600401AA1D3443D30020EAAB /* ADDefaultEvent.m */; }; + D69A721C1D4FF68300E91DB3 /* ADTelemetryDefaultEvent.m in Sources */ = {isa = PBXBuildFile; fileRef = 600401AA1D3443D30020EAAB /* ADTelemetryDefaultEvent.m */; }; D69A721D1D4FF68400E91DB3 /* ADTelemetry.m in Sources */ = {isa = PBXBuildFile; fileRef = 600401A31D3421480020EAAB /* ADTelemetry.m */; }; D69A721E1D4FF68400E91DB3 /* ADDefaultDispatcher.m in Sources */ = {isa = PBXBuildFile; fileRef = 600401BC1D377E9F0020EAAB /* ADDefaultDispatcher.m */; }; D69A721F1D4FF68400E91DB3 /* ADAggregatedDispatcher.m in Sources */ = {isa = PBXBuildFile; fileRef = 600401B51D37658C0020EAAB /* ADAggregatedDispatcher.m */; }; - D69A72201D4FF68400E91DB3 /* ADDefaultEvent.m in Sources */ = {isa = PBXBuildFile; fileRef = 600401AA1D3443D30020EAAB /* ADDefaultEvent.m */; }; + D69A72201D4FF68400E91DB3 /* ADTelemetryDefaultEvent.m in Sources */ = {isa = PBXBuildFile; fileRef = 600401AA1D3443D30020EAAB /* ADTelemetryDefaultEvent.m */; }; D6D8A8401D4FD14E00D20DE6 /* ADKeychainUtil.m in Sources */ = {isa = PBXBuildFile; fileRef = D6D8A83F1D4FD14E00D20DE6 /* ADKeychainUtil.m */; }; D6D8A8411D4FD14E00D20DE6 /* ADKeychainUtil.m in Sources */ = {isa = PBXBuildFile; fileRef = D6D8A83F1D4FD14E00D20DE6 /* ADKeychainUtil.m */; }; D6F095151CDC072200D28FC2 /* ADAcquireTokenSilentHandler.h in Headers */ = {isa = PBXBuildFile; fileRef = D6F095131CDC072200D28FC2 /* ADAcquireTokenSilentHandler.h */; }; @@ -1804,6 +1807,12 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( + 6033892D1D595AFF0024A9BF /* ADRequestParameters.m in Sources */, + 6033892E1D595AFF0024A9BF /* ADTelemetryAPIEvent.m in Sources */, + 6033892F1D595AFF0024A9BF /* ADTelemetryUIEvent.m in Sources */, + 603389301D595AFF0024A9BF /* ADTelemetryHttpEvent.m in Sources */, + 603389311D595AFF0024A9BF /* ADTelemetryCacheEvent.m in Sources */, + 603389321D595AFF0024A9BF /* ADTelemetryBrokerEvent.m in Sources */, D610010B1D3986440087AB81 /* ADWebAuthRequest.m in Sources */, D610010C1D3986440087AB81 /* ADNTLMUIPrompt.m in Sources */, D610010D1D3986440087AB81 /* ADOAuth2Constants.m in Sources */, @@ -1851,7 +1860,7 @@ D61001341D3986440087AB81 /* ADAuthenticationContext+Internal.m in Sources */, D61001351D3986440087AB81 /* ADTokenCache.m in Sources */, D61001361D3986440087AB81 /* ADBrokerHelper.m in Sources */, - D69A72201D4FF68400E91DB3 /* ADDefaultEvent.m in Sources */, + D69A72201D4FF68400E91DB3 /* ADTelemetryDefaultEvent.m in Sources */, D61001371D3986440087AB81 /* ADCustomHeaderHandler.m in Sources */, D61001381D3986440087AB81 /* ADAuthenticationRequest+AcquireAssertion.m in Sources */, D61001391D3986440087AB81 /* UIApplication+ADExtensions.m in Sources */, @@ -1925,6 +1934,12 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( + 603389291D595AD50024A9BF /* ADTelemetryUIEvent.m in Sources */, + 6033892A1D595AD50024A9BF /* ADTelemetryHttpEvent.m in Sources */, + 6033892B1D595AD50024A9BF /* ADTelemetryCacheEvent.m in Sources */, + 6033892C1D595AD50024A9BF /* ADTelemetryBrokerEvent.m in Sources */, + 603389281D595AA70024A9BF /* ADTelemetryAPIEvent.m in Sources */, + 603389271D595A920024A9BF /* ADRequestParameters.m in Sources */, D664F17A1D302B9C0017B799 /* ADWebAuthRequest.m in Sources */, D664F17B1D302B9C0017B799 /* ADNTLMUIPrompt.m in Sources */, D664F17C1D302B9C0017B799 /* ADOAuth2Constants.m in Sources */, @@ -1972,7 +1987,7 @@ D664F1A31D302B9C0017B799 /* ADAuthenticationContext+Internal.m in Sources */, D664F1A41D302B9C0017B799 /* ADTokenCache.m in Sources */, D664F1A51D302B9C0017B799 /* ADBrokerHelper.m in Sources */, - D69A721C1D4FF68300E91DB3 /* ADDefaultEvent.m in Sources */, + D69A721C1D4FF68300E91DB3 /* ADTelemetryDefaultEvent.m in Sources */, D664F1A61D302B9C0017B799 /* ADCustomHeaderHandler.m in Sources */, D664F1A71D302B9C0017B799 /* ADAuthenticationRequest+AcquireAssertion.m in Sources */, D664F1A81D302B9C0017B799 /* UIApplication+ADExtensions.m in Sources */, diff --git a/ADAL/src/telemetry/ADTelemetryDefaultEvent.m b/ADAL/src/telemetry/ADTelemetryDefaultEvent.m index d7fac8060..54529621f 100644 --- a/ADAL/src/telemetry/ADTelemetryDefaultEvent.m +++ b/ADAL/src/telemetry/ADTelemetryDefaultEvent.m @@ -129,7 +129,6 @@ - (NSArray*)defaultParameters CFStringRef macSerialNumber = nil; CopySerialNumber(&macSerialNumber); NSString* deviceId = CFBridgingRelease(macSerialNumber); - SAFE_ARC_AUTORELEASE(deviceId); NSString* applicationName = [[NSProcessInfo processInfo] processName]; #endif From e7966c44b0d9c9aadd6a4b386cdffd68c0ad0075 Mon Sep 17 00:00:00 2001 From: YONG ZENG Date: Fri, 12 Aug 2016 00:13:41 -0700 Subject: [PATCH 10/92] address PR comments: simply code by using local var to store correlation id;use SHA256 hash; add request id as parameter to flush function;add response time for telemetry and more --- ADAL/src/ADAuthenticationContext.m | 161 +++++++++++++++++- ADAL/src/ADInstanceDiscovery.m | 18 +- ADAL/src/cache/ADTokenCacheAccessor.m | 75 +++++--- .../src/request/ADAcquireTokenSilentHandler.m | 21 ++- ...ADAuthenticationRequest+AcquireAssertion.m | 7 +- .../ADAuthenticationRequest+AcquireToken.m | 70 ++++---- .../request/ADAuthenticationRequest+Broker.m | 32 ++-- .../ADAuthenticationRequest+WebRequest.m | 4 +- ADAL/src/request/ADAuthenticationRequest.m | 1 + ADAL/src/request/ADWebRequest.m | 4 +- ADAL/src/telemetry/ADAggregatedDispatcher.m | 63 ++++--- ADAL/src/telemetry/ADDefaultDispatcher.h | 2 +- ADAL/src/telemetry/ADDefaultDispatcher.m | 42 +---- ADAL/src/telemetry/ADTelemetry+Internal.h | 2 +- ADAL/src/telemetry/ADTelemetry.m | 9 +- ADAL/src/telemetry/ADTelemetryAPIEvent.h | 2 + ADAL/src/telemetry/ADTelemetryAPIEvent.m | 7 +- ADAL/src/telemetry/ADTelemetryDefaultEvent.h | 5 +- ADAL/src/telemetry/ADTelemetryDefaultEvent.m | 35 ++-- .../src/telemetry/ADTelemetryEventInterface.h | 1 + ADAL/src/telemetry/ADTelemetryHttpEvent.m | 2 +- ADAL/src/telemetry/ADTelemetryUIEvent.m | 2 +- ADAL/tests/ADTelemetryTests.m | 92 +++++++--- 23 files changed, 455 insertions(+), 202 deletions(-) diff --git a/ADAL/src/ADAuthenticationContext.m b/ADAL/src/ADAuthenticationContext.m index f88055fc8..1fd4c1cda 100755 --- a/ADAL/src/ADAuthenticationContext.m +++ b/ADAL/src/ADAuthenticationContext.m @@ -30,6 +30,9 @@ #endif #import "ADAuthenticationContext+Internal.h" +#import "ADTelemetry.h" +#import "ADTelemetry+Internal.h" +#import "ADTelemetryAPIEvent.h" typedef void(^ADAuthorizationCodeCallback)(NSString*, ADAuthenticationError*); @@ -308,7 +311,24 @@ - (void)acquireTokenForAssertion:(NSString*)assertion [request setSamlAssertion:assertion]; [request setAssertionType:assertionType]; - [request acquireToken:completionBlock]; + //prepare telemetry for the acquire token call + [[ADTelemetry sharedInstance] startEvent:[request telemetryRequestId] + eventName:@"acquireTokenWithAssertion:assertionType:resource:clientId:userId:completionBlock:"]; + ADAuthenticationCallback requestCompletion = ^void(ADAuthenticationResult *result) + { + ADTelemetryAPIEvent* event = [[ADTelemetryAPIEvent alloc] initWithName:@"acquireTokenWithAssertion:assertionType:resource:clientId:userId:completionBlock:" + requestId:[request telemetryRequestId] + correlationId:[request correlationId]]; + [event setAPIId:@"?"]; + [[ADTelemetry sharedInstance] stopEvent:[request telemetryRequestId] event:event]; + SAFE_ARC_RELEASE(event); + //flush all events in the end of the acquireToken call + [[ADTelemetry sharedInstance] flush:[request telemetryRequestId]]; + + completionBlock(result); + }; + + [request acquireToken:requestCompletion]; } @@ -321,7 +341,24 @@ - (void)acquireTokenWithResource:(NSString*)resource API_ENTRY; REQUEST_WITH_REDIRECT_URL(redirectUri, clientId, resource); - [request acquireToken:completionBlock]; + //prepare telemetry for the acquire token call + [[ADTelemetry sharedInstance] startEvent:[request telemetryRequestId] + eventName:@"acquireTokenWithResource:clientId:redirectUri:completionBlock:"]; + ADAuthenticationCallback requestCompletion = ^void(ADAuthenticationResult *result) + { + ADTelemetryAPIEvent* event = [[ADTelemetryAPIEvent alloc] initWithName:@"acquireTokenWithResource:clientId:redirectUri:completionBlock:" + requestId:[request telemetryRequestId] + correlationId:[request correlationId]]; + [event setAPIId:@"?"]; + [[ADTelemetry sharedInstance] stopEvent:[request telemetryRequestId] event:event]; + SAFE_ARC_RELEASE(event); + //flush all events in the end of the acquireToken call + [[ADTelemetry sharedInstance] flush:[request telemetryRequestId]]; + + completionBlock(result); + }; + + [request acquireToken:requestCompletion]; } - (void)acquireTokenWithResource:(NSString*)resource @@ -334,7 +371,25 @@ - (void)acquireTokenWithResource:(NSString*)resource REQUEST_WITH_REDIRECT_URL(redirectUri, clientId, resource); [request setUserId:userId]; - [request acquireToken:completionBlock]; + + //prepare telemetry for the acquire token call + [[ADTelemetry sharedInstance] startEvent:[request telemetryRequestId] + eventName:@"acquireTokenWithResource:clientId:redirectUri:userId:completionBlock:"]; + ADAuthenticationCallback requestCompletion = ^void(ADAuthenticationResult *result) + { + ADTelemetryAPIEvent* event = [[ADTelemetryAPIEvent alloc] initWithName:@"acquireTokenWithResource:clientId:redirectUri:userId:completionBlock:" + requestId:[request telemetryRequestId] + correlationId:[request correlationId]]; + [event setAPIId:@"?"]; + [[ADTelemetry sharedInstance] stopEvent:[request telemetryRequestId] event:event]; + SAFE_ARC_RELEASE(event); + //flush all events in the end of the acquireToken call + [[ADTelemetry sharedInstance] flush:[request telemetryRequestId]]; + + completionBlock(result); + }; + + [request acquireToken:requestCompletion]; } @@ -350,7 +405,25 @@ - (void)acquireTokenWithResource:(NSString*)resource [request setUserId:userId]; [request setExtraQueryParameters:queryParams]; - [request acquireToken:completionBlock]; + + //prepare telemetry for the acquire token call + [[ADTelemetry sharedInstance] startEvent:[request telemetryRequestId] + eventName:@"acquireTokenWithResource:clientId:redirectUri:userId:extraQueryParameters:completionBlock:"]; + ADAuthenticationCallback requestCompletion = ^void(ADAuthenticationResult *result) + { + ADTelemetryAPIEvent* event = [[ADTelemetryAPIEvent alloc] initWithName:@"acquireTokenWithResource:clientId:redirectUri:userId:extraQueryParameters:completionBlock:" + requestId:[request telemetryRequestId] + correlationId:[request correlationId]]; + [event setAPIId:@"?"]; + [[ADTelemetry sharedInstance] stopEvent:[request telemetryRequestId] event:event]; + SAFE_ARC_RELEASE(event); + //flush all events in the end of the acquireToken call + [[ADTelemetry sharedInstance] flush:[request telemetryRequestId]]; + + completionBlock(result); + }; + + [request acquireToken:requestCompletion]; } - (void)acquireTokenSilentWithResource:(NSString*)resource @@ -362,7 +435,25 @@ - (void)acquireTokenSilentWithResource:(NSString*)resource REQUEST_WITH_REDIRECT_URL(redirectUri, clientId, resource); [request setSilent:YES]; - [request acquireToken:completionBlock]; + + //prepare telemetry for the acquire token call + [[ADTelemetry sharedInstance] startEvent:[request telemetryRequestId] + eventName:@"acquireTokenSilentWithResource:clientId:redirectId:redirectUri:completionBlock:"]; + ADAuthenticationCallback requestCompletion = ^void(ADAuthenticationResult *result) + { + ADTelemetryAPIEvent* event = [[ADTelemetryAPIEvent alloc] initWithName:@"acquireTokenSilentWithResource:clientId:redirectId:redirectUri:completionBlock:" + requestId:[request telemetryRequestId] + correlationId:[request correlationId]]; + [event setAPIId:@"?"]; + [[ADTelemetry sharedInstance] stopEvent:[request telemetryRequestId] event:event]; + SAFE_ARC_RELEASE(event); + //flush all events in the end of the acquireToken call + [[ADTelemetry sharedInstance] flush:[request telemetryRequestId]]; + + completionBlock(result); + }; + + [request acquireToken:requestCompletion]; } - (void)acquireTokenSilentWithResource:(NSString*)resource @@ -376,7 +467,25 @@ - (void)acquireTokenSilentWithResource:(NSString*)resource [request setUserId:userId]; [request setSilent:YES]; - [request acquireToken:completionBlock]; + + //prepare telemetry for the acquire token call + [[ADTelemetry sharedInstance] startEvent:[request telemetryRequestId] + eventName:@"acquireTokenSilentWithResource:clientId:redirectId:redirectUri:userId:completionBlock:"]; + ADAuthenticationCallback requestCompletion = ^void(ADAuthenticationResult *result) + { + ADTelemetryAPIEvent* event = [[ADTelemetryAPIEvent alloc] initWithName:@"acquireTokenSilentWithResource:clientId:redirectId:redirectUri:userId:completionBlock:" + requestId:[request telemetryRequestId] + correlationId:[request correlationId]]; + [event setAPIId:@"?"]; + [[ADTelemetry sharedInstance] stopEvent:[request telemetryRequestId] event:event]; + SAFE_ARC_RELEASE(event); + //flush all events in the end of the acquireToken call + [[ADTelemetry sharedInstance] flush:[request telemetryRequestId]]; + + completionBlock(result); + }; + + [request acquireToken:requestCompletion]; } - (void)acquireTokenWithResource:(NSString*)resource @@ -393,7 +502,25 @@ - (void)acquireTokenWithResource:(NSString*)resource [request setUserId:userId]; [request setPromptBehavior:promptBehavior]; [request setExtraQueryParameters:queryParams]; - [request acquireToken:completionBlock]; + + //prepare telemetry for the acquire token call + [[ADTelemetry sharedInstance] startEvent:[request telemetryRequestId] + eventName:@"acquireTokenWithResource:clientId:redirectUri:promptBehavior:userId:extraQueryParameters:completionBlock:"]; + ADAuthenticationCallback requestCompletion = ^void(ADAuthenticationResult *result) + { + ADTelemetryAPIEvent* event = [[ADTelemetryAPIEvent alloc] initWithName:@"acquireTokenWithResource:clientId:redirectUri:promptBehavior:userId:extraQueryParameters:completionBlock:" + requestId:[request telemetryRequestId] + correlationId:[request correlationId]]; + [event setAPIId:@"?"]; + [[ADTelemetry sharedInstance] stopEvent:[request telemetryRequestId] event:event]; + SAFE_ARC_RELEASE(event); + //flush all events in the end of the acquireToken call + [[ADTelemetry sharedInstance] flush:[request telemetryRequestId]]; + + completionBlock(result); + }; + + [request acquireToken:requestCompletion]; } - (void)acquireTokenWithResource:(NSString*)resource @@ -410,7 +537,25 @@ - (void)acquireTokenWithResource:(NSString*)resource [request setPromptBehavior:promptBehavior]; [request setUserIdentifier:userId]; [request setExtraQueryParameters:queryParams]; - [request acquireToken:completionBlock]; + + //prepare telemetry for the acquire token call + [[ADTelemetry sharedInstance] startEvent:[request telemetryRequestId] + eventName:@"acquireTokenWithResource:clientId:redirectUri:promptBehavior:userIdentifier:extraQueryParameters:completionBlock:"]; + ADAuthenticationCallback requestCompletion = ^void(ADAuthenticationResult *result) + { + ADTelemetryAPIEvent* event = [[ADTelemetryAPIEvent alloc] initWithName:@"acquireTokenWithResource:clientId:redirectUri:promptBehavior:userIdentifier:extraQueryParameters:completionBlock:" + requestId:[request telemetryRequestId] + correlationId:[request correlationId]]; + [event setAPIId:@"?"]; + [[ADTelemetry sharedInstance] stopEvent:[request telemetryRequestId] event:event]; + SAFE_ARC_RELEASE(event); + //flush all events in the end of the acquireToken call + [[ADTelemetry sharedInstance] flush:[request telemetryRequestId]]; + + completionBlock(result); + }; + + [request acquireToken:requestCompletion]; } @end diff --git a/ADAL/src/ADInstanceDiscovery.m b/ADAL/src/ADInstanceDiscovery.m index b6a3416a3..a4854855f 100644 --- a/ADAL/src/ADInstanceDiscovery.m +++ b/ADAL/src/ADInstanceDiscovery.m @@ -145,14 +145,15 @@ - (void)validateAuthority:(NSString *)authority { API_ENTRY; THROW_ON_NIL_ARGUMENT(completionBlock); + NSUUID* correlationId = [requestParams correlationId]; - NSString* message = [NSString stringWithFormat:@"Attempting to validate the authority: %@; CorrelationId: %@", authority, [[requestParams correlationId] UUIDString]]; + NSString* message = [NSString stringWithFormat:@"Attempting to validate the authority: %@; CorrelationId: %@", authority, [correlationId UUIDString]]; AD_LOG_VERBOSE(@"Instance discovery", [requestParams correlationId], message); authority = [authority lowercaseString]; ADAuthenticationError* error = nil; - NSString* authorityHost = [self extractHost:authority correlationId:[requestParams correlationId] error:&error]; + NSString* authorityHost = [self extractHost:authority correlationId:correlationId error:&error]; if (!authorityHost) { completionBlock(NO, error); @@ -275,7 +276,8 @@ - (void)requestValidationOfAuthority:(NSString *)authority completionBlock:(ADDiscoveryCallback)completionBlock { THROW_ON_NIL_ARGUMENT(completionBlock); - THROW_ON_NIL_ARGUMENT([requestParams correlationId]);//Should be set by the caller + NSUUID* correlationId = [requestParams correlationId]; + THROW_ON_NIL_ARGUMENT(correlationId);//Should be set by the caller //All attempts to complete are done. Now try to validate the authorization ednpoint: NSString* authorizationEndpoint = [authority stringByAppendingString:OAUTH2_AUTHORIZE_SUFFIX]; @@ -287,7 +289,7 @@ - (void)requestValidationOfAuthority:(NSString *)authority NSString* endPoint = [NSString stringWithFormat:@"%@/%@?%@", trustedAuthority, OAUTH2_INSTANCE_DISCOVERY_SUFFIX, [request_data adURLFormEncode]]; - AD_LOG_VERBOSE(@"Authority Validation Request", [requestParams correlationId], endPoint); + AD_LOG_VERBOSE(@"Authority Validation Request", correlationId, endPoint); ADWebRequest *webRequest = [[ADWebRequest alloc] initWithURL:[NSURL URLWithString:endPoint] requestParams:requestParams]; @@ -302,22 +304,22 @@ - (void)requestValidationOfAuthority:(NSString *)authority ADAuthenticationError* adError = nil; if (error) { - AD_LOG_WARN(@"System error while making request.", [requestParams correlationId], error.description); + AD_LOG_WARN(@"System error while making request.", correlationId, error.description); adError = [ADAuthenticationError errorFromNSError:error errorDetails:error.localizedDescription - correlationId:[requestParams correlationId]]; + correlationId:correlationId]; } else { adError = [self processWebReponse:webResponse authorityHost:authorityHost - correlationId:[requestParams correlationId]]; + correlationId:correlationId]; } NSString* errorDetails = [adError errorDetails]; [[ADClientMetrics getInstance] endClientMetricsRecord:endPoint startTime:startTime - correlationId:[requestParams correlationId] + correlationId:correlationId errorDetails:errorDetails]; SAFE_ARC_RELEASE(startTime); diff --git a/ADAL/src/cache/ADTokenCacheAccessor.m b/ADAL/src/cache/ADTokenCacheAccessor.m index 2006d7b9d..df3be7f94 100644 --- a/ADAL/src/cache/ADTokenCacheAccessor.m +++ b/ADAL/src/cache/ADTokenCacheAccessor.m @@ -101,7 +101,9 @@ - (ADTokenCacheItem *)getATRTItemForUser:(ADUserIdentifier *)identifier ADTokenCacheItem* item = [self getItemForUser:identifier resource:resource clientId:clientId requestParams:requestParams error:error]; - ADTelemetryCacheEvent* event = [[ADTelemetryCacheEvent alloc] initWithName:@"token_cache_lookup"]; + ADTelemetryCacheEvent* event = [[ADTelemetryCacheEvent alloc] initWithName:@"token_cache_lookup" + requestId:[requestParams telemetryRequestId] + correlationId:[requestParams correlationId]]; [event setTokenType:@"access token/refresh token"]; [event setStatus:item? @"succeeded" : @"failed"]; [[ADTelemetry sharedInstance] stopEvent:[requestParams telemetryRequestId] event:event]; @@ -123,7 +125,9 @@ - (ADTokenCacheItem *)getMRRTItemForUser:(ADUserIdentifier *)identifier ADTokenCacheItem* item = [self getItemForUser:identifier resource:nil clientId:clientId requestParams:requestParams error:error]; - ADTelemetryCacheEvent* event = [[ADTelemetryCacheEvent alloc] initWithName:@"token_cache_lookup"]; + ADTelemetryCacheEvent* event = [[ADTelemetryCacheEvent alloc] initWithName:@"token_cache_lookup" + requestId:[requestParams telemetryRequestId] + correlationId:[requestParams correlationId]]; [event setTokenType:@"multi-resource refresh token"]; [event setStatus:item? @"succeeded" : @"failed"]; [[ADTelemetry sharedInstance] stopEvent:[requestParams telemetryRequestId] event:event]; @@ -146,7 +150,9 @@ - (ADTokenCacheItem *)getFRTItemForUser:(ADUserIdentifier *)identifier NSString* fociClientId = [ADTokenCacheAccessor familyClientId:familyId]; ADTokenCacheItem* item = [self getItemForUser:identifier resource:nil clientId:fociClientId requestParams:requestParams error:error]; - ADTelemetryCacheEvent* event = [[ADTelemetryCacheEvent alloc] initWithName:@"token_cache_lookup"]; + ADTelemetryCacheEvent* event = [[ADTelemetryCacheEvent alloc] initWithName:@"token_cache_lookup" + requestId:[requestParams telemetryRequestId] + correlationId:[requestParams correlationId]]; [event setTokenType:@"family refresh token"]; [event setStatus:item? @"succeeded" : @"failed"]; [[ADTelemetry sharedInstance] stopEvent:[requestParams telemetryRequestId] event:event]; @@ -177,7 +183,9 @@ - (ADTokenCacheItem*)getADFSUserTokenForResource:(NSString *)resource ADTokenCacheItem* item = [_dataSource getItemWithKey:key userId:@"" correlationId:[requestParams correlationId] error:error]; - ADTelemetryCacheEvent* event = [[ADTelemetryCacheEvent alloc] initWithName:@"token_cache_lookup"]; + ADTelemetryCacheEvent* event = [[ADTelemetryCacheEvent alloc] initWithName:@"token_cache_lookup" + requestId:[requestParams telemetryRequestId] + correlationId:[requestParams correlationId]]; [event setTokenType:@"ADFS access token/refresh token"]; [event setStatus:item? @"succeeded" : @"failed"]; [[ADTelemetry sharedInstance] stopEvent:[requestParams telemetryRequestId] event:event]; @@ -240,11 +248,14 @@ - (void)updateCacheToItem:(ADTokenCacheItem *)cacheItem MRRT:(BOOL)isMRRT requestParams:(ADRequestParameters*)requestParams { + NSUUID* correlationId = [requestParams correlationId]; + NSString* telemetryRequestId = [requestParams telemetryRequestId]; + NSString* savedRefreshToken = cacheItem.refreshToken; if (isMRRT) { - AD_LOG_VERBOSE_F(@"Token cache store", [requestParams correlationId], @"Storing multi-resource refresh token for authority: %@", _authority); - [[ADTelemetry sharedInstance] startEvent:[requestParams telemetryRequestId] eventName:@"token_cache_write"]; + AD_LOG_VERBOSE_F(@"Token cache store", correlationId, @"Storing multi-resource refresh token for authority: %@", _authority); + [[ADTelemetry sharedInstance] startEvent:telemetryRequestId eventName:@"token_cache_write"]; //If the server returned a multi-resource refresh token, we break //the item into two: one with the access token and no refresh token and @@ -256,11 +267,13 @@ - (void)updateCacheToItem:(ADTokenCacheItem *)cacheItem multiRefreshTokenItem.accessToken = nil; multiRefreshTokenItem.resource = nil; multiRefreshTokenItem.expiresOn = nil; - [_dataSource addOrUpdateItem:multiRefreshTokenItem correlationId:[requestParams correlationId] error:nil]; + [_dataSource addOrUpdateItem:multiRefreshTokenItem correlationId:correlationId error:nil]; - ADTelemetryCacheEvent* event = [[ADTelemetryCacheEvent alloc] initWithName:@"token_cache_write"]; + ADTelemetryCacheEvent* event = [[ADTelemetryCacheEvent alloc] initWithName:@"token_cache_write" + requestId:telemetryRequestId + correlationId:correlationId]; [event setTokenType:@"multi-resource refresh token"]; - [[ADTelemetry sharedInstance] stopEvent:[requestParams telemetryRequestId] event:event]; + [[ADTelemetry sharedInstance] stopEvent:telemetryRequestId event:event]; SAFE_ARC_RELEASE(event); // If the item is also a Family Refesh Token (FRT) we update the FRT @@ -268,31 +281,35 @@ - (void)updateCacheToItem:(ADTokenCacheItem *)cacheItem NSString* familyId = cacheItem.familyId; if (familyId) { - [[ADTelemetry sharedInstance] startEvent:[requestParams telemetryRequestId] eventName:@"token_cache_write"]; + [[ADTelemetry sharedInstance] startEvent:telemetryRequestId eventName:@"token_cache_write"]; ADTokenCacheItem* frtItem = [multiRefreshTokenItem copy]; NSString* fociClientId = [ADTokenCacheAccessor familyClientId:familyId]; frtItem.clientId = fociClientId; - [_dataSource addOrUpdateItem:frtItem correlationId:[requestParams correlationId] error:nil]; + [_dataSource addOrUpdateItem:frtItem correlationId:correlationId error:nil]; SAFE_ARC_RELEASE(frtItem); - ADTelemetryCacheEvent* event = [[ADTelemetryCacheEvent alloc] initWithName:@"token_cache_write"]; + ADTelemetryCacheEvent* event = [[ADTelemetryCacheEvent alloc] initWithName:@"token_cache_write" + requestId:telemetryRequestId + correlationId:correlationId]; [event setTokenType:@"family refresh token"]; - [[ADTelemetry sharedInstance] stopEvent:[requestParams telemetryRequestId] event:event]; + [[ADTelemetry sharedInstance] stopEvent:telemetryRequestId event:event]; SAFE_ARC_RELEASE(event); } SAFE_ARC_RELEASE(multiRefreshTokenItem); } - AD_LOG_VERBOSE_F(@"Token cache store", [requestParams correlationId], @"Storing access token for resource: %@", cacheItem.resource); - [[ADTelemetry sharedInstance] startEvent:[requestParams telemetryRequestId] eventName:@"token_cache_write"]; + AD_LOG_VERBOSE_F(@"Token cache store", correlationId, @"Storing access token for resource: %@", cacheItem.resource); + [[ADTelemetry sharedInstance] startEvent:telemetryRequestId eventName:@"token_cache_write"]; - [_dataSource addOrUpdateItem:cacheItem correlationId:[requestParams correlationId] error:nil]; + [_dataSource addOrUpdateItem:cacheItem correlationId:correlationId error:nil]; cacheItem.refreshToken = savedRefreshToken;//Restore for the result - ADTelemetryCacheEvent* event = [[ADTelemetryCacheEvent alloc] initWithName:@"token_cache_write"]; + ADTelemetryCacheEvent* event = [[ADTelemetryCacheEvent alloc] initWithName:@"token_cache_write" + requestId:telemetryRequestId + correlationId:correlationId]; [event setTokenType:@"access token"]; - [[ADTelemetry sharedInstance] stopEvent:[requestParams telemetryRequestId] event:event]; + [[ADTelemetry sharedInstance] stopEvent:telemetryRequestId event:event]; SAFE_ARC_RELEASE(event); } @@ -306,6 +323,8 @@ - (void)removeItemFromCache:(ADTokenCacheItem *)cacheItem return; } + NSUUID* correlationId = [requestParams correlationId]; + [[ADTelemetry sharedInstance] startEvent:[requestParams telemetryRequestId] eventName:@"token_cache_delete_token"]; BOOL removed = NO; @@ -313,15 +332,15 @@ - (void)removeItemFromCache:(ADTokenCacheItem *)cacheItem ADTokenCacheKey* exactKey = [cacheItem extractKey:nil]; if (exactKey) { - ADTokenCacheItem* existing = [_dataSource getItemWithKey:exactKey userId:cacheItem.userInformation.userId correlationId:[requestParams correlationId] error:nil]; + ADTokenCacheItem* existing = [_dataSource getItemWithKey:exactKey userId:cacheItem.userInformation.userId correlationId:correlationId error:nil]; if ([refreshToken isEqualToString:existing.refreshToken])//If still there, attempt to remove { - AD_LOG_VERBOSE_F(@"Token cache store", [requestParams correlationId], @"Tombstoning cache for resource: %@", cacheItem.resource); + AD_LOG_VERBOSE_F(@"Token cache store", correlationId, @"Tombstoning cache for resource: %@", cacheItem.resource); //update tombstone property before update the tombstone in cache - [existing makeTombstone:@{ @"correlationId" : [[requestParams correlationId] UUIDString], + [existing makeTombstone:@{ @"correlationId" : [correlationId UUIDString], @"errorDetails" : [error errorDetails], @"protocolCode" : [error protocolCode] }]; - [_dataSource addOrUpdateItem:existing correlationId:[requestParams correlationId] error:nil]; + [_dataSource addOrUpdateItem:existing correlationId:correlationId error:nil]; removed = YES; } } @@ -335,20 +354,22 @@ - (void)removeItemFromCache:(ADTokenCacheItem *)cacheItem error:nil]; if (broadKey) { - ADTokenCacheItem* broadItem = [_dataSource getItemWithKey:broadKey userId:cacheItem.userInformation.userId correlationId:[requestParams correlationId] error:nil]; + ADTokenCacheItem* broadItem = [_dataSource getItemWithKey:broadKey userId:cacheItem.userInformation.userId correlationId:correlationId error:nil]; if (broadItem && [refreshToken isEqualToString:broadItem.refreshToken])//Remove if still there { - AD_LOG_VERBOSE_F(@"Token cache store", [requestParams correlationId], @"Tombstoning multi-resource refresh token for authority: %@", _authority); + AD_LOG_VERBOSE_F(@"Token cache store", correlationId, @"Tombstoning multi-resource refresh token for authority: %@", _authority); //update tombstone property before update the tombstone in cache - [broadItem makeTombstone:@{ @"correlationId" : [[requestParams correlationId] UUIDString], + [broadItem makeTombstone:@{ @"correlationId" : [correlationId UUIDString], @"errorDetails" : [error errorDetails], @"protocolCode" : [error protocolCode] }]; - [_dataSource addOrUpdateItem:broadItem correlationId:[requestParams correlationId] error:nil]; + [_dataSource addOrUpdateItem:broadItem correlationId:correlationId error:nil]; } } } - ADTelemetryCacheEvent* event = [[ADTelemetryCacheEvent alloc] initWithName:@"token_cache_delete_token"]; + ADTelemetryCacheEvent* event = [[ADTelemetryCacheEvent alloc] initWithName:@"token_cache_delete_token" + requestId:[requestParams telemetryRequestId] + correlationId:correlationId]; [[ADTelemetry sharedInstance] stopEvent:[requestParams telemetryRequestId] event:event]; SAFE_ARC_RELEASE(event); } diff --git a/ADAL/src/request/ADAcquireTokenSilentHandler.m b/ADAL/src/request/ADAcquireTokenSilentHandler.m index 29f722f5b..8013d03d6 100644 --- a/ADAL/src/request/ADAcquireTokenSilentHandler.m +++ b/ADAL/src/request/ADAcquireTokenSilentHandler.m @@ -99,9 +99,11 @@ - (void)acquireTokenByRefreshToken:(NSString*)refreshToken cacheItem:(ADTokenCacheItem*)cacheItem completionBlock:(ADAuthenticationCallback)completionBlock { - AD_LOG_VERBOSE_F(@"Attempting to acquire an access token from refresh token.", [_requestParams correlationId], @"Resource: %@", [_requestParams resource]); + NSUUID* correlationId = [_requestParams correlationId]; + + AD_LOG_VERBOSE_F(@"Attempting to acquire an access token from refresh token.", correlationId, @"Resource: %@", [_requestParams resource]); - [ADLogger logToken:refreshToken tokenType:@"refresh token" expiresOn:nil correlationId:[_requestParams correlationId]]; + [ADLogger logToken:refreshToken tokenType:@"refresh token" expiresOn:nil correlationId:correlationId]; //Fill the data for the token refreshing: NSMutableDictionary *request_data = nil; @@ -147,7 +149,7 @@ - (void)acquireTokenByRefreshToken:(NSString*)refreshToken resultItem.authority = [_requestParams authority]; - ADAuthenticationResult *result = [resultItem processTokenResponse:response fromRefresh:YES requestCorrelationId:[_requestParams correlationId]]; + ADAuthenticationResult *result = [resultItem processTokenResponse:response fromRefresh:YES requestCorrelationId:correlationId]; if (cacheItem)//The request came from the cache item, update it: { [[_requestParams tokenCache] updateCacheToResult:result @@ -207,7 +209,9 @@ - (void)acquireTokenWithItem:(ADTokenCacheItem *)item cacheItem:item completionBlock:^(ADAuthenticationResult *result) { - ADTelemetryAPIEvent* event = [[ADTelemetryAPIEvent alloc] initWithName:@"token_grant"]; + ADTelemetryAPIEvent* event = [[ADTelemetryAPIEvent alloc] initWithName:@"token_grant" + requestId:[_requestParams telemetryRequestId] + correlationId:[_requestParams correlationId]]; [event setGrantType:@"by refresh token"]; [event setResultStatus:[result status]]; [[ADTelemetry sharedInstance] stopEvent:[_requestParams telemetryRequestId] event:event]; @@ -259,6 +263,7 @@ - (void)getAccessToken:(ADAuthenticationCallback)completionBlock { //All of these should be set before calling this method: THROW_ON_NIL_ARGUMENT(completionBlock); + NSUUID* correlationId = [_requestParams correlationId]; ADAuthenticationError* error = nil; ADTokenCacheItem* item = [[_requestParams tokenCache] getATRTItemForUser:[_requestParams identifier] @@ -269,7 +274,7 @@ - (void)getAccessToken:(ADAuthenticationCallback)completionBlock // If some error ocurred during the cache lookup then we need to fail out right away. if (!item && error) { - completionBlock([ADAuthenticationResult resultFromError:error correlationId:[_requestParams correlationId]]); + completionBlock([ADAuthenticationResult resultFromError:error correlationId:correlationId]); return; } @@ -280,7 +285,7 @@ - (void)getAccessToken:(ADAuthenticationCallback)completionBlock item = [[_requestParams tokenCache] getADFSUserTokenForResource:[_requestParams resource] clientId:[_requestParams clientId] requestParams:_requestParams error:&error]; if (!item && error) { - completionBlock([ADAuthenticationResult resultFromError:error correlationId:[_requestParams correlationId]]); + completionBlock([ADAuthenticationResult resultFromError:error correlationId:correlationId]); return; } @@ -296,8 +301,8 @@ - (void)getAccessToken:(ADAuthenticationCallback)completionBlock // If we have a good (non-expired) access token then return it right away if (item.accessToken && !item.isExpired) { - [ADLogger logToken:item.accessToken tokenType:@"access token" expiresOn:item.expiresOn correlationId:[_requestParams correlationId]]; - ADAuthenticationResult* result = [ADAuthenticationResult resultFromTokenCacheItem:item multiResourceRefreshToken:NO correlationId:[_requestParams correlationId]]; + [ADLogger logToken:item.accessToken tokenType:@"access token" expiresOn:item.expiresOn correlationId:correlationId]; + ADAuthenticationResult* result = [ADAuthenticationResult resultFromTokenCacheItem:item multiResourceRefreshToken:NO correlationId:correlationId]; completionBlock(result); return; } diff --git a/ADAL/src/request/ADAuthenticationRequest+AcquireAssertion.m b/ADAL/src/request/ADAuthenticationRequest+AcquireAssertion.m index 3b65f16ea..de399977c 100644 --- a/ADAL/src/request/ADAuthenticationRequest+AcquireAssertion.m +++ b/ADAL/src/request/ADAuthenticationRequest+AcquireAssertion.m @@ -49,7 +49,8 @@ - (NSString*)assertionTypeString - (void)requestTokenByAssertion:(ADAuthenticationCallback)completionBlock { [self ensureRequest]; - AD_LOG_INFO_F(@"Requesting token from SAML Assertion", [_requestParams correlationId], @"resource: %@, clientId: %@", [_requestParams resource], [_requestParams clientId]); + NSUUID* correlationId = [_requestParams correlationId]; + AD_LOG_INFO_F(@"Requesting token from SAML Assertion", correlationId, @"resource: %@, clientId: %@", [_requestParams resource], [_requestParams clientId]); NSData *encodeData = [_samlAssertion dataUsingEncoding:NSUTF8StringEncoding]; NSString *base64String = [encodeData base64EncodedStringWithOptions:0]; @@ -58,8 +59,8 @@ - (void)requestTokenByAssertion:(ADAuthenticationCallback)completionBlock if (!assertionType) { ADAuthenticationError* error = [ADAuthenticationError invalidArgumentError:@"Unrecognized assertion type." - correlationId:[_requestParams correlationId]]; - completionBlock([ADAuthenticationResult resultFromError:error correlationId:[_requestParams correlationId]]); + correlationId:correlationId]; + completionBlock([ADAuthenticationResult resultFromError:error correlationId:correlationId]); return; } diff --git a/ADAL/src/request/ADAuthenticationRequest+AcquireToken.m b/ADAL/src/request/ADAuthenticationRequest+AcquireToken.m index b9d6994da..493258cda 100644 --- a/ADAL/src/request/ADAuthenticationRequest+AcquireToken.m +++ b/ADAL/src/request/ADAuthenticationRequest+AcquireToken.m @@ -43,23 +43,25 @@ - (void)acquireToken:(ADAuthenticationCallback)completionBlock THROW_ON_NIL_ARGUMENT(completionBlock); AD_REQUEST_CHECK_ARGUMENT([_requestParams resource]); [self ensureRequest]; + NSUUID* correlationId = [_requestParams correlationId]; + NSString* telemetryRequestId = [_requestParams telemetryRequestId]; - [[ADTelemetry sharedInstance] startEvent:[self telemetryRequestId] eventName:@"acauire_token_call"]; + [[ADTelemetry sharedInstance] startEvent:telemetryRequestId eventName:@"acquire_token"]; ADAuthenticationCallback requestCompletion = ^void(ADAuthenticationResult *result) { - ADTelemetryAPIEvent* event = [[ADTelemetryAPIEvent alloc] initWithName:@"acauire_token_call"]; + ADTelemetryAPIEvent* event = [[ADTelemetryAPIEvent alloc] initWithName:@"acquire_token" + requestId:telemetryRequestId + correlationId:correlationId]; [self fillTelemetryForAcquireToken:event result:result]; - [[ADTelemetry sharedInstance] stopEvent:[self telemetryRequestId] event:event]; + [[ADTelemetry sharedInstance] stopEvent:telemetryRequestId event:event]; SAFE_ARC_RELEASE(event); - //flush all events in the end of the acquireToken call - [[ADTelemetry sharedInstance] flush]; completionBlock(result); }; NSString* log = [NSString stringWithFormat:@"acquireToken (authority = %@, resource = %@, clientId = %@, idtype = %@)", [_requestParams authority], [_requestParams resource], [_requestParams clientId], [[_requestParams identifier] typeAsString]]; - AD_LOG_INFO_F(log, [_requestParams correlationId], @"userId = %@", [_requestParams identifier].userId); + AD_LOG_INFO_F(log, correlationId, @"userId = %@", [_requestParams identifier].userId); if (!_silent && ![NSThread isMainThread]) { @@ -67,7 +69,7 @@ - (void)acquireToken:(ADAuthenticationCallback)completionBlock [ADAuthenticationError errorFromAuthenticationError:AD_ERROR_UI_NOT_ON_MAIN_THREAD protocolCode:nil errorDetails:@"Interactive authentication requests must originate from the main thread" - correlationId:[_requestParams correlationId]]; + correlationId:correlationId]; requestCompletion([ADAuthenticationResult resultFromError:error]); return; @@ -79,8 +81,8 @@ - (void)acquireToken:(ADAuthenticationCallback)completionBlock [ADAuthenticationError errorFromAuthenticationError:AD_ERROR_TOKENBROKER_INVALID_REDIRECT_URI protocolCode:nil errorDetails:ADRedirectUriInvalidError - correlationId:[_requestParams correlationId]]; - requestCompletion([ADAuthenticationResult resultFromError:error correlationId:[_requestParams correlationId]]); + correlationId:correlationId]; + requestCompletion([ADAuthenticationResult resultFromError:error correlationId:correlationId]); return; } @@ -90,20 +92,22 @@ - (void)acquireToken:(ADAuthenticationCallback)completionBlock return; } - [[ADTelemetry sharedInstance] startEvent:[self telemetryRequestId] eventName:@"authority_validation"]; + [[ADTelemetry sharedInstance] startEvent:telemetryRequestId eventName:@"authority_validation"]; [[ADInstanceDiscovery sharedInstance] validateAuthority:_context.authority requestParams:_requestParams completionBlock:^(BOOL validated, ADAuthenticationError *error) { - ADTelemetryAPIEvent* event = [[ADTelemetryAPIEvent alloc] initWithName:@"authority_validation"]; + ADTelemetryAPIEvent* event = [[ADTelemetryAPIEvent alloc] initWithName:@"authority_validation" + requestId:telemetryRequestId + correlationId:correlationId]; [event setAuthorityValidationStatus:validated ? @"YES" : @"NO"]; [event setAuthority:_context.authority]; - [[ADTelemetry sharedInstance] stopEvent:[self telemetryRequestId] event:event]; + [[ADTelemetry sharedInstance] stopEvent:telemetryRequestId event:event]; SAFE_ARC_RELEASE(event); if (error) { - requestCompletion([ADAuthenticationResult resultFromError:error correlationId:[_requestParams correlationId]]); + requestCompletion([ADAuthenticationResult resultFromError:error correlationId:correlationId]); } else { @@ -119,11 +123,13 @@ - (void)validatedAcquireToken:(ADAuthenticationCallback)completionBlock if (![ADAuthenticationContext isForcedAuthorization:_promptBehavior] && [_context hasCacheStore]) { - [[ADTelemetry sharedInstance] startEvent:[self telemetryRequestId] eventName:@"acquire_token_silent"]; + [[ADTelemetry sharedInstance] startEvent:[self telemetryRequestId] eventName:@"acquire_token_silent_handler"]; [ADAcquireTokenSilentHandler acquireTokenSilentForRequestParams:_requestParams completionBlock:^(ADAuthenticationResult *result) { - ADTelemetryAPIEvent* event = [[ADTelemetryAPIEvent alloc] initWithName:@"acquire_token_silent"]; + ADTelemetryAPIEvent* event = [[ADTelemetryAPIEvent alloc] initWithName:@"acquire_token_silent_handler" + requestId:[self telemetryRequestId] + correlationId:[self correlationId]]; [[ADTelemetry sharedInstance] stopEvent:[self telemetryRequestId] event:event]; SAFE_ARC_RELEASE(event); @@ -148,6 +154,8 @@ - (void)validatedAcquireToken:(ADAuthenticationCallback)completionBlock - (void)requestToken:(ADAuthenticationCallback)completionBlock { [self ensureRequest]; + NSUUID* correlationId = [_requestParams correlationId]; + NSString* telemetryRequestId = [_requestParams telemetryRequestId]; if (_samlAssertion) { @@ -166,9 +174,9 @@ - (void)requestToken:(ADAuthenticationCallback)completionBlock protocolCode:nil errorDetails:ADCredentialsNeeded userInfo:underlyingError - correlationId:[_requestParams correlationId]]; + correlationId:correlationId]; - ADAuthenticationResult* result = [ADAuthenticationResult resultFromError:error correlationId:[_requestParams correlationId]]; + ADAuthenticationResult* result = [ADAuthenticationResult resultFromError:error correlationId:correlationId]; completionBlock(result); return; } @@ -185,8 +193,8 @@ - (void)requestToken:(ADAuthenticationCallback)completionBlock [ADAuthenticationError errorFromAuthenticationError:AD_ERROR_UI_NOT_SUPPORTED_IN_APP_EXTENSION protocolCode:nil errorDetails:ADInteractionNotSupportedInExtension - correlationId:[_requestParams correlationId]]; - ADAuthenticationResult* result = [ADAuthenticationResult resultFromError:error correlationId:[_requestParams correlationId]]; + correlationId:correlationId]; + ADAuthenticationResult* result = [ADAuthenticationResult resultFromError:error correlationId:correlationId]; completionBlock(result); return; } @@ -204,10 +212,12 @@ - (void)requestToken:(ADAuthenticationCallback)completionBlock __block BOOL silentRequest = _allowSilent; // Get the code first: - [[ADTelemetry sharedInstance] startEvent:[self telemetryRequestId] eventName:@"authorization_code"]; + [[ADTelemetry sharedInstance] startEvent:telemetryRequestId eventName:@"authorization_code"]; [self requestCode:^(NSString * code, ADAuthenticationError *error) { - ADTelemetryAPIEvent* event = [[ADTelemetryAPIEvent alloc] initWithName:@"authorization_code"]; + ADTelemetryAPIEvent* event = [[ADTelemetryAPIEvent alloc] initWithName:@"authorization_code" + requestId:telemetryRequestId + correlationId:correlationId]; if (error) { @@ -218,11 +228,11 @@ - (void)requestToken:(ADAuthenticationCallback)completionBlock return; } - ADAuthenticationResult* result = (AD_ERROR_UI_USER_CANCEL == error.code) ? [ADAuthenticationResult resultFromCancellation:[_requestParams correlationId]] - : [ADAuthenticationResult resultFromError:error correlationId:[_requestParams correlationId]]; + ADAuthenticationResult* result = (AD_ERROR_UI_USER_CANCEL == error.code) ? [ADAuthenticationResult resultFromCancellation:correlationId] + : [ADAuthenticationResult resultFromError:error correlationId:correlationId]; [event setAPIStatus:(AD_ERROR_UI_USER_CANCEL == error.code) ? @"canceled":@"failed"]; - [[ADTelemetry sharedInstance] stopEvent:[self telemetryRequestId] event:event]; + [[ADTelemetry sharedInstance] stopEvent:telemetryRequestId event:event]; completionBlock(result); } @@ -231,7 +241,7 @@ - (void)requestToken:(ADAuthenticationCallback)completionBlock if([code hasPrefix:@"msauth://"]) { [event setAPIStatus:@"try to invoke broker from webview"]; - [[ADTelemetry sharedInstance] stopEvent:[self telemetryRequestId] event:event]; + [[ADTelemetry sharedInstance] stopEvent:telemetryRequestId event:event]; [self handleBrokerFromWebiewResponse:code completionBlock:completionBlock]; @@ -239,16 +249,18 @@ - (void)requestToken:(ADAuthenticationCallback)completionBlock else { [event setAPIStatus:@"succeeded"]; - [[ADTelemetry sharedInstance] stopEvent:[self telemetryRequestId] event:event]; + [[ADTelemetry sharedInstance] stopEvent:telemetryRequestId event:event]; - [[ADTelemetry sharedInstance] startEvent:[self telemetryRequestId] eventName:@"token_grant"]; + [[ADTelemetry sharedInstance] startEvent:telemetryRequestId eventName:@"token_grant"]; [self requestTokenByCode:code completionBlock:^(ADAuthenticationResult *result) { - ADTelemetryAPIEvent* event = [[ADTelemetryAPIEvent alloc] initWithName:@"token_grant"]; + ADTelemetryAPIEvent* event = [[ADTelemetryAPIEvent alloc] initWithName:@"token_grant" + requestId:telemetryRequestId + correlationId:correlationId]; [event setGrantType:@"by code"]; [event setResultStatus:[result status]]; - [[ADTelemetry sharedInstance] stopEvent:[self telemetryRequestId] event:event]; + [[ADTelemetry sharedInstance] stopEvent:telemetryRequestId event:event]; SAFE_ARC_RELEASE(event); if (AD_SUCCEEDED == result.status) diff --git a/ADAL/src/request/ADAuthenticationRequest+Broker.m b/ADAL/src/request/ADAuthenticationRequest+Broker.m index 888147d6e..e069b01b8 100644 --- a/ADAL/src/request/ADAuthenticationRequest+Broker.m +++ b/ADAL/src/request/ADAuthenticationRequest+Broker.m @@ -198,6 +198,7 @@ - (void)callBroker:(ADAuthenticationCallback)completionBlock CHECK_FOR_NIL([_requestParams resource]); CHECK_FOR_NIL([_requestParams clientId]); CHECK_FOR_NIL([_requestParams correlationId]); + NSUUID* correlationId = [_requestParams correlationId]; ADAuthenticationError* error = nil; if(![ADAuthenticationRequest validBrokerRedirectUri:[_requestParams redirectUri]]) @@ -205,8 +206,8 @@ - (void)callBroker:(ADAuthenticationCallback)completionBlock error = [ADAuthenticationError errorFromAuthenticationError:AD_ERROR_TOKENBROKER_INVALID_REDIRECT_URI protocolCode:nil errorDetails:ADRedirectUriInvalidError - correlationId:[_requestParams correlationId]]; - completionBlock([ADAuthenticationResult resultFromError:error correlationId:[_requestParams correlationId]]); + correlationId:correlationId]; + completionBlock([ADAuthenticationResult resultFromError:error correlationId:correlationId]); return; } @@ -217,8 +218,8 @@ - (void)callBroker:(ADAuthenticationCallback)completionBlock ADAuthenticationError* error = [ADAuthenticationError errorFromAuthenticationError:AD_ERROR_UI_MULTLIPLE_INTERACTIVE_REQUESTS protocolCode:nil errorDetails:message - correlationId:[_requestParams correlationId]]; - completionBlock([ADAuthenticationResult resultFromError:error correlationId:[_requestParams correlationId]]); + correlationId:correlationId]; + completionBlock([ADAuthenticationResult resultFromError:error correlationId:correlationId]); return; } @@ -228,7 +229,9 @@ - (void)callBroker:(ADAuthenticationCallback)completionBlock { [self releaseUserInterationLock]; // Release the lock when completion block is called. - ADTelemetryBrokerEvent* event = [[ADTelemetryBrokerEvent alloc] initWithName:@"launch_broker"]; + ADTelemetryBrokerEvent* event = [[ADTelemetryBrokerEvent alloc] initWithName:@"launch_broker" + requestId:[_requestParams telemetryRequestId] + correlationId:correlationId]; [event setResultStatus:[result status]]; [event setBrokerAppVersion:s_brokerAppVersion]; [event setBrokerProtocolVersion:s_brokerProtocolVersion]; @@ -237,14 +240,14 @@ - (void)callBroker:(ADAuthenticationCallback)completionBlock completionBlock(result); }; - AD_LOG_INFO(@"Invoking broker for authentication", [_requestParams correlationId], nil); + AD_LOG_INFO(@"Invoking broker for authentication", correlationId, nil); #if TARGET_OS_IPHONE // Broker Message Encryption ADBrokerKeyHelper* brokerHelper = [[ADBrokerKeyHelper alloc] init]; NSData* key = [brokerHelper getBrokerKey:&error]; if (!key) { - ADAuthenticationError* adError = [ADAuthenticationError unexpectedInternalError:@"Unable to retrieve broker key." correlationId:[_requestParams correlationId]]; - completionBlock([ADAuthenticationResult resultFromError:adError correlationId:[_requestParams correlationId]]); + ADAuthenticationError* adError = [ADAuthenticationError unexpectedInternalError:@"Unable to retrieve broker key." correlationId:correlationId]; + completionBlock([ADAuthenticationResult resultFromError:adError correlationId:correlationId]); return; } @@ -264,7 +267,7 @@ - (void)callBroker:(ADAuthenticationCallback)completionBlock @"username_type": [_requestParams identifier] ? [[_requestParams identifier] typeAsString] : @"", @"username": [_requestParams identifier].userId ? [_requestParams identifier].userId : @"", @"force" : _promptBehavior == AD_FORCE_PROMPT ? @"YES" : @"NO", - @"correlation_id": [_requestParams correlationId], + @"correlation_id": correlationId, #if TARGET_OS_IPHONE // Broker Message Encryption @"broker_key": base64UrlKey, #endif // TARGET_OS_IPHONE Broker Message Encryption @@ -280,6 +283,7 @@ - (void)handleBrokerFromWebiewResponse:(NSString*)urlString completionBlock:(ADAuthenticationCallback)completionBlock { CHECK_FOR_NIL([_requestParams resource]); + NSUUID* correlationId = [_requestParams correlationId]; ADAuthenticationError* error = nil; if(![ADAuthenticationRequest validBrokerRedirectUri:[_requestParams redirectUri]]) @@ -287,8 +291,8 @@ - (void)handleBrokerFromWebiewResponse:(NSString*)urlString error = [ADAuthenticationError errorFromAuthenticationError:AD_ERROR_TOKENBROKER_INVALID_REDIRECT_URI protocolCode:nil errorDetails:ADRedirectUriInvalidError - correlationId:[_requestParams correlationId]]; - completionBlock([ADAuthenticationResult resultFromError:error correlationId:[_requestParams correlationId]]); + correlationId:correlationId]; + completionBlock([ADAuthenticationResult resultFromError:error correlationId:correlationId]); return; } @@ -301,7 +305,7 @@ - (void)handleBrokerFromWebiewResponse:(NSString*)urlString #endif // TARGET_OS_IPHONE Broker Message Encryption NSString* adalVersion = [ADLogger getAdalVersion]; - NSString* correlationIdStr = [[_requestParams correlationId] UUIDString]; + NSString* correlationIdStr = [correlationId UUIDString]; NSString* authority = _context.authority; CHECK_FOR_NIL(adalVersion); @@ -329,7 +333,9 @@ - (void)handleBrokerFromWebiewResponse:(NSString*)urlString [[ADTelemetry sharedInstance] startEvent:[self telemetryRequestId] eventName:@"launch_broker"]; void(^requestCompletion)(ADAuthenticationResult* result) = ^void(ADAuthenticationResult* result) { - ADTelemetryBrokerEvent* event = [[ADTelemetryBrokerEvent alloc] initWithName:@"launch_broker"]; + ADTelemetryBrokerEvent* event = [[ADTelemetryBrokerEvent alloc] initWithName:@"launch_broker" + requestId:[_requestParams telemetryRequestId] + correlationId:correlationId]; [event setResultStatus:[result status]]; [event setBrokerAppVersion:s_brokerAppVersion]; [event setBrokerProtocolVersion:s_brokerProtocolVersion]; diff --git a/ADAL/src/request/ADAuthenticationRequest+WebRequest.m b/ADAL/src/request/ADAuthenticationRequest+WebRequest.m index 52ca05724..933797b7a 100755 --- a/ADAL/src/request/ADAuthenticationRequest+WebRequest.m +++ b/ADAL/src/request/ADAuthenticationRequest+WebRequest.m @@ -181,7 +181,9 @@ - (void)launchWebView:(NSString*)startUrl [[ADTelemetry sharedInstance] startEvent:[self telemetryRequestId] eventName:@"launch_web_view"]; void(^requestCompletion)(ADAuthenticationError *error, NSURL *end) = ^void(ADAuthenticationError *error, NSURL *end) { - ADTelemetryUIEvent* event = [[ADTelemetryUIEvent alloc] initWithName:@"launch_web_view"]; + ADTelemetryUIEvent* event = [[ADTelemetryUIEvent alloc] initWithName:@"launch_web_view" + requestId:[self telemetryRequestId] + correlationId:[self correlationId]]; [self fillTelemetryUIEvent:event]; [[ADTelemetry sharedInstance] stopEvent:[self telemetryRequestId] event:event]; diff --git a/ADAL/src/request/ADAuthenticationRequest.m b/ADAL/src/request/ADAuthenticationRequest.m index 8b7a6b473..b6180f0f0 100644 --- a/ADAL/src/request/ADAuthenticationRequest.m +++ b/ADAL/src/request/ADAuthenticationRequest.m @@ -264,6 +264,7 @@ - (void)ensureRequest } [self correlationId]; + [self telemetryRequestId]; _requestStarted = YES; } diff --git a/ADAL/src/request/ADWebRequest.m b/ADAL/src/request/ADWebRequest.m index dd51b036c..c3aba1e01 100644 --- a/ADAL/src/request/ADWebRequest.m +++ b/ADAL/src/request/ADWebRequest.m @@ -321,10 +321,10 @@ -(void)connection:(NSURLConnection *)connection didSendBodyData:(NSInteger)bytes - (void)stopTelemetryEvent:(NSError *)error response:(ADWebResponse *)response { - ADTelemetryHttpEvent* event = [[ADTelemetryHttpEvent alloc] initWithName:@"http_request"]; + ADTelemetryHttpEvent* event = [[ADTelemetryHttpEvent alloc] initWithName:@"http_request" requestId:_telemetryRequestId correlationId:_correlationId]; [event setHttpMethod:_isGetRequest ? @"GET" : @"POST"]; - [event setHttpPath:[[_requestURL host] stringByAppendingPathComponent:[_requestURL path]]]; + [event setHttpPath:[NSString stringWithFormat:@"%@://%@/%@", _requestURL.scheme, _requestURL.host, _requestURL.path]]; [event setHttpRequestQueryParams:[_requestURL query]]; if (error) { diff --git a/ADAL/src/telemetry/ADAggregatedDispatcher.m b/ADAL/src/telemetry/ADAggregatedDispatcher.m index 5254c4c4e..b464503d1 100644 --- a/ADAL/src/telemetry/ADAggregatedDispatcher.m +++ b/ADAL/src/telemetry/ADAggregatedDispatcher.m @@ -40,40 +40,57 @@ - (id)initWithDispatcher:(id)dispatcher return self; } -- (void)flush +- (void)flush:(NSString*)requestId { [_dispatchLock lock]; //avoid access conflict when manipulating _objectsToBeDispatched - NSMutableDictionary* objectsToBeDispatched = _objectsToBeDispatched; - _objectsToBeDispatched = [NSMutableDictionary new]; + NSArray* eventsToBeDispatched = [_objectsToBeDispatched objectForKey:requestId]; + [_objectsToBeDispatched removeObjectForKey:requestId]; [_dispatchLock unlock]; // Integrate events of a particular request id into one single event - for (NSString* requestId in objectsToBeDispatched) + NSMutableArray* aggregatedEvent = [NSMutableArray new]; + SAFE_ARC_AUTORELEASE(aggregatedEvent); + + for (id event in eventsToBeDispatched) { - NSArray* events = [objectsToBeDispatched objectForKey:requestId]; - NSMutableArray* aggregatedEvent = [NSMutableArray new]; + NSArray* properties = [event getProperties]; + + NSInteger propertiesToSkip = 0; + // default properties are duplicate for all events, + // so they are skipped from 2nd event onwards + if (event != [eventsToBeDispatched objectAtIndex:0]) + { + propertiesToSkip = [event getDefaultPropertyCount]; + } - for (id event in events) + for (NSInteger i = propertiesToSkip; i < [properties count]; i++) { - NSArray* properties = [event getProperties]; - - NSInteger propertiesToSkip = 0; - // default properties are duplicate for all events, - // so they are skipped from 2nd event onwards - if (event != [events objectAtIndex:0]) - { - propertiesToSkip = [event getDefaultPropertyCount]; - } - - for (NSInteger i = propertiesToSkip; i < [properties count]; i++) - { - [aggregatedEvent addObject:properties[i]]; - } + [aggregatedEvent addObject:properties[i]]; } - [_dispatcher dispatch:aggregatedEvent]; } + [_dispatcher dispatch:aggregatedEvent]; +} + +- (void)receive:(NSString *)requestId + event:(id)event +{ + if ([NSString adIsStringNilOrBlank:requestId] || !event) + { + return; + + } + + [_dispatchLock lock]; //make sure no one changes _objectsToBeDispatched while using it + NSMutableArray* eventsForRequestId = [_objectsToBeDispatched objectForKey:requestId]; + if (!eventsForRequestId) + { + eventsForRequestId = [NSMutableArray new]; + [_objectsToBeDispatched setObject:eventsForRequestId forKey:requestId]; + } + + [eventsForRequestId addObject:event]; + [_dispatchLock unlock]; - SAFE_ARC_RELEASE(objectsToBeDispatched); } @end \ No newline at end of file diff --git a/ADAL/src/telemetry/ADDefaultDispatcher.h b/ADAL/src/telemetry/ADDefaultDispatcher.h index 5db71bfe7..99b9b6c7b 100644 --- a/ADAL/src/telemetry/ADDefaultDispatcher.h +++ b/ADAL/src/telemetry/ADDefaultDispatcher.h @@ -33,6 +33,6 @@ - (void)receive:(NSString *)requestId event:(id)event; -- (void)flush; +- (void)flush:(NSString*)requestId; @end \ No newline at end of file diff --git a/ADAL/src/telemetry/ADDefaultDispatcher.m b/ADAL/src/telemetry/ADDefaultDispatcher.m index 50946a2a2..6bbb7f0b3 100644 --- a/ADAL/src/telemetry/ADDefaultDispatcher.m +++ b/ADAL/src/telemetry/ADDefaultDispatcher.m @@ -48,48 +48,22 @@ - (id)initWithDispatcher:(id)dispatcher return self; } -- (void)flush +- (void)flush:(NSString*)requestId { - [_dispatchLock lock]; //avoid access conflict when manipulating _objectsToBeDispatched - NSMutableDictionary* objectsToBeDispatched = _objectsToBeDispatched; - _objectsToBeDispatched = [NSMutableDictionary new]; - [_dispatchLock unlock];; - - for (NSString* requestId in objectsToBeDispatched) - { - NSArray* events = [objectsToBeDispatched objectForKey:requestId]; - - for (id event in events) - { - NSArray* properties = [event getProperties]; - if (properties) - { - [_dispatcher dispatch:properties]; - } - } - - SAFE_ARC_RELEASE(objectsToBeDispatched); - } +#pragma unused(requestId) + //default dispatcher does not cache any event + //so here is empty } - (void)receive:(NSString *)requestId event:(id)event { - if ([NSString adIsStringNilOrBlank:requestId] || !event) +#pragma unused(requestId) + NSArray* properties = [event getProperties]; + if (properties) { - return; + [_dispatcher dispatch:properties]; } - - [_dispatchLock lock]; //make sure no one changes _objectsToBeDispatched while using it - NSMutableArray* eventsForRequestId = [_objectsToBeDispatched objectForKey:requestId]; - if (!eventsForRequestId) - { - eventsForRequestId = [NSMutableArray new]; - [_objectsToBeDispatched setObject:eventsForRequestId forKey:requestId]; - } - - [eventsForRequestId addObject:event]; - [_dispatchLock unlock]; } - (void)dealloc diff --git a/ADAL/src/telemetry/ADTelemetry+Internal.h b/ADAL/src/telemetry/ADTelemetry+Internal.h index 54557ea25..c6acd01fb 100644 --- a/ADAL/src/telemetry/ADTelemetry+Internal.h +++ b/ADAL/src/telemetry/ADTelemetry+Internal.h @@ -36,6 +36,6 @@ - (void)dispatchEventNow:(NSString*)requestId event:(id)event; -- (void)flush; +- (void)flush:(NSString*)requestId; @end \ No newline at end of file diff --git a/ADAL/src/telemetry/ADTelemetry.m b/ADAL/src/telemetry/ADTelemetry.m index f20d75ab3..33dd6cc1c 100644 --- a/ADAL/src/telemetry/ADTelemetry.m +++ b/ADAL/src/telemetry/ADTelemetry.m @@ -113,6 +113,7 @@ - (void)startEvent:(NSString*)requestId - (void)stopEvent:(NSString*)requestId event:(id)event { + NSDate* stopTime = [NSDate date]; NSString* eventName = [self getPropertyFromEvent:event propertyName:@"event_name"]; if ([NSString adIsStringNilOrBlank:requestId] || [NSString adIsStringNilOrBlank:eventName] || !event) @@ -129,10 +130,10 @@ - (void)stopEvent:(NSString*)requestId [event setStartTime:startTime]; [_eventTracking removeObjectForKey:key]; - NSDate* stopTime = [NSDate date]; [event setStopTime:stopTime]; + [event setResponseTime:[stopTime timeIntervalSinceDate:startTime]]; - [self dispatchEventNow:requestId event:event]; + [_dispatcher receive:requestId event:event]; } - (void)dispatchEventNow:(NSString*)requestId @@ -167,13 +168,13 @@ - (NSString*)getPropertyFromEvent:(id)event return nil; } -- (void)flush +- (void)flush:(NSString*)requestId { @synchronized(self) { if (_dispatcher) { - [_dispatcher flush]; + [_dispatcher flush:requestId]; } } } diff --git a/ADAL/src/telemetry/ADTelemetryAPIEvent.h b/ADAL/src/telemetry/ADTelemetryAPIEvent.h index aa06c095f..d2afcfb24 100644 --- a/ADAL/src/telemetry/ADTelemetryAPIEvent.h +++ b/ADAL/src/telemetry/ADTelemetryAPIEvent.h @@ -41,4 +41,6 @@ - (void)setGrantType:(NSString*)grantType; - (void)setAPIStatus:(NSString*)status; +- (void)setAPIId:(NSString*)apiId; + @end \ No newline at end of file diff --git a/ADAL/src/telemetry/ADTelemetryAPIEvent.m b/ADAL/src/telemetry/ADTelemetryAPIEvent.m index c8d4b4188..6106bc5d1 100644 --- a/ADAL/src/telemetry/ADTelemetryAPIEvent.m +++ b/ADAL/src/telemetry/ADTelemetryAPIEvent.m @@ -52,7 +52,7 @@ - (void)setCorrelationId:(NSUUID*)correlationId - (void)setUserId:(NSString*)userId; { - [self setProperty:@"user_id" value:[NSString stringWithFormat:@"%lu", (unsigned long)[userId hash]]]; + [self setProperty:@"user_id" value:[userId adComputeSHA256]]; } - (void)setClientId:(NSString*)clientId @@ -105,4 +105,9 @@ - (void)setAPIStatus:(NSString*)status [self setProperty:@"api_status" value:status]; } +- (void)setAPIId:(NSString*)apiId +{ + [self setProperty:@"api_id" value:apiId]; +} + @end \ No newline at end of file diff --git a/ADAL/src/telemetry/ADTelemetryDefaultEvent.h b/ADAL/src/telemetry/ADTelemetryDefaultEvent.h index 5a6fa45a8..1338fdfbc 100644 --- a/ADAL/src/telemetry/ADTelemetryDefaultEvent.h +++ b/ADAL/src/telemetry/ADTelemetryDefaultEvent.h @@ -26,8 +26,11 @@ @interface ADTelemetryDefaultEvent : NSObject { NSMutableArray* _propertyMap; + NSInteger _defaultPropertyCount; } -- (id)initWithName:(NSString*)eventName; +- (id)initWithName:(NSString*)eventName + requestId:(NSString*)requestId + correlationId:(NSUUID*)correlationId; @end \ No newline at end of file diff --git a/ADAL/src/telemetry/ADTelemetryDefaultEvent.m b/ADAL/src/telemetry/ADTelemetryDefaultEvent.m index 54529621f..024eea6d4 100644 --- a/ADAL/src/telemetry/ADTelemetryDefaultEvent.m +++ b/ADAL/src/telemetry/ADTelemetryDefaultEvent.m @@ -30,6 +30,14 @@ #include #endif +#define SET_IF_NOT_NIL(DICT, NAME, OBJECT) \ +{ \ +if (OBJECT) \ +{ \ +[(DICT) addObject:@[(NAME), (OBJECT)]]; \ +} \ +} + @implementation ADTelemetryDefaultEvent @synthesize propertyMap = _propertyMap; @@ -42,6 +50,8 @@ - (id)init } - (id)initWithName:(NSString*)eventName + requestId:(NSString*)requestId + correlationId:(NSUUID*)correlationId { if (!(self = [super init])) { @@ -49,7 +59,11 @@ - (id)initWithName:(NSString*)eventName } _propertyMap = [[self defaultParameters] mutableCopy]; - [_propertyMap addObject:@[@"event_name", eventName]]; + SET_IF_NOT_NIL(_propertyMap, @"request_id", requestId); + SET_IF_NOT_NIL(_propertyMap, @"correlation_id", [correlationId UUIDString]); + _defaultPropertyCount = [_propertyMap count]; + + SET_IF_NOT_NIL(_propertyMap, @"event_name", eventName); return self; } @@ -90,6 +104,11 @@ - (void)setStopTime:(NSDate*)time [_propertyMap addObject:@[@"stop_time", [self getStringFromDate:time]]]; } +- (void)setResponseTime:(NSTimeInterval)responseTime +{ + [_propertyMap addObject:@[@"response_time", [NSString stringWithFormat:@"%f", responseTime]]]; +} + - (NSString*)getStringFromDate:(NSDate*)date { static NSDateFormatter* s_dateFormatter = nil; @@ -104,17 +123,9 @@ - (NSString*)getStringFromDate:(NSDate*)date return [s_dateFormatter stringFromDate:date]; } -#define SET_IF_NOT_NIL(DICT, NAME, OBJECT) \ -{ \ -if (OBJECT) \ -{ \ -[(DICT) addObject:@[(NAME), (OBJECT)]]; \ -} \ -} - - (NSArray*)defaultParameters { - static NSMutableArray* s_defaultParameters = nil; + static NSMutableArray* s_defaultParameters; static dispatch_once_t s_parametersOnce; dispatch_once(&s_parametersOnce, ^{ @@ -132,7 +143,7 @@ - (NSArray*)defaultParameters NSString* applicationName = [[NSProcessInfo processInfo] processName]; #endif - SET_IF_NOT_NIL(s_defaultParameters, @"device_id", ([NSString stringWithFormat:@"%lu", (unsigned long)[deviceId hash]])); + SET_IF_NOT_NIL(s_defaultParameters, @"device_id", [deviceId adComputeSHA256]); SET_IF_NOT_NIL(s_defaultParameters, @"application_name", applicationName); SET_IF_NOT_NIL(s_defaultParameters, @"application_version", [[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleVersion"]); @@ -148,7 +159,7 @@ - (NSArray*)defaultParameters - (NSInteger)getDefaultPropertyCount { - return [[self defaultParameters] count]; + return _defaultPropertyCount; } - (void)dealloc diff --git a/ADAL/src/telemetry/ADTelemetryEventInterface.h b/ADAL/src/telemetry/ADTelemetryEventInterface.h index 248edb54f..56ef4219f 100644 --- a/ADAL/src/telemetry/ADTelemetryEventInterface.h +++ b/ADAL/src/telemetry/ADTelemetryEventInterface.h @@ -30,5 +30,6 @@ - (NSArray*)getProperties; - (void)setStartTime:(NSDate*)time; - (void)setStopTime:(NSDate*)time; +- (void)setResponseTime:(NSTimeInterval)responseTime; @end \ No newline at end of file diff --git a/ADAL/src/telemetry/ADTelemetryHttpEvent.m b/ADAL/src/telemetry/ADTelemetryHttpEvent.m index aa5690b6f..5358456da 100644 --- a/ADAL/src/telemetry/ADTelemetryHttpEvent.m +++ b/ADAL/src/telemetry/ADTelemetryHttpEvent.m @@ -32,7 +32,7 @@ - (void)setHttpMethod:(NSString*)method - (void)setHttpPath:(NSString*)path { - [self setProperty:@"http_path" value:[self scrubTenantFromUrl:path]]; + [self setProperty:@"http_path" value:path]; } - (void)setHttpResponseCode:(NSString*)code diff --git a/ADAL/src/telemetry/ADTelemetryUIEvent.m b/ADAL/src/telemetry/ADTelemetryUIEvent.m index 91ca18c00..0ecd4ed72 100644 --- a/ADAL/src/telemetry/ADTelemetryUIEvent.m +++ b/ADAL/src/telemetry/ADTelemetryUIEvent.m @@ -27,7 +27,7 @@ @implementation ADTelemetryUIEvent - (void)setLoginHint:(NSString*)hint { - [self setProperty:@"login_hint" value:[NSString stringWithFormat:@"%lu", (unsigned long)[hint hash]]]; + [self setProperty:@"login_hint" value:[hint adComputeSHA256]]; } @end \ No newline at end of file diff --git a/ADAL/tests/ADTelemetryTests.m b/ADAL/tests/ADTelemetryTests.m index 007c8c7f5..428e3dc3e 100644 --- a/ADAL/tests/ADTelemetryTests.m +++ b/ADAL/tests/ADTelemetryTests.m @@ -87,9 +87,11 @@ - (void)testDefaultEventProperties { NSString* requestId = [[ADTelemetry sharedInstance] registerNewRequest]; [[ADTelemetry sharedInstance] startEvent:requestId eventName:@"testEvent"]; [[ADTelemetry sharedInstance] stopEvent:requestId - event:[[ADTelemetryDefaultEvent alloc] initWithName:@"testEvent"]]; + event:[[ADTelemetryDefaultEvent alloc] initWithName:@"testEvent" + requestId:requestId + correlationId:[NSUUID UUID]]]; - [[ADTelemetry sharedInstance] flush]; + [[ADTelemetry sharedInstance] flush:requestId]; // there should be 1 telemetry event recorded as we only generated one above XCTAssertEqual([receivedEvents count], 1); @@ -111,6 +113,16 @@ - (void)testDefaultEventProperties { XCTAssertEqual([self getPropertyCount:[receivedEvents firstObject] propertyName:@"device_id"], 1); + XCTAssertNotNil([self getPropertyFromEvent:[receivedEvents firstObject] + propertyName:@"request_id"]); + XCTAssertEqual([self getPropertyCount:[receivedEvents firstObject] + propertyName:@"request_id"], 1); + + XCTAssertNotNil([self getPropertyFromEvent:[receivedEvents firstObject] + propertyName:@"correlation_id"]); + XCTAssertEqual([self getPropertyCount:[receivedEvents firstObject] + propertyName:@"correlation_id"], 1); + // application_name, application_version are also default properties, // but they are not available in unit test framework, so we omit them here @@ -134,16 +146,20 @@ - (void)testSequentialEvents { NSString* requestId = [[ADTelemetry sharedInstance] registerNewRequest]; [[ADTelemetry sharedInstance] startEvent:requestId eventName:@"testEvent1"]; [[ADTelemetry sharedInstance] stopEvent:requestId - event:[[ADTelemetryDefaultEvent alloc] initWithName:@"testEvent1"]]; + event:[[ADTelemetryDefaultEvent alloc] initWithName:@"testEvent1" + requestId:requestId + correlationId:nil]]; // generate telemetry event 2 [[ADTelemetry sharedInstance] startEvent:requestId eventName:@"testEvent2"]; - ADTelemetryDefaultEvent* event2 = [[ADTelemetryDefaultEvent alloc] initWithName:@"testEvent2"]; + ADTelemetryDefaultEvent* event2 = [[ADTelemetryDefaultEvent alloc] initWithName:@"testEvent2" + requestId:requestId + correlationId:nil]; [event2 setProperty:@"customized_property" value:@"customized_value"]; [[ADTelemetry sharedInstance] stopEvent:requestId event:event2]; - [[ADTelemetry sharedInstance] flush]; + [[ADTelemetry sharedInstance] flush:requestId]; // there should be 2 telemetry events recorded as we generated two XCTAssertEqual([receivedEvents count], 2); @@ -204,16 +220,20 @@ - (void)testSequentialEventsWithAggregation { NSString* requestId = [[ADTelemetry sharedInstance] registerNewRequest]; [[ADTelemetry sharedInstance] startEvent:requestId eventName:@"testEvent1"]; [[ADTelemetry sharedInstance] stopEvent:requestId - event:[[ADTelemetryDefaultEvent alloc] initWithName:@"testEvent1"]]; + event:[[ADTelemetryDefaultEvent alloc] initWithName:@"testEvent1" + requestId:requestId + correlationId:nil]]; // generate telemetry event 2 [[ADTelemetry sharedInstance] startEvent:requestId eventName:@"testEvent2"]; - ADTelemetryDefaultEvent* event2 = [[ADTelemetryDefaultEvent alloc] initWithName:@"testEvent2"]; + ADTelemetryDefaultEvent* event2 = [[ADTelemetryDefaultEvent alloc] initWithName:@"testEvent2" + requestId:requestId + correlationId:nil]; [event2 setProperty:@"customized_property" value:@"customized_value"]; [[ADTelemetry sharedInstance] stopEvent:requestId event:event2]; - [[ADTelemetry sharedInstance] flush]; + [[ADTelemetry sharedInstance] flush:requestId]; // there should be 1 telemetry event recorded as aggregation flag is on XCTAssertEqual([receivedEvents count], 1); @@ -253,15 +273,19 @@ - (void)testNestedEvents { [[ADTelemetry sharedInstance] startEvent:requestId eventName:@"testEvent1"]; [[ADTelemetry sharedInstance] startEvent:requestId eventName:@"testEvent2"]; - ADTelemetryDefaultEvent* event2 = [[ADTelemetryDefaultEvent alloc] initWithName:@"testEvent2"]; + ADTelemetryDefaultEvent* event2 = [[ADTelemetryDefaultEvent alloc] initWithName:@"testEvent2" + requestId:requestId + correlationId:nil]; [event2 setProperty:@"customized_property" value:@"customized_value"]; [[ADTelemetry sharedInstance] stopEvent:requestId event:event2]; [[ADTelemetry sharedInstance] stopEvent:requestId - event:[[ADTelemetryDefaultEvent alloc] initWithName:@"testEvent1"]]; + event:[[ADTelemetryDefaultEvent alloc] initWithName:@"testEvent1" + requestId:requestId + correlationId:nil]]; - [[ADTelemetry sharedInstance] flush]; + [[ADTelemetry sharedInstance] flush:requestId]; // there should be 2 telemetry events recorded as we generated two XCTAssertEqual([receivedEvents count], 2); @@ -326,15 +350,19 @@ - (void)testNestedEventsWithAggregation { [[ADTelemetry sharedInstance] startEvent:requestId eventName:@"testEvent1"]; [[ADTelemetry sharedInstance] startEvent:requestId eventName:@"testEvent2"]; - ADTelemetryDefaultEvent* event2 = [[ADTelemetryDefaultEvent alloc] initWithName:@"testEvent2"]; + ADTelemetryDefaultEvent* event2 = [[ADTelemetryDefaultEvent alloc] initWithName:@"testEvent2" + requestId:requestId + correlationId:nil]; [event2 setProperty:@"customized_property" value:@"customized_value"]; [[ADTelemetry sharedInstance] stopEvent:requestId event:event2]; [[ADTelemetry sharedInstance] stopEvent:requestId - event:[[ADTelemetryDefaultEvent alloc] initWithName:@"testEvent1"]]; + event:[[ADTelemetryDefaultEvent alloc] initWithName:@"testEvent1" + requestId:requestId + correlationId:nil]]; - [[ADTelemetry sharedInstance] flush]; + [[ADTelemetry sharedInstance] flush:requestId]; // there should be 1 telemetry event recorded as aggregation flag is ON XCTAssertEqual([receivedEvents count], 1); @@ -375,19 +403,27 @@ - (void)testComplexEvents { [[ADTelemetry sharedInstance] startEvent:requestId eventName:@"testEvent3"]; [[ADTelemetry sharedInstance] stopEvent:requestId - event:[[ADTelemetryDefaultEvent alloc] initWithName:@"testEvent3"]]; + event:[[ADTelemetryDefaultEvent alloc] initWithName:@"testEvent3" + requestId:requestId + correlationId:nil]]; [[ADTelemetry sharedInstance] stopEvent:requestId - event:[[ADTelemetryDefaultEvent alloc] initWithName:@"testEvent2"]]; + event:[[ADTelemetryDefaultEvent alloc] initWithName:@"testEvent2" + requestId:requestId + correlationId:nil]]; [[ADTelemetry sharedInstance] stopEvent:requestId - event:[[ADTelemetryDefaultEvent alloc] initWithName:@"testEvent1"]]; + event:[[ADTelemetryDefaultEvent alloc] initWithName:@"testEvent1" + requestId:requestId + correlationId:nil]]; [[ADTelemetry sharedInstance] startEvent:requestId eventName:@"testEvent4"]; [[ADTelemetry sharedInstance] stopEvent:requestId - event:[[ADTelemetryDefaultEvent alloc] initWithName:@"testEvent4"]]; + event:[[ADTelemetryDefaultEvent alloc] initWithName:@"testEvent4" + requestId:requestId + correlationId:nil]]; - [[ADTelemetry sharedInstance] flush]; + [[ADTelemetry sharedInstance] flush:requestId]; // there should be 4 telemetry events recorded as we generated four XCTAssertEqual([receivedEvents count], 4); @@ -479,19 +515,27 @@ - (void)testComplexEventsWithAggregation { [[ADTelemetry sharedInstance] startEvent:requestId eventName:@"testEvent3"]; [[ADTelemetry sharedInstance] stopEvent:requestId - event:[[ADTelemetryDefaultEvent alloc] initWithName:@"testEvent3"]]; + event:[[ADTelemetryDefaultEvent alloc] initWithName:@"testEvent3" + requestId:requestId + correlationId:nil]]; [[ADTelemetry sharedInstance] stopEvent:requestId - event:[[ADTelemetryDefaultEvent alloc] initWithName:@"testEvent2"]]; + event:[[ADTelemetryDefaultEvent alloc] initWithName:@"testEvent2" + requestId:requestId + correlationId:nil]]; [[ADTelemetry sharedInstance] stopEvent:requestId - event:[[ADTelemetryDefaultEvent alloc] initWithName:@"testEvent1"]]; + event:[[ADTelemetryDefaultEvent alloc] initWithName:@"testEvent1" + requestId:requestId + correlationId:nil]]; [[ADTelemetry sharedInstance] startEvent:requestId eventName:@"testEvent4"]; [[ADTelemetry sharedInstance] stopEvent:requestId - event:[[ADTelemetryDefaultEvent alloc] initWithName:@"testEvent4"]]; + event:[[ADTelemetryDefaultEvent alloc] initWithName:@"testEvent4" + requestId:requestId + correlationId:nil]]; - [[ADTelemetry sharedInstance] flush]; + [[ADTelemetry sharedInstance] flush:requestId]; // there should be 1 telemetry events recorded as aggregation flag is ON XCTAssertEqual([receivedEvents count], 1); From 578adef9226b257e460ff8da15a61283345c03d0 Mon Sep 17 00:00:00 2001 From: YONG ZENG Date: Fri, 12 Aug 2016 20:08:19 -0700 Subject: [PATCH 11/92] fix a place for 32-bit Mac --- ADAL/src/telemetry/ADTelemetry.m | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/ADAL/src/telemetry/ADTelemetry.m b/ADAL/src/telemetry/ADTelemetry.m index 33dd6cc1c..9f7728bd1 100644 --- a/ADAL/src/telemetry/ADTelemetry.m +++ b/ADAL/src/telemetry/ADTelemetry.m @@ -128,10 +128,9 @@ - (void)stopEvent:(NSString*)requestId return; } [event setStartTime:startTime]; - [_eventTracking removeObjectForKey:key]; - [event setStopTime:stopTime]; [event setResponseTime:[stopTime timeIntervalSinceDate:startTime]]; + [_eventTracking removeObjectForKey:key]; [_dispatcher receive:requestId event:event]; } From 085e75803251b335e77105e8017136765337c0b5 Mon Sep 17 00:00:00 2001 From: YONG ZENG Date: Mon, 15 Aug 2016 00:42:59 -0700 Subject: [PATCH 12/92] specify api id for telemetry; record query params from http body for http telemetry event; --- ADAL/src/ADAuthenticationContext.m | 40 +++++++++++++++---- .../ADAuthenticationRequest+AcquireToken.m | 37 +++-------------- ADAL/src/request/ADAuthenticationRequest.h | 1 + ADAL/src/request/ADAuthenticationRequest.m | 5 +++ ADAL/src/request/ADWebRequest.m | 4 +- ADAL/src/telemetry/ADTelemetryAPIEvent.h | 2 +- ADAL/src/telemetry/ADTelemetryAPIEvent.m | 2 +- 7 files changed, 47 insertions(+), 44 deletions(-) diff --git a/ADAL/src/ADAuthenticationContext.m b/ADAL/src/ADAuthenticationContext.m index 1fd4c1cda..86ab4f61a 100755 --- a/ADAL/src/ADAuthenticationContext.m +++ b/ADAL/src/ADAuthenticationContext.m @@ -33,6 +33,7 @@ #import "ADTelemetry.h" #import "ADTelemetry+Internal.h" #import "ADTelemetryAPIEvent.h" +#import "ADUserIdentifier.h" typedef void(^ADAuthorizationCodeCallback)(NSString*, ADAuthenticationError*); @@ -319,7 +320,8 @@ - (void)acquireTokenForAssertion:(NSString*)assertion ADTelemetryAPIEvent* event = [[ADTelemetryAPIEvent alloc] initWithName:@"acquireTokenWithAssertion:assertionType:resource:clientId:userId:completionBlock:" requestId:[request telemetryRequestId] correlationId:[request correlationId]]; - [event setAPIId:@"?"]; + [event setApiId:@"21"]; + [self fillTelemetryForAcquireTokenCall:event request:request result:result]; [[ADTelemetry sharedInstance] stopEvent:[request telemetryRequestId] event:event]; SAFE_ARC_RELEASE(event); //flush all events in the end of the acquireToken call @@ -349,7 +351,8 @@ - (void)acquireTokenWithResource:(NSString*)resource ADTelemetryAPIEvent* event = [[ADTelemetryAPIEvent alloc] initWithName:@"acquireTokenWithResource:clientId:redirectUri:completionBlock:" requestId:[request telemetryRequestId] correlationId:[request correlationId]]; - [event setAPIId:@"?"]; + [event setApiId:@"121"]; + [self fillTelemetryForAcquireTokenCall:event request:request result:result]; [[ADTelemetry sharedInstance] stopEvent:[request telemetryRequestId] event:event]; SAFE_ARC_RELEASE(event); //flush all events in the end of the acquireToken call @@ -380,7 +383,8 @@ - (void)acquireTokenWithResource:(NSString*)resource ADTelemetryAPIEvent* event = [[ADTelemetryAPIEvent alloc] initWithName:@"acquireTokenWithResource:clientId:redirectUri:userId:completionBlock:" requestId:[request telemetryRequestId] correlationId:[request correlationId]]; - [event setAPIId:@"?"]; + [event setApiId:@"122"]; + [self fillTelemetryForAcquireTokenCall:event request:request result:result]; [[ADTelemetry sharedInstance] stopEvent:[request telemetryRequestId] event:event]; SAFE_ARC_RELEASE(event); //flush all events in the end of the acquireToken call @@ -414,7 +418,8 @@ - (void)acquireTokenWithResource:(NSString*)resource ADTelemetryAPIEvent* event = [[ADTelemetryAPIEvent alloc] initWithName:@"acquireTokenWithResource:clientId:redirectUri:userId:extraQueryParameters:completionBlock:" requestId:[request telemetryRequestId] correlationId:[request correlationId]]; - [event setAPIId:@"?"]; + [event setApiId:@"123"]; + [self fillTelemetryForAcquireTokenCall:event request:request result:result]; [[ADTelemetry sharedInstance] stopEvent:[request telemetryRequestId] event:event]; SAFE_ARC_RELEASE(event); //flush all events in the end of the acquireToken call @@ -444,7 +449,8 @@ - (void)acquireTokenSilentWithResource:(NSString*)resource ADTelemetryAPIEvent* event = [[ADTelemetryAPIEvent alloc] initWithName:@"acquireTokenSilentWithResource:clientId:redirectId:redirectUri:completionBlock:" requestId:[request telemetryRequestId] correlationId:[request correlationId]]; - [event setAPIId:@"?"]; + [event setApiId:@"22"]; + [self fillTelemetryForAcquireTokenCall:event request:request result:result]; [[ADTelemetry sharedInstance] stopEvent:[request telemetryRequestId] event:event]; SAFE_ARC_RELEASE(event); //flush all events in the end of the acquireToken call @@ -476,7 +482,8 @@ - (void)acquireTokenSilentWithResource:(NSString*)resource ADTelemetryAPIEvent* event = [[ADTelemetryAPIEvent alloc] initWithName:@"acquireTokenSilentWithResource:clientId:redirectId:redirectUri:userId:completionBlock:" requestId:[request telemetryRequestId] correlationId:[request correlationId]]; - [event setAPIId:@"?"]; + [event setApiId:@"23"]; + [self fillTelemetryForAcquireTokenCall:event request:request result:result]; [[ADTelemetry sharedInstance] stopEvent:[request telemetryRequestId] event:event]; SAFE_ARC_RELEASE(event); //flush all events in the end of the acquireToken call @@ -511,7 +518,8 @@ - (void)acquireTokenWithResource:(NSString*)resource ADTelemetryAPIEvent* event = [[ADTelemetryAPIEvent alloc] initWithName:@"acquireTokenWithResource:clientId:redirectUri:promptBehavior:userId:extraQueryParameters:completionBlock:" requestId:[request telemetryRequestId] correlationId:[request correlationId]]; - [event setAPIId:@"?"]; + [event setApiId:@"124"]; + [self fillTelemetryForAcquireTokenCall:event request:request result:result]; [[ADTelemetry sharedInstance] stopEvent:[request telemetryRequestId] event:event]; SAFE_ARC_RELEASE(event); //flush all events in the end of the acquireToken call @@ -546,7 +554,8 @@ - (void)acquireTokenWithResource:(NSString*)resource ADTelemetryAPIEvent* event = [[ADTelemetryAPIEvent alloc] initWithName:@"acquireTokenWithResource:clientId:redirectUri:promptBehavior:userIdentifier:extraQueryParameters:completionBlock:" requestId:[request telemetryRequestId] correlationId:[request correlationId]]; - [event setAPIId:@"?"]; + [event setApiId:@"125"]; + [self fillTelemetryForAcquireTokenCall:event request:request result:result]; [[ADTelemetry sharedInstance] stopEvent:[request telemetryRequestId] event:event]; SAFE_ARC_RELEASE(event); //flush all events in the end of the acquireToken call @@ -558,6 +567,21 @@ - (void)acquireTokenWithResource:(NSString*)resource [request acquireToken:requestCompletion]; } +- (void)fillTelemetryForAcquireTokenCall:(ADTelemetryAPIEvent*)event + request:(ADAuthenticationRequest*)request + result:(ADAuthenticationResult*)result +{ + [event setCorrelationId:[request.requestParams correlationId]]; + [event setUserId:[[request.requestParams identifier] userId]]; + [event setClientId:[request.requestParams clientId]]; + [event setResultStatus:[result status]]; + [event setIsExtendedLifeTimeToken:[result extendedLifeTimeToken]? @"YES":@"NO"]; + [event setErrorCode:[NSString stringWithFormat:@"%ld",(long)[result.error code]]]; + [event setErrorDomain:[result.error domain]]; + [event setProtocolCode:[[result error] protocolCode]]; + [event setErrorDescription:[[result error] errorDetails]]; +} + @end @implementation ADAuthenticationContext (CacheStorage) diff --git a/ADAL/src/request/ADAuthenticationRequest+AcquireToken.m b/ADAL/src/request/ADAuthenticationRequest+AcquireToken.m index 493258cda..1f0663321 100644 --- a/ADAL/src/request/ADAuthenticationRequest+AcquireToken.m +++ b/ADAL/src/request/ADAuthenticationRequest+AcquireToken.m @@ -46,19 +46,6 @@ - (void)acquireToken:(ADAuthenticationCallback)completionBlock NSUUID* correlationId = [_requestParams correlationId]; NSString* telemetryRequestId = [_requestParams telemetryRequestId]; - [[ADTelemetry sharedInstance] startEvent:telemetryRequestId eventName:@"acquire_token"]; - ADAuthenticationCallback requestCompletion = ^void(ADAuthenticationResult *result) - { - ADTelemetryAPIEvent* event = [[ADTelemetryAPIEvent alloc] initWithName:@"acquire_token" - requestId:telemetryRequestId - correlationId:correlationId]; - [self fillTelemetryForAcquireToken:event result:result]; - [[ADTelemetry sharedInstance] stopEvent:telemetryRequestId event:event]; - SAFE_ARC_RELEASE(event); - - completionBlock(result); - }; - NSString* log = [NSString stringWithFormat:@"acquireToken (authority = %@, resource = %@, clientId = %@, idtype = %@)", [_requestParams authority], [_requestParams resource], [_requestParams clientId], [[_requestParams identifier] typeAsString]]; AD_LOG_INFO_F(log, correlationId, @"userId = %@", [_requestParams identifier].userId); @@ -71,7 +58,7 @@ - (void)acquireToken:(ADAuthenticationCallback)completionBlock errorDetails:@"Interactive authentication requests must originate from the main thread" correlationId:correlationId]; - requestCompletion([ADAuthenticationResult resultFromError:error]); + completionBlock([ADAuthenticationResult resultFromError:error]); return; } @@ -82,13 +69,13 @@ - (void)acquireToken:(ADAuthenticationCallback)completionBlock protocolCode:nil errorDetails:ADRedirectUriInvalidError correlationId:correlationId]; - requestCompletion([ADAuthenticationResult resultFromError:error correlationId:correlationId]); + completionBlock([ADAuthenticationResult resultFromError:error correlationId:correlationId]); return; } if (!_context.validateAuthority) { - [self validatedAcquireToken:requestCompletion]; + [self validatedAcquireToken:completionBlock]; return; } @@ -107,11 +94,11 @@ - (void)acquireToken:(ADAuthenticationCallback)completionBlock if (error) { - requestCompletion([ADAuthenticationResult resultFromError:error correlationId:correlationId]); + completionBlock([ADAuthenticationResult resultFromError:error correlationId:correlationId]); } else { - [self validatedAcquireToken:requestCompletion]; + [self validatedAcquireToken:completionBlock]; } }]; @@ -301,18 +288,4 @@ - (void)requestTokenByCode:(NSString *)code completion:completionBlock]; } -- (void)fillTelemetryForAcquireToken:(ADTelemetryAPIEvent*)event - result:(ADAuthenticationResult*)result -{ - [event setCorrelationId:[_requestParams correlationId]]; - [event setUserId:[[_requestParams identifier] userId]]; - [event setClientId:[_requestParams clientId]]; - [event setResultStatus:[result status]]; - [event setIsExtendedLifeTimeToken:[result extendedLifeTimeToken]? @"YES":@"NO"]; - [event setErrorCode:[NSString stringWithFormat:@"%ld",(long)[result.error code]]]; - [event setErrorDomain:[result.error domain]]; - [event setProtocolCode:[[result error] protocolCode]]; - [event setErrorDescription:[[result error] errorDetails]]; -} - @end diff --git a/ADAL/src/request/ADAuthenticationRequest.h b/ADAL/src/request/ADAuthenticationRequest.h index 2774046ed..a4ce44837 100644 --- a/ADAL/src/request/ADAuthenticationRequest.h +++ b/ADAL/src/request/ADAuthenticationRequest.h @@ -103,6 +103,7 @@ - (void)setCorrelationId:(NSUUID*)correlationId; - (NSUUID*)correlationId; - (NSString*)telemetryRequestId; +- (ADRequestParameters*)requestParams; #if AD_BROKER - (NSString*)redirectUri; - (void)setRedirectUri:(NSString*)redirectUri; diff --git a/ADAL/src/request/ADAuthenticationRequest.m b/ADAL/src/request/ADAuthenticationRequest.m index b6180f0f0..78a8b0e24 100644 --- a/ADAL/src/request/ADAuthenticationRequest.m +++ b/ADAL/src/request/ADAuthenticationRequest.m @@ -296,6 +296,11 @@ - (NSString*)telemetryRequestId return [_requestParams telemetryRequestId]; } +- (ADRequestParameters*)requestParams +{ + return _requestParams; +} + - (BOOL)takeUserInterationLock { return !dispatch_semaphore_wait(sInteractionInProgress, DISPATCH_TIME_NOW); diff --git a/ADAL/src/request/ADWebRequest.m b/ADAL/src/request/ADWebRequest.m index c3aba1e01..3a0178145 100644 --- a/ADAL/src/request/ADWebRequest.m +++ b/ADAL/src/request/ADWebRequest.m @@ -324,8 +324,8 @@ - (void)stopTelemetryEvent:(NSError *)error ADTelemetryHttpEvent* event = [[ADTelemetryHttpEvent alloc] initWithName:@"http_request" requestId:_telemetryRequestId correlationId:_correlationId]; [event setHttpMethod:_isGetRequest ? @"GET" : @"POST"]; - [event setHttpPath:[NSString stringWithFormat:@"%@://%@/%@", _requestURL.scheme, _requestURL.host, _requestURL.path]]; - [event setHttpRequestQueryParams:[_requestURL query]]; + [event setHttpPath:[_requestURL absoluteString]]; + [event setHttpRequestQueryParams:[[NSString alloc] initWithData:[self body] encoding:NSUTF8StringEncoding]]; if (error) { [event setHttpResponseCode:[NSString stringWithFormat: @"%ld", (long)[error code]]]; diff --git a/ADAL/src/telemetry/ADTelemetryAPIEvent.h b/ADAL/src/telemetry/ADTelemetryAPIEvent.h index d2afcfb24..3079469a1 100644 --- a/ADAL/src/telemetry/ADTelemetryAPIEvent.h +++ b/ADAL/src/telemetry/ADTelemetryAPIEvent.h @@ -41,6 +41,6 @@ - (void)setGrantType:(NSString*)grantType; - (void)setAPIStatus:(NSString*)status; -- (void)setAPIId:(NSString*)apiId; +- (void)setApiId:(NSString*)apiId; @end \ No newline at end of file diff --git a/ADAL/src/telemetry/ADTelemetryAPIEvent.m b/ADAL/src/telemetry/ADTelemetryAPIEvent.m index 6106bc5d1..fa855935e 100644 --- a/ADAL/src/telemetry/ADTelemetryAPIEvent.m +++ b/ADAL/src/telemetry/ADTelemetryAPIEvent.m @@ -105,7 +105,7 @@ - (void)setAPIStatus:(NSString*)status [self setProperty:@"api_status" value:status]; } -- (void)setAPIId:(NSString*)apiId +- (void)setApiId:(NSString*)apiId { [self setProperty:@"api_id" value:apiId]; } From eca5f80551a81062e0b81e8e7204b3f870823424 Mon Sep 17 00:00:00 2001 From: YONG ZENG Date: Wed, 17 Aug 2016 16:34:54 -0700 Subject: [PATCH 13/92] change API ID and remove query parameters for telemetry --- ADAL/src/ADAuthenticationContext.m | 16 ++++++++-------- ADAL/src/cache/ADTokenCacheAccessor.m | 2 +- ADAL/src/request/ADWebRequest.m | 3 +-- 3 files changed, 10 insertions(+), 11 deletions(-) diff --git a/ADAL/src/ADAuthenticationContext.m b/ADAL/src/ADAuthenticationContext.m index 86ab4f61a..27e6b577b 100755 --- a/ADAL/src/ADAuthenticationContext.m +++ b/ADAL/src/ADAuthenticationContext.m @@ -320,7 +320,7 @@ - (void)acquireTokenForAssertion:(NSString*)assertion ADTelemetryAPIEvent* event = [[ADTelemetryAPIEvent alloc] initWithName:@"acquireTokenWithAssertion:assertionType:resource:clientId:userId:completionBlock:" requestId:[request telemetryRequestId] correlationId:[request correlationId]]; - [event setApiId:@"21"]; + [event setApiId:@"6"]; [self fillTelemetryForAcquireTokenCall:event request:request result:result]; [[ADTelemetry sharedInstance] stopEvent:[request telemetryRequestId] event:event]; SAFE_ARC_RELEASE(event); @@ -351,7 +351,7 @@ - (void)acquireTokenWithResource:(NSString*)resource ADTelemetryAPIEvent* event = [[ADTelemetryAPIEvent alloc] initWithName:@"acquireTokenWithResource:clientId:redirectUri:completionBlock:" requestId:[request telemetryRequestId] correlationId:[request correlationId]]; - [event setApiId:@"121"]; + [event setApiId:@"118"]; [self fillTelemetryForAcquireTokenCall:event request:request result:result]; [[ADTelemetry sharedInstance] stopEvent:[request telemetryRequestId] event:event]; SAFE_ARC_RELEASE(event); @@ -383,7 +383,7 @@ - (void)acquireTokenWithResource:(NSString*)resource ADTelemetryAPIEvent* event = [[ADTelemetryAPIEvent alloc] initWithName:@"acquireTokenWithResource:clientId:redirectUri:userId:completionBlock:" requestId:[request telemetryRequestId] correlationId:[request correlationId]]; - [event setApiId:@"122"]; + [event setApiId:@"121"]; [self fillTelemetryForAcquireTokenCall:event request:request result:result]; [[ADTelemetry sharedInstance] stopEvent:[request telemetryRequestId] event:event]; SAFE_ARC_RELEASE(event); @@ -418,7 +418,7 @@ - (void)acquireTokenWithResource:(NSString*)resource ADTelemetryAPIEvent* event = [[ADTelemetryAPIEvent alloc] initWithName:@"acquireTokenWithResource:clientId:redirectUri:userId:extraQueryParameters:completionBlock:" requestId:[request telemetryRequestId] correlationId:[request correlationId]]; - [event setApiId:@"123"]; + [event setApiId:@"124"]; [self fillTelemetryForAcquireTokenCall:event request:request result:result]; [[ADTelemetry sharedInstance] stopEvent:[request telemetryRequestId] event:event]; SAFE_ARC_RELEASE(event); @@ -449,7 +449,7 @@ - (void)acquireTokenSilentWithResource:(NSString*)resource ADTelemetryAPIEvent* event = [[ADTelemetryAPIEvent alloc] initWithName:@"acquireTokenSilentWithResource:clientId:redirectId:redirectUri:completionBlock:" requestId:[request telemetryRequestId] correlationId:[request correlationId]]; - [event setApiId:@"22"]; + [event setApiId:@"7"]; [self fillTelemetryForAcquireTokenCall:event request:request result:result]; [[ADTelemetry sharedInstance] stopEvent:[request telemetryRequestId] event:event]; SAFE_ARC_RELEASE(event); @@ -482,7 +482,7 @@ - (void)acquireTokenSilentWithResource:(NSString*)resource ADTelemetryAPIEvent* event = [[ADTelemetryAPIEvent alloc] initWithName:@"acquireTokenSilentWithResource:clientId:redirectId:redirectUri:userId:completionBlock:" requestId:[request telemetryRequestId] correlationId:[request correlationId]]; - [event setApiId:@"23"]; + [event setApiId:@"8"]; [self fillTelemetryForAcquireTokenCall:event request:request result:result]; [[ADTelemetry sharedInstance] stopEvent:[request telemetryRequestId] event:event]; SAFE_ARC_RELEASE(event); @@ -518,7 +518,7 @@ - (void)acquireTokenWithResource:(NSString*)resource ADTelemetryAPIEvent* event = [[ADTelemetryAPIEvent alloc] initWithName:@"acquireTokenWithResource:clientId:redirectUri:promptBehavior:userId:extraQueryParameters:completionBlock:" requestId:[request telemetryRequestId] correlationId:[request correlationId]]; - [event setApiId:@"124"]; + [event setApiId:@"127"]; [self fillTelemetryForAcquireTokenCall:event request:request result:result]; [[ADTelemetry sharedInstance] stopEvent:[request telemetryRequestId] event:event]; SAFE_ARC_RELEASE(event); @@ -554,7 +554,7 @@ - (void)acquireTokenWithResource:(NSString*)resource ADTelemetryAPIEvent* event = [[ADTelemetryAPIEvent alloc] initWithName:@"acquireTokenWithResource:clientId:redirectUri:promptBehavior:userIdentifier:extraQueryParameters:completionBlock:" requestId:[request telemetryRequestId] correlationId:[request correlationId]]; - [event setApiId:@"125"]; + [event setApiId:@"130"]; [self fillTelemetryForAcquireTokenCall:event request:request result:result]; [[ADTelemetry sharedInstance] stopEvent:[request telemetryRequestId] event:event]; SAFE_ARC_RELEASE(event); diff --git a/ADAL/src/cache/ADTokenCacheAccessor.m b/ADAL/src/cache/ADTokenCacheAccessor.m index df3be7f94..e6e1fb4e4 100644 --- a/ADAL/src/cache/ADTokenCacheAccessor.m +++ b/ADAL/src/cache/ADTokenCacheAccessor.m @@ -104,7 +104,7 @@ - (ADTokenCacheItem *)getATRTItemForUser:(ADUserIdentifier *)identifier ADTelemetryCacheEvent* event = [[ADTelemetryCacheEvent alloc] initWithName:@"token_cache_lookup" requestId:[requestParams telemetryRequestId] correlationId:[requestParams correlationId]]; - [event setTokenType:@"access token/refresh token"]; + [event setTokenType:@"access token"]; [event setStatus:item? @"succeeded" : @"failed"]; [[ADTelemetry sharedInstance] stopEvent:[requestParams telemetryRequestId] event:event]; SAFE_ARC_RELEASE(event); diff --git a/ADAL/src/request/ADWebRequest.m b/ADAL/src/request/ADWebRequest.m index 3a0178145..809f32cce 100644 --- a/ADAL/src/request/ADWebRequest.m +++ b/ADAL/src/request/ADWebRequest.m @@ -324,8 +324,7 @@ - (void)stopTelemetryEvent:(NSError *)error ADTelemetryHttpEvent* event = [[ADTelemetryHttpEvent alloc] initWithName:@"http_request" requestId:_telemetryRequestId correlationId:_correlationId]; [event setHttpMethod:_isGetRequest ? @"GET" : @"POST"]; - [event setHttpPath:[_requestURL absoluteString]]; - [event setHttpRequestQueryParams:[[NSString alloc] initWithData:[self body] encoding:NSUTF8StringEncoding]]; + [event setHttpPath:[NSString stringWithFormat:@"%@://%@/%@", _requestURL.scheme, _requestURL.host, _requestURL.path]]; if (error) { [event setHttpResponseCode:[NSString stringWithFormat: @"%ld", (long)[error code]]]; From b0483b4c31384e7b09fe7e67513444199d28ac54 Mon Sep 17 00:00:00 2001 From: YONG ZENG Date: Mon, 29 Aug 2016 11:37:58 -0700 Subject: [PATCH 14/92] set telemetry response time in milliseconds --- ADAL/src/telemetry/ADTelemetryDefaultEvent.m | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/ADAL/src/telemetry/ADTelemetryDefaultEvent.m b/ADAL/src/telemetry/ADTelemetryDefaultEvent.m index 024eea6d4..4a7c22b7f 100644 --- a/ADAL/src/telemetry/ADTelemetryDefaultEvent.m +++ b/ADAL/src/telemetry/ADTelemetryDefaultEvent.m @@ -106,7 +106,8 @@ - (void)setStopTime:(NSDate*)time - (void)setResponseTime:(NSTimeInterval)responseTime { - [_propertyMap addObject:@[@"response_time", [NSString stringWithFormat:@"%f", responseTime]]]; + //the property is set in milliseconds + [_propertyMap addObject:@[@"response_time", [NSString stringWithFormat:@"%f", responseTime*1000]]]; } - (NSString*)getStringFromDate:(NSDate*)date From e6083ec452d1c98dba912064742f9935ae55c813 Mon Sep 17 00:00:00 2001 From: YONG ZENG Date: Wed, 31 Aug 2016 22:02:20 -0700 Subject: [PATCH 15/92] add macro to turn of telemetry for the time being --- ADAL/src/ADAuthenticationContext.m | 38 +++++++++++-- ADAL/src/cache/ADTokenCacheAccessor.m | 57 +++++++++++-------- .../src/request/ADAcquireTokenSilentHandler.m | 4 ++ .../ADAuthenticationRequest+AcquireToken.m | 34 ++++++++--- .../request/ADAuthenticationRequest+Broker.m | 16 ++++-- .../ADAuthenticationRequest+WebRequest.m | 5 +- ADAL/src/request/ADWebRequest.m | 11 ++-- 7 files changed, 118 insertions(+), 47 deletions(-) diff --git a/ADAL/src/ADAuthenticationContext.m b/ADAL/src/ADAuthenticationContext.m index 27e6b577b..ded23341d 100755 --- a/ADAL/src/ADAuthenticationContext.m +++ b/ADAL/src/ADAuthenticationContext.m @@ -312,11 +312,14 @@ - (void)acquireTokenForAssertion:(NSString*)assertion [request setSamlAssertion:assertion]; [request setAssertionType:assertionType]; +#if AD_TELEMETRY //prepare telemetry for the acquire token call [[ADTelemetry sharedInstance] startEvent:[request telemetryRequestId] eventName:@"acquireTokenWithAssertion:assertionType:resource:clientId:userId:completionBlock:"]; +#endif ADAuthenticationCallback requestCompletion = ^void(ADAuthenticationResult *result) { +#if AD_TELEMETRY ADTelemetryAPIEvent* event = [[ADTelemetryAPIEvent alloc] initWithName:@"acquireTokenWithAssertion:assertionType:resource:clientId:userId:completionBlock:" requestId:[request telemetryRequestId] correlationId:[request correlationId]]; @@ -326,6 +329,7 @@ - (void)acquireTokenForAssertion:(NSString*)assertion SAFE_ARC_RELEASE(event); //flush all events in the end of the acquireToken call [[ADTelemetry sharedInstance] flush:[request telemetryRequestId]]; +#endif completionBlock(result); }; @@ -343,11 +347,14 @@ - (void)acquireTokenWithResource:(NSString*)resource API_ENTRY; REQUEST_WITH_REDIRECT_URL(redirectUri, clientId, resource); +#if AD_TELEMETRY //prepare telemetry for the acquire token call [[ADTelemetry sharedInstance] startEvent:[request telemetryRequestId] eventName:@"acquireTokenWithResource:clientId:redirectUri:completionBlock:"]; +#endif ADAuthenticationCallback requestCompletion = ^void(ADAuthenticationResult *result) { +#if AD_TELEMETRY ADTelemetryAPIEvent* event = [[ADTelemetryAPIEvent alloc] initWithName:@"acquireTokenWithResource:clientId:redirectUri:completionBlock:" requestId:[request telemetryRequestId] correlationId:[request correlationId]]; @@ -357,6 +364,7 @@ - (void)acquireTokenWithResource:(NSString*)resource SAFE_ARC_RELEASE(event); //flush all events in the end of the acquireToken call [[ADTelemetry sharedInstance] flush:[request telemetryRequestId]]; +#endif completionBlock(result); }; @@ -375,11 +383,14 @@ - (void)acquireTokenWithResource:(NSString*)resource [request setUserId:userId]; +#if AD_TELEMETRY //prepare telemetry for the acquire token call [[ADTelemetry sharedInstance] startEvent:[request telemetryRequestId] eventName:@"acquireTokenWithResource:clientId:redirectUri:userId:completionBlock:"]; +#endif ADAuthenticationCallback requestCompletion = ^void(ADAuthenticationResult *result) { +#if AD_TELEMETRY ADTelemetryAPIEvent* event = [[ADTelemetryAPIEvent alloc] initWithName:@"acquireTokenWithResource:clientId:redirectUri:userId:completionBlock:" requestId:[request telemetryRequestId] correlationId:[request correlationId]]; @@ -389,6 +400,7 @@ - (void)acquireTokenWithResource:(NSString*)resource SAFE_ARC_RELEASE(event); //flush all events in the end of the acquireToken call [[ADTelemetry sharedInstance] flush:[request telemetryRequestId]]; +#endif completionBlock(result); }; @@ -410,11 +422,14 @@ - (void)acquireTokenWithResource:(NSString*)resource [request setUserId:userId]; [request setExtraQueryParameters:queryParams]; +#if AD_TELEMETRY //prepare telemetry for the acquire token call [[ADTelemetry sharedInstance] startEvent:[request telemetryRequestId] eventName:@"acquireTokenWithResource:clientId:redirectUri:userId:extraQueryParameters:completionBlock:"]; +#endif ADAuthenticationCallback requestCompletion = ^void(ADAuthenticationResult *result) { +#if AD_TELEMETRY ADTelemetryAPIEvent* event = [[ADTelemetryAPIEvent alloc] initWithName:@"acquireTokenWithResource:clientId:redirectUri:userId:extraQueryParameters:completionBlock:" requestId:[request telemetryRequestId] correlationId:[request correlationId]]; @@ -424,7 +439,7 @@ - (void)acquireTokenWithResource:(NSString*)resource SAFE_ARC_RELEASE(event); //flush all events in the end of the acquireToken call [[ADTelemetry sharedInstance] flush:[request telemetryRequestId]]; - +#endif completionBlock(result); }; @@ -440,12 +455,14 @@ - (void)acquireTokenSilentWithResource:(NSString*)resource REQUEST_WITH_REDIRECT_URL(redirectUri, clientId, resource); [request setSilent:YES]; - +#if AD_TELEMETRY //prepare telemetry for the acquire token call [[ADTelemetry sharedInstance] startEvent:[request telemetryRequestId] eventName:@"acquireTokenSilentWithResource:clientId:redirectId:redirectUri:completionBlock:"]; +#endif ADAuthenticationCallback requestCompletion = ^void(ADAuthenticationResult *result) { +#if AD_TELEMETRY ADTelemetryAPIEvent* event = [[ADTelemetryAPIEvent alloc] initWithName:@"acquireTokenSilentWithResource:clientId:redirectId:redirectUri:completionBlock:" requestId:[request telemetryRequestId] correlationId:[request correlationId]]; @@ -455,7 +472,7 @@ - (void)acquireTokenSilentWithResource:(NSString*)resource SAFE_ARC_RELEASE(event); //flush all events in the end of the acquireToken call [[ADTelemetry sharedInstance] flush:[request telemetryRequestId]]; - +#endif completionBlock(result); }; @@ -474,11 +491,14 @@ - (void)acquireTokenSilentWithResource:(NSString*)resource [request setUserId:userId]; [request setSilent:YES]; +#if AD_TELEMETRY //prepare telemetry for the acquire token call [[ADTelemetry sharedInstance] startEvent:[request telemetryRequestId] eventName:@"acquireTokenSilentWithResource:clientId:redirectId:redirectUri:userId:completionBlock:"]; +#endif ADAuthenticationCallback requestCompletion = ^void(ADAuthenticationResult *result) { +#if AD_TELEMETRY ADTelemetryAPIEvent* event = [[ADTelemetryAPIEvent alloc] initWithName:@"acquireTokenSilentWithResource:clientId:redirectId:redirectUri:userId:completionBlock:" requestId:[request telemetryRequestId] correlationId:[request correlationId]]; @@ -488,7 +508,7 @@ - (void)acquireTokenSilentWithResource:(NSString*)resource SAFE_ARC_RELEASE(event); //flush all events in the end of the acquireToken call [[ADTelemetry sharedInstance] flush:[request telemetryRequestId]]; - +#endif completionBlock(result); }; @@ -510,11 +530,14 @@ - (void)acquireTokenWithResource:(NSString*)resource [request setPromptBehavior:promptBehavior]; [request setExtraQueryParameters:queryParams]; +#if AD_TELEMETRY //prepare telemetry for the acquire token call [[ADTelemetry sharedInstance] startEvent:[request telemetryRequestId] eventName:@"acquireTokenWithResource:clientId:redirectUri:promptBehavior:userId:extraQueryParameters:completionBlock:"]; +#endif ADAuthenticationCallback requestCompletion = ^void(ADAuthenticationResult *result) { +#if AD_TELEMETRY ADTelemetryAPIEvent* event = [[ADTelemetryAPIEvent alloc] initWithName:@"acquireTokenWithResource:clientId:redirectUri:promptBehavior:userId:extraQueryParameters:completionBlock:" requestId:[request telemetryRequestId] correlationId:[request correlationId]]; @@ -524,7 +547,7 @@ - (void)acquireTokenWithResource:(NSString*)resource SAFE_ARC_RELEASE(event); //flush all events in the end of the acquireToken call [[ADTelemetry sharedInstance] flush:[request telemetryRequestId]]; - +#endif completionBlock(result); }; @@ -546,11 +569,14 @@ - (void)acquireTokenWithResource:(NSString*)resource [request setUserIdentifier:userId]; [request setExtraQueryParameters:queryParams]; +#if AD_TELEMETRY //prepare telemetry for the acquire token call [[ADTelemetry sharedInstance] startEvent:[request telemetryRequestId] eventName:@"acquireTokenWithResource:clientId:redirectUri:promptBehavior:userIdentifier:extraQueryParameters:completionBlock:"]; +#endif ADAuthenticationCallback requestCompletion = ^void(ADAuthenticationResult *result) { +#if AD_TELEMETRY ADTelemetryAPIEvent* event = [[ADTelemetryAPIEvent alloc] initWithName:@"acquireTokenWithResource:clientId:redirectUri:promptBehavior:userIdentifier:extraQueryParameters:completionBlock:" requestId:[request telemetryRequestId] correlationId:[request correlationId]]; @@ -560,7 +586,7 @@ - (void)acquireTokenWithResource:(NSString*)resource SAFE_ARC_RELEASE(event); //flush all events in the end of the acquireToken call [[ADTelemetry sharedInstance] flush:[request telemetryRequestId]]; - +#endif completionBlock(result); }; diff --git a/ADAL/src/cache/ADTokenCacheAccessor.m b/ADAL/src/cache/ADTokenCacheAccessor.m index e6e1fb4e4..0643ff0c1 100644 --- a/ADAL/src/cache/ADTokenCacheAccessor.m +++ b/ADAL/src/cache/ADTokenCacheAccessor.m @@ -97,10 +97,11 @@ - (ADTokenCacheItem *)getATRTItemForUser:(ADUserIdentifier *)identifier requestParams:(ADRequestParameters*)requestParams error:(ADAuthenticationError * __autoreleasing *)error { +#if AD_TELEMETRY [[ADTelemetry sharedInstance] startEvent:[requestParams telemetryRequestId] eventName:@"token_cache_lookup"]; - +#endif ADTokenCacheItem* item = [self getItemForUser:identifier resource:resource clientId:clientId requestParams:requestParams error:error]; - +#if AD_TELEMETRY ADTelemetryCacheEvent* event = [[ADTelemetryCacheEvent alloc] initWithName:@"token_cache_lookup" requestId:[requestParams telemetryRequestId] correlationId:[requestParams correlationId]]; @@ -108,7 +109,7 @@ - (ADTokenCacheItem *)getATRTItemForUser:(ADUserIdentifier *)identifier [event setStatus:item? @"succeeded" : @"failed"]; [[ADTelemetry sharedInstance] stopEvent:[requestParams telemetryRequestId] event:event]; SAFE_ARC_RELEASE(event); - +#endif return item; } @@ -121,10 +122,11 @@ - (ADTokenCacheItem *)getMRRTItemForUser:(ADUserIdentifier *)identifier requestParams:(ADRequestParameters*)requestParams error:(ADAuthenticationError * __autoreleasing *)error { +#if AD_TELEMETRY [[ADTelemetry sharedInstance] startEvent:[requestParams telemetryRequestId] eventName:@"token_cache_lookup"]; - +#endif ADTokenCacheItem* item = [self getItemForUser:identifier resource:nil clientId:clientId requestParams:requestParams error:error]; - +#if AD_TELEMETRY ADTelemetryCacheEvent* event = [[ADTelemetryCacheEvent alloc] initWithName:@"token_cache_lookup" requestId:[requestParams telemetryRequestId] correlationId:[requestParams correlationId]]; @@ -132,7 +134,7 @@ - (ADTokenCacheItem *)getMRRTItemForUser:(ADUserIdentifier *)identifier [event setStatus:item? @"succeeded" : @"failed"]; [[ADTelemetry sharedInstance] stopEvent:[requestParams telemetryRequestId] event:event]; SAFE_ARC_RELEASE(event); - +#endif return item; } @@ -145,11 +147,12 @@ - (ADTokenCacheItem *)getFRTItemForUser:(ADUserIdentifier *)identifier requestParams:(ADRequestParameters*)requestParams error:(ADAuthenticationError * __autoreleasing *)error { +#if AD_TELEMETRY [[ADTelemetry sharedInstance] startEvent:[requestParams telemetryRequestId] eventName:@"token_cache_lookup"]; - +#endif NSString* fociClientId = [ADTokenCacheAccessor familyClientId:familyId]; ADTokenCacheItem* item = [self getItemForUser:identifier resource:nil clientId:fociClientId requestParams:requestParams error:error]; - +#if AD_TELEMETRY ADTelemetryCacheEvent* event = [[ADTelemetryCacheEvent alloc] initWithName:@"token_cache_lookup" requestId:[requestParams telemetryRequestId] correlationId:[requestParams correlationId]]; @@ -157,7 +160,7 @@ - (ADTokenCacheItem *)getFRTItemForUser:(ADUserIdentifier *)identifier [event setStatus:item? @"succeeded" : @"failed"]; [[ADTelemetry sharedInstance] stopEvent:[requestParams telemetryRequestId] event:event]; SAFE_ARC_RELEASE(event); - +#endif return item; } @@ -178,11 +181,11 @@ - (ADTokenCacheItem*)getADFSUserTokenForResource:(NSString *)resource { return nil; } - +#if AD_TELEMETRY [[ADTelemetry sharedInstance] startEvent:[requestParams telemetryRequestId] eventName:@"token_cache_lookup"]; - +#endif ADTokenCacheItem* item = [_dataSource getItemWithKey:key userId:@"" correlationId:[requestParams correlationId] error:error]; - +#if AD_TELEMETRY ADTelemetryCacheEvent* event = [[ADTelemetryCacheEvent alloc] initWithName:@"token_cache_lookup" requestId:[requestParams telemetryRequestId] correlationId:[requestParams correlationId]]; @@ -190,7 +193,7 @@ - (ADTokenCacheItem*)getADFSUserTokenForResource:(NSString *)resource [event setStatus:item? @"succeeded" : @"failed"]; [[ADTelemetry sharedInstance] stopEvent:[requestParams telemetryRequestId] event:event]; SAFE_ARC_RELEASE(event); - +#endif return item; } @@ -249,14 +252,17 @@ - (void)updateCacheToItem:(ADTokenCacheItem *)cacheItem requestParams:(ADRequestParameters*)requestParams { NSUUID* correlationId = [requestParams correlationId]; +#if AD_TELEMETRY NSString* telemetryRequestId = [requestParams telemetryRequestId]; +#endif NSString* savedRefreshToken = cacheItem.refreshToken; if (isMRRT) { AD_LOG_VERBOSE_F(@"Token cache store", correlationId, @"Storing multi-resource refresh token for authority: %@", _authority); +#if AD_TELEMETRY [[ADTelemetry sharedInstance] startEvent:telemetryRequestId eventName:@"token_cache_write"]; - +#endif //If the server returned a multi-resource refresh token, we break //the item into two: one with the access token and no refresh token and //another one with the broad refresh token and no access token and no resource. @@ -268,49 +274,53 @@ - (void)updateCacheToItem:(ADTokenCacheItem *)cacheItem multiRefreshTokenItem.resource = nil; multiRefreshTokenItem.expiresOn = nil; [_dataSource addOrUpdateItem:multiRefreshTokenItem correlationId:correlationId error:nil]; - +#if AD_TELEMETRY ADTelemetryCacheEvent* event = [[ADTelemetryCacheEvent alloc] initWithName:@"token_cache_write" requestId:telemetryRequestId correlationId:correlationId]; [event setTokenType:@"multi-resource refresh token"]; [[ADTelemetry sharedInstance] stopEvent:telemetryRequestId event:event]; SAFE_ARC_RELEASE(event); - +#endif // If the item is also a Family Refesh Token (FRT) we update the FRT // as well so we have a guaranteed spot to look for the most recent FRT. NSString* familyId = cacheItem.familyId; if (familyId) { +#if AD_TELEMETRY [[ADTelemetry sharedInstance] startEvent:telemetryRequestId eventName:@"token_cache_write"]; - +#endif ADTokenCacheItem* frtItem = [multiRefreshTokenItem copy]; NSString* fociClientId = [ADTokenCacheAccessor familyClientId:familyId]; frtItem.clientId = fociClientId; [_dataSource addOrUpdateItem:frtItem correlationId:correlationId error:nil]; SAFE_ARC_RELEASE(frtItem); - +#if AD_TELEMETRY ADTelemetryCacheEvent* event = [[ADTelemetryCacheEvent alloc] initWithName:@"token_cache_write" requestId:telemetryRequestId correlationId:correlationId]; [event setTokenType:@"family refresh token"]; [[ADTelemetry sharedInstance] stopEvent:telemetryRequestId event:event]; SAFE_ARC_RELEASE(event); +#endif } SAFE_ARC_RELEASE(multiRefreshTokenItem); } AD_LOG_VERBOSE_F(@"Token cache store", correlationId, @"Storing access token for resource: %@", cacheItem.resource); +#if AD_TELEMETRY [[ADTelemetry sharedInstance] startEvent:telemetryRequestId eventName:@"token_cache_write"]; - +#endif [_dataSource addOrUpdateItem:cacheItem correlationId:correlationId error:nil]; cacheItem.refreshToken = savedRefreshToken;//Restore for the result - +#if AD_TELEMETRY ADTelemetryCacheEvent* event = [[ADTelemetryCacheEvent alloc] initWithName:@"token_cache_write" requestId:telemetryRequestId correlationId:correlationId]; [event setTokenType:@"access token"]; [[ADTelemetry sharedInstance] stopEvent:telemetryRequestId event:event]; SAFE_ARC_RELEASE(event); +#endif } - (void)removeItemFromCache:(ADTokenCacheItem *)cacheItem @@ -324,9 +334,9 @@ - (void)removeItemFromCache:(ADTokenCacheItem *)cacheItem } NSUUID* correlationId = [requestParams correlationId]; - +#if AD_TELEMETRY [[ADTelemetry sharedInstance] startEvent:[requestParams telemetryRequestId] eventName:@"token_cache_delete_token"]; - +#endif BOOL removed = NO; //The refresh token didn't work. We need to tombstone this refresh item in the cache. ADTokenCacheKey* exactKey = [cacheItem extractKey:nil]; @@ -366,12 +376,13 @@ - (void)removeItemFromCache:(ADTokenCacheItem *)cacheItem } } } - +#if AD_TELEMETRY ADTelemetryCacheEvent* event = [[ADTelemetryCacheEvent alloc] initWithName:@"token_cache_delete_token" requestId:[requestParams telemetryRequestId] correlationId:correlationId]; [[ADTelemetry sharedInstance] stopEvent:[requestParams telemetryRequestId] event:event]; SAFE_ARC_RELEASE(event); +#endif } @end diff --git a/ADAL/src/request/ADAcquireTokenSilentHandler.m b/ADAL/src/request/ADAcquireTokenSilentHandler.m index 8013d03d6..f52d57e85 100644 --- a/ADAL/src/request/ADAcquireTokenSilentHandler.m +++ b/ADAL/src/request/ADAcquireTokenSilentHandler.m @@ -204,11 +204,14 @@ - (void)acquireTokenWithItem:(ADTokenCacheItem *)item completionBlock:(ADAuthenticationCallback)completionBlock fallback:(ADAuthenticationCallback)fallback { +#if AD_TELEMETRY [[ADTelemetry sharedInstance] startEvent:[_requestParams telemetryRequestId] eventName:@"token_grant"]; +#endif [self acquireTokenByRefreshToken:item.refreshToken cacheItem:item completionBlock:^(ADAuthenticationResult *result) { +#if AD_TELEMETRY ADTelemetryAPIEvent* event = [[ADTelemetryAPIEvent alloc] initWithName:@"token_grant" requestId:[_requestParams telemetryRequestId] correlationId:[_requestParams correlationId]]; @@ -216,6 +219,7 @@ - (void)acquireTokenWithItem:(ADTokenCacheItem *)item [event setResultStatus:[result status]]; [[ADTelemetry sharedInstance] stopEvent:[_requestParams telemetryRequestId] event:event]; SAFE_ARC_RELEASE(event); +#endif NSString* resultStatus = @"Succeded"; diff --git a/ADAL/src/request/ADAuthenticationRequest+AcquireToken.m b/ADAL/src/request/ADAuthenticationRequest+AcquireToken.m index 1f0663321..8afbefeea 100644 --- a/ADAL/src/request/ADAuthenticationRequest+AcquireToken.m +++ b/ADAL/src/request/ADAuthenticationRequest+AcquireToken.m @@ -44,7 +44,9 @@ - (void)acquireToken:(ADAuthenticationCallback)completionBlock AD_REQUEST_CHECK_ARGUMENT([_requestParams resource]); [self ensureRequest]; NSUUID* correlationId = [_requestParams correlationId]; +#if AD_TELEMETRY NSString* telemetryRequestId = [_requestParams telemetryRequestId]; +#endif NSString* log = [NSString stringWithFormat:@"acquireToken (authority = %@, resource = %@, clientId = %@, idtype = %@)", [_requestParams authority], [_requestParams resource], [_requestParams clientId], [[_requestParams identifier] typeAsString]]; @@ -78,12 +80,15 @@ - (void)acquireToken:(ADAuthenticationCallback)completionBlock [self validatedAcquireToken:completionBlock]; return; } - +#if AD_TELEMETRY [[ADTelemetry sharedInstance] startEvent:telemetryRequestId eventName:@"authority_validation"]; +#endif [[ADInstanceDiscovery sharedInstance] validateAuthority:_context.authority requestParams:_requestParams completionBlock:^(BOOL validated, ADAuthenticationError *error) { + (void)validated; +#if AD_TELEMETRY ADTelemetryAPIEvent* event = [[ADTelemetryAPIEvent alloc] initWithName:@"authority_validation" requestId:telemetryRequestId correlationId:correlationId]; @@ -91,7 +96,7 @@ - (void)acquireToken:(ADAuthenticationCallback)completionBlock [event setAuthority:_context.authority]; [[ADTelemetry sharedInstance] stopEvent:telemetryRequestId event:event]; SAFE_ARC_RELEASE(event); - +#endif if (error) { completionBlock([ADAuthenticationResult resultFromError:error correlationId:correlationId]); @@ -110,16 +115,19 @@ - (void)validatedAcquireToken:(ADAuthenticationCallback)completionBlock if (![ADAuthenticationContext isForcedAuthorization:_promptBehavior] && [_context hasCacheStore]) { +#if AD_TELEMETRY [[ADTelemetry sharedInstance] startEvent:[self telemetryRequestId] eventName:@"acquire_token_silent_handler"]; +#endif [ADAcquireTokenSilentHandler acquireTokenSilentForRequestParams:_requestParams completionBlock:^(ADAuthenticationResult *result) { +#if AD_TELEMETRY ADTelemetryAPIEvent* event = [[ADTelemetryAPIEvent alloc] initWithName:@"acquire_token_silent_handler" requestId:[self telemetryRequestId] correlationId:[self correlationId]]; [[ADTelemetry sharedInstance] stopEvent:[self telemetryRequestId] event:event]; SAFE_ARC_RELEASE(event); - +#endif if ([ADAuthenticationContext isFinalResult:result]) { completionBlock(result); @@ -142,7 +150,9 @@ - (void)requestToken:(ADAuthenticationCallback)completionBlock { [self ensureRequest]; NSUUID* correlationId = [_requestParams correlationId]; +#if AD_TELEMETRY NSString* telemetryRequestId = [_requestParams telemetryRequestId]; +#endif if (_samlAssertion) { @@ -199,12 +209,16 @@ - (void)requestToken:(ADAuthenticationCallback)completionBlock __block BOOL silentRequest = _allowSilent; // Get the code first: +#if AD_TELEMETRY [[ADTelemetry sharedInstance] startEvent:telemetryRequestId eventName:@"authorization_code"]; +#endif [self requestCode:^(NSString * code, ADAuthenticationError *error) { +#if AD_TELEMETRY ADTelemetryAPIEvent* event = [[ADTelemetryAPIEvent alloc] initWithName:@"authorization_code" requestId:telemetryRequestId correlationId:correlationId]; +#endif if (error) { @@ -217,31 +231,36 @@ - (void)requestToken:(ADAuthenticationCallback)completionBlock ADAuthenticationResult* result = (AD_ERROR_UI_USER_CANCEL == error.code) ? [ADAuthenticationResult resultFromCancellation:correlationId] : [ADAuthenticationResult resultFromError:error correlationId:correlationId]; - +#if AD_TELEMETRY [event setAPIStatus:(AD_ERROR_UI_USER_CANCEL == error.code) ? @"canceled":@"failed"]; [[ADTelemetry sharedInstance] stopEvent:telemetryRequestId event:event]; - +#endif completionBlock(result); } else { if([code hasPrefix:@"msauth://"]) { +#if AD_TELEMETRY [event setAPIStatus:@"try to invoke broker from webview"]; [[ADTelemetry sharedInstance] stopEvent:telemetryRequestId event:event]; +#endif [self handleBrokerFromWebiewResponse:code completionBlock:completionBlock]; } else { +#if AD_TELEMETRY [event setAPIStatus:@"succeeded"]; [[ADTelemetry sharedInstance] stopEvent:telemetryRequestId event:event]; [[ADTelemetry sharedInstance] startEvent:telemetryRequestId eventName:@"token_grant"]; +#endif [self requestTokenByCode:code completionBlock:^(ADAuthenticationResult *result) { +#if AD_TELEMETRY ADTelemetryAPIEvent* event = [[ADTelemetryAPIEvent alloc] initWithName:@"token_grant" requestId:telemetryRequestId correlationId:correlationId]; @@ -249,7 +268,7 @@ - (void)requestToken:(ADAuthenticationCallback)completionBlock [event setResultStatus:[result status]]; [[ADTelemetry sharedInstance] stopEvent:telemetryRequestId event:event]; SAFE_ARC_RELEASE(event); - +#endif if (AD_SUCCEEDED == result.status) { [[_requestParams tokenCache] updateCacheToResult:result cacheItem:nil refreshToken:nil requestParams:_requestParams]; @@ -259,8 +278,9 @@ - (void)requestToken:(ADAuthenticationCallback)completionBlock }]; } } - +#if AD_TELEMETRY SAFE_ARC_RELEASE(event); +#endif }]; } diff --git a/ADAL/src/request/ADAuthenticationRequest+Broker.m b/ADAL/src/request/ADAuthenticationRequest+Broker.m index e069b01b8..d96fbbca4 100644 --- a/ADAL/src/request/ADAuthenticationRequest+Broker.m +++ b/ADAL/src/request/ADAuthenticationRequest+Broker.m @@ -52,6 +52,9 @@ @implementation ADAuthenticationRequest (Broker) + (BOOL)validBrokerRedirectUri:(NSString*)url { + (void)s_brokerAppVersion; + (void)s_brokerProtocolVersion; + NSArray* urlTypes = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleURLTypes"]; NSURL* redirectURI = [NSURL URLWithString:url]; @@ -222,13 +225,13 @@ - (void)callBroker:(ADAuthenticationCallback)completionBlock completionBlock([ADAuthenticationResult resultFromError:error correlationId:correlationId]); return; } - +#if AD_TELEMETRY [[ADTelemetry sharedInstance] startEvent:[self telemetryRequestId] eventName:@"launch_broker"]; - +#endif void(^requestCompletion)(ADAuthenticationResult* result) = ^void(ADAuthenticationResult* result) { [self releaseUserInterationLock]; // Release the lock when completion block is called. - +#if AD_TELEMETRY ADTelemetryBrokerEvent* event = [[ADTelemetryBrokerEvent alloc] initWithName:@"launch_broker" requestId:[_requestParams telemetryRequestId] correlationId:correlationId]; @@ -236,7 +239,7 @@ - (void)callBroker:(ADAuthenticationCallback)completionBlock [event setBrokerAppVersion:s_brokerAppVersion]; [event setBrokerProtocolVersion:s_brokerProtocolVersion]; [[ADTelemetry sharedInstance] stopEvent:[self telemetryRequestId] event:event]; - +#endif completionBlock(result); }; @@ -330,9 +333,12 @@ - (void)handleBrokerFromWebiewResponse:(NSString*)urlString if ([ADBrokerHelper canUseBroker]) { +#if AD_TELEMETRY [[ADTelemetry sharedInstance] startEvent:[self telemetryRequestId] eventName:@"launch_broker"]; +#endif void(^requestCompletion)(ADAuthenticationResult* result) = ^void(ADAuthenticationResult* result) { +#if AD_TELEMETRY ADTelemetryBrokerEvent* event = [[ADTelemetryBrokerEvent alloc] initWithName:@"launch_broker" requestId:[_requestParams telemetryRequestId] correlationId:correlationId]; @@ -340,7 +346,7 @@ - (void)handleBrokerFromWebiewResponse:(NSString*)urlString [event setBrokerAppVersion:s_brokerAppVersion]; [event setBrokerProtocolVersion:s_brokerProtocolVersion]; [[ADTelemetry sharedInstance] stopEvent:[self telemetryRequestId] event:event]; - +#endif completionBlock(result); }; diff --git a/ADAL/src/request/ADAuthenticationRequest+WebRequest.m b/ADAL/src/request/ADAuthenticationRequest+WebRequest.m index 933797b7a..5cc726fa7 100755 --- a/ADAL/src/request/ADAuthenticationRequest+WebRequest.m +++ b/ADAL/src/request/ADAuthenticationRequest+WebRequest.m @@ -178,15 +178,18 @@ - (NSString*)generateQueryStringForRequestType:(NSString*)requestType - (void)launchWebView:(NSString*)startUrl completionBlock:(void (^)(ADAuthenticationError*, NSURL*))completionBlock { +#if AD_TELEMETRY [[ADTelemetry sharedInstance] startEvent:[self telemetryRequestId] eventName:@"launch_web_view"]; +#endif void(^requestCompletion)(ADAuthenticationError *error, NSURL *end) = ^void(ADAuthenticationError *error, NSURL *end) { +#if AD_TELEMETRY ADTelemetryUIEvent* event = [[ADTelemetryUIEvent alloc] initWithName:@"launch_web_view" requestId:[self telemetryRequestId] correlationId:[self correlationId]]; [self fillTelemetryUIEvent:event]; [[ADTelemetry sharedInstance] stopEvent:[self telemetryRequestId] event:event]; - +#endif completionBlock(error, end); }; diff --git a/ADAL/src/request/ADWebRequest.m b/ADAL/src/request/ADWebRequest.m index 809f32cce..e8645a7e8 100644 --- a/ADAL/src/request/ADWebRequest.m +++ b/ADAL/src/request/ADWebRequest.m @@ -150,8 +150,9 @@ - (void)completeWithError:(NSError *)error andResponse:(ADWebResponse *)response SAFE_ARC_RELEASE(_connection); _connection = nil; - +#if AD_TELEMETRY [self stopTelemetryEvent:error response:response]; +#endif _completionHandler(error, response); } @@ -180,8 +181,9 @@ - (void)resend - (void)send { +#if AD_TELEMETRY [[ADTelemetry sharedInstance] startEvent:_telemetryRequestId eventName:@"http_request"]; - +#endif [_requestHeaders addEntriesFromDictionary:[ADLogger adalId]]; //Correlation id: if (_correlationId) @@ -322,7 +324,7 @@ - (void)stopTelemetryEvent:(NSError *)error response:(ADWebResponse *)response { ADTelemetryHttpEvent* event = [[ADTelemetryHttpEvent alloc] initWithName:@"http_request" requestId:_telemetryRequestId correlationId:_correlationId]; - + [event setHttpMethod:_isGetRequest ? @"GET" : @"POST"]; [event setHttpPath:[NSString stringWithFormat:@"%@://%@/%@", _requestURL.scheme, _requestURL.host, _requestURL.path]]; if (error) @@ -334,10 +336,9 @@ - (void)stopTelemetryEvent:(NSError *)error { [event setHttpResponseCode:[NSString stringWithFormat: @"%ld", (long)[response statusCode]]]; } - + [[ADTelemetry sharedInstance] stopEvent:_telemetryRequestId event:event]; SAFE_ARC_RELEASE(event); - } @end From 62ec5f8c19e03e30ca9fc338b7c10be08451ffca Mon Sep 17 00:00:00 2001 From: Jevgeni Date: Thu, 8 Sep 2016 14:10:00 +0200 Subject: [PATCH 16/92] Resource can be nil as it is specified in the comment therefore it makes sense to add "nullable" in Objective-C layer, which will generate optinal String? type in Swift projection. Reviewed by Claus. --- ADAL/src/public/ADTokenCacheItem.h | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/ADAL/src/public/ADTokenCacheItem.h b/ADAL/src/public/ADTokenCacheItem.h index f6fcd7f86..01ea3b710 100644 --- a/ADAL/src/public/ADTokenCacheItem.h +++ b/ADAL/src/public/ADTokenCacheItem.h @@ -55,8 +55,10 @@ NSMutableDictionary* _additionalClient; } +NS_ASSUME_NONNULL_BEGIN + /*! Applicable resource. Should be nil, in case the item stores multi-resource refresh token. */ -@property (copy) NSString* resource; +@property (copy, nullable) NSString* resource; @property (copy) NSString* authority; @@ -65,15 +67,15 @@ @property (copy) NSString* familyId; /*! The access token received. Should be nil, in case the item stores multi-resource refresh token. */ -@property (copy) NSString* accessToken; +@property (copy, nullable) NSString* accessToken; @property (copy) NSString* accessTokenType; -@property (copy) NSString* refreshToken; +@property (copy, nullable) NSString* refreshToken; @property (copy) NSData* sessionKey; -@property (copy) NSDate* expiresOn; +@property (copy, nullable) NSDate* expiresOn; @property (retain) ADUserInformation* userInformation; @@ -91,7 +93,7 @@ /*! Obtains a key to be used for the internal cache from the full cache item. @param error: if a key cannot be extracted, the method will return nil and if this parameter is not nil, it will be filled with the appropriate error information.*/ -- (ADTokenCacheKey*) extractKey:(ADAuthenticationError * __autoreleasing *)error; +- (ADTokenCacheKey*) extractKey:(ADAuthenticationError * _Nullable __autoreleasing * _Nullable)error; /*! Compares expiresOn with the current time. If expiresOn is not nil, the function returns the comparison of expires on and the current time. If expiresOn is nil, the function returns NO, @@ -110,3 +112,5 @@ - (BOOL)isMultiResourceRefreshToken; @end + +NS_ASSUME_NONNULL_END From 723250588be2b8beba0bc7910b3aedf84878363f Mon Sep 17 00:00:00 2001 From: Ryan Pangrle Date: Thu, 8 Sep 2016 11:12:40 -0700 Subject: [PATCH 17/92] add code to allow for "validateAuthority" and "enableBroker" settings in our settings profiles --- .../MyTestiOSApp/ADTestAppAcquireTokenViewController.m | 7 +++++-- Samples/MyTestiOSApp/MyTestiOSApp/ADTestAppSettings.h | 2 ++ Samples/MyTestiOSApp/MyTestiOSApp/ADTestAppSettings.m | 4 ++++ 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/Samples/MyTestiOSApp/MyTestiOSApp/ADTestAppAcquireTokenViewController.m b/Samples/MyTestiOSApp/MyTestiOSApp/ADTestAppAcquireTokenViewController.m index b6ad72117..ff1ae05c9 100644 --- a/Samples/MyTestiOSApp/MyTestiOSApp/ADTestAppAcquireTokenViewController.m +++ b/Samples/MyTestiOSApp/MyTestiOSApp/ADTestAppAcquireTokenViewController.m @@ -82,11 +82,14 @@ - (void)textFieldChanged:(id)sender - (void)viewWillAppear:(BOOL)animated { + ADTestAppSettings* settings = [ADTestAppSettings settings]; if (!_userIdEdited) { - NSString* defaultUser = [[ADTestAppSettings settings] defaultUser]; - [_userIdField setText:defaultUser]; + [_userIdField setText:settings.defaultUser]; } + + [_validateAuthority setSelectedSegmentIndex:settings.validateAuthority ? 0 : 1]; + [_credentialsType setSelectedSegmentIndex:settings.enableBroker ? 0 : 1]; } - (void)didReceiveMemoryWarning { diff --git a/Samples/MyTestiOSApp/MyTestiOSApp/ADTestAppSettings.h b/Samples/MyTestiOSApp/MyTestiOSApp/ADTestAppSettings.h index 50abc2d94..0c96be227 100644 --- a/Samples/MyTestiOSApp/MyTestiOSApp/ADTestAppSettings.h +++ b/Samples/MyTestiOSApp/MyTestiOSApp/ADTestAppSettings.h @@ -33,6 +33,8 @@ extern NSString* ADTestAppCacheChangeNotification; @property NSString* clientId; @property NSString* resource; @property NSString* defaultUser; +@property BOOL validateAuthority; +@property BOOL enableBroker; + (ADTestAppSettings*)settings; + (NSUInteger)numberOfProfiles; diff --git a/Samples/MyTestiOSApp/MyTestiOSApp/ADTestAppSettings.m b/Samples/MyTestiOSApp/MyTestiOSApp/ADTestAppSettings.m index 691a59e23..9e0081433 100644 --- a/Samples/MyTestiOSApp/MyTestiOSApp/ADTestAppSettings.m +++ b/Samples/MyTestiOSApp/MyTestiOSApp/ADTestAppSettings.m @@ -162,6 +162,10 @@ - (void)setProfileFromIndex:(NSInteger)idx self.redirectUri = [NSURL URLWithString:[settings objectForKey:@"redirectUri"]]; self.resource = [settings objectForKey:@"resource"]; self.defaultUser = [settings objectForKey:@"defaultUser"]; + NSNumber* validate = [settings objectForKey:@"validateAuthority"]; + self.validateAuthority = validate ? [validate boolValue] : YES; + NSNumber* enableBroker = [settings objectForKey:@"enableBroker"]; + self.enableBroker = [enableBroker boolValue]; } @end From 2c19c5752fa983576fc1802efb2d0b8192a10e4e Mon Sep 17 00:00:00 2001 From: Ryan Pangrle Date: Thu, 8 Sep 2016 12:12:08 -0700 Subject: [PATCH 18/92] enableBroker needed to be flipped when selecting segment index --- .../MyTestiOSApp/ADTestAppAcquireTokenViewController.m | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Samples/MyTestiOSApp/MyTestiOSApp/ADTestAppAcquireTokenViewController.m b/Samples/MyTestiOSApp/MyTestiOSApp/ADTestAppAcquireTokenViewController.m index ff1ae05c9..b44ae4bc4 100644 --- a/Samples/MyTestiOSApp/MyTestiOSApp/ADTestAppAcquireTokenViewController.m +++ b/Samples/MyTestiOSApp/MyTestiOSApp/ADTestAppAcquireTokenViewController.m @@ -89,7 +89,7 @@ - (void)viewWillAppear:(BOOL)animated } [_validateAuthority setSelectedSegmentIndex:settings.validateAuthority ? 0 : 1]; - [_credentialsType setSelectedSegmentIndex:settings.enableBroker ? 0 : 1]; + [_credentialsType setSelectedSegmentIndex:settings.enableBroker ? 1 : 0]; } - (void)didReceiveMemoryWarning { From 75c6040ef7257418441290307c97704dbf844e53 Mon Sep 17 00:00:00 2001 From: Ryan Pangrle Date: Fri, 9 Sep 2016 12:00:29 -0700 Subject: [PATCH 19/92] iOS test app should be consuming the ADAL static lib, not the framework. --- .../MyTestiOSApp.xcodeproj/project.pbxproj | 52 +++++++------------ .../AppIcon.appiconset/Contents.json | 20 +++++++ 2 files changed, 40 insertions(+), 32 deletions(-) diff --git a/Samples/MyTestiOSApp/MyTestiOSApp.xcodeproj/project.pbxproj b/Samples/MyTestiOSApp/MyTestiOSApp.xcodeproj/project.pbxproj index 0ec8ead40..60d2f2f2d 100644 --- a/Samples/MyTestiOSApp/MyTestiOSApp.xcodeproj/project.pbxproj +++ b/Samples/MyTestiOSApp/MyTestiOSApp.xcodeproj/project.pbxproj @@ -7,9 +7,6 @@ objects = { /* Begin PBXBuildFile section */ - 8B3F7A021D74F0A700F95A44 /* ADAL.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 8B3F79FB1D74F0A200F95A44 /* ADAL.framework */; }; - 8B3F7A031D74F0A700F95A44 /* ADAL.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 8B3F79FB1D74F0A200F95A44 /* ADAL.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; - 8B3F7A071D74F0B400F95A44 /* ADAL.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 8B3F79FB1D74F0A200F95A44 /* ADAL.framework */; }; 8B87548818988C4B0061999F /* TestData.plist in Resources */ = {isa = PBXBuildFile; fileRef = 8B87548718988C4B0061999F /* TestData.plist */; }; 8B87548918988C4B0061999F /* TestData.plist in Resources */ = {isa = PBXBuildFile; fileRef = 8B87548718988C4B0061999F /* TestData.plist */; }; 8B87548C189978350061999F /* ADTestAppSettings.m in Sources */ = {isa = PBXBuildFile; fileRef = 8B87548B189978350061999F /* ADTestAppSettings.m */; }; @@ -34,6 +31,8 @@ D68B4A371CB5AB0C00758FB3 /* ADTestAppLogViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = D68B4A361CB5AB0C00758FB3 /* ADTestAppLogViewController.m */; }; D6D034871CB6D74E00406721 /* ADTestAppSettingsViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = D6D034851CB6D74E00406721 /* ADTestAppSettingsViewController.m */; }; D6D034881CB6D74E00406721 /* ADTestAppSettingsView.xib in Resources */ = {isa = PBXBuildFile; fileRef = D6D034861CB6D74E00406721 /* ADTestAppSettingsView.xib */; }; + D6D64BB81D83319A0077C1A0 /* libADAL-core.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 8B3F79F91D74F0A200F95A44 /* libADAL-core.a */; }; + D6D64BB91D83320B0077C1A0 /* libADAL-core.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 8B3F79F91D74F0A200F95A44 /* libADAL-core.a */; }; D6EA53AB1D541012008A0BC3 /* ShareViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = D6EA53AA1D541012008A0BC3 /* ShareViewController.m */; }; D6EA53AE1D541012008A0BC3 /* MainInterface.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = D6EA53AC1D541012008A0BC3 /* MainInterface.storyboard */; }; D6EA53B21D541012008A0BC3 /* adal-extension.appex in Embed App Extensions */ = {isa = PBXBuildFile; fileRef = D6EA53A71D541011008A0BC3 /* adal-extension.appex */; settings = {ATTRIBUTES = (RemoveHeadersOnCopy, ); }; }; @@ -82,20 +81,6 @@ remoteGlobalIDString = 94DD18E11C5ACFBF00F80C62; remoteInfo = "ADAL Mac Tests"; }; - 8B3F7A041D74F0A700F95A44 /* PBXContainerItemProxy */ = { - isa = PBXContainerItemProxy; - containerPortal = 8B3F79EC1D74F0A100F95A44 /* ADAL.xcodeproj */; - proxyType = 1; - remoteGlobalIDString = 9453C3CB1C583E07006B9E79; - remoteInfo = ADAL; - }; - 8B3F7A081D74F0DD00F95A44 /* PBXContainerItemProxy */ = { - isa = PBXContainerItemProxy; - containerPortal = 8B3F79EC1D74F0A100F95A44 /* ADAL.xcodeproj */; - proxyType = 1; - remoteGlobalIDString = 9453C3CB1C583E07006B9E79; - remoteInfo = ADAL; - }; 8BA42B2817E3C150002D206E /* PBXContainerItemProxy */ = { isa = PBXContainerItemProxy; containerPortal = 8BA42AEE17E3C150002D206E /* Project object */; @@ -103,6 +88,13 @@ remoteGlobalIDString = 8BA42AF517E3C150002D206E; remoteInfo = MyTestiOSApp; }; + D6D64BBA1D83320F0077C1A0 /* PBXContainerItemProxy */ = { + isa = PBXContainerItemProxy; + containerPortal = 8B3F79EC1D74F0A100F95A44 /* ADAL.xcodeproj */; + proxyType = 1; + remoteGlobalIDString = D664F16A1D302B9C0017B799; + remoteInfo = "ADAL-core"; + }; D6EA53B01D541012008A0BC3 /* PBXContainerItemProxy */ = { isa = PBXContainerItemProxy; containerPortal = 8BA42AEE17E3C150002D206E /* Project object */; @@ -119,7 +111,6 @@ dstPath = ""; dstSubfolderSpec = 10; files = ( - 8B3F7A031D74F0A700F95A44 /* ADAL.framework in Embed Frameworks */, ); name = "Embed Frameworks"; runOnlyForDeploymentPostprocessing = 0; @@ -184,9 +175,9 @@ isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; files = ( + D6D64BB81D83319A0077C1A0 /* libADAL-core.a in Frameworks */, 8BA42AFC17E3C150002D206E /* CoreGraphics.framework in Frameworks */, 8BA42B0017E3C150002D206E /* CoreData.framework in Frameworks */, - 8B3F7A021D74F0A700F95A44 /* ADAL.framework in Frameworks */, 8BA42AFE17E3C150002D206E /* UIKit.framework in Frameworks */, 8BA42AFA17E3C150002D206E /* Foundation.framework in Frameworks */, ); @@ -207,7 +198,7 @@ isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; files = ( - 8B3F7A071D74F0B400F95A44 /* ADAL.framework in Frameworks */, + D6D64BB91D83320B0077C1A0 /* libADAL-core.a in Frameworks */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -345,7 +336,6 @@ ); dependencies = ( D6EA53B11D541012008A0BC3 /* PBXTargetDependency */, - 8B3F7A051D74F0A700F95A44 /* PBXTargetDependency */, ); name = MyTestiOSApp; productName = MyTestiOSApp; @@ -381,7 +371,7 @@ buildRules = ( ); dependencies = ( - 8B3F7A091D74F0DD00F95A44 /* PBXTargetDependency */, + D6D64BBB1D83320F0077C1A0 /* PBXTargetDependency */, ); name = "adal-extension"; productName = "adal-extension"; @@ -552,21 +542,16 @@ /* End PBXSourcesBuildPhase section */ /* Begin PBXTargetDependency section */ - 8B3F7A051D74F0A700F95A44 /* PBXTargetDependency */ = { - isa = PBXTargetDependency; - name = ADAL; - targetProxy = 8B3F7A041D74F0A700F95A44 /* PBXContainerItemProxy */; - }; - 8B3F7A091D74F0DD00F95A44 /* PBXTargetDependency */ = { - isa = PBXTargetDependency; - name = ADAL; - targetProxy = 8B3F7A081D74F0DD00F95A44 /* PBXContainerItemProxy */; - }; 8BA42B2917E3C150002D206E /* PBXTargetDependency */ = { isa = PBXTargetDependency; target = 8BA42AF517E3C150002D206E /* MyTestiOSApp */; targetProxy = 8BA42B2817E3C150002D206E /* PBXContainerItemProxy */; }; + D6D64BBB1D83320F0077C1A0 /* PBXTargetDependency */ = { + isa = PBXTargetDependency; + name = "ADAL-core"; + targetProxy = D6D64BBA1D83320F0077C1A0 /* PBXContainerItemProxy */; + }; D6EA53B11D541012008A0BC3 /* PBXTargetDependency */ = { isa = PBXTargetDependency; target = D6EA53A61D541011008A0BC3 /* adal-extension */; @@ -883,6 +868,7 @@ MTL_ENABLE_DEBUG_INFO = YES; PRODUCT_BUNDLE_IDENTIFIER = "com.microsoft.adal.2.1.0.TestApp.adal-extension"; PRODUCT_NAME = "$(TARGET_NAME)"; + PROVISIONING_PROFILE = ""; SKIP_INSTALL = YES; }; name = Debug; @@ -906,6 +892,7 @@ MTL_ENABLE_DEBUG_INFO = NO; PRODUCT_BUNDLE_IDENTIFIER = "com.microsoft.adal.2.1.0.TestApp.adal-extension"; PRODUCT_NAME = "$(TARGET_NAME)"; + PROVISIONING_PROFILE = ""; SKIP_INSTALL = YES; }; name = CodeCoverage; @@ -929,6 +916,7 @@ MTL_ENABLE_DEBUG_INFO = NO; PRODUCT_BUNDLE_IDENTIFIER = "com.microsoft.adal.2.1.0.TestApp.adal-extension"; PRODUCT_NAME = "$(TARGET_NAME)"; + PROVISIONING_PROFILE = ""; SKIP_INSTALL = YES; }; name = Release; diff --git a/Samples/MyTestiOSApp/MyTestiOSApp/Images.xcassets/AppIcon.appiconset/Contents.json b/Samples/MyTestiOSApp/MyTestiOSApp/Images.xcassets/AppIcon.appiconset/Contents.json index 52191ee6b..96a594329 100644 --- a/Samples/MyTestiOSApp/MyTestiOSApp/Images.xcassets/AppIcon.appiconset/Contents.json +++ b/Samples/MyTestiOSApp/MyTestiOSApp/Images.xcassets/AppIcon.appiconset/Contents.json @@ -1,5 +1,15 @@ { "images" : [ + { + "idiom" : "iphone", + "size" : "20x20", + "scale" : "2x" + }, + { + "idiom" : "iphone", + "size" : "20x20", + "scale" : "3x" + }, { "idiom" : "iphone", "size" : "29x29", @@ -30,6 +40,16 @@ "size" : "60x60", "scale" : "3x" }, + { + "idiom" : "ipad", + "size" : "20x20", + "scale" : "1x" + }, + { + "idiom" : "ipad", + "size" : "20x20", + "scale" : "2x" + }, { "idiom" : "ipad", "size" : "29x29", From 62b0fb5e6dd67b04bee1563d3906a9bad88605af Mon Sep 17 00:00:00 2001 From: Claus Joergensen Date: Sat, 10 Sep 2016 02:09:56 +0200 Subject: [PATCH 20/92] Added nullable annotation to ADTokenCacheItem.userInformation --- ADAL/src/public/ADTokenCacheItem.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ADAL/src/public/ADTokenCacheItem.h b/ADAL/src/public/ADTokenCacheItem.h index 01ea3b710..5a77091d8 100644 --- a/ADAL/src/public/ADTokenCacheItem.h +++ b/ADAL/src/public/ADTokenCacheItem.h @@ -78,7 +78,7 @@ NS_ASSUME_NONNULL_BEGIN @property (copy, nullable) NSDate* expiresOn; -@property (retain) ADUserInformation* userInformation; +@property (retain, nullable) ADUserInformation* userInformation; /*! The item is a tombstone if this property if not nil; From 5c187821afe1eacc3f2a538401c95e8b0528ce8e Mon Sep 17 00:00:00 2001 From: Claus Joergensen Date: Sat, 10 Sep 2016 13:09:15 +0200 Subject: [PATCH 21/92] Adjusted the SampleSwiftApp to account for nullability in the tokenCacheItem.expiresOn property --- Samples/SampleSwiftApp/SampleSwiftApp/ViewController.swift | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Samples/SampleSwiftApp/SampleSwiftApp/ViewController.swift b/Samples/SampleSwiftApp/SampleSwiftApp/ViewController.swift index 834860c66..6576922c5 100644 --- a/Samples/SampleSwiftApp/SampleSwiftApp/ViewController.swift +++ b/Samples/SampleSwiftApp/SampleSwiftApp/ViewController.swift @@ -57,8 +57,8 @@ class ViewController: UIViewController { self.updateStatusField(result.error.description) return; } - - let status = String(format: "Access token: %@\nexpiration:%@", result.accessToken, result.tokenCacheItem.expiresOn) + + let status = String(format: "Access token: %@\nexpiration:%@", result.accessToken, result.tokenCacheItem.expiresOn ?? "(nil)") self.updateStatusField(status) } } From 30211fe6f0b51ef72d6fca699b932374fd3992d6 Mon Sep 17 00:00:00 2001 From: Claus Joergensen Date: Mon, 12 Sep 2016 16:06:19 +0200 Subject: [PATCH 22/92] Nullable annotations for everything but the accessToken in ADTokenCacheItem --- ADAL/src/public/ADTokenCacheItem.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/ADAL/src/public/ADTokenCacheItem.h b/ADAL/src/public/ADTokenCacheItem.h index 5a77091d8..633474ac0 100644 --- a/ADAL/src/public/ADTokenCacheItem.h +++ b/ADAL/src/public/ADTokenCacheItem.h @@ -62,18 +62,18 @@ NS_ASSUME_NONNULL_BEGIN @property (copy) NSString* authority; -@property (copy) NSString* clientId; +@property (copy, nullable) NSString* clientId; -@property (copy) NSString* familyId; +@property (copy, nullable) NSString* familyId; /*! The access token received. Should be nil, in case the item stores multi-resource refresh token. */ @property (copy, nullable) NSString* accessToken; -@property (copy) NSString* accessTokenType; +@property (copy, nullable) NSString* accessTokenType; @property (copy, nullable) NSString* refreshToken; -@property (copy) NSData* sessionKey; +@property (copy, nullable) NSData* sessionKey; @property (copy, nullable) NSDate* expiresOn; From 2f72a44d040e97d4ba62e510bc24da92b393447d Mon Sep 17 00:00:00 2001 From: YONG ZENG Date: Tue, 20 Sep 2016 16:28:38 -0700 Subject: [PATCH 23/92] change aggregated event to comply with the new requirements --- ADAL/ADAL.xcodeproj/project.pbxproj | 20 ++-- ADAL/src/ADAuthenticationContext.m | 8 +- ADAL/src/cache/ADTokenCacheAccessor.m | 17 +++- .../ADAuthenticationRequest+AcquireToken.m | 3 +- ADAL/src/request/ADAuthenticationRequest.h | 1 + ADAL/src/request/ADAuthenticationRequest.m | 5 + ADAL/src/telemetry/ADAggregatedDispatcher.m | 27 ++---- ADAL/src/telemetry/ADTelemetryAPIEvent.h | 4 +- ADAL/src/telemetry/ADTelemetryAPIEvent.m | 92 ++++++++++++++++--- ADAL/src/telemetry/ADTelemetryBrokerEvent.m | 22 ++++- ADAL/src/telemetry/ADTelemetryCacheEvent.h | 3 + ADAL/src/telemetry/ADTelemetryCacheEvent.m | 45 ++++++++- ADAL/src/telemetry/ADTelemetryDefaultEvent.m | 11 ++- .../src/telemetry/ADTelemetryEventInterface.h | 1 + ADAL/src/telemetry/ADTelemetryEventStrings.h | 66 +++++++++++++ ADAL/src/telemetry/ADTelemetryEventStrings.m | 66 +++++++++++++ ADAL/src/telemetry/ADTelemetryHttpEvent.m | 15 +++ ADAL/src/telemetry/ADTelemetryUIEvent.m | 25 ++++- 18 files changed, 382 insertions(+), 49 deletions(-) create mode 100644 ADAL/src/telemetry/ADTelemetryEventStrings.h create mode 100644 ADAL/src/telemetry/ADTelemetryEventStrings.m diff --git a/ADAL/ADAL.xcodeproj/project.pbxproj b/ADAL/ADAL.xcodeproj/project.pbxproj index 8d0ec6cb2..694ff882d 100755 --- a/ADAL/ADAL.xcodeproj/project.pbxproj +++ b/ADAL/ADAL.xcodeproj/project.pbxproj @@ -54,12 +54,9 @@ 6033892A1D595AD50024A9BF /* ADTelemetryHttpEvent.m in Sources */ = {isa = PBXBuildFile; fileRef = 6010EDEF1D47B2A600B62072 /* ADTelemetryHttpEvent.m */; }; 6033892B1D595AD50024A9BF /* ADTelemetryCacheEvent.m in Sources */ = {isa = PBXBuildFile; fileRef = 6010EDF41D47B2CE00B62072 /* ADTelemetryCacheEvent.m */; }; 6033892C1D595AD50024A9BF /* ADTelemetryBrokerEvent.m in Sources */ = {isa = PBXBuildFile; fileRef = 6010EDF91D47B2F300B62072 /* ADTelemetryBrokerEvent.m */; }; - 6033892D1D595AFF0024A9BF /* ADRequestParameters.m in Sources */ = {isa = PBXBuildFile; fileRef = 60D2F4001D531F16008725D9 /* ADRequestParameters.m */; }; - 6033892E1D595AFF0024A9BF /* ADTelemetryAPIEvent.m in Sources */ = {isa = PBXBuildFile; fileRef = 6010EDE51D47B21600B62072 /* ADTelemetryAPIEvent.m */; }; - 6033892F1D595AFF0024A9BF /* ADTelemetryUIEvent.m in Sources */ = {isa = PBXBuildFile; fileRef = 6010EDEA1D47B27400B62072 /* ADTelemetryUIEvent.m */; }; - 603389301D595AFF0024A9BF /* ADTelemetryHttpEvent.m in Sources */ = {isa = PBXBuildFile; fileRef = 6010EDEF1D47B2A600B62072 /* ADTelemetryHttpEvent.m */; }; - 603389311D595AFF0024A9BF /* ADTelemetryCacheEvent.m in Sources */ = {isa = PBXBuildFile; fileRef = 6010EDF41D47B2CE00B62072 /* ADTelemetryCacheEvent.m */; }; - 603389321D595AFF0024A9BF /* ADTelemetryBrokerEvent.m in Sources */ = {isa = PBXBuildFile; fileRef = 6010EDF91D47B2F300B62072 /* ADTelemetryBrokerEvent.m */; }; + 605C167C1D8FBA5A0097DBA0 /* ADTelemetryEventStrings.h in Headers */ = {isa = PBXBuildFile; fileRef = 605C167B1D8FBA590097DBA0 /* ADTelemetryEventStrings.h */; }; + 605C16821D8FD0AC0097DBA0 /* ADTelemetryEventStrings.m in Sources */ = {isa = PBXBuildFile; fileRef = 605C16801D8FD0AC0097DBA0 /* ADTelemetryEventStrings.m */; }; + 605C16831D8FD1AC0097DBA0 /* ADTelemetryEventStrings.m in Sources */ = {isa = PBXBuildFile; fileRef = 605C16801D8FD0AC0097DBA0 /* ADTelemetryEventStrings.m */; }; 6071B5E41C14C0B0006F6CC2 /* ADTestURLConnection.m in Sources */ = {isa = PBXBuildFile; fileRef = 6071B5E31C14C0B0006F6CC2 /* ADTestURLConnection.m */; }; 60D2F3FF1D524F7A008725D9 /* ADRequestParameters.h in Headers */ = {isa = PBXBuildFile; fileRef = 60D2F3FE1D524F7A008725D9 /* ADRequestParameters.h */; }; 60D2F4021D531F16008725D9 /* ADRequestParameters.m in Sources */ = {isa = PBXBuildFile; fileRef = 60D2F4001D531F16008725D9 /* ADRequestParameters.m */; }; @@ -284,10 +281,6 @@ D69A721A1D4FF68300E91DB3 /* ADDefaultDispatcher.m in Sources */ = {isa = PBXBuildFile; fileRef = 600401BC1D377E9F0020EAAB /* ADDefaultDispatcher.m */; }; D69A721B1D4FF68300E91DB3 /* ADAggregatedDispatcher.m in Sources */ = {isa = PBXBuildFile; fileRef = 600401B51D37658C0020EAAB /* ADAggregatedDispatcher.m */; }; D69A721C1D4FF68300E91DB3 /* ADTelemetryDefaultEvent.m in Sources */ = {isa = PBXBuildFile; fileRef = 600401AA1D3443D30020EAAB /* ADTelemetryDefaultEvent.m */; }; - D69A721D1D4FF68400E91DB3 /* ADTelemetry.m in Sources */ = {isa = PBXBuildFile; fileRef = 600401A31D3421480020EAAB /* ADTelemetry.m */; }; - D69A721E1D4FF68400E91DB3 /* ADDefaultDispatcher.m in Sources */ = {isa = PBXBuildFile; fileRef = 600401BC1D377E9F0020EAAB /* ADDefaultDispatcher.m */; }; - D69A721F1D4FF68400E91DB3 /* ADAggregatedDispatcher.m in Sources */ = {isa = PBXBuildFile; fileRef = 600401B51D37658C0020EAAB /* ADAggregatedDispatcher.m */; }; - D69A72201D4FF68400E91DB3 /* ADTelemetryDefaultEvent.m in Sources */ = {isa = PBXBuildFile; fileRef = 600401AA1D3443D30020EAAB /* ADTelemetryDefaultEvent.m */; }; D6D8A8401D4FD14E00D20DE6 /* ADKeychainUtil.m in Sources */ = {isa = PBXBuildFile; fileRef = D6D8A83F1D4FD14E00D20DE6 /* ADKeychainUtil.m */; }; D6F095151CDC072200D28FC2 /* ADAcquireTokenSilentHandler.h in Headers */ = {isa = PBXBuildFile; fileRef = D6F095131CDC072200D28FC2 /* ADAcquireTokenSilentHandler.h */; }; D6F095171CDC072200D28FC2 /* ADAcquireTokenSilentHandler.m in Sources */ = {isa = PBXBuildFile; fileRef = D6F095141CDC072200D28FC2 /* ADAcquireTokenSilentHandler.m */; }; @@ -385,6 +378,8 @@ 601BEE2F1C6D9CCE004AA8C1 /* ADTestAuthenticationViewController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ADTestAuthenticationViewController.h; sourceTree = ""; }; 601BEE301C6DAA86004AA8C1 /* ADTestAuthenticationViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ADTestAuthenticationViewController.m; sourceTree = ""; }; 601BEE331C6DCB0B004AA8C1 /* ADWebAuthControllerTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ADWebAuthControllerTests.m; sourceTree = ""; }; + 605C167B1D8FBA590097DBA0 /* ADTelemetryEventStrings.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ADTelemetryEventStrings.h; sourceTree = ""; }; + 605C16801D8FD0AC0097DBA0 /* ADTelemetryEventStrings.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ADTelemetryEventStrings.m; sourceTree = ""; }; 6071B5E21C14C0B0006F6CC2 /* ADTestURLConnection.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ADTestURLConnection.h; sourceTree = ""; }; 6071B5E31C14C0B0006F6CC2 /* ADTestURLConnection.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ADTestURLConnection.m; sourceTree = ""; }; 60D2F3FE1D524F7A008725D9 /* ADRequestParameters.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ADRequestParameters.h; sourceTree = ""; }; @@ -646,6 +641,8 @@ 6010EDF41D47B2CE00B62072 /* ADTelemetryCacheEvent.m */, 6010EDF71D47B2E300B62072 /* ADTelemetryBrokerEvent.h */, 6010EDF91D47B2F300B62072 /* ADTelemetryBrokerEvent.m */, + 605C167B1D8FBA590097DBA0 /* ADTelemetryEventStrings.h */, + 605C16801D8FD0AC0097DBA0 /* ADTelemetryEventStrings.m */, ); path = telemetry; sourceTree = ""; @@ -1135,6 +1132,7 @@ 9453C4221C586462006B9E79 /* ADTokenCacheAccessor.h in Headers */, D68040331D22F686007A61AC /* ADWebAuthResponse.h in Headers */, 9453C44A1C586485006B9E79 /* ADRegistrationInformation.h in Headers */, + 605C167C1D8FBA5A0097DBA0 /* ADTelemetryEventStrings.h in Headers */, 9453C4261C586462006B9E79 /* ADTokenCacheKey.h in Headers */, 60D2F3FF1D524F7A008725D9 /* ADRequestParameters.h in Headers */, 94DD18D21C5AC8DE00F80C62 /* ADAuthenticationParameters.h in Headers */, @@ -1435,6 +1433,7 @@ 9453C40C1C586456006B9E79 /* ADAuthenticationParameters+Internal.m in Sources */, 9453C4491C58647E006B9E79 /* NSUUID+ADExtensions.m in Sources */, 9453C40A1C586456006B9E79 /* ADAuthenticationError.m in Sources */, + 605C16821D8FD0AC0097DBA0 /* ADTelemetryEventStrings.m in Sources */, 9453C4451C58647E006B9E79 /* NSString+ADHelperMethods.m in Sources */, 9453C46E1C5872B0006B9E79 /* ADJwtHelper.m in Sources */, 9453C4471C58647E006B9E79 /* NSURL+ADExtensions.m in Sources */, @@ -1510,6 +1509,7 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( + 605C16831D8FD1AC0097DBA0 /* ADTelemetryEventStrings.m in Sources */, 603389291D595AD50024A9BF /* ADTelemetryUIEvent.m in Sources */, 6033892A1D595AD50024A9BF /* ADTelemetryHttpEvent.m in Sources */, 6033892B1D595AD50024A9BF /* ADTelemetryCacheEvent.m in Sources */, diff --git a/ADAL/src/ADAuthenticationContext.m b/ADAL/src/ADAuthenticationContext.m index ded23341d..e48bc6c82 100755 --- a/ADAL/src/ADAuthenticationContext.m +++ b/ADAL/src/ADAuthenticationContext.m @@ -33,7 +33,9 @@ #import "ADTelemetry.h" #import "ADTelemetry+Internal.h" #import "ADTelemetryAPIEvent.h" +#import "ADTelemetryEventStrings.h" #import "ADUserIdentifier.h" +#import "ADTokenCacheItem.h" typedef void(^ADAuthorizationCodeCallback)(NSString*, ADAuthenticationError*); @@ -598,10 +600,12 @@ - (void)fillTelemetryForAcquireTokenCall:(ADTelemetryAPIEvent*)event result:(ADAuthenticationResult*)result { [event setCorrelationId:[request.requestParams correlationId]]; - [event setUserId:[[request.requestParams identifier] userId]]; [event setClientId:[request.requestParams clientId]]; + [event setExtendedExpiresOnSetting:[request.requestParams extendedLifetime]? TELEMETRY_YES:TELEMETRY_NO]; + [event setPromptBehavior:[request promptBehavior]]; + [event setUserInformation:[[result tokenCacheItem] userInformation]]; [event setResultStatus:[result status]]; - [event setIsExtendedLifeTimeToken:[result extendedLifeTimeToken]? @"YES":@"NO"]; + [event setIsExtendedLifeTimeToken:[result extendedLifeTimeToken]? TELEMETRY_YES:TELEMETRY_NO]; [event setErrorCode:[NSString stringWithFormat:@"%ld",(long)[result.error code]]]; [event setErrorDomain:[result.error domain]]; [event setProtocolCode:[[result error] protocolCode]]; diff --git a/ADAL/src/cache/ADTokenCacheAccessor.m b/ADAL/src/cache/ADTokenCacheAccessor.m index 0643ff0c1..b47fa3be5 100644 --- a/ADAL/src/cache/ADTokenCacheAccessor.m +++ b/ADAL/src/cache/ADTokenCacheAccessor.m @@ -30,6 +30,7 @@ #import "ADTelemetry.h" #import "ADTelemetry+Internal.h" #import "ADTelemetryCacheEvent.h" +#import "ADTelemetryEventStrings.h" @implementation ADTokenCacheAccessor @@ -131,7 +132,11 @@ - (ADTokenCacheItem *)getMRRTItemForUser:(ADUserIdentifier *)identifier requestId:[requestParams telemetryRequestId] correlationId:[requestParams correlationId]]; [event setTokenType:@"multi-resource refresh token"]; - [event setStatus:item? @"succeeded" : @"failed"]; + if (item) + { + [event setIsMRRT:TELEMETRY_YES]; + } + [event setStatus:item? @"succeeded":@"failed"]; [[ADTelemetry sharedInstance] stopEvent:[requestParams telemetryRequestId] event:event]; SAFE_ARC_RELEASE(event); #endif @@ -157,6 +162,10 @@ - (ADTokenCacheItem *)getFRTItemForUser:(ADUserIdentifier *)identifier requestId:[requestParams telemetryRequestId] correlationId:[requestParams correlationId]]; [event setTokenType:@"family refresh token"]; + if (item) + { + [event setIsFRT:TELEMETRY_YES]; + } [event setStatus:item? @"succeeded" : @"failed"]; [[ADTelemetry sharedInstance] stopEvent:[requestParams telemetryRequestId] event:event]; SAFE_ARC_RELEASE(event); @@ -190,6 +199,10 @@ - (ADTokenCacheItem*)getADFSUserTokenForResource:(NSString *)resource requestId:[requestParams telemetryRequestId] correlationId:[requestParams correlationId]]; [event setTokenType:@"ADFS access token/refresh token"]; + if ([item refreshToken]) + { + [event setIsRT:TELEMETRY_YES]; + } [event setStatus:item? @"succeeded" : @"failed"]; [[ADTelemetry sharedInstance] stopEvent:[requestParams telemetryRequestId] event:event]; SAFE_ARC_RELEASE(event); @@ -278,6 +291,7 @@ - (void)updateCacheToItem:(ADTokenCacheItem *)cacheItem ADTelemetryCacheEvent* event = [[ADTelemetryCacheEvent alloc] initWithName:@"token_cache_write" requestId:telemetryRequestId correlationId:correlationId]; + [event setIsMRRT:TELEMETRY_YES]; [event setTokenType:@"multi-resource refresh token"]; [[ADTelemetry sharedInstance] stopEvent:telemetryRequestId event:event]; SAFE_ARC_RELEASE(event); @@ -299,6 +313,7 @@ - (void)updateCacheToItem:(ADTokenCacheItem *)cacheItem ADTelemetryCacheEvent* event = [[ADTelemetryCacheEvent alloc] initWithName:@"token_cache_write" requestId:telemetryRequestId correlationId:correlationId]; + [event setIsFRT:TELEMETRY_YES]; [event setTokenType:@"family refresh token"]; [[ADTelemetry sharedInstance] stopEvent:telemetryRequestId event:event]; SAFE_ARC_RELEASE(event); diff --git a/ADAL/src/request/ADAuthenticationRequest+AcquireToken.m b/ADAL/src/request/ADAuthenticationRequest+AcquireToken.m index 8afbefeea..bc3eab2c1 100644 --- a/ADAL/src/request/ADAuthenticationRequest+AcquireToken.m +++ b/ADAL/src/request/ADAuthenticationRequest+AcquireToken.m @@ -32,6 +32,7 @@ #import "ADTelemetry.h" #import "ADTelemetry+Internal.h" #import "ADTelemetryAPIEvent.h" +#import "ADTelemetryEventStrings.h" @implementation ADAuthenticationRequest (AcquireToken) @@ -92,7 +93,7 @@ - (void)acquireToken:(ADAuthenticationCallback)completionBlock ADTelemetryAPIEvent* event = [[ADTelemetryAPIEvent alloc] initWithName:@"authority_validation" requestId:telemetryRequestId correlationId:correlationId]; - [event setAuthorityValidationStatus:validated ? @"YES" : @"NO"]; + [event setAuthorityValidationStatus:validated ? TELEMETRY_YES:TELEMETRY_NO]; [event setAuthority:_context.authority]; [[ADTelemetry sharedInstance] stopEvent:telemetryRequestId event:event]; SAFE_ARC_RELEASE(event); diff --git a/ADAL/src/request/ADAuthenticationRequest.h b/ADAL/src/request/ADAuthenticationRequest.h index a4ce44837..a8adc6b5c 100644 --- a/ADAL/src/request/ADAuthenticationRequest.h +++ b/ADAL/src/request/ADAuthenticationRequest.h @@ -103,6 +103,7 @@ - (void)setCorrelationId:(NSUUID*)correlationId; - (NSUUID*)correlationId; - (NSString*)telemetryRequestId; +- (ADPromptBehavior)promptBehavior; - (ADRequestParameters*)requestParams; #if AD_BROKER - (NSString*)redirectUri; diff --git a/ADAL/src/request/ADAuthenticationRequest.m b/ADAL/src/request/ADAuthenticationRequest.m index 78a8b0e24..09bd76057 100644 --- a/ADAL/src/request/ADAuthenticationRequest.m +++ b/ADAL/src/request/ADAuthenticationRequest.m @@ -296,6 +296,11 @@ - (NSString*)telemetryRequestId return [_requestParams telemetryRequestId]; } +- (ADPromptBehavior)promptBehavior +{ + return _promptBehavior; +} + - (ADRequestParameters*)requestParams { return _requestParams; diff --git a/ADAL/src/telemetry/ADAggregatedDispatcher.m b/ADAL/src/telemetry/ADAggregatedDispatcher.m index b464503d1..71a2b7136 100644 --- a/ADAL/src/telemetry/ADAggregatedDispatcher.m +++ b/ADAL/src/telemetry/ADAggregatedDispatcher.m @@ -47,27 +47,20 @@ - (void)flush:(NSString*)requestId [_objectsToBeDispatched removeObjectForKey:requestId]; [_dispatchLock unlock]; - // Integrate events of a particular request id into one single event + NSMutableDictionary* aggregatedEventMap = [NSMutableDictionary new]; + for (id event in eventsToBeDispatched) + { + [event processEvent:aggregatedEventMap]; + } + + // convert the aggregated event from a map to a list NSMutableArray* aggregatedEvent = [NSMutableArray new]; SAFE_ARC_AUTORELEASE(aggregatedEvent); - - for (id event in eventsToBeDispatched) + for (NSString* key in aggregatedEventMap) { - NSArray* properties = [event getProperties]; - - NSInteger propertiesToSkip = 0; - // default properties are duplicate for all events, - // so they are skipped from 2nd event onwards - if (event != [eventsToBeDispatched objectAtIndex:0]) - { - propertiesToSkip = [event getDefaultPropertyCount]; - } - - for (NSInteger i = propertiesToSkip; i < [properties count]; i++) - { - [aggregatedEvent addObject:properties[i]]; - } + [aggregatedEvent addObject:@[key, [aggregatedEventMap objectForKey:key]]]; } + [_dispatcher dispatch:aggregatedEvent]; } diff --git a/ADAL/src/telemetry/ADTelemetryAPIEvent.h b/ADAL/src/telemetry/ADTelemetryAPIEvent.h index 3079469a1..273660572 100644 --- a/ADAL/src/telemetry/ADTelemetryAPIEvent.h +++ b/ADAL/src/telemetry/ADTelemetryAPIEvent.h @@ -27,7 +27,9 @@ - (void)setResultStatus:(ADAuthenticationResultStatus)status; - (void)setCorrelationId:(NSUUID*)correlationId; -- (void)setUserId:(NSString*)userId; +- (void)setExtendedExpiresOnSetting:(NSString*)extendedExpiresOnSetting; +- (void)setPromptBehavior:(ADPromptBehavior)promptBehavior; +- (void)setUserInformation:(ADUserInformation*)userInfo; - (void)setClientId:(NSString*)clientId; - (void)setIsExtendedLifeTimeToken:(NSString*)isExtendedLifeToken; - (void)setErrorCode:(NSString*)errorCode; diff --git a/ADAL/src/telemetry/ADTelemetryAPIEvent.m b/ADAL/src/telemetry/ADTelemetryAPIEvent.m index fa855935e..c0c017cd3 100644 --- a/ADAL/src/telemetry/ADTelemetryAPIEvent.m +++ b/ADAL/src/telemetry/ADTelemetryAPIEvent.m @@ -22,6 +22,9 @@ // THE SOFTWARE. #import "ADTelemetryAPIEvent.h" +#import "ADUserInformation.h" +#import "ADTelemetryEventStrings.h" +#import "ADHelpers.h" @implementation ADTelemetryAPIEvent @@ -30,19 +33,20 @@ - (void)setResultStatus:(ADAuthenticationResultStatus)status NSString* statusStr = nil; switch (status) { case AD_SUCCEEDED: - statusStr = @"SUCCEEDED"; + statusStr = TELEMETRY_SUCCEEDED; break; case AD_FAILED: - statusStr = @"FAILED"; + statusStr = TELEMETRY_FAILED; break; case AD_USER_CANCELLED: - statusStr = @"USER_CANCELLED"; + statusStr = TELEMETRY_USER_CANCELLED; + [self setProperty:TELEMETRY_USER_CANCEL value:TELEMETRY_YES]; break; default: - statusStr = @"UNKNOWN"; + statusStr = TELEMETRY_UNKNOWN; } - [self setProperty:@"status" value:statusStr]; + [self setProperty:TELEMETRY_RESULT_STATUS value:statusStr]; } - (void)setCorrelationId:(NSUUID*)correlationId @@ -50,9 +54,16 @@ - (void)setCorrelationId:(NSUUID*)correlationId [self setProperty:@"correlation_id" value:[correlationId UUIDString]]; } -- (void)setUserId:(NSString*)userId; +- (void)setExtendedExpiresOnSetting:(NSString*)extendedExpiresOnSetting { - [self setProperty:@"user_id" value:[userId adComputeSHA256]]; + [self setProperty:TELEMETRY_EXTENDED_EXPIRES_ON_SETTING value:extendedExpiresOnSetting]; +} + +- (void)setUserInformation:(ADUserInformation*)userInfo +{ + [self setProperty:TELEMETRY_USER_ID value:[[userInfo userId] adComputeSHA256]]; + [self setProperty:TELEMETRY_TENANT_ID value:[[userInfo tenantId] adComputeSHA256]]; + [self setProperty:TELEMETRY_IDP value:[userInfo identityProvider]]; } - (void)setClientId:(NSString*)clientId @@ -87,27 +98,84 @@ - (void)setErrorDomain:(NSString*)errorDomain - (void)setAuthorityValidationStatus:(NSString*)status { - [self setProperty:@"validation_status" value:status]; + [self setProperty:TELEMETRY_AUTHORITY_VALIDATION_STATUS value:status]; } - (void)setAuthority:(NSString*)authority { - [self setProperty:@"authority" value:authority]; + [self setProperty:TELEMETRY_AUTHORITY value:authority]; + + // set authority type + NSString* authorityType = TELEMETRY_AUTHORITY_AAD; + if ([ADHelpers isADFSInstance:authority]) + { + authorityType = TELEMETRY_AUTHORITY_ADFS; + } + [self setProperty:TELEMETRY_AUTHORITY_TYPE value:authorityType]; } - (void)setGrantType:(NSString*)grantType { - [self setProperty:@"grant_type" value:grantType]; + [self setProperty:TELEMETRY_GRANT_TYPE value:grantType]; } - (void)setAPIStatus:(NSString*)status { - [self setProperty:@"api_status" value:status]; + [self setProperty:TELEMETRY_API_STATUS value:status]; } - (void)setApiId:(NSString*)apiId { - [self setProperty:@"api_id" value:apiId]; + [self setProperty:TELEMETRY_API_ID value:apiId]; +} + +- (void)setPromptBehavior:(ADPromptBehavior)promptBehavior +{ + NSString* promptBehaviorString = nil; + switch (promptBehavior) { + case AD_PROMPT_AUTO: + promptBehaviorString = @"AD_PROMPT_AUTO"; + break; + case AD_PROMPT_ALWAYS: + promptBehaviorString = @"AD_PROMPT_ALWAYS"; + break; + case AD_PROMPT_REFRESH_SESSION: + promptBehaviorString = @"AD_PROMPT_REFRESH_SESSION"; + break; + case AD_FORCE_PROMPT: + promptBehaviorString = @"AD_FORCE_PROMPT"; + break; + default: + promptBehaviorString = TELEMETRY_UNKNOWN; + } + + [self setProperty:TELEMETRY_PROMPT_BEHAVIOR value:promptBehaviorString]; +} + +- (void)processEvent:(NSMutableDictionary*)eventToBeDispatched +{ + [super processEvent:eventToBeDispatched]; + + (void)eventToBeDispatched; + NSArray* properties = [self getProperties]; + for (NSArray* property in properties) + { + if ([property[0] isEqualToString:TELEMETRY_AUTHORITY_TYPE] + ||[property[0] isEqualToString:TELEMETRY_AUTHORITY_VALIDATION_STATUS] + ||[property[0] isEqualToString:TELEMETRY_EXTENDED_EXPIRES_ON_SETTING] + ||[property[0] isEqualToString:TELEMETRY_PROMPT_BEHAVIOR] + ||[property[0] isEqualToString:TELEMETRY_RESULT_STATUS] + ||[property[0] isEqualToString:TELEMETRY_IDP] + ||[property[0] isEqualToString:TELEMETRY_TENANT_ID] + ||[property[0] isEqualToString:TELEMETRY_USER_ID] + ||[property[0] isEqualToString:TELEMETRY_RESPONSE_TIME] + ||[property[0] isEqualToString:TELEMETRY_CLIENT_ID] + ||[property[0] isEqualToString:TELEMETRY_API_ID] + ||[property[0] isEqualToString:TELEMETRY_USER_CANCEL]) + { + [eventToBeDispatched setObject:property[1] forKey:property[0]]; + } + } } @end \ No newline at end of file diff --git a/ADAL/src/telemetry/ADTelemetryBrokerEvent.m b/ADAL/src/telemetry/ADTelemetryBrokerEvent.m index 915740e03..0b6538846 100644 --- a/ADAL/src/telemetry/ADTelemetryBrokerEvent.m +++ b/ADAL/src/telemetry/ADTelemetryBrokerEvent.m @@ -22,6 +22,7 @@ // THE SOFTWARE. #import "ADTelemetryBrokerEvent.h" +#import "ADTelemetryEventStrings.h" @implementation ADTelemetryBrokerEvent @@ -40,7 +41,7 @@ -(id) init - (void)setBrokerAppVersion:(NSString*)version { - [self setProperty:@"broker_app_version" value:version]; + [self setProperty:TELEMETRY_BROKER_VERSION value:version]; } - (void)setBrokerProtocolVersion:(NSString*)version @@ -70,7 +71,24 @@ - (void)setResultStatus:(ADAuthenticationResultStatus)status - (void)setBrokerApp:(NSString*)appName { - [self setProperty:@"broker_app" value:appName]; + [self setProperty:TELEMETRY_BROKER_APP value:appName]; +} + +- (void)processEvent:(NSMutableDictionary*)eventToBeDispatched +{ + [super processEvent:eventToBeDispatched]; + + (void)eventToBeDispatched; + NSArray* properties = [self getProperties]; + for (NSArray* property in properties) + { + if ([property[0] isEqualToString:TELEMETRY_BROKER_APP] + ||[property[0] isEqualToString:TELEMETRY_BROKER_VERSION]) + { + [eventToBeDispatched setObject:property[1] forKey:property[0]]; + } + } + [eventToBeDispatched setObject:TELEMETRY_YES forKey:TELEMETRY_BROKER_APP_USED]; } @end \ No newline at end of file diff --git a/ADAL/src/telemetry/ADTelemetryCacheEvent.h b/ADAL/src/telemetry/ADTelemetryCacheEvent.h index 50e4283c8..f51ae3658 100644 --- a/ADAL/src/telemetry/ADTelemetryCacheEvent.h +++ b/ADAL/src/telemetry/ADTelemetryCacheEvent.h @@ -27,5 +27,8 @@ - (void)setTokenType:(NSString*)tokenType; - (void)setStatus:(NSString*)status; +- (void)setIsRT:(NSString*)isRT; +- (void)setIsMRRT:(NSString*)isMRRT; +- (void)setIsFRT:(NSString*)isFRT; @end \ No newline at end of file diff --git a/ADAL/src/telemetry/ADTelemetryCacheEvent.m b/ADAL/src/telemetry/ADTelemetryCacheEvent.m index dd4837d9f..931166253 100644 --- a/ADAL/src/telemetry/ADTelemetryCacheEvent.m +++ b/ADAL/src/telemetry/ADTelemetryCacheEvent.m @@ -22,12 +22,13 @@ // THE SOFTWARE. #import "ADTelemetryCacheEvent.h" +#import "ADTelemetryEventStrings.h" @implementation ADTelemetryCacheEvent - (void)setTokenType:(NSString*)tokenType { - [self setProperty:@"token_type" value:tokenType]; + [self setProperty:TELEMETRY_TOKEN_TYPE value:tokenType]; } - (void)setStatus:(NSString*)status @@ -35,4 +36,46 @@ - (void)setStatus:(NSString*)status [self setProperty:@"status" value:status]; } +- (void)setIsRT:(NSString*)isRT +{ + [self setProperty:TELEMETRY_IS_RT value:isRT]; +} + +- (void)setIsMRRT:(NSString*)isMRRT +{ + [self setProperty:TELEMETRY_IS_MRRT value:isMRRT]; +} + +- (void)setIsFRT:(NSString*)isFRT +{ + [self setProperty:TELEMETRY_IS_FRT value:isFRT]; +} + +- (void)processEvent:(NSMutableDictionary*)eventToBeDispatched +{ + [super processEvent:eventToBeDispatched]; + + (void)eventToBeDispatched; + NSArray* properties = [self getProperties]; + for (NSArray* property in properties) + { + if ([property[0] isEqualToString:TELEMETRY_IS_RT] + ||[property[0] isEqualToString:TELEMETRY_IS_MRRT] + ||[property[0] isEqualToString:TELEMETRY_IS_FRT]) + { + [eventToBeDispatched removeObjectForKey:TELEMETRY_IS_RT]; + [eventToBeDispatched removeObjectForKey:TELEMETRY_IS_MRRT]; + [eventToBeDispatched removeObjectForKey:TELEMETRY_IS_FRT]; + [eventToBeDispatched setObject:property[1] forKey:property[0]]; + } + } + + int cacheEventCount = 1; + if ([eventToBeDispatched objectForKey:TELEMETRY_CACHE_EVENT_COUNT]) + { + cacheEventCount = [[eventToBeDispatched objectForKey:TELEMETRY_CACHE_EVENT_COUNT] intValue] + 1; + } + [eventToBeDispatched setObject:[NSString stringWithFormat:@"%d", cacheEventCount] forKey:TELEMETRY_CACHE_EVENT_COUNT]; +} + @end \ No newline at end of file diff --git a/ADAL/src/telemetry/ADTelemetryDefaultEvent.m b/ADAL/src/telemetry/ADTelemetryDefaultEvent.m index 4a7c22b7f..a530b9cf7 100644 --- a/ADAL/src/telemetry/ADTelemetryDefaultEvent.m +++ b/ADAL/src/telemetry/ADTelemetryDefaultEvent.m @@ -23,6 +23,7 @@ #import "ADTelemetryDefaultEvent.h" #import "ADTelemetryEventInterface.h" +#import "ADTelemetryEventStrings.h" #import "ADLogger.h" #if !TARGET_OS_IPHONE @@ -107,7 +108,7 @@ - (void)setStopTime:(NSDate*)time - (void)setResponseTime:(NSTimeInterval)responseTime { //the property is set in milliseconds - [_propertyMap addObject:@[@"response_time", [NSString stringWithFormat:@"%f", responseTime*1000]]]; + [_propertyMap addObject:@[TELEMETRY_RESPONSE_TIME, [NSString stringWithFormat:@"%f", responseTime*1000]]]; } - (NSString*)getStringFromDate:(NSDate*)date @@ -124,6 +125,14 @@ - (NSString*)getStringFromDate:(NSDate*)date return [s_dateFormatter stringFromDate:date]; } +- (void)processEvent:(NSMutableDictionary*)eventToBeDispatched +{ + for (int i=0; i<[self getDefaultPropertyCount]; i++) + { + [eventToBeDispatched setObject:_propertyMap[i][1] forKey:_propertyMap[i][0]]; + } +} + - (NSArray*)defaultParameters { static NSMutableArray* s_defaultParameters; diff --git a/ADAL/src/telemetry/ADTelemetryEventInterface.h b/ADAL/src/telemetry/ADTelemetryEventInterface.h index 56ef4219f..dd7bb4fae 100644 --- a/ADAL/src/telemetry/ADTelemetryEventInterface.h +++ b/ADAL/src/telemetry/ADTelemetryEventInterface.h @@ -31,5 +31,6 @@ - (void)setStartTime:(NSDate*)time; - (void)setStopTime:(NSDate*)time; - (void)setResponseTime:(NSTimeInterval)responseTime; +- (void)processEvent:(NSMutableDictionary*)eventToBeDispatched; @end \ No newline at end of file diff --git a/ADAL/src/telemetry/ADTelemetryEventStrings.h b/ADAL/src/telemetry/ADTelemetryEventStrings.h new file mode 100644 index 000000000..5efe61282 --- /dev/null +++ b/ADAL/src/telemetry/ADTelemetryEventStrings.h @@ -0,0 +1,66 @@ +// Copyright (c) Microsoft Corporation. +// All rights reserved. +// +// This code is licensed under the MIT License. +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files(the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and / or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions : +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE. + +#pragma once + +extern NSString *const TELEMETRY_AUTHORITY_TYPE; +extern NSString *const TELEMETRY_AUTHORITY_VALIDATION_STATUS; +extern NSString *const TELEMETRY_EXTENDED_EXPIRES_ON_SETTING; +extern NSString *const TELEMETRY_PROMPT_BEHAVIOR; +extern NSString *const TELEMETRY_RESULT_STATUS; +extern NSString *const TELEMETRY_IDP; +extern NSString *const TELEMETRY_TENANT_ID; +extern NSString *const TELEMETRY_USER_ID; +extern NSString *const TELEMETRY_RESPONSE_TIME; +extern NSString *const TELEMETRY_LOGIN_HINT; +extern NSString *const TELEMETRY_UI_EVENT_COUNT; +extern NSString *const TELEMETRY_BROKER_APP; +extern NSString *const TELEMETRY_BROKER_VERSION; +extern NSString *const TELEMETRY_BROKER_APP_USED; +extern NSString *const TELEMETRY_CLIENT_ID; +extern NSString *const TELEMETRY_HTTP_EVENT_COUNT; +extern NSString *const TELEMETRY_CACHE_EVENT_COUNT; +extern NSString *const TELEMETRY_API_ID; +extern NSString *const TELEMETRY_TOKEN_TYPE; +extern NSString *const TELEMETRY_USER_CANCEL; +extern NSString *const TELEMETRY_IS_RT; +extern NSString *const TELEMETRY_IS_MRRT; +extern NSString *const TELEMETRY_IS_FRT; +extern NSString *const TELEMETRY_YES; +extern NSString *const TELEMETRY_NO; +extern NSString *const TELEMETRY_SUCCEEDED; +extern NSString *const TELEMETRY_FAILED; +extern NSString *const TELEMETRY_USER_CANCELLED; +extern NSString *const TELEMETRY_UNKNOWN; +extern NSString *const TELEMETRY_CORRELATION_ID; +extern NSString *const TELEMETRY_CLIENT_ID; +extern NSString *const TELEMETRY_IS_EXTENED_LIFE_TIME_TOKEN; +extern NSString *const TELEMETRY_ERROR_CODE; +extern NSString *const TELEMETRY_PROTOCOL_CODE; +extern NSString *const TELEMETRY_ERROR_DESCRIPTION; +extern NSString *const TELEMETRY_ERROR_DOMAIN; +extern NSString *const TELEMETRY_AUTHORITY; +extern NSString *const TELEMETRY_AUTHORITY_AAD; +extern NSString *const TELEMETRY_AUTHORITY_ADFS; +extern NSString *const TELEMETRY_GRANT_TYPE; +extern NSString *const TELEMETRY_API_STATUS; \ No newline at end of file diff --git a/ADAL/src/telemetry/ADTelemetryEventStrings.m b/ADAL/src/telemetry/ADTelemetryEventStrings.m new file mode 100644 index 000000000..0fbee8e3c --- /dev/null +++ b/ADAL/src/telemetry/ADTelemetryEventStrings.m @@ -0,0 +1,66 @@ +// Copyright (c) Microsoft Corporation. +// All rights reserved. +// +// This code is licensed under the MIT License. +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files(the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and / or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions : +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE. + +#import "ADTelemetryEventStrings.h" + +NSString *const TELEMETRY_AUTHORITY_TYPE = @"authority_type"; +NSString *const TELEMETRY_AUTHORITY_VALIDATION_STATUS = @"authority_validation_status"; +NSString *const TELEMETRY_EXTENDED_EXPIRES_ON_SETTING = @"extended_expires_on_setting"; +NSString *const TELEMETRY_PROMPT_BEHAVIOR = @"prompt_behavior"; +NSString *const TELEMETRY_RESULT_STATUS = @"status"; +NSString *const TELEMETRY_IDP = @"idp"; +NSString *const TELEMETRY_TENANT_ID = @"tenant_id"; +NSString *const TELEMETRY_USER_ID = @"user_id"; +NSString *const TELEMETRY_RESPONSE_TIME = @"response_time"; +NSString *const TELEMETRY_LOGIN_HINT = @"login_hint"; +NSString *const TELEMETRY_UI_EVENT_COUNT = @"ui_event_count"; +NSString *const TELEMETRY_BROKER_APP = @"broker_app"; +NSString *const TELEMETRY_BROKER_VERSION = @"broker_version"; +NSString *const TELEMETRY_BROKER_APP_USED = @"broker_app_used"; +NSString *const TELEMETRY_CLIENT_ID = @"client_id"; +NSString *const TELEMETRY_HTTP_EVENT_COUNT = @"http_event_count"; +NSString *const TELEMETRY_CACHE_EVENT_COUNT = @"cache_event_count"; +NSString *const TELEMETRY_API_ID = @"api_id"; +NSString *const TELEMETRY_TOKEN_TYPE = @"token_type"; +NSString *const TELEMETRY_USER_CANCEL = @"user_cancel"; +NSString *const TELEMETRY_IS_RT = @"is_rt"; +NSString *const TELEMETRY_IS_MRRT = @"is_mrrt"; +NSString *const TELEMETRY_IS_FRT = @"is_frt"; +NSString *const TELEMETRY_YES = @"yes"; +NSString *const TELEMETRY_NO = @"no"; +NSString *const TELEMETRY_SUCCEEDED = @"succeeded"; +NSString *const TELEMETRY_FAILED = @"failed"; +NSString *const TELEMETRY_USER_CANCELLED = @"user_cancelled"; +NSString *const TELEMETRY_UNKNOWN = @"unknown"; +NSString *const TELEMETRY_CORRELATION_ID = +NSString *const TELEMETRY_CLIENT_ID; +NSString *const TELEMETRY_IS_EXTENED_LIFE_TIME_TOKEN; +NSString *const TELEMETRY_ERROR_CODE; +NSString *const TELEMETRY_PROTOCOL_CODE; +NSString *const TELEMETRY_ERROR_DESCRIPTION; +NSString *const TELEMETRY_ERROR_DOMAIN; +NSString *const TELEMETRY_AUTHORITY = @"authority"; +NSString *const TELEMETRY_AUTHORITY_AAD = @"aad"; +NSString *const TELEMETRY_AUTHORITY_ADFS = @"adfs"; +NSString *const TELEMETRY_GRANT_TYPE = @"grant_type"; +NSString *const TELEMETRY_API_STATUS = @"api_status"; \ No newline at end of file diff --git a/ADAL/src/telemetry/ADTelemetryHttpEvent.m b/ADAL/src/telemetry/ADTelemetryHttpEvent.m index 5358456da..69bd9fe59 100644 --- a/ADAL/src/telemetry/ADTelemetryHttpEvent.m +++ b/ADAL/src/telemetry/ADTelemetryHttpEvent.m @@ -22,6 +22,7 @@ // THE SOFTWARE. #import "ADTelemetryHttpEvent.h" +#import "ADTelemetryEventStrings.h" @implementation ADTelemetryHttpEvent @@ -60,6 +61,20 @@ - (void)setHttpErrorDomain:(NSString*)errorDomain [self setProperty:@"http_error_domain" value:errorDomain]; } +- (void)processEvent:(NSMutableDictionary*)eventToBeDispatched +{ + [super processEvent:eventToBeDispatched]; + + (void)eventToBeDispatched; + + int httpEventCount = 1; + if ([eventToBeDispatched objectForKey:TELEMETRY_HTTP_EVENT_COUNT]) + { + httpEventCount = [[eventToBeDispatched objectForKey:TELEMETRY_HTTP_EVENT_COUNT] intValue] + 1; + } + [eventToBeDispatched setObject:[NSString stringWithFormat:@"%d", httpEventCount] forKey:TELEMETRY_HTTP_EVENT_COUNT]; +} + - (NSString*)scrubTenantFromUrl:(NSString*)url { //Scrub the tenant domain from the url diff --git a/ADAL/src/telemetry/ADTelemetryUIEvent.m b/ADAL/src/telemetry/ADTelemetryUIEvent.m index 0ecd4ed72..e35b31794 100644 --- a/ADAL/src/telemetry/ADTelemetryUIEvent.m +++ b/ADAL/src/telemetry/ADTelemetryUIEvent.m @@ -22,12 +22,35 @@ // THE SOFTWARE. #import "ADTelemetryUIEvent.h" +#import "ADTelemetryEventStrings.h" @implementation ADTelemetryUIEvent - (void)setLoginHint:(NSString*)hint { - [self setProperty:@"login_hint" value:[hint adComputeSHA256]]; + [self setProperty:TELEMETRY_LOGIN_HINT value:[hint adComputeSHA256]]; +} + +- (void)processEvent:(NSMutableDictionary*)eventToBeDispatched +{ + [super processEvent:eventToBeDispatched]; + + (void)eventToBeDispatched; + NSArray* properties = [self getProperties]; + for (NSArray* property in properties) + { + if ([property[0] isEqualToString:TELEMETRY_LOGIN_HINT]) + { + [eventToBeDispatched setObject:property[1] forKey:property[0]]; + } + } + + int UIEventCount = 1; + if ([eventToBeDispatched objectForKey:TELEMETRY_UI_EVENT_COUNT]) + { + UIEventCount = [[eventToBeDispatched objectForKey:TELEMETRY_UI_EVENT_COUNT] intValue] + 1; + } + [eventToBeDispatched setObject:[NSString stringWithFormat:@"%d", UIEventCount] forKey:TELEMETRY_UI_EVENT_COUNT]; } @end \ No newline at end of file From 890dedbe0e60dbe802875838f40f3f1d2b148093 Mon Sep 17 00:00:00 2001 From: Ryan Pangrle Date: Tue, 20 Sep 2016 18:12:56 -0700 Subject: [PATCH 24/92] Object Model changes for broker refactor Typedef the completionBlock type for ADWebAuthRequest Define an ADRequestContext protocol for passing through the correlation ID and telemetry ID into internal ADAL APIs Change many internal ADAL APIs to accept a id Fix ADUserIdentifier to conform to NSCopying --- ADAL/ADAL.xcodeproj/project.pbxproj | 2 + ADAL/src/ADAuthenticationContext+Internal.h | 5 ++ ADAL/src/ADAuthenticationContext+Internal.m | 28 +++++++ ADAL/src/ADAuthenticationContext.m | 27 ------ ADAL/src/ADAuthenticationParameters.m | 2 +- ADAL/src/ADInstanceDiscovery.m | 2 +- ADAL/src/ADLogger+Internal.h | 2 + ADAL/src/ADLogger.m | 9 +- ADAL/src/ADRequestContext.h | 32 ++++++++ ADAL/src/ADRequestParameters.h | 7 +- ADAL/src/ADRequestParameters.m | 23 ++++++ ADAL/src/ADUserIdentifier.m | 14 ++++ ADAL/src/cache/ADTokenCacheAccessor.h | 11 +-- ADAL/src/cache/ADTokenCacheAccessor.m | 82 ++++++++++--------- ADAL/src/cache/ADTokenCacheItem+Internal.m | 2 +- ADAL/src/public/ADAuthenticationResult.h | 2 +- ADAL/src/public/ADUserIdentifier.h | 2 +- ADAL/src/public/ios/ADKeychainTokenCache.h | 4 +- .../src/request/ADAcquireTokenSilentHandler.h | 5 +- .../src/request/ADAcquireTokenSilentHandler.m | 47 +++++++---- .../ADAuthenticationRequest+AcquireToken.m | 9 +- .../request/ADAuthenticationRequest+Broker.m | 2 +- .../ADAuthenticationRequest+WebRequest.m | 6 +- ADAL/src/request/ADAuthenticationRequest.m | 9 +- ADAL/src/request/ADWebAuthRequest.h | 2 +- ADAL/src/request/ADWebAuthRequest.m | 6 +- ADAL/src/request/ADWebAuthResponse.h | 6 +- ADAL/src/request/ADWebAuthResponse.m | 20 +++-- ADAL/src/request/ADWebRequest.h | 6 +- ADAL/src/request/ADWebRequest.m | 6 +- ADAL/src/ui/ADWebAuthController.m | 2 +- 31 files changed, 247 insertions(+), 135 deletions(-) create mode 100644 ADAL/src/ADRequestContext.h diff --git a/ADAL/ADAL.xcodeproj/project.pbxproj b/ADAL/ADAL.xcodeproj/project.pbxproj index 6c68111fe..a59885d7d 100755 --- a/ADAL/ADAL.xcodeproj/project.pbxproj +++ b/ADAL/ADAL.xcodeproj/project.pbxproj @@ -537,6 +537,7 @@ 946818A41C59B7EE00CA0378 /* ADWebAuthController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = ADWebAuthController.m; sourceTree = ""; }; 946818A51C59B7EE00CA0378 /* ADWebAuthController+Internal.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "ADWebAuthController+Internal.h"; sourceTree = ""; }; 946818A81C59B80800CA0378 /* ADAuthenticationViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ADAuthenticationViewController.m; sourceTree = ""; }; + 94A0BDE61D779AB0007BEB63 /* ADRequestContext.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ADRequestContext.h; sourceTree = ""; }; 94DD18C91C5A00BC00F80C62 /* ADAuthenticationViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ADAuthenticationViewController.m; sourceTree = ""; }; 94DD18E11C5ACFBF00F80C62 /* ADAL Mac Tests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = "ADAL Mac Tests.xctest"; sourceTree = BUILT_PRODUCTS_DIR; }; 94DD19011C5AD39A00F80C62 /* ADALiOSTests-Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = "ADALiOSTests-Info.plist"; sourceTree = ""; }; @@ -720,6 +721,7 @@ 97A522481A1A752D001D77CE /* ADClientMetrics.m */, 97A522511A1A89C4001D77CE /* ADClientMetrics.h */, D6FB3E3B1B30D3630032F883 /* ADUserIdentifier.m */, + 94A0BDE61D779AB0007BEB63 /* ADRequestContext.h */, 60D2F3FE1D524F7A008725D9 /* ADRequestParameters.h */, 60D2F4001D531F16008725D9 /* ADRequestParameters.m */, 9453C3771C58017F006B9E79 /* broker */, diff --git a/ADAL/src/ADAuthenticationContext+Internal.h b/ADAL/src/ADAuthenticationContext+Internal.h index 5ab51e159..5ce2cccd3 100644 --- a/ADAL/src/ADAuthenticationContext+Internal.h +++ b/ADAL/src/ADAuthenticationContext+Internal.h @@ -70,6 +70,11 @@ extern NSString* const ADRedirectUriInvalidError; errorCode:(ADErrorCode)errorCode; +- (id)initWithAuthority:(NSString *)authority + validateAuthority:(BOOL)validateAuthority + tokenCache:(id)tokenCache + error:(ADAuthenticationError *__autoreleasing *)error; + + (BOOL)isFinalResult:(ADAuthenticationResult *)result; + (NSString*)getPromptParameter:(ADPromptBehavior)prompt; diff --git a/ADAL/src/ADAuthenticationContext+Internal.m b/ADAL/src/ADAuthenticationContext+Internal.m index 0584fa811..ba390262f 100644 --- a/ADAL/src/ADAuthenticationContext+Internal.m +++ b/ADAL/src/ADAuthenticationContext+Internal.m @@ -24,6 +24,7 @@ #import "ADAuthenticationContext+Internal.h" #import "ADUserIdentifier.h" #import "ADTokenCacheItem+Internal.h" +#import "ADInstanceDiscovery.h" NSString* const ADUnknownError = @"Uknown error."; NSString* const ADCredentialsNeeded = @"The user credentials are needed to obtain access token. Please call the non-silent acquireTokenWithResource methods."; @@ -34,6 +35,33 @@ @implementation ADAuthenticationContext (Internal) +- (id)initWithAuthority:(NSString *)authority + validateAuthority:(BOOL)validateAuthority + tokenCache:(id)tokenCache + error:(ADAuthenticationError *__autoreleasing *)error +{ + API_ENTRY; + if (!(self = [super init])) + { + return nil; + } + + NSString* extractedAuthority = [ADInstanceDiscovery canonicalizeAuthority:authority]; + if (!extractedAuthority) + { + SAFE_ARC_RELEASE(self); + RETURN_ON_INVALID_ARGUMENT(!extractedAuthority, authority, nil); + } + + _authority = extractedAuthority; + _validateAuthority = validateAuthority; + _credentialsType = AD_CREDENTIALS_EMBEDDED; + _extendedLifetimeEnabled = NO; + [self setTokenCacheStore:tokenCache]; + + return self; +} + // ADAL_RESILIENCY_NOT_YET: Remove when feature goes into public API - (BOOL)extendedLifetimeEnabled { diff --git a/ADAL/src/ADAuthenticationContext.m b/ADAL/src/ADAuthenticationContext.m index ded23341d..dcf479bb0 100755 --- a/ADAL/src/ADAuthenticationContext.m +++ b/ADAL/src/ADAuthenticationContext.m @@ -85,33 +85,6 @@ - (id)initWithAuthority:(NSString*) authority } #endif -- (id)initWithAuthority:(NSString *)authority - validateAuthority:(BOOL)validateAuthority - tokenCache:(id)tokenCache - error:(ADAuthenticationError *__autoreleasing *)error -{ - API_ENTRY; - if (!(self = [super init])) - { - return nil; - } - - NSString* extractedAuthority = [ADInstanceDiscovery canonicalizeAuthority:authority]; - if (!extractedAuthority) - { - SAFE_ARC_RELEASE(self); - RETURN_ON_INVALID_ARGUMENT(!extractedAuthority, authority, nil); - } - - _authority = extractedAuthority; - _validateAuthority = validateAuthority; - _credentialsType = AD_CREDENTIALS_EMBEDDED; - _extendedLifetimeEnabled = NO; - [self setTokenCacheStore:tokenCache]; - - return self; -} - - (id)initWithAuthority:(NSString *)authority validateAuthority:(BOOL)validateAuthority cacheDelegate:(id) delegate diff --git a/ADAL/src/ADAuthenticationParameters.m b/ADAL/src/ADAuthenticationParameters.m index acd9b9638..a04739bb9 100644 --- a/ADAL/src/ADAuthenticationParameters.m +++ b/ADAL/src/ADAuthenticationParameters.m @@ -90,7 +90,7 @@ + (void)parametersFromResourceUrl:(NSURL*)resourceUrl return; } - ADWebRequest* request = [[ADWebRequest alloc] initWithURL:resourceUrl requestParams:nil]; + ADWebRequest* request = [[ADWebRequest alloc] initWithURL:resourceUrl context:nil]; [request setIsGetRequest:YES]; AD_LOG_VERBOSE_F(@"Starting authorization challenge request", nil, @"Resource: %@", resourceUrl); diff --git a/ADAL/src/ADInstanceDiscovery.m b/ADAL/src/ADInstanceDiscovery.m index a4854855f..e05c997b2 100644 --- a/ADAL/src/ADInstanceDiscovery.m +++ b/ADAL/src/ADInstanceDiscovery.m @@ -291,7 +291,7 @@ - (void)requestValidationOfAuthority:(NSString *)authority AD_LOG_VERBOSE(@"Authority Validation Request", correlationId, endPoint); ADWebRequest *webRequest = [[ADWebRequest alloc] initWithURL:[NSURL URLWithString:endPoint] - requestParams:requestParams]; + context:requestParams]; [webRequest setIsGetRequest:YES]; [webRequest.headers setObject:@"application/json" forKey:@"Accept"]; diff --git a/ADAL/src/ADLogger+Internal.h b/ADAL/src/ADLogger+Internal.h index b6c450811..2571cf396 100644 --- a/ADAL/src/ADLogger+Internal.h +++ b/ADAL/src/ADLogger+Internal.h @@ -87,6 +87,8 @@ the actual contents, but still want to log something that can be correlated. */ + (NSString*)getHash:(NSString*)input; ++ (void)setAdalVersion:(NSString*)version; + + (NSString*)getAdalVersion; + (NSString*)getCPUInfo; diff --git a/ADAL/src/ADLogger.m b/ADAL/src/ADLogger.m index 08af6c396..17f4e1bb1 100644 --- a/ADAL/src/ADLogger.m +++ b/ADAL/src/ADLogger.m @@ -245,7 +245,7 @@ + (NSDictionary*)adalId NSMutableDictionary* result = [NSMutableDictionary dictionaryWithDictionary: @{ ADAL_ID_PLATFORM:@"OSX", - ADAL_ID_VERSION:[NSString stringWithFormat:@"%d.%d", ADAL_VER_HIGH, ADAL_VER_LOW], + ADAL_ID_VERSION:[NSString stringWithFormat:@"%d.%d.%d", ADAL_VER_HIGH, ADAL_VER_LOW, ADAL_VER_PATCH], ADAL_ID_OS_VER:[NSString stringWithFormat:@"%ld.%ld.%ld", (long)osVersion.majorVersion, (long)osVersion.minorVersion, (long)osVersion.patchVersion], }]; #endif @@ -262,6 +262,11 @@ + (NSDictionary*)adalId return s_adalId; } ++ (void)setAdalVersion:(NSString*)version +{ + [s_adalId setObject:version forKey:ADAL_ID_VERSION]; +} + + (NSString*)getHash:(NSString*)input { if (!input) @@ -280,7 +285,7 @@ + (NSString*)getHash:(NSString*)input return toReturn; } -+ (NSString*) getAdalVersion ++ (NSString*)getAdalVersion { return ADAL_VERSION_NSSTRING; } diff --git a/ADAL/src/ADRequestContext.h b/ADAL/src/ADRequestContext.h new file mode 100644 index 000000000..fad79d763 --- /dev/null +++ b/ADAL/src/ADRequestContext.h @@ -0,0 +1,32 @@ +// Copyright (c) Microsoft Corporation. +// All rights reserved. +// +// This code is licensed under the MIT License. +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files(the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and / or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions : +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE. + + +#import + +@protocol ADRequestContext + +- (NSUUID *)correlationId; +- (NSString *)telemetryRequestId; + +@end diff --git a/ADAL/src/ADRequestParameters.h b/ADAL/src/ADRequestParameters.h index 25bdb1534..113ff3a4b 100644 --- a/ADAL/src/ADRequestParameters.h +++ b/ADAL/src/ADRequestParameters.h @@ -21,7 +21,12 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN // THE SOFTWARE. -@interface ADRequestParameters : NSObject +#import "ADTokenCacheDataSource.h" +#import "ADRequestContext.h" + +@class ADTokenCacheAccessor; + +@interface ADRequestParameters : NSObject { NSString* _authority; NSString* _resource; diff --git a/ADAL/src/ADRequestParameters.m b/ADAL/src/ADRequestParameters.m index e0070718f..4c49399b6 100644 --- a/ADAL/src/ADRequestParameters.m +++ b/ADAL/src/ADRequestParameters.m @@ -22,6 +22,8 @@ // THE SOFTWARE. #import "ADRequestParameters.h" +#import "ADUserIdentifier.h" +#import "ADTokenCacheAccessor.h" @implementation ADRequestParameters @@ -45,6 +47,7 @@ - (id)initWithAuthority:(NSString *)authority correlationId:(NSUUID *)correlationId telemetryRequestId:(NSString *)telemetryRequestId { + (void)tokenCache; if (!(self = [super init])) { return nil; @@ -63,6 +66,26 @@ - (id)initWithAuthority:(NSString *)authority return self; } +- (id)copyWithZone:(NSZone*)zone +{ + ADRequestParameters* parameters = [[ADRequestParameters allocWithZone:zone] init]; + + parameters->_authority = [_authority copyWithZone:zone]; + parameters->_resource = [_resource copyWithZone:zone]; + parameters->_clientId = [_clientId copyWithZone:zone]; + parameters->_redirectUri = [_redirectUri copyWithZone:zone]; + parameters->_identifier = [_identifier copyWithZone:zone]; + + // "copy" doesn't make much sense on the token cache object, as it's just a proxy around a data source + parameters->_tokenCache = _tokenCache; + SAFE_ARC_RETAIN(parameters->_tokenCache); + parameters->_correlationId = [_correlationId copyWithZone:zone]; + parameters->_extendedLifetime = _extendedLifetime; + parameters->_telemetryRequestId = [_telemetryRequestId copyWithZone:zone]; + + return parameters; +} + - (void)setResource:(NSString *)resource { SAFE_ARC_RELEASE(_resource); diff --git a/ADAL/src/ADUserIdentifier.m b/ADAL/src/ADUserIdentifier.m index a03a4436f..a890d5c40 100644 --- a/ADAL/src/ADUserIdentifier.m +++ b/ADAL/src/ADUserIdentifier.m @@ -112,6 +112,20 @@ + (BOOL)identifier:(ADUserIdentifier*)identifier return NO; } +- (id)copyWithZone:(NSZone*)zone +{ + ADUserIdentifier* identifier = [[ADUserIdentifier allocWithZone:zone] init]; + if (!identifier) + { + return nil; + } + + identifier->_type = _type; + identifier->_userId = [_userId copyWithZone:zone]; + + return identifier; +} + - (NSString*)userIdMatchString:(ADUserInformation*)info { switch(_type) diff --git a/ADAL/src/cache/ADTokenCacheAccessor.h b/ADAL/src/cache/ADTokenCacheAccessor.h index 8a9229f8d..5827c86a5 100644 --- a/ADAL/src/cache/ADTokenCacheAccessor.h +++ b/ADAL/src/cache/ADTokenCacheAccessor.h @@ -23,6 +23,7 @@ #import #import "ADTokenCacheDataSource.h" +#import "ADRequestContext.h" @interface ADTokenCacheAccessor : NSObject { @@ -43,7 +44,7 @@ - (ADTokenCacheItem *)getATRTItemForUser:(ADUserIdentifier *)identifier resource:(NSString *)resource clientId:(NSString *)clientId - requestParams:(ADRequestParameters*)requestParams + context:(id)context error:(ADAuthenticationError * __autoreleasing *)error; /*! @@ -52,7 +53,7 @@ */ - (ADTokenCacheItem *)getMRRTItemForUser:(ADUserIdentifier *)identifier clientId:(NSString *)clientId - requestParams:(ADRequestParameters*)requestParams + context:(id)context error:(ADAuthenticationError * __autoreleasing *)error; /*! @@ -61,7 +62,7 @@ */ - (ADTokenCacheItem *)getFRTItemForUser:(ADUserIdentifier *)identifier familyId:(NSString *)familyId - requestParams:(ADRequestParameters*)requestParams + context:(id)context error:(ADAuthenticationError * __autoreleasing *)error; /*! @@ -70,7 +71,7 @@ */ - (ADTokenCacheItem*)getADFSUserTokenForResource:(NSString *)resource clientId:(NSString *)clientId - requestParams:(ADRequestParameters*)requestParams + context:(id)context error:(ADAuthenticationError * __autoreleasing *)error; /*! @@ -83,6 +84,6 @@ - (void)updateCacheToResult:(ADAuthenticationResult *)result cacheItem:(ADTokenCacheItem *)cacheItem refreshToken:(NSString *)refreshToken - requestParams:(ADRequestParameters*)requestParams; + context:(id)context; @end diff --git a/ADAL/src/cache/ADTokenCacheAccessor.m b/ADAL/src/cache/ADTokenCacheAccessor.m index 0643ff0c1..1ce7f1494 100644 --- a/ADAL/src/cache/ADTokenCacheAccessor.m +++ b/ADAL/src/cache/ADTokenCacheAccessor.m @@ -68,7 +68,7 @@ - (id)initWithDataSource:(id)dataSource - (ADTokenCacheItem *)getItemForUser:(ADUserIdentifier *)identifier resource:(NSString *)resource clientId:(NSString *)clientId - requestParams:(ADRequestParameters*)requestParams + context:(id)context error:(ADAuthenticationError * __autoreleasing *)error { ADTokenCacheKey* key = [ADTokenCacheKey keyWithAuthority:_authority @@ -82,7 +82,7 @@ - (ADTokenCacheItem *)getItemForUser:(ADUserIdentifier *)identifier return [_dataSource getItemWithKey:key userId:identifier.userId - correlationId:[requestParams correlationId] + correlationId:[context correlationId] error:error]; } @@ -94,20 +94,21 @@ - (ADTokenCacheItem *)getItemForUser:(ADUserIdentifier *)identifier - (ADTokenCacheItem *)getATRTItemForUser:(ADUserIdentifier *)identifier resource:(NSString *)resource clientId:(NSString *)clientId - requestParams:(ADRequestParameters*)requestParams + context:(id)context error:(ADAuthenticationError * __autoreleasing *)error { -#if AD_TELEMETRY - [[ADTelemetry sharedInstance] startEvent:[requestParams telemetryRequestId] eventName:@"token_cache_lookup"]; +#if AD_TELEMETERY + [[ADTelemetry sharedInstance] startEvent:[context telemetryRequestId] eventName:@"token_cache_lookup"]; #endif - ADTokenCacheItem* item = [self getItemForUser:identifier resource:resource clientId:clientId requestParams:requestParams error:error]; + + ADTokenCacheItem* item = [self getItemForUser:identifier resource:resource clientId:clientId context:context error:error]; #if AD_TELEMETRY ADTelemetryCacheEvent* event = [[ADTelemetryCacheEvent alloc] initWithName:@"token_cache_lookup" - requestId:[requestParams telemetryRequestId] - correlationId:[requestParams correlationId]]; + requestId:[context telemetryRequestId] + correlationId:[context correlationId]]; [event setTokenType:@"access token"]; [event setStatus:item? @"succeeded" : @"failed"]; - [[ADTelemetry sharedInstance] stopEvent:[requestParams telemetryRequestId] event:event]; + [[ADTelemetry sharedInstance] stopEvent:[context telemetryRequestId] event:event]; SAFE_ARC_RELEASE(event); #endif return item; @@ -119,20 +120,20 @@ - (ADTokenCacheItem *)getATRTItemForUser:(ADUserIdentifier *)identifier */ - (ADTokenCacheItem *)getMRRTItemForUser:(ADUserIdentifier *)identifier clientId:(NSString *)clientId - requestParams:(ADRequestParameters*)requestParams + context:(id)context error:(ADAuthenticationError * __autoreleasing *)error { #if AD_TELEMETRY - [[ADTelemetry sharedInstance] startEvent:[requestParams telemetryRequestId] eventName:@"token_cache_lookup"]; + [[ADTelemetry sharedInstance] startEvent:[context telemetryRequestId] eventName:@"token_cache_lookup"]; #endif - ADTokenCacheItem* item = [self getItemForUser:identifier resource:nil clientId:clientId requestParams:requestParams error:error]; + ADTokenCacheItem* item = [self getItemForUser:identifier resource:nil clientId:clientId context:context error:error]; #if AD_TELEMETRY ADTelemetryCacheEvent* event = [[ADTelemetryCacheEvent alloc] initWithName:@"token_cache_lookup" - requestId:[requestParams telemetryRequestId] - correlationId:[requestParams correlationId]]; + requestId:[context telemetryRequestId] + correlationId:[context correlationId]]; [event setTokenType:@"multi-resource refresh token"]; [event setStatus:item? @"succeeded" : @"failed"]; - [[ADTelemetry sharedInstance] stopEvent:[requestParams telemetryRequestId] event:event]; + [[ADTelemetry sharedInstance] stopEvent:[context telemetryRequestId] event:event]; SAFE_ARC_RELEASE(event); #endif return item; @@ -144,21 +145,23 @@ - (ADTokenCacheItem *)getMRRTItemForUser:(ADUserIdentifier *)identifier */ - (ADTokenCacheItem *)getFRTItemForUser:(ADUserIdentifier *)identifier familyId:(NSString *)familyId - requestParams:(ADRequestParameters*)requestParams + context:(id)context error:(ADAuthenticationError * __autoreleasing *)error { #if AD_TELEMETRY - [[ADTelemetry sharedInstance] startEvent:[requestParams telemetryRequestId] eventName:@"token_cache_lookup"]; + [[ADTelemetry sharedInstance] startEvent:context.telemetryRequestId eventName:@"token_cache_lookup"]; #endif + NSString* fociClientId = [ADTokenCacheAccessor familyClientId:familyId]; - ADTokenCacheItem* item = [self getItemForUser:identifier resource:nil clientId:fociClientId requestParams:requestParams error:error]; + ADTokenCacheItem* item = [self getItemForUser:identifier resource:nil clientId:fociClientId context:context error:error]; + #if AD_TELEMETRY ADTelemetryCacheEvent* event = [[ADTelemetryCacheEvent alloc] initWithName:@"token_cache_lookup" - requestId:[requestParams telemetryRequestId] - correlationId:[requestParams correlationId]]; + requestId:context.telemetryRequestId + correlationId:context.correlationId]; [event setTokenType:@"family refresh token"]; [event setStatus:item? @"succeeded" : @"failed"]; - [[ADTelemetry sharedInstance] stopEvent:[requestParams telemetryRequestId] event:event]; + [[ADTelemetry sharedInstance] stopEvent:[context telemetryRequestId] event:event]; SAFE_ARC_RELEASE(event); #endif return item; @@ -166,7 +169,7 @@ - (ADTokenCacheItem *)getFRTItemForUser:(ADUserIdentifier *)identifier - (ADTokenCacheItem*)getADFSUserTokenForResource:(NSString *)resource clientId:(NSString *)clientId - requestParams:(ADRequestParameters*)requestParams + context:(id)context error:(ADAuthenticationError * __autoreleasing *)error { // ADFS fix: When talking to ADFS directly we can get ATs and RTs (but not MRRTs or FRTs) without @@ -181,17 +184,18 @@ - (ADTokenCacheItem*)getADFSUserTokenForResource:(NSString *)resource { return nil; } + #if AD_TELEMETRY - [[ADTelemetry sharedInstance] startEvent:[requestParams telemetryRequestId] eventName:@"token_cache_lookup"]; + [[ADTelemetry sharedInstance] startEvent:[context telemetryRequestId] eventName:@"token_cache_lookup"]; #endif - ADTokenCacheItem* item = [_dataSource getItemWithKey:key userId:@"" correlationId:[requestParams correlationId] error:error]; + ADTokenCacheItem* item = [_dataSource getItemWithKey:key userId:@"" correlationId:[context correlationId] error:error]; #if AD_TELEMETRY ADTelemetryCacheEvent* event = [[ADTelemetryCacheEvent alloc] initWithName:@"token_cache_lookup" - requestId:[requestParams telemetryRequestId] - correlationId:[requestParams correlationId]]; + requestId:[context telemetryRequestId] + correlationId:[context correlationId]]; [event setTokenType:@"ADFS access token/refresh token"]; [event setStatus:item? @"succeeded" : @"failed"]; - [[ADTelemetry sharedInstance] stopEvent:[requestParams telemetryRequestId] event:event]; + [[ADTelemetry sharedInstance] stopEvent:[context telemetryRequestId] event:event]; SAFE_ARC_RELEASE(event); #endif return item; @@ -203,7 +207,7 @@ - (ADTokenCacheItem*)getADFSUserTokenForResource:(NSString *)resource - (void)updateCacheToResult:(ADAuthenticationResult *)result cacheItem:(ADTokenCacheItem *)cacheItem refreshToken:(NSString *)refreshToken - requestParams:(ADRequestParameters*)requestParams + context:(id)context { if(!result) @@ -220,13 +224,13 @@ - (void)updateCacheToResult:(ADAuthenticationResult *)result || ![ADAuthenticationContext handleNilOrEmptyAsResult:item argumentName:@"resource" authenticationResult:&result] || ![ADAuthenticationContext handleNilOrEmptyAsResult:item argumentName:@"accessToken" authenticationResult:&result]) { - AD_LOG_WARN(@"Told to update cache to an invalid token cache item", [requestParams correlationId], nil); + AD_LOG_WARN(@"Told to update cache to an invalid token cache item", [context correlationId], nil); return; } [self updateCacheToItem:item MRRT:[result multiResourceRefreshToken] - requestParams:requestParams]; + context:context]; return; } @@ -243,17 +247,17 @@ - (void)updateCacheToResult:(ADAuthenticationResult *)result [self removeItemFromCache:cacheItem refreshToken:refreshToken - requestParams:requestParams + context:context error:result.error]; } - (void)updateCacheToItem:(ADTokenCacheItem *)cacheItem MRRT:(BOOL)isMRRT - requestParams:(ADRequestParameters*)requestParams + context:(id)context { - NSUUID* correlationId = [requestParams correlationId]; + NSUUID* correlationId = [context correlationId]; #if AD_TELEMETRY - NSString* telemetryRequestId = [requestParams telemetryRequestId]; + NSString* telemetryRequestId = [context telemetryRequestId]; #endif NSString* savedRefreshToken = cacheItem.refreshToken; @@ -325,7 +329,7 @@ - (void)updateCacheToItem:(ADTokenCacheItem *)cacheItem - (void)removeItemFromCache:(ADTokenCacheItem *)cacheItem refreshToken:(NSString *)refreshToken - requestParams:(ADRequestParameters*)requestParams + context:(id)context error:(ADAuthenticationError *)error { if (!cacheItem && !refreshToken) @@ -333,9 +337,9 @@ - (void)removeItemFromCache:(ADTokenCacheItem *)cacheItem return; } - NSUUID* correlationId = [requestParams correlationId]; + NSUUID* correlationId = [context correlationId]; #if AD_TELEMETRY - [[ADTelemetry sharedInstance] startEvent:[requestParams telemetryRequestId] eventName:@"token_cache_delete_token"]; + [[ADTelemetry sharedInstance] startEvent:[context telemetryRequestId] eventName:@"token_cache_delete_token"]; #endif BOOL removed = NO; //The refresh token didn't work. We need to tombstone this refresh item in the cache. @@ -378,9 +382,9 @@ - (void)removeItemFromCache:(ADTokenCacheItem *)cacheItem } #if AD_TELEMETRY ADTelemetryCacheEvent* event = [[ADTelemetryCacheEvent alloc] initWithName:@"token_cache_delete_token" - requestId:[requestParams telemetryRequestId] + requestId:[context telemetryRequestId] correlationId:correlationId]; - [[ADTelemetry sharedInstance] stopEvent:[requestParams telemetryRequestId] event:event]; + [[ADTelemetry sharedInstance] stopEvent:[context telemetryRequestId] event:event]; SAFE_ARC_RELEASE(event); #endif } diff --git a/ADAL/src/cache/ADTokenCacheItem+Internal.m b/ADAL/src/cache/ADTokenCacheItem+Internal.m index 003ce3cc6..6ce4eef7c 100644 --- a/ADAL/src/cache/ADTokenCacheItem+Internal.m +++ b/ADAL/src/cache/ADTokenCacheItem+Internal.m @@ -79,7 +79,7 @@ - (ADAuthenticationResult *)processTokenResponse:(NSDictionary *)response if (!response) { ADAuthenticationError* error = [ADAuthenticationError errorFromAuthenticationError:AD_ERROR_UNEXPECTED - protocolCode:@"adal cachce" + protocolCode:nil errorDetails:@"processTokenResponse called without a response dictionary" correlationId:requestCorrelationId]; return [ADAuthenticationResult resultFromError:error]; diff --git a/ADAL/src/public/ADAuthenticationResult.h b/ADAL/src/public/ADAuthenticationResult.h index ec70a686e..c41f49d46 100644 --- a/ADAL/src/public/ADAuthenticationResult.h +++ b/ADAL/src/public/ADAuthenticationResult.h @@ -46,7 +46,7 @@ typedef enum { @protected //See the corresponding properties for details. - ADTokenCacheItem* _tokenCacheItem; + ADTokenCacheItem* _tokenCacheItem; ADAuthenticationResultStatus _status; ADAuthenticationError* _error; NSUUID* _correlationId; diff --git a/ADAL/src/public/ADUserIdentifier.h b/ADAL/src/public/ADUserIdentifier.h index b08a10fb0..a34d1cebb 100644 --- a/ADAL/src/public/ADUserIdentifier.h +++ b/ADAL/src/public/ADUserIdentifier.h @@ -51,7 +51,7 @@ typedef enum ADUserIdentifierType @class ADUserInformation; -@interface ADUserIdentifier : NSObject +@interface ADUserIdentifier : NSObject { NSString* _userId; ADUserIdentifierType _type; diff --git a/ADAL/src/public/ios/ADKeychainTokenCache.h b/ADAL/src/public/ios/ADKeychainTokenCache.h index adbc10f2e..17318de47 100644 --- a/ADAL/src/public/ios/ADKeychainTokenCache.h +++ b/ADAL/src/public/ios/ADKeychainTokenCache.h @@ -79,7 +79,7 @@ error:(ADAuthenticationError * __nullable __autoreleasing * __nullable)error; - (BOOL)removeAllForUserId:(NSString * __nonnull)userId - clientId:(NSString * __nonnull)clientId - error:(ADAuthenticationError * __nullable __autoreleasing * __nullable)error; + clientId:(NSString * __nonnull)clientId + error:(ADAuthenticationError * __nullable __autoreleasing * __nullable)error; @end \ No newline at end of file diff --git a/ADAL/src/request/ADAcquireTokenSilentHandler.h b/ADAL/src/request/ADAcquireTokenSilentHandler.h index 45b610661..b757cc61e 100644 --- a/ADAL/src/request/ADAcquireTokenSilentHandler.h +++ b/ADAL/src/request/ADAcquireTokenSilentHandler.h @@ -41,7 +41,8 @@ BOOL _attemptedFRT; } -+ (void)acquireTokenSilentForRequestParams:(ADRequestParameters*)requestParams - completionBlock:(ADAuthenticationCallback)completionBlock; ++ (ADAcquireTokenSilentHandler *)requestWithParams:(ADRequestParameters*)requestParams; + +- (void)getToken:(ADAuthenticationCallback)completionBlock; @end diff --git a/ADAL/src/request/ADAcquireTokenSilentHandler.m b/ADAL/src/request/ADAcquireTokenSilentHandler.m index f52d57e85..2acaf3808 100644 --- a/ADAL/src/request/ADAcquireTokenSilentHandler.m +++ b/ADAL/src/request/ADAcquireTokenSilentHandler.m @@ -38,8 +38,7 @@ @implementation ADAcquireTokenSilentHandler -+ (void)acquireTokenSilentForRequestParams:(ADRequestParameters*)requestParams - completionBlock:(ADAuthenticationCallback)completionBlock ++ (ADAcquireTokenSilentHandler *)requestWithParams:(ADRequestParameters*)requestParams { ADAcquireTokenSilentHandler* handler = [ADAcquireTokenSilentHandler new]; @@ -49,23 +48,28 @@ + (void)acquireTokenSilentForRequestParams:(ADRequestParameters*)requestParams handler->_requestParams = requestParams; SAFE_ARC_RETAIN(requestParams); - [handler getAccessToken:^(ADAuthenticationResult *result) + return handler; +} + +- (void)getToken:(ADAuthenticationCallback)completionBlock +{ + [self getAccessToken:^(ADAuthenticationResult *result) { // Logic for returning extended lifetime token - if ([requestParams extendedLifetime] && [handler isServerUnavailable:result] && handler->_extendedLifetimeAccessTokenItem) + if ([_requestParams extendedLifetime] && [self isServerUnavailable:result] && _extendedLifetimeAccessTokenItem) { - handler->_extendedLifetimeAccessTokenItem.expiresOn = - [handler->_extendedLifetimeAccessTokenItem.additionalServer valueForKey:@"ext_expires_on"]; + _extendedLifetimeAccessTokenItem.expiresOn = + [_extendedLifetimeAccessTokenItem.additionalServer valueForKey:@"ext_expires_on"]; // give the stale token as result - [ADLogger logToken:handler->_extendedLifetimeAccessTokenItem.accessToken + [ADLogger logToken:_extendedLifetimeAccessTokenItem.accessToken tokenType:@"access token (extended lifetime)" - expiresOn:handler->_extendedLifetimeAccessTokenItem.expiresOn - correlationId:[handler->_requestParams correlationId]]; + expiresOn:_extendedLifetimeAccessTokenItem.expiresOn + correlationId:[_requestParams correlationId]]; - result = [ADAuthenticationResult resultFromTokenCacheItem:handler->_extendedLifetimeAccessTokenItem + result = [ADAuthenticationResult resultFromTokenCacheItem:_extendedLifetimeAccessTokenItem multiResourceRefreshToken:NO - correlationId:[handler->_requestParams correlationId]]; + correlationId:[_requestParams correlationId]]; [result setExtendedLifeTimeToken:YES]; } @@ -135,7 +139,7 @@ - (void)acquireTokenByRefreshToken:(NSString*)refreshToken ADWebAuthRequest* webReq = [[ADWebAuthRequest alloc] initWithURL:[NSURL URLWithString:[[_requestParams authority] stringByAppendingString:OAUTH2_TOKEN_SUFFIX]] - requestParams:_requestParams]; + context:_requestParams]; [webReq setRequestDictionary:request_data]; AD_LOG_INFO_F(@"Attempting to acquire an access token from refresh token", nil, @"clientId: '%@'; resource: '%@';", [_requestParams clientId], [_requestParams resource]); [webReq sendRequest:^(NSDictionary *response) @@ -155,7 +159,7 @@ - (void)acquireTokenByRefreshToken:(NSString*)refreshToken [[_requestParams tokenCache] updateCacheToResult:result cacheItem:resultItem refreshToken:refreshToken - requestParams:_requestParams]; + context:_requestParams]; } result = [ADAuthenticationContext updateResult:result toUser:[_requestParams identifier]];//Verify the user (just in case) // @@ -273,7 +277,7 @@ - (void)getAccessToken:(ADAuthenticationCallback)completionBlock ADTokenCacheItem* item = [[_requestParams tokenCache] getATRTItemForUser:[_requestParams identifier] resource:[_requestParams resource] clientId:[_requestParams clientId] - requestParams:_requestParams + context:_requestParams error:&error]; // If some error ocurred during the cache lookup then we need to fail out right away. if (!item && error) @@ -286,7 +290,10 @@ - (void)getAccessToken:(ADAuthenticationCallback)completionBlock // and we need to check the unknown user ADFS token as well if (!item) { - item = [[_requestParams tokenCache] getADFSUserTokenForResource:[_requestParams resource] clientId:[_requestParams clientId] requestParams:_requestParams error:&error]; + item = [[_requestParams tokenCache] getADFSUserTokenForResource:[_requestParams resource] + clientId:[_requestParams clientId] + context:_requestParams + error:&error]; if (!item && error) { completionBlock([ADAuthenticationResult resultFromError:error correlationId:correlationId]); @@ -368,7 +375,10 @@ - (void)tryMRRT:(ADAuthenticationCallback)completionBlock // If we don't have an item yet see if we can pull one out of the cache if (!_mrrtItem) { - _mrrtItem = [[_requestParams tokenCache] getMRRTItemForUser:[_requestParams identifier] clientId:[_requestParams clientId] requestParams:_requestParams error:&error]; + _mrrtItem = [[_requestParams tokenCache] getMRRTItemForUser:[_requestParams identifier] + clientId:[_requestParams clientId] + context:_requestParams + error:&error]; if (!_mrrtItem && error) { completionBlock([ADAuthenticationResult resultFromError:error correlationId:[_requestParams correlationId]]); @@ -429,7 +439,10 @@ - (void)tryFRT:(NSString*)familyId completionBlock:(ADAuthenticationCallback)com _attemptedFRT = YES; ADAuthenticationError* error = nil; - ADTokenCacheItem* frtItem = [[_requestParams tokenCache] getFRTItemForUser:[_requestParams identifier] familyId:familyId requestParams:_requestParams error:&error]; + ADTokenCacheItem* frtItem = [[_requestParams tokenCache] getFRTItemForUser:[_requestParams identifier] + familyId:familyId + context:_requestParams + error:&error]; if (!frtItem && error) { completionBlock([ADAuthenticationResult resultFromError:error correlationId:[_requestParams correlationId]]); diff --git a/ADAL/src/request/ADAuthenticationRequest+AcquireToken.m b/ADAL/src/request/ADAuthenticationRequest+AcquireToken.m index 8afbefeea..897ab78e4 100644 --- a/ADAL/src/request/ADAuthenticationRequest+AcquireToken.m +++ b/ADAL/src/request/ADAuthenticationRequest+AcquireToken.m @@ -118,8 +118,8 @@ - (void)validatedAcquireToken:(ADAuthenticationCallback)completionBlock #if AD_TELEMETRY [[ADTelemetry sharedInstance] startEvent:[self telemetryRequestId] eventName:@"acquire_token_silent_handler"]; #endif - [ADAcquireTokenSilentHandler acquireTokenSilentForRequestParams:_requestParams - completionBlock:^(ADAuthenticationResult *result) + ADAcquireTokenSilentHandler* request = [ADAcquireTokenSilentHandler requestWithParams:_requestParams]; + [request getToken:^(ADAuthenticationResult *result) { #if AD_TELEMETRY ADTelemetryAPIEvent* event = [[ADTelemetryAPIEvent alloc] initWithName:@"acquire_token_silent_handler" @@ -271,7 +271,10 @@ - (void)requestToken:(ADAuthenticationCallback)completionBlock #endif if (AD_SUCCEEDED == result.status) { - [[_requestParams tokenCache] updateCacheToResult:result cacheItem:nil refreshToken:nil requestParams:_requestParams]; + [[_requestParams tokenCache] updateCacheToResult:result + cacheItem:nil + refreshToken:nil + context:_requestParams]; result = [ADAuthenticationContext updateResult:result toUser:[_requestParams identifier]]; } completionBlock(result); diff --git a/ADAL/src/request/ADAuthenticationRequest+Broker.m b/ADAL/src/request/ADAuthenticationRequest+Broker.m index d96fbbca4..342cfb9e3 100644 --- a/ADAL/src/request/ADAuthenticationRequest+Broker.m +++ b/ADAL/src/request/ADAuthenticationRequest+Broker.m @@ -164,7 +164,7 @@ + (void)internalHandleBrokerResponse:(NSURL *)response ADTokenCacheAccessor* cache = [[ADTokenCacheAccessor alloc] initWithDataSource:[ADKeychainTokenCache defaultKeychainCache] authority:result.tokenCacheItem.authority]; - [cache updateCacheToResult:result cacheItem:nil refreshToken:nil requestParams:nil]; + [cache updateCacheToResult:result cacheItem:nil refreshToken:nil context:nil]; NSString* userId = [[[result tokenCacheItem] userInformation] userId]; [ADAuthenticationContext updateResult:result diff --git a/ADAL/src/request/ADAuthenticationRequest+WebRequest.m b/ADAL/src/request/ADAuthenticationRequest+WebRequest.m index 5cc726fa7..9aa6ededf 100755 --- a/ADAL/src/request/ADAuthenticationRequest+WebRequest.m +++ b/ADAL/src/request/ADAuthenticationRequest+WebRequest.m @@ -57,7 +57,7 @@ - (void)executeRequest:(NSDictionary *)request_data { NSString* urlString = [_context.authority stringByAppendingString:OAUTH2_TOKEN_SUFFIX]; ADWebAuthRequest* req = [[ADWebAuthRequest alloc] initWithURL:[NSURL URLWithString:urlString] - requestParams:_requestParams]; + context:_requestParams]; [req setRequestDictionary:request_data]; [req sendRequest:^(NSDictionary *response) { @@ -244,7 +244,7 @@ - (void)requestCode:(ADAuthorizationCodeCallback)completionBlock NSError* err = [NSError errorWithDomain:ADAuthenticationErrorDomain code:AD_ERROR_SERVER_WPJ_REQUIRED userInfo:userInfo]; - error = [ADAuthenticationError errorFromNSError:err errorDetails:@"work place join is required"]; + error = [ADAuthenticationError errorFromNSError:err errorDetails:@"work place join is required" correlationId:_requestParams.correlationId]; } #else code = end.absoluteString; @@ -304,7 +304,7 @@ - (void)requestCode:(ADAuthorizationCodeCallback)completionBlock NSURL* reqURL = [NSURL URLWithString:[_context.authority stringByAppendingString:OAUTH2_AUTHORIZE_SUFFIX]]; ADWebAuthRequest* req = [[ADWebAuthRequest alloc] initWithURL:reqURL - requestParams:_requestParams]; + context:_requestParams]; [req setIsGetRequest:YES]; [req setRequestDictionary:requestData]; [req sendRequest:^(NSDictionary * parameters) diff --git a/ADAL/src/request/ADAuthenticationRequest.m b/ADAL/src/request/ADAuthenticationRequest.m index 78a8b0e24..c38f57044 100644 --- a/ADAL/src/request/ADAuthenticationRequest.m +++ b/ADAL/src/request/ADAuthenticationRequest.m @@ -204,19 +204,14 @@ - (void)setCorrelationId:(NSUUID*)correlationId - (NSString*)redirectUri { - return _redirectUri; + return _requestParams.redirectUri; } - (void)setRedirectUri:(NSString *)redirectUri { // We knowingly do this mid-request when we have to change auth types // Thus no CHECK_REQUEST_STARTED - if (_redirectUri == redirectUri) - { - return; - } - SAFE_ARC_RELEASE(_redirectUri); - _redirectUri = [redirectUri copy]; + [_requestParams setRedirectUri:redirectUri]; } - (void)setAllowSilentRequests:(BOOL)allowSilent diff --git a/ADAL/src/request/ADWebAuthRequest.h b/ADAL/src/request/ADWebAuthRequest.h index d026f1474..481b0bd37 100644 --- a/ADAL/src/request/ADWebAuthRequest.h +++ b/ADAL/src/request/ADWebAuthRequest.h @@ -43,6 +43,6 @@ @property (readonly) NSDate* startTime; - (void)setRequestDictionary:(NSDictionary *)requestDictionary; -- (void)sendRequest:(void(^)(NSDictionary *))completionBlock; +- (void)sendRequest:(ADWebResponseCallback)completionBlock; @end diff --git a/ADAL/src/request/ADWebAuthRequest.m b/ADAL/src/request/ADWebAuthRequest.m index aaaac18b6..014a73c8d 100644 --- a/ADAL/src/request/ADWebAuthRequest.m +++ b/ADAL/src/request/ADWebAuthRequest.m @@ -38,9 +38,9 @@ @implementation ADWebAuthRequest @synthesize handledPkeyAuthChallenge = _handledPkeyAuthChallenge; - (id)initWithURL:(NSURL *)url - requestParams:(ADRequestParameters*)requestParams + context:(id)context { - self = [super initWithURL:url requestParams:requestParams]; + self = [super initWithURL:url context:context]; if (!self) { return nil; @@ -66,7 +66,7 @@ - (void)setRequestDictionary:(NSDictionary*)requestDictionary _requestDictionary = [requestDictionary copy]; } -- (void)sendRequest:(void (^)(NSDictionary *))completionBlock +- (void)sendRequest:(ADWebResponseCallback)completionBlock { if ([self isGetRequest]) { diff --git a/ADAL/src/request/ADWebAuthResponse.h b/ADAL/src/request/ADWebAuthResponse.h index 3fe14e586..73a20b655 100644 --- a/ADAL/src/request/ADWebAuthResponse.h +++ b/ADAL/src/request/ADWebAuthResponse.h @@ -26,6 +26,8 @@ @class ADWebResponse; @class ADWebAuthRequest; +typedef void (^ADWebResponseCallback)(NSMutableDictionary *); + @interface ADWebAuthResponse : NSObject { NSMutableDictionary* _responseDictionary; @@ -36,10 +38,10 @@ + (void)processError:(NSError *)error correlationId:(NSUUID *)correlationId - completion:(void (^)(NSDictionary *))completionBlock; + completion:(ADWebResponseCallback)completionBlock; + (void)processResponse:(ADWebResponse *)webResponse request:(ADWebAuthRequest *)request - completion:(void (^)(NSDictionary *))completionBlock; + completion:(ADWebResponseCallback)completionBlock; @end diff --git a/ADAL/src/request/ADWebAuthResponse.m b/ADAL/src/request/ADWebAuthResponse.m index 7387b23f6..97871f3b8 100644 --- a/ADAL/src/request/ADWebAuthResponse.m +++ b/ADAL/src/request/ADWebAuthResponse.m @@ -34,7 +34,7 @@ @implementation ADWebAuthResponse + (void)processError:(NSError *)error correlationId:(NSUUID *)correlationId - completion:(void (^)(NSDictionary *))completionBlock + completion:(ADWebResponseCallback)completionBlock { ADWebAuthResponse* response = [ADWebAuthResponse new]; response->_correlationId = correlationId; @@ -46,7 +46,7 @@ + (void)processError:(NSError *)error + (void)processResponse:(ADWebResponse *)webResponse request:(ADWebAuthRequest *)request - completion:(void (^)(NSDictionary *))completionBlock + completion:(ADWebResponseCallback)completionBlock { ADWebAuthResponse* response = [ADWebAuthResponse new]; response->_request = request; @@ -92,7 +92,7 @@ - (void)checkCorrelationId:(ADWebResponse*)webResponse } - (void)handleResponse:(ADWebResponse *)webResponse - completionBlock:(void (^)(NSDictionary *))completionBlock + completionBlock:(ADWebResponseCallback)completionBlock { [self checkCorrelationId:webResponse]; [_responseDictionary setObject:webResponse.URL forKey:@"url"]; @@ -162,7 +162,7 @@ - (void)handleResponse:(ADWebResponse *)webResponse } - (void)handleJSONResponse:(ADWebResponse*)webResponse - completionBlock:(void (^)(NSDictionary *))completionBlock + completionBlock:(ADWebResponseCallback)completionBlock { NSError *jsonError = nil; id jsonObject = [NSJSONSerialization JSONObjectWithData:webResponse.body options:0 error:&jsonError]; @@ -189,7 +189,7 @@ - (void)handleJSONResponse:(ADWebResponse*)webResponse } - (void)handlePKeyAuthChallenge:(NSString *)wwwAuthHeaderValue - completion:(void (^)(NSDictionary *))completionBlock + completion:(ADWebResponseCallback)completionBlock { //pkeyauth word length=8 + 1 whitespace wwwAuthHeaderValue = [wwwAuthHeaderValue substringFromIndex:[pKeyAuthName length] + 1]; @@ -219,7 +219,7 @@ - (void)handlePKeyAuthChallenge:(NSString *)wwwAuthHeaderValue [_request resend]; } -- (void)handleSuccess:(void (^)(NSDictionary *))completionBlock +- (void)handleSuccess:(ADWebResponseCallback)completionBlock { [[ADClientMetrics getInstance] endClientMetricsRecord:[[_request URL] absoluteString] startTime:[_request startTime] @@ -234,7 +234,7 @@ - (void)handleSuccess:(void (^)(NSDictionary *))completionBlock - (void)handleJSONError:(NSError*)jsonError body:(NSData*)body - completionBlock:(void (^)(NSDictionary *))completionBlock + completionBlock:(ADWebResponseCallback)completionBlock { // Unrecognized JSON response @@ -268,7 +268,8 @@ - (void)handleJSONError:(NSError*)jsonError [self handleNSError:jsonError completionBlock:completionBlock]; } -- (void)handleNSError:(NSError*)error completionBlock:(void (^)(NSDictionary*))completionBlock +- (void)handleNSError:(NSError*)error + completionBlock:(ADWebResponseCallback)completionBlock { if ([[error domain] isEqualToString:@"NSURLErrorDomain"] && [error code] == -1002) { @@ -289,7 +290,8 @@ - (void)handleNSError:(NSError*)error completionBlock:(void (^)(NSDictionary*))c [self handleADError:adError completionBlock:completionBlock]; } -- (void)handleADError:(ADAuthenticationError*)adError completionBlock:(void (^)(NSDictionary*))completionBlock +- (void)handleADError:(ADAuthenticationError*)adError + completionBlock:(ADWebResponseCallback)completionBlock { [_responseDictionary setObject:adError forKey:AUTH_NON_PROTOCOL_ERROR]; diff --git a/ADAL/src/request/ADWebRequest.h b/ADAL/src/request/ADWebRequest.h index c050e3faa..9de7923b8 100644 --- a/ADAL/src/request/ADWebRequest.h +++ b/ADAL/src/request/ADWebRequest.h @@ -24,6 +24,8 @@ @class ADWebRequest; @class ADWebResponse; +typedef void (^ADWebResponseCallback)(NSMutableDictionary *); + @interface ADWebRequest : NSObject { NSURLConnection * _connection; @@ -55,8 +57,8 @@ @property BOOL isGetRequest; @property (readonly) NSUUID* correlationId; -- (id)initWithURL: (NSURL*)url - requestParams:(ADRequestParameters*)requestParams; +- (id)initWithURL:(NSURL *)url + context:(id)context; - (void)send:( void (^)( NSError *, ADWebResponse *) )completionHandler; diff --git a/ADAL/src/request/ADWebRequest.m b/ADAL/src/request/ADWebRequest.m index e8645a7e8..46233297f 100644 --- a/ADAL/src/request/ADWebRequest.m +++ b/ADAL/src/request/ADWebRequest.m @@ -80,7 +80,7 @@ - (void)setBody:(NSData *)body #pragma mark - Initialization - (id)initWithURL:(NSURL *)requestURL - requestParams:(ADRequestParameters*)requestParams + context:(id)context { if (!(self = [super init])) { @@ -93,10 +93,10 @@ - (id)initWithURL:(NSURL *)requestURL // Default timeout for ADWebRequest is 30 seconds _timeout = [[ADAuthenticationSettings sharedInstance] requestTimeOut]; - _correlationId = [requestParams correlationId]; + _correlationId = context.correlationId; SAFE_ARC_RETAIN(_correlationId); - _telemetryRequestId = [requestParams telemetryRequestId]; + _telemetryRequestId = context.telemetryRequestId; SAFE_ARC_RETAIN(_telemetryRequestId); _operationQueue = [[NSOperationQueue alloc] init]; diff --git a/ADAL/src/ui/ADWebAuthController.m b/ADAL/src/ui/ADWebAuthController.m index 33b68ccfb..807d9921f 100755 --- a/ADAL/src/ui/ADWebAuthController.m +++ b/ADAL/src/ui/ADWebAuthController.m @@ -359,7 +359,7 @@ - (BOOL)webAuthShouldStartLoadRequest:(NSURLRequest *)request // client cert auth flow if ([[[request.URL scheme] lowercaseString] isEqualToString:@"msauth"]) { - dispatch_async( dispatch_get_main_queue(), ^{ [_delegate webAuthDidCompleteWithURL:request.URL]; } ); + [self webAuthDidCompleteWithURL:request.URL]; return NO; } #endif From 28b130664e24c5fd0a04753faeb07f557ceff7d0 Mon Sep 17 00:00:00 2001 From: Yong Zeng Date: Thu, 29 Sep 2016 07:53:40 -0700 Subject: [PATCH 25/92] add host for unit test --- ADAL/ADAL.xcodeproj/project.pbxproj | 228 ++++++++++++++++++ ADAL/UnitTestHostApp/AppDelegate.h | 17 ++ ADAL/UnitTestHostApp/AppDelegate.m | 51 ++++ .../AppIcon.appiconset/Contents.json | 93 +++++++ .../Base.lproj/LaunchScreen.storyboard | 27 +++ .../Base.lproj/Main.storyboard | 26 ++ ADAL/UnitTestHostApp/Info.plist | 45 ++++ .../UnitTestHostApp.entitlements | 12 + ADAL/UnitTestHostApp/ViewController.h | 15 ++ ADAL/UnitTestHostApp/ViewController.m | 29 +++ ADAL/UnitTestHostApp/main.m | 16 ++ 11 files changed, 559 insertions(+) create mode 100644 ADAL/UnitTestHostApp/AppDelegate.h create mode 100644 ADAL/UnitTestHostApp/AppDelegate.m create mode 100644 ADAL/UnitTestHostApp/Assets.xcassets/AppIcon.appiconset/Contents.json create mode 100644 ADAL/UnitTestHostApp/Base.lproj/LaunchScreen.storyboard create mode 100644 ADAL/UnitTestHostApp/Base.lproj/Main.storyboard create mode 100644 ADAL/UnitTestHostApp/Info.plist create mode 100644 ADAL/UnitTestHostApp/UnitTestHostApp.entitlements create mode 100644 ADAL/UnitTestHostApp/ViewController.h create mode 100644 ADAL/UnitTestHostApp/ViewController.m create mode 100644 ADAL/UnitTestHostApp/main.m diff --git a/ADAL/ADAL.xcodeproj/project.pbxproj b/ADAL/ADAL.xcodeproj/project.pbxproj index 6d05ccc72..bf3623340 100755 --- a/ADAL/ADAL.xcodeproj/project.pbxproj +++ b/ADAL/ADAL.xcodeproj/project.pbxproj @@ -22,6 +22,12 @@ /* End PBXAggregateTarget section */ /* Begin PBXBuildFile section */ + 04AB6D461D9D619B007E9A83 /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 04AB6D451D9D619B007E9A83 /* main.m */; }; + 04AB6D491D9D619B007E9A83 /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 04AB6D481D9D619B007E9A83 /* AppDelegate.m */; }; + 04AB6D4C1D9D619B007E9A83 /* ViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 04AB6D4B1D9D619B007E9A83 /* ViewController.m */; }; + 04AB6D4F1D9D619B007E9A83 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 04AB6D4D1D9D619B007E9A83 /* Main.storyboard */; }; + 04AB6D511D9D619B007E9A83 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 04AB6D501D9D619B007E9A83 /* Assets.xcassets */; }; + 04AB6D541D9D619B007E9A83 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 04AB6D521D9D619B007E9A83 /* LaunchScreen.storyboard */; }; 600401A51D3421480020EAAB /* ADTelemetry.m in Sources */ = {isa = PBXBuildFile; fileRef = 600401A31D3421480020EAAB /* ADTelemetry.m */; }; 600401A71D3426250020EAAB /* ADTelemetry+Internal.h in Headers */ = {isa = PBXBuildFile; fileRef = 600401A61D3426250020EAAB /* ADTelemetry+Internal.h */; }; 600401A91D3428770020EAAB /* ADDefaultEvent.h in Headers */ = {isa = PBXBuildFile; fileRef = 600401A81D3428770020EAAB /* ADDefaultEvent.h */; }; @@ -270,6 +276,13 @@ /* End PBXBuildFile section */ /* Begin PBXContainerItemProxy section */ + 04AB6D5B1D9D61E2007E9A83 /* PBXContainerItemProxy */ = { + isa = PBXContainerItemProxy; + containerPortal = 8B0965A217F25770002BDFB8 /* Project object */; + proxyType = 1; + remoteGlobalIDString = 04AB6D411D9D619B007E9A83; + remoteInfo = UnitTestHostApp; + }; 9453C45C1C5866D8006B9E79 /* PBXContainerItemProxy */ = { isa = PBXContainerItemProxy; containerPortal = 8B0965A217F25770002BDFB8 /* Project object */; @@ -334,6 +347,17 @@ /* End PBXCopyFilesBuildPhase section */ /* Begin PBXFileReference section */ + 04AB6D421D9D619B007E9A83 /* UnitTestHostApp.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = UnitTestHostApp.app; sourceTree = BUILT_PRODUCTS_DIR; }; + 04AB6D451D9D619B007E9A83 /* main.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = ""; }; + 04AB6D471D9D619B007E9A83 /* AppDelegate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = AppDelegate.h; sourceTree = ""; }; + 04AB6D481D9D619B007E9A83 /* AppDelegate.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = AppDelegate.m; sourceTree = ""; }; + 04AB6D4A1D9D619B007E9A83 /* ViewController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ViewController.h; sourceTree = ""; }; + 04AB6D4B1D9D619B007E9A83 /* ViewController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = ViewController.m; sourceTree = ""; }; + 04AB6D4E1D9D619B007E9A83 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = ""; }; + 04AB6D501D9D619B007E9A83 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; + 04AB6D531D9D619B007E9A83 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = ""; }; + 04AB6D551D9D619B007E9A83 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; + 04AB6D5A1D9D61CA007E9A83 /* UnitTestHostApp.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = UnitTestHostApp.entitlements; sourceTree = ""; }; 6004019F1D340B760020EAAB /* ADTelemetry.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ADTelemetry.h; sourceTree = ""; }; 600401A31D3421480020EAAB /* ADTelemetry.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ADTelemetry.m; sourceTree = ""; }; 600401A61D3426250020EAAB /* ADTelemetry+Internal.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "ADTelemetry+Internal.h"; sourceTree = ""; }; @@ -530,6 +554,13 @@ /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ + 04AB6D3F1D9D619B007E9A83 /* Frameworks */ = { + isa = PBXFrameworksBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + runOnlyForDeploymentPostprocessing = 0; + }; 8B0965A717F25770002BDFB8 /* Frameworks */ = { isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; @@ -586,6 +617,32 @@ /* End PBXFrameworksBuildPhase section */ /* Begin PBXGroup section */ + 04AB6D431D9D619B007E9A83 /* UnitTestHostApp */ = { + isa = PBXGroup; + children = ( + 04AB6D5A1D9D61CA007E9A83 /* UnitTestHostApp.entitlements */, + 04AB6D471D9D619B007E9A83 /* AppDelegate.h */, + 04AB6D481D9D619B007E9A83 /* AppDelegate.m */, + 04AB6D4A1D9D619B007E9A83 /* ViewController.h */, + 04AB6D4B1D9D619B007E9A83 /* ViewController.m */, + 04AB6D4D1D9D619B007E9A83 /* Main.storyboard */, + 04AB6D501D9D619B007E9A83 /* Assets.xcassets */, + 04AB6D521D9D619B007E9A83 /* LaunchScreen.storyboard */, + 04AB6D551D9D619B007E9A83 /* Info.plist */, + 04AB6D441D9D619B007E9A83 /* Supporting Files */, + ); + name = UnitTestHostApp; + path = ../UnitTestHostApp; + sourceTree = ""; + }; + 04AB6D441D9D619B007E9A83 /* Supporting Files */ = { + isa = PBXGroup; + children = ( + 04AB6D451D9D619B007E9A83 /* main.m */, + ); + name = "Supporting Files"; + sourceTree = ""; + }; 600401A21D3420C10020EAAB /* telemetry */ = { isa = PBXGroup; children = ( @@ -627,6 +684,7 @@ 9453C3FD1C586425006B9E79 /* ADAL.framework */, 94DD18E11C5ACFBF00F80C62 /* ADAL Mac Tests.xctest */, D664F1B41D302B9C0017B799 /* libADAL-core.a */, + 04AB6D421D9D619B007E9A83 /* UnitTestHostApp.app */, ); name = Products; sourceTree = ""; @@ -687,6 +745,7 @@ 8B0965C317F25770002BDFB8 /* tests */ = { isa = PBXGroup; children = ( + 04AB6D431D9D619B007E9A83 /* UnitTestHostApp */, 6071B5E21C14C0B0006F6CC2 /* ADTestURLConnection.h */, 6071B5E31C14C0B0006F6CC2 /* ADTestURLConnection.m */, 8BB8346A1807BE3F007F9F0D /* ADAcquireTokenTests.m */, @@ -1132,6 +1191,23 @@ /* End PBXHeadersBuildPhase section */ /* Begin PBXNativeTarget section */ + 04AB6D411D9D619B007E9A83 /* UnitTestHostApp */ = { + isa = PBXNativeTarget; + buildConfigurationList = 04AB6D591D9D619B007E9A83 /* Build configuration list for PBXNativeTarget "UnitTestHostApp" */; + buildPhases = ( + 04AB6D3E1D9D619B007E9A83 /* Sources */, + 04AB6D3F1D9D619B007E9A83 /* Frameworks */, + 04AB6D401D9D619B007E9A83 /* Resources */, + ); + buildRules = ( + ); + dependencies = ( + ); + name = UnitTestHostApp; + productName = UnitTestHostApp; + productReference = 04AB6D421D9D619B007E9A83 /* UnitTestHostApp.app */; + productType = "com.apple.product-type.application"; + }; 8B0965A917F25770002BDFB8 /* ADALiOS */ = { isa = PBXNativeTarget; buildConfigurationList = 8B0965CD17F25770002BDFB8 /* Build configuration list for PBXNativeTarget "ADALiOS" */; @@ -1162,6 +1238,7 @@ ); dependencies = ( D69A720A1D4FEC4200E91DB3 /* PBXTargetDependency */, + 04AB6D5C1D9D61E2007E9A83 /* PBXTargetDependency */, ); name = ADALiOSTests; productName = ADALiOSTests; @@ -1251,6 +1328,19 @@ LastUpgradeCheck = 0720; ORGANIZATIONNAME = "MS Open Tech"; TargetAttributes = { + 04AB6D411D9D619B007E9A83 = { + CreatedOnToolsVersion = 8.0; + DevelopmentTeam = UBF8T346G9; + ProvisioningStyle = Automatic; + SystemCapabilities = { + com.apple.Keychain = { + enabled = 1; + }; + }; + }; + 8B0965B917F25770002BDFB8 = { + TestTargetID = 04AB6D411D9D619B007E9A83; + }; 9453C3CB1C583E07006B9E79 = { CreatedOnToolsVersion = 7.2; }; @@ -1271,6 +1361,7 @@ hasScannedForEncodings = 0; knownRegions = ( en, + Base, ); mainGroup = 8B0965A117F25770002BDFB8; productRefGroup = 8B0965AB17F25770002BDFB8 /* Products */; @@ -1284,11 +1375,22 @@ 9453C3FC1C586425006B9E79 /* ADAL Mac */, 94DD18E01C5ACFBF00F80C62 /* ADAL Mac Tests */, 9453C4571C5866D0006B9E79 /* Build All */, + 04AB6D411D9D619B007E9A83 /* UnitTestHostApp */, ); }; /* End PBXProject section */ /* Begin PBXResourcesBuildPhase section */ + 04AB6D401D9D619B007E9A83 /* Resources */ = { + isa = PBXResourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + 04AB6D541D9D619B007E9A83 /* LaunchScreen.storyboard in Resources */, + 04AB6D511D9D619B007E9A83 /* Assets.xcassets in Resources */, + 04AB6D4F1D9D619B007E9A83 /* Main.storyboard in Resources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; 8B0965B817F25770002BDFB8 /* Resources */ = { isa = PBXResourcesBuildPhase; buildActionMask = 2147483647; @@ -1376,6 +1478,16 @@ /* End PBXShellScriptBuildPhase section */ /* Begin PBXSourcesBuildPhase section */ + 04AB6D3E1D9D619B007E9A83 /* Sources */ = { + isa = PBXSourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + 04AB6D4C1D9D619B007E9A83 /* ViewController.m in Sources */, + 04AB6D491D9D619B007E9A83 /* AppDelegate.m in Sources */, + 04AB6D461D9D619B007E9A83 /* main.m in Sources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; 8B0965A617F25770002BDFB8 /* Sources */ = { isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; @@ -1574,6 +1686,11 @@ /* End PBXSourcesBuildPhase section */ /* Begin PBXTargetDependency section */ + 04AB6D5C1D9D61E2007E9A83 /* PBXTargetDependency */ = { + isa = PBXTargetDependency; + target = 04AB6D411D9D619B007E9A83 /* UnitTestHostApp */; + targetProxy = 04AB6D5B1D9D61E2007E9A83 /* PBXContainerItemProxy */; + }; 9453C45D1C5866D8006B9E79 /* PBXTargetDependency */ = { isa = PBXTargetDependency; target = 9453C3FC1C586425006B9E79 /* ADAL Mac */; @@ -1602,6 +1719,22 @@ /* End PBXTargetDependency section */ /* Begin PBXVariantGroup section */ + 04AB6D4D1D9D619B007E9A83 /* Main.storyboard */ = { + isa = PBXVariantGroup; + children = ( + 04AB6D4E1D9D619B007E9A83 /* Base */, + ); + name = Main.storyboard; + sourceTree = ""; + }; + 04AB6D521D9D619B007E9A83 /* LaunchScreen.storyboard */ = { + isa = PBXVariantGroup; + children = ( + 04AB6D531D9D619B007E9A83 /* Base */, + ); + name = LaunchScreen.storyboard; + sourceTree = ""; + }; 8BFEF066182DA57800122C0C /* InfoPlist.strings */ = { isa = PBXVariantGroup; children = ( @@ -1621,6 +1754,89 @@ /* End PBXVariantGroup section */ /* Begin XCBuildConfiguration section */ + 04AB6D561D9D619B007E9A83 /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; + CLANG_ANALYZER_NONNULL = YES; + CLANG_ENABLE_OBJC_ARC = YES; + CLANG_WARN_DOCUMENTATION_COMMENTS = YES; + CLANG_WARN_INFINITE_RECURSION = YES; + CLANG_WARN_SUSPICIOUS_MOVES = YES; + CLANG_WARN_UNREACHABLE_CODE = YES; + CODE_SIGN_ENTITLEMENTS = UnitTestHostApp/UnitTestHostApp.entitlements; + "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; + DEBUG_INFORMATION_FORMAT = dwarf; + DEVELOPMENT_TEAM = UBF8T346G9; + ENABLE_STRICT_OBJC_MSGSEND = YES; + GCC_NO_COMMON_BLOCKS = YES; + GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; + INFOPLIST_FILE = UnitTestHostApp/Info.plist; + IPHONEOS_DEPLOYMENT_TARGET = 10.0; + LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; + MTL_ENABLE_DEBUG_INFO = YES; + PRODUCT_BUNDLE_IDENTIFIER = com.MSOpenTech.UnitTestHostApp; + PRODUCT_NAME = "$(TARGET_NAME)"; + TARGETED_DEVICE_FAMILY = "1,2"; + }; + name = Debug; + }; + 04AB6D571D9D619B007E9A83 /* CodeCoverage */ = { + isa = XCBuildConfiguration; + buildSettings = { + ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; + CLANG_ANALYZER_NONNULL = YES; + CLANG_ENABLE_OBJC_ARC = YES; + CLANG_WARN_DOCUMENTATION_COMMENTS = YES; + CLANG_WARN_INFINITE_RECURSION = YES; + CLANG_WARN_SUSPICIOUS_MOVES = YES; + CLANG_WARN_UNREACHABLE_CODE = YES; + CODE_SIGN_ENTITLEMENTS = UnitTestHostApp/UnitTestHostApp.entitlements; + "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; + COPY_PHASE_STRIP = NO; + DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; + DEVELOPMENT_TEAM = UBF8T346G9; + ENABLE_STRICT_OBJC_MSGSEND = YES; + GCC_NO_COMMON_BLOCKS = YES; + GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; + INFOPLIST_FILE = UnitTestHostApp/Info.plist; + IPHONEOS_DEPLOYMENT_TARGET = 10.0; + LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; + MTL_ENABLE_DEBUG_INFO = NO; + PRODUCT_BUNDLE_IDENTIFIER = com.MSOpenTech.UnitTestHostApp; + PRODUCT_NAME = "$(TARGET_NAME)"; + TARGETED_DEVICE_FAMILY = "1,2"; + }; + name = CodeCoverage; + }; + 04AB6D581D9D619B007E9A83 /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; + CLANG_ANALYZER_NONNULL = YES; + CLANG_ENABLE_OBJC_ARC = YES; + CLANG_WARN_DOCUMENTATION_COMMENTS = YES; + CLANG_WARN_INFINITE_RECURSION = YES; + CLANG_WARN_SUSPICIOUS_MOVES = YES; + CLANG_WARN_UNREACHABLE_CODE = YES; + CODE_SIGN_ENTITLEMENTS = UnitTestHostApp/UnitTestHostApp.entitlements; + "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; + COPY_PHASE_STRIP = NO; + DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; + DEVELOPMENT_TEAM = UBF8T346G9; + ENABLE_STRICT_OBJC_MSGSEND = YES; + GCC_NO_COMMON_BLOCKS = YES; + GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; + INFOPLIST_FILE = UnitTestHostApp/Info.plist; + IPHONEOS_DEPLOYMENT_TARGET = 10.0; + LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; + MTL_ENABLE_DEBUG_INFO = NO; + PRODUCT_BUNDLE_IDENTIFIER = com.MSOpenTech.UnitTestHostApp; + PRODUCT_NAME = "$(TARGET_NAME)"; + TARGETED_DEVICE_FAMILY = "1,2"; + }; + name = Release; + }; 8B0965CB17F25770002BDFB8 /* Debug */ = { isa = XCBuildConfiguration; baseConfigurationReference = 946347821C644E13000A6DA1 /* adal__debug.xcconfig */; @@ -1784,6 +2000,7 @@ PRECOMPS_INCLUDE_HEADERS_FROM_BUILT_PRODUCTS_DIR = YES; PRODUCT_BUNDLE_IDENTIFIER = "MS-Open-Tech.${PRODUCT_NAME:rfc1034identifier}"; PRODUCT_NAME = "$(TARGET_NAME)"; + TEST_HOST = "$(BUILT_PRODUCTS_DIR)/UnitTestHostApp.app/UnitTestHostApp"; WRAPPER_EXTENSION = xctest; }; name = Debug; @@ -1812,6 +2029,7 @@ PRECOMPS_INCLUDE_HEADERS_FROM_BUILT_PRODUCTS_DIR = YES; PRODUCT_BUNDLE_IDENTIFIER = "MS-Open-Tech.${PRODUCT_NAME:rfc1034identifier}"; PRODUCT_NAME = "$(TARGET_NAME)"; + TEST_HOST = "$(BUILT_PRODUCTS_DIR)/UnitTestHostApp.app/UnitTestHostApp"; WRAPPER_EXTENSION = xctest; }; name = Release; @@ -1914,6 +2132,7 @@ PRECOMPS_INCLUDE_HEADERS_FROM_BUILT_PRODUCTS_DIR = YES; PRODUCT_BUNDLE_IDENTIFIER = "MS-Open-Tech.${PRODUCT_NAME:rfc1034identifier}"; PRODUCT_NAME = "$(TARGET_NAME)"; + TEST_HOST = "$(BUILT_PRODUCTS_DIR)/UnitTestHostApp.app/UnitTestHostApp"; WRAPPER_EXTENSION = xctest; }; name = CodeCoverage; @@ -2254,6 +2473,15 @@ /* End XCBuildConfiguration section */ /* Begin XCConfigurationList section */ + 04AB6D591D9D619B007E9A83 /* Build configuration list for PBXNativeTarget "UnitTestHostApp" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + 04AB6D561D9D619B007E9A83 /* Debug */, + 04AB6D571D9D619B007E9A83 /* CodeCoverage */, + 04AB6D581D9D619B007E9A83 /* Release */, + ); + defaultConfigurationIsVisible = 0; + }; 8B0965A517F25770002BDFB8 /* Build configuration list for PBXProject "ADAL" */ = { isa = XCConfigurationList; buildConfigurations = ( diff --git a/ADAL/UnitTestHostApp/AppDelegate.h b/ADAL/UnitTestHostApp/AppDelegate.h new file mode 100644 index 000000000..7c2955ab9 --- /dev/null +++ b/ADAL/UnitTestHostApp/AppDelegate.h @@ -0,0 +1,17 @@ +// +// AppDelegate.h +// UnitTestHostApp +// +// Created by Yong Zeng on 2016-09-29. +// Copyright © 2016 MS Open Tech. All rights reserved. +// + +#import + +@interface AppDelegate : UIResponder + +@property (strong, nonatomic) UIWindow *window; + + +@end + diff --git a/ADAL/UnitTestHostApp/AppDelegate.m b/ADAL/UnitTestHostApp/AppDelegate.m new file mode 100644 index 000000000..1060e25a1 --- /dev/null +++ b/ADAL/UnitTestHostApp/AppDelegate.m @@ -0,0 +1,51 @@ +// +// AppDelegate.m +// UnitTestHostApp +// +// Created by Yong Zeng on 2016-09-29. +// Copyright © 2016 MS Open Tech. All rights reserved. +// + +#import "AppDelegate.h" + +@interface AppDelegate () + +@end + +@implementation AppDelegate + + +- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { + // Override point for customization after application launch. + return YES; +} + + +- (void)applicationWillResignActive:(UIApplication *)application { + // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state. + // Use this method to pause ongoing tasks, disable timers, and invalidate graphics rendering callbacks. Games should use this method to pause the game. +} + + +- (void)applicationDidEnterBackground:(UIApplication *)application { + // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later. + // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits. +} + + +- (void)applicationWillEnterForeground:(UIApplication *)application { + // Called as part of the transition from the background to the active state; here you can undo many of the changes made on entering the background. +} + + +- (void)applicationDidBecomeActive:(UIApplication *)application { + // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface. +} + + +- (void)applicationWillTerminate:(UIApplication *)application { + // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:. +} + + +@end diff --git a/ADAL/UnitTestHostApp/Assets.xcassets/AppIcon.appiconset/Contents.json b/ADAL/UnitTestHostApp/Assets.xcassets/AppIcon.appiconset/Contents.json new file mode 100644 index 000000000..1d060ed28 --- /dev/null +++ b/ADAL/UnitTestHostApp/Assets.xcassets/AppIcon.appiconset/Contents.json @@ -0,0 +1,93 @@ +{ + "images" : [ + { + "idiom" : "iphone", + "size" : "20x20", + "scale" : "2x" + }, + { + "idiom" : "iphone", + "size" : "20x20", + "scale" : "3x" + }, + { + "idiom" : "iphone", + "size" : "29x29", + "scale" : "2x" + }, + { + "idiom" : "iphone", + "size" : "29x29", + "scale" : "3x" + }, + { + "idiom" : "iphone", + "size" : "40x40", + "scale" : "2x" + }, + { + "idiom" : "iphone", + "size" : "40x40", + "scale" : "3x" + }, + { + "idiom" : "iphone", + "size" : "60x60", + "scale" : "2x" + }, + { + "idiom" : "iphone", + "size" : "60x60", + "scale" : "3x" + }, + { + "idiom" : "ipad", + "size" : "20x20", + "scale" : "1x" + }, + { + "idiom" : "ipad", + "size" : "20x20", + "scale" : "2x" + }, + { + "idiom" : "ipad", + "size" : "29x29", + "scale" : "1x" + }, + { + "idiom" : "ipad", + "size" : "29x29", + "scale" : "2x" + }, + { + "idiom" : "ipad", + "size" : "40x40", + "scale" : "1x" + }, + { + "idiom" : "ipad", + "size" : "40x40", + "scale" : "2x" + }, + { + "idiom" : "ipad", + "size" : "76x76", + "scale" : "1x" + }, + { + "idiom" : "ipad", + "size" : "76x76", + "scale" : "2x" + }, + { + "idiom" : "ipad", + "size" : "83.5x83.5", + "scale" : "2x" + } + ], + "info" : { + "version" : 1, + "author" : "xcode" + } +} \ No newline at end of file diff --git a/ADAL/UnitTestHostApp/Base.lproj/LaunchScreen.storyboard b/ADAL/UnitTestHostApp/Base.lproj/LaunchScreen.storyboard new file mode 100644 index 000000000..fdf3f97d1 --- /dev/null +++ b/ADAL/UnitTestHostApp/Base.lproj/LaunchScreen.storyboard @@ -0,0 +1,27 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/ADAL/UnitTestHostApp/Base.lproj/Main.storyboard b/ADAL/UnitTestHostApp/Base.lproj/Main.storyboard new file mode 100644 index 000000000..4529698c4 --- /dev/null +++ b/ADAL/UnitTestHostApp/Base.lproj/Main.storyboard @@ -0,0 +1,26 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/ADAL/UnitTestHostApp/Info.plist b/ADAL/UnitTestHostApp/Info.plist new file mode 100644 index 000000000..d05247386 --- /dev/null +++ b/ADAL/UnitTestHostApp/Info.plist @@ -0,0 +1,45 @@ + + + + + CFBundleDevelopmentRegion + en + CFBundleExecutable + $(EXECUTABLE_NAME) + CFBundleIdentifier + $(PRODUCT_BUNDLE_IDENTIFIER) + CFBundleInfoDictionaryVersion + 6.0 + CFBundleName + $(PRODUCT_NAME) + CFBundlePackageType + APPL + CFBundleShortVersionString + 1.0 + CFBundleVersion + 1 + LSRequiresIPhoneOS + + UILaunchStoryboardName + LaunchScreen + UIMainStoryboardFile + Main + UIRequiredDeviceCapabilities + + armv7 + + UISupportedInterfaceOrientations + + UIInterfaceOrientationPortrait + UIInterfaceOrientationLandscapeLeft + UIInterfaceOrientationLandscapeRight + + UISupportedInterfaceOrientations~ipad + + UIInterfaceOrientationPortrait + UIInterfaceOrientationPortraitUpsideDown + UIInterfaceOrientationLandscapeLeft + UIInterfaceOrientationLandscapeRight + + + diff --git a/ADAL/UnitTestHostApp/UnitTestHostApp.entitlements b/ADAL/UnitTestHostApp/UnitTestHostApp.entitlements new file mode 100644 index 000000000..dfa9b9e28 --- /dev/null +++ b/ADAL/UnitTestHostApp/UnitTestHostApp.entitlements @@ -0,0 +1,12 @@ + + + + + keychain-access-groups + + $(AppIdentifierPrefix)com.MSOpenTech.UnitTestHostApp + $(AppIdentifierPrefix)com.microsoft.adalcache + $(AppIdentifierPrefix)com.microsoft.workplacejoin + + + diff --git a/ADAL/UnitTestHostApp/ViewController.h b/ADAL/UnitTestHostApp/ViewController.h new file mode 100644 index 000000000..7844d08d3 --- /dev/null +++ b/ADAL/UnitTestHostApp/ViewController.h @@ -0,0 +1,15 @@ +// +// ViewController.h +// UnitTestHostApp +// +// Created by Yong Zeng on 2016-09-29. +// Copyright © 2016 MS Open Tech. All rights reserved. +// + +#import + +@interface ViewController : UIViewController + + +@end + diff --git a/ADAL/UnitTestHostApp/ViewController.m b/ADAL/UnitTestHostApp/ViewController.m new file mode 100644 index 000000000..c8a18ac4d --- /dev/null +++ b/ADAL/UnitTestHostApp/ViewController.m @@ -0,0 +1,29 @@ +// +// ViewController.m +// UnitTestHostApp +// +// Created by Yong Zeng on 2016-09-29. +// Copyright © 2016 MS Open Tech. All rights reserved. +// + +#import "ViewController.h" + +@interface ViewController () + +@end + +@implementation ViewController + +- (void)viewDidLoad { + [super viewDidLoad]; + // Do any additional setup after loading the view, typically from a nib. +} + + +- (void)didReceiveMemoryWarning { + [super didReceiveMemoryWarning]; + // Dispose of any resources that can be recreated. +} + + +@end diff --git a/ADAL/UnitTestHostApp/main.m b/ADAL/UnitTestHostApp/main.m new file mode 100644 index 000000000..4c0d1fceb --- /dev/null +++ b/ADAL/UnitTestHostApp/main.m @@ -0,0 +1,16 @@ +// +// main.m +// UnitTestHostApp +// +// Created by Yong Zeng on 2016-09-29. +// Copyright © 2016 MS Open Tech. All rights reserved. +// + +#import +#import "AppDelegate.h" + +int main(int argc, char * argv[]) { + @autoreleasepool { + return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class])); + } +} From 404d89b6c52ee82f409b79a06f539362496c0aba Mon Sep 17 00:00:00 2001 From: Yong Zeng Date: Thu, 29 Sep 2016 07:59:14 -0700 Subject: [PATCH 26/92] change travis xcode to 8.0 --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index f5b40e316..88479992b 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,5 +1,5 @@ language: objective-c -osx_image: xcode7.2 +osx_image: xcode8.0 # Set up our rubygems (slather and xcpretty, namely) install: From 3cf5a94b49c9e2847774331a7b9cded8ef5de8a9 Mon Sep 17 00:00:00 2001 From: Yong Zeng Date: Thu, 29 Sep 2016 08:33:18 -0700 Subject: [PATCH 27/92] fix travis osx_image --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 88479992b..e7b669a7f 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,5 +1,5 @@ language: objective-c -osx_image: xcode8.0 +osx_image: xcode8 # Set up our rubygems (slather and xcpretty, namely) install: From b0bc7739efff28cb777410240ce0bfde844b7184 Mon Sep 17 00:00:00 2001 From: Yong Zeng Date: Thu, 29 Sep 2016 11:22:14 -0700 Subject: [PATCH 28/92] Change to Swift 2.3 to make the SampleSwiftApp work --- .../SampleSwiftApp.xcodeproj/project.pbxproj | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/Samples/SampleSwiftApp/SampleSwiftApp.xcodeproj/project.pbxproj b/Samples/SampleSwiftApp/SampleSwiftApp.xcodeproj/project.pbxproj index 3b0b4adea..6e060c196 100644 --- a/Samples/SampleSwiftApp/SampleSwiftApp.xcodeproj/project.pbxproj +++ b/Samples/SampleSwiftApp/SampleSwiftApp.xcodeproj/project.pbxproj @@ -17,6 +17,13 @@ /* End PBXBuildFile section */ /* Begin PBXContainerItemProxy section */ + 04AB6D7D1D9D91FD007E9A83 /* PBXContainerItemProxy */ = { + isa = PBXContainerItemProxy; + containerPortal = 8BD644301D74EFA400EE0AB4 /* ADAL.xcodeproj */; + proxyType = 2; + remoteGlobalIDString = 04AB6D421D9D619B007E9A83; + remoteInfo = UnitTestHostApp; + }; 8BD6443A1D74EFA400EE0AB4 /* PBXContainerItemProxy */ = { isa = PBXContainerItemProxy; containerPortal = 8BD644301D74EFA400EE0AB4 /* ADAL.xcodeproj */; @@ -114,6 +121,7 @@ 8BD644411D74EFA400EE0AB4 /* ADALiOSTests.xctest */, 8BD644431D74EFA400EE0AB4 /* ADAL.framework */, 8BD644451D74EFA400EE0AB4 /* ADAL Mac Tests.xctest */, + 04AB6D7E1D9D91FD007E9A83 /* UnitTestHostApp.app */, ); name = Products; sourceTree = ""; @@ -182,6 +190,7 @@ TargetAttributes = { D664F1521D3014F60017B799 = { CreatedOnToolsVersion = 7.3.1; + LastSwiftMigration = 0800; }; }; }; @@ -210,6 +219,13 @@ /* End PBXProject section */ /* Begin PBXReferenceProxy section */ + 04AB6D7E1D9D91FD007E9A83 /* UnitTestHostApp.app */ = { + isa = PBXReferenceProxy; + fileType = wrapper.application; + path = UnitTestHostApp.app; + remoteRef = 04AB6D7D1D9D91FD007E9A83 /* PBXContainerItemProxy */; + sourceTree = BUILT_PRODUCTS_DIR; + }; 8BD6443B1D74EFA400EE0AB4 /* libADALiOS.a */ = { isa = PBXReferenceProxy; fileType = archive.ar; @@ -404,6 +420,7 @@ LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = com.microsoft.SampleSwiftApp; PRODUCT_NAME = "$(TARGET_NAME)"; + SWIFT_VERSION = 2.3; }; name = Debug; }; @@ -415,6 +432,7 @@ LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = com.microsoft.SampleSwiftApp; PRODUCT_NAME = "$(TARGET_NAME)"; + SWIFT_VERSION = 2.3; }; name = Release; }; @@ -474,6 +492,7 @@ LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = com.microsoft.SampleSwiftApp; PRODUCT_NAME = "$(TARGET_NAME)"; + SWIFT_VERSION = 2.3; }; name = CodeCoverage; }; From 376263e99a8c42f3b4df8e45ad24d6fc97389102 Mon Sep 17 00:00:00 2001 From: Yong Zeng Date: Thu, 29 Sep 2016 12:38:02 -0700 Subject: [PATCH 29/92] make the storyboard Xcode 7 compatible for Unit Test Host App --- ADAL/ADAL.xcodeproj/project.pbxproj | 7 ++++--- .../Base.lproj/LaunchScreen.storyboard | 11 ++++++----- ADAL/UnitTestHostApp/Base.lproj/Main.storyboard | 13 +++++++------ 3 files changed, 17 insertions(+), 14 deletions(-) diff --git a/ADAL/ADAL.xcodeproj/project.pbxproj b/ADAL/ADAL.xcodeproj/project.pbxproj index bf3623340..b17dcc799 100755 --- a/ADAL/ADAL.xcodeproj/project.pbxproj +++ b/ADAL/ADAL.xcodeproj/project.pbxproj @@ -1772,7 +1772,7 @@ GCC_NO_COMMON_BLOCKS = YES; GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; INFOPLIST_FILE = UnitTestHostApp/Info.plist; - IPHONEOS_DEPLOYMENT_TARGET = 10.0; + IPHONEOS_DEPLOYMENT_TARGET = 8.0; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; MTL_ENABLE_DEBUG_INFO = YES; PRODUCT_BUNDLE_IDENTIFIER = com.MSOpenTech.UnitTestHostApp; @@ -1800,7 +1800,7 @@ GCC_NO_COMMON_BLOCKS = YES; GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; INFOPLIST_FILE = UnitTestHostApp/Info.plist; - IPHONEOS_DEPLOYMENT_TARGET = 10.0; + IPHONEOS_DEPLOYMENT_TARGET = 8.0; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; MTL_ENABLE_DEBUG_INFO = NO; PRODUCT_BUNDLE_IDENTIFIER = com.MSOpenTech.UnitTestHostApp; @@ -1828,7 +1828,7 @@ GCC_NO_COMMON_BLOCKS = YES; GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; INFOPLIST_FILE = UnitTestHostApp/Info.plist; - IPHONEOS_DEPLOYMENT_TARGET = 10.0; + IPHONEOS_DEPLOYMENT_TARGET = 8.0; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; MTL_ENABLE_DEBUG_INFO = NO; PRODUCT_BUNDLE_IDENTIFIER = com.MSOpenTech.UnitTestHostApp; @@ -2481,6 +2481,7 @@ 04AB6D581D9D619B007E9A83 /* Release */, ); defaultConfigurationIsVisible = 0; + defaultConfigurationName = Debug; }; 8B0965A517F25770002BDFB8 /* Build configuration list for PBXProject "ADAL" */ = { isa = XCConfigurationList; diff --git a/ADAL/UnitTestHostApp/Base.lproj/LaunchScreen.storyboard b/ADAL/UnitTestHostApp/Base.lproj/LaunchScreen.storyboard index fdf3f97d1..d9c93bbe7 100644 --- a/ADAL/UnitTestHostApp/Base.lproj/LaunchScreen.storyboard +++ b/ADAL/UnitTestHostApp/Base.lproj/LaunchScreen.storyboard @@ -1,8 +1,9 @@ - + - - + + + @@ -14,9 +15,9 @@ - + - + diff --git a/ADAL/UnitTestHostApp/Base.lproj/Main.storyboard b/ADAL/UnitTestHostApp/Base.lproj/Main.storyboard index 4529698c4..b1b8968c2 100644 --- a/ADAL/UnitTestHostApp/Base.lproj/Main.storyboard +++ b/ADAL/UnitTestHostApp/Base.lproj/Main.storyboard @@ -1,22 +1,23 @@ - + - - + + + - + - + - + From 7cbe892984f567e7476ffb47dbc626cde716a255 Mon Sep 17 00:00:00 2001 From: Yong Zeng Date: Thu, 29 Sep 2016 16:01:28 -0700 Subject: [PATCH 30/92] add MIT license to some newly added files --- ADAL/UnitTestHostApp/AppDelegate.h | 23 +++++++++++++++++++---- ADAL/UnitTestHostApp/AppDelegate.m | 23 +++++++++++++++++++---- ADAL/UnitTestHostApp/ViewController.h | 23 +++++++++++++++++++---- ADAL/UnitTestHostApp/ViewController.m | 23 +++++++++++++++++++---- ADAL/UnitTestHostApp/main.m | 23 +++++++++++++++++++---- 5 files changed, 95 insertions(+), 20 deletions(-) diff --git a/ADAL/UnitTestHostApp/AppDelegate.h b/ADAL/UnitTestHostApp/AppDelegate.h index 7c2955ab9..5806d897d 100644 --- a/ADAL/UnitTestHostApp/AppDelegate.h +++ b/ADAL/UnitTestHostApp/AppDelegate.h @@ -1,10 +1,25 @@ +// Copyright (c) Microsoft Corporation. +// All rights reserved. // -// AppDelegate.h -// UnitTestHostApp +// This code is licensed under the MIT License. // -// Created by Yong Zeng on 2016-09-29. -// Copyright © 2016 MS Open Tech. All rights reserved. +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files(the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and / or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions : // +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE. #import diff --git a/ADAL/UnitTestHostApp/AppDelegate.m b/ADAL/UnitTestHostApp/AppDelegate.m index 1060e25a1..136da13f2 100644 --- a/ADAL/UnitTestHostApp/AppDelegate.m +++ b/ADAL/UnitTestHostApp/AppDelegate.m @@ -1,10 +1,25 @@ +// Copyright (c) Microsoft Corporation. +// All rights reserved. // -// AppDelegate.m -// UnitTestHostApp +// This code is licensed under the MIT License. // -// Created by Yong Zeng on 2016-09-29. -// Copyright © 2016 MS Open Tech. All rights reserved. +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files(the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and / or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions : // +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE. #import "AppDelegate.h" diff --git a/ADAL/UnitTestHostApp/ViewController.h b/ADAL/UnitTestHostApp/ViewController.h index 7844d08d3..ae183093e 100644 --- a/ADAL/UnitTestHostApp/ViewController.h +++ b/ADAL/UnitTestHostApp/ViewController.h @@ -1,10 +1,25 @@ +// Copyright (c) Microsoft Corporation. +// All rights reserved. // -// ViewController.h -// UnitTestHostApp +// This code is licensed under the MIT License. // -// Created by Yong Zeng on 2016-09-29. -// Copyright © 2016 MS Open Tech. All rights reserved. +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files(the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and / or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions : // +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE. #import diff --git a/ADAL/UnitTestHostApp/ViewController.m b/ADAL/UnitTestHostApp/ViewController.m index c8a18ac4d..9edc06c80 100644 --- a/ADAL/UnitTestHostApp/ViewController.m +++ b/ADAL/UnitTestHostApp/ViewController.m @@ -1,10 +1,25 @@ +// Copyright (c) Microsoft Corporation. +// All rights reserved. // -// ViewController.m -// UnitTestHostApp +// This code is licensed under the MIT License. // -// Created by Yong Zeng on 2016-09-29. -// Copyright © 2016 MS Open Tech. All rights reserved. +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files(the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and / or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions : // +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE. #import "ViewController.h" diff --git a/ADAL/UnitTestHostApp/main.m b/ADAL/UnitTestHostApp/main.m index 4c0d1fceb..acc4db8c7 100644 --- a/ADAL/UnitTestHostApp/main.m +++ b/ADAL/UnitTestHostApp/main.m @@ -1,10 +1,25 @@ +// Copyright (c) Microsoft Corporation. +// All rights reserved. // -// main.m -// UnitTestHostApp +// This code is licensed under the MIT License. // -// Created by Yong Zeng on 2016-09-29. -// Copyright © 2016 MS Open Tech. All rights reserved. +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files(the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and / or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions : // +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE. #import #import "AppDelegate.h" From 65fc01331e799487bf0eb32cd475bdac92561cac Mon Sep 17 00:00:00 2001 From: Yong Zeng Date: Sat, 1 Oct 2016 22:45:43 -0700 Subject: [PATCH 31/92] add a dummy ADAL.m such that libADALiOS.a will be generated --- ADAL/ADAL.xcodeproj/project.pbxproj | 4 ++++ ADAL/src/ADAL.m | 24 ++++++++++++++++++++++++ 2 files changed, 28 insertions(+) create mode 100644 ADAL/src/ADAL.m diff --git a/ADAL/ADAL.xcodeproj/project.pbxproj b/ADAL/ADAL.xcodeproj/project.pbxproj index b17dcc799..89f60c8f6 100755 --- a/ADAL/ADAL.xcodeproj/project.pbxproj +++ b/ADAL/ADAL.xcodeproj/project.pbxproj @@ -45,6 +45,7 @@ 601BEE341C6DCB0B004AA8C1 /* ADWebAuthControllerTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 601BEE331C6DCB0B004AA8C1 /* ADWebAuthControllerTests.m */; }; 601BEE351C6DCB0B004AA8C1 /* ADWebAuthControllerTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 601BEE331C6DCB0B004AA8C1 /* ADWebAuthControllerTests.m */; }; 6071B5E41C14C0B0006F6CC2 /* ADTestURLConnection.m in Sources */ = {isa = PBXBuildFile; fileRef = 6071B5E31C14C0B0006F6CC2 /* ADTestURLConnection.m */; }; + 60C351BA1DA0D588006C8435 /* ADAL.m in Sources */ = {isa = PBXBuildFile; fileRef = 60C351B91DA0D588006C8435 /* ADAL.m */; }; 8B0965AE17F25770002BDFB8 /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 8B0965AD17F25770002BDFB8 /* Foundation.framework */; }; 8B0965BC17F25770002BDFB8 /* XCTest.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 8B0965BB17F25770002BDFB8 /* XCTest.framework */; }; 8B0965BD17F25770002BDFB8 /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 8B0965AD17F25770002BDFB8 /* Foundation.framework */; }; @@ -375,6 +376,7 @@ 6071B5E21C14C0B0006F6CC2 /* ADTestURLConnection.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ADTestURLConnection.h; sourceTree = ""; }; 6071B5E31C14C0B0006F6CC2 /* ADTestURLConnection.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ADTestURLConnection.m; sourceTree = ""; }; 60967E191D76B62B00863853 /* tools */ = {isa = PBXFileReference; lastKnownFileType = folder; path = tools; sourceTree = SOURCE_ROOT; }; + 60C351B91DA0D588006C8435 /* ADAL.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ADAL.m; sourceTree = ""; }; 8B0965AA17F25770002BDFB8 /* libADALiOS.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = libADALiOS.a; sourceTree = BUILT_PRODUCTS_DIR; }; 8B0965AD17F25770002BDFB8 /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = System/Library/Frameworks/Foundation.framework; sourceTree = SDKROOT; }; 8B0965BA17F25770002BDFB8 /* ADALiOSTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = ADALiOSTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; @@ -707,6 +709,7 @@ isa = PBXGroup; children = ( 9453C3A41C583AA8006B9E79 /* public */, + 60C351B91DA0D588006C8435 /* ADAL.m */, 9453C3A31C583A9C006B9E79 /* ADAL_Internal.h */, 8BB8345B18074A58007F9F0D /* ADAuthenticationContext.m */, D6E43A681B04026D000F5BE2 /* ADAuthenticationContext+Internal.h */, @@ -1492,6 +1495,7 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( + 60C351BA1DA0D588006C8435 /* ADAL.m in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; diff --git a/ADAL/src/ADAL.m b/ADAL/src/ADAL.m new file mode 100644 index 000000000..d6de918af --- /dev/null +++ b/ADAL/src/ADAL.m @@ -0,0 +1,24 @@ +// Copyright (c) Microsoft Corporation. +// All rights reserved. +// +// This code is licensed under the MIT License. +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files(the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and / or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions : +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE. + +#import "ADAL.h" From 6379d8f9a269c92167176fdeefd364dfc5a76b17 Mon Sep 17 00:00:00 2001 From: Ryan Pangrle Date: Mon, 10 Oct 2016 11:28:53 -0700 Subject: [PATCH 32/92] Don't create a WPJ-not-supported error on Mac This causes the authentication flow to error out early whenever we get a pkeyauth challenge on Mac. Some ADFS servers are configured to always send pkeyauth challenges even if they aren't mandatory. Not erroring out here lets us finish the authentication fflow through other methods. --- ADAL/src/workplacejoin/mac/ADWorkPlaceJoinUtil.m | 13 ++----------- 1 file changed, 2 insertions(+), 11 deletions(-) diff --git a/ADAL/src/workplacejoin/mac/ADWorkPlaceJoinUtil.m b/ADAL/src/workplacejoin/mac/ADWorkPlaceJoinUtil.m index 4907a4165..e7865d439 100644 --- a/ADAL/src/workplacejoin/mac/ADWorkPlaceJoinUtil.m +++ b/ADAL/src/workplacejoin/mac/ADWorkPlaceJoinUtil.m @@ -28,17 +28,8 @@ @implementation ADWorkPlaceJoinUtil + (ADRegistrationInformation*)getRegistrationInformation:(NSUUID *)correlationId error:(ADAuthenticationError * __autoreleasing *)error { - ADAuthenticationError* adError = - [ADAuthenticationError errorFromAuthenticationError:AD_ERROR_SERVER_UNSUPPORTED_REQUEST - protocolCode:nil - errorDetails:@"Conditional Access is not supported on macOS." - correlationId:correlationId]; - - if (error) - { - *error = adError; - } - + (void)correlationId; + (void)error; return nil; } From 066be931be81f0b831894213b1d45ff35a15839e Mon Sep 17 00:00:00 2001 From: Ryan Pangrle Date: Mon, 10 Oct 2016 14:41:53 -0700 Subject: [PATCH 33/92] Add +[ADTokenCache defaultTokenCache] convenience method This method returns a singleton for the default token cache using the default storage delegate. This should make it a little easier for application developers to discover how to manipulate the cache on MacOS. --- ADAL/src/ADAuthenticationContext.m | 3 +-- ADAL/src/ADAuthenticationSettings.m | 19 ++++++++++++++----- ADAL/src/cache/ADTokenCache+Internal.h | 2 ++ ADAL/src/cache/ADTokenCache.m | 18 ++++++++++++++++++ ADAL/src/public/mac/ADTokenCache.h | 4 ++++ 5 files changed, 39 insertions(+), 7 deletions(-) diff --git a/ADAL/src/ADAuthenticationContext.m b/ADAL/src/ADAuthenticationContext.m index 7f8c1d37d..22870ca7a 100755 --- a/ADAL/src/ADAuthenticationContext.m +++ b/ADAL/src/ADAuthenticationContext.m @@ -144,8 +144,7 @@ - (id)initWithAuthority:(NSString *)authority return nil; } #else - tokenCache = [ADTokenCache new]; - [(ADTokenCache*)tokenCache setDelegate:[ADAuthenticationSettings sharedInstance].defaultStorageDelegate]; + tokenCache = [ADTokenCache defaultCache]; #endif return [self initWithAuthority:authority diff --git a/ADAL/src/ADAuthenticationSettings.m b/ADAL/src/ADAuthenticationSettings.m index dfa6bcadc..52f65c94e 100644 --- a/ADAL/src/ADAuthenticationSettings.m +++ b/ADAL/src/ADAuthenticationSettings.m @@ -25,17 +25,16 @@ #if TARGET_OS_IPHONE #import "ADKeychainTokenCache.h" +#else +#import "ADTokenCache+Internal.h" #endif // TARGET_OS_IPHONE + @implementation ADAuthenticationSettings @synthesize requestTimeOut = _requestTimeOut; @synthesize expirationBuffer = _expirationBuffer; -#if !TARGET_OS_IPHONE -@synthesize defaultStorageDelegate = _defaultStorageDelegate; -#endif // !TARGET_OS_IPHONE - /*! An internal initializer used from the static creation function. */ @@ -57,7 +56,7 @@ -(id) initInternal +(ADAuthenticationSettings*)sharedInstance { /* Below is a standard objective C singleton pattern*/ - static ADAuthenticationSettings* instance; + static ADAuthenticationSettings* instance = nil; static dispatch_once_t onceToken; @synchronized(self) { @@ -78,6 +77,16 @@ - (void)setDefaultKeychainGroup:(NSString*)keychainGroup { [ADKeychainTokenCache setDefaultKeychainGroup:keychainGroup]; } +#elif !TARGET_OS_IPHONE +- (id)defaultStorageDelegate +{ + return [[ADTokenCache defaultCache] delegate]; +} + +- (void)setDefaultStorageDelegate:(id)defaultStorageDelegate +{ + [[ADTokenCache defaultCache] setDelegate:defaultStorageDelegate]; +} #endif @end diff --git a/ADAL/src/cache/ADTokenCache+Internal.h b/ADAL/src/cache/ADTokenCache+Internal.h index 482e3ff1e..a7bbfbaca 100644 --- a/ADAL/src/cache/ADTokenCache+Internal.h +++ b/ADAL/src/cache/ADTokenCache+Internal.h @@ -29,5 +29,7 @@ - (BOOL)validateCache:(nullable NSDictionary *)dict error:(ADAuthenticationError * __nullable __autoreleasing * __nullable)error; +- (nullable id)delegate; + @end diff --git a/ADAL/src/cache/ADTokenCache.m b/ADAL/src/cache/ADTokenCache.m index a117ab555..b3f2d2e09 100644 --- a/ADAL/src/cache/ADTokenCache.m +++ b/ADAL/src/cache/ADTokenCache.m @@ -48,6 +48,7 @@ #import "ADUserInformation.h" #import "ADTokenCache+Internal.h" #import "ADTokenCacheKey.h" +#import "ADAuthenticationSettings.h" #include @@ -61,6 +62,18 @@ @implementation ADTokenCache ++ (ADTokenCache *)defaultCache +{ + static dispatch_once_t once; + static ADTokenCache * cache = nil; + + dispatch_once(&once, ^{ + cache = [ADTokenCache new]; + }); + + return cache; +} + - (id)init { if (!(self = [super init])) @@ -422,6 +435,11 @@ -(NSMutableArray*)filterOutTombstones:(NSArray*) items @implementation ADTokenCache (Internal) +- (id)delegate +{ + return _delegate; +} + - (BOOL)validateCache:(NSDictionary*)dict error:(ADAuthenticationError * __autoreleasing *)error { diff --git a/ADAL/src/public/mac/ADTokenCache.h b/ADAL/src/public/mac/ADTokenCache.h index 672d11182..ec1e70f71 100644 --- a/ADAL/src/public/mac/ADTokenCache.h +++ b/ADAL/src/public/mac/ADTokenCache.h @@ -46,6 +46,10 @@ pthread_rwlock_t _lock; } +/*! Returns the default cache object using the ADTokenCacheDelegate set in + ADAuthenticationSettings */ ++ (nonnull ADTokenCache *)defaultCache; + - (void)setDelegate:(nullable id)delegate; - (nullable NSData *)serialize; From 31cc74483e11e5a6c5bda2f4caf6912e3443042a Mon Sep 17 00:00:00 2001 From: Ryan Pangrle Date: Mon, 10 Oct 2016 14:46:42 -0700 Subject: [PATCH 34/92] Retain the port number when canonicalizing URLs --- ADAL/src/ADInstanceDiscovery.m | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/ADAL/src/ADInstanceDiscovery.m b/ADAL/src/ADInstanceDiscovery.m index 3b98b6d75..80f15b3b9 100644 --- a/ADAL/src/ADInstanceDiscovery.m +++ b/ADAL/src/ADInstanceDiscovery.m @@ -365,7 +365,15 @@ + (NSString*)canonicalizeAuthority:(NSString *)authority { return nil; } - trimmedAuthority = [NSString stringWithFormat:@"%@://%@/%@", scheme, host, tenant]; + NSNumber* port = url.port; + if (port) + { + trimmedAuthority = [NSString stringWithFormat:@"%@://%@:%d/%@", scheme, host, port.intValue, tenant]; + } + else + { + trimmedAuthority = [NSString stringWithFormat:@"%@://%@/%@", scheme, host, tenant]; + } return trimmedAuthority; } From 1029bd6cc3d4f13eb96c5b39613dbea3f1d985b9 Mon Sep 17 00:00:00 2001 From: Ryan Pangrle Date: Mon, 10 Oct 2016 16:01:07 -0700 Subject: [PATCH 35/92] Dispatch to main thread before showing NTLM UI --- ADAL/src/ui/mac/ADNTLMUIPrompt.m | 52 +++++++++++++++++--------------- 1 file changed, 27 insertions(+), 25 deletions(-) diff --git a/ADAL/src/ui/mac/ADNTLMUIPrompt.m b/ADAL/src/ui/mac/ADNTLMUIPrompt.m index 4ac0af6fc..0868f3fc0 100644 --- a/ADAL/src/ui/mac/ADNTLMUIPrompt.m +++ b/ADAL/src/ui/mac/ADNTLMUIPrompt.m @@ -35,32 +35,34 @@ @implementation ADNTLMUIPrompt + (void)presentPrompt:(void (^)(NSString * username, NSString * password))completionHandler { - NSAlert* alert = [NSAlert new]; - - [alert setMessageText:NSLocalizedString(@"Enter your credentials", nil)]; - [alert addButtonWithTitle:NSLocalizedString(@"Login", nil)]; - [alert addButtonWithTitle:NSLocalizedString(@"Cancel", nil)]; - - ADCredentialCollectionController* view = [ADCredentialCollectionController new]; - SAFE_ARC_AUTORELEASE(view); - [view.usernameLabel setStringValue:NSLocalizedString(@"Username", nil)]; - [view.passwordLabel setStringValue:NSLocalizedString(@"Password", nil)]; - [alert setAccessoryView:view.customView]; - - [alert beginSheetModalForWindow:[NSApp keyWindow] completionHandler:^(NSModalResponse returnCode) - { - if (returnCode == 1000) - { - NSString* username = [view.usernameField stringValue]; - NSString* password = [view.passwordField stringValue]; + dispatch_async(dispatch_get_main_queue(), ^{ + NSAlert* alert = [NSAlert new]; + + [alert setMessageText:NSLocalizedString(@"Enter your credentials", nil)]; + [alert addButtonWithTitle:NSLocalizedString(@"Login", nil)]; + [alert addButtonWithTitle:NSLocalizedString(@"Cancel", nil)]; + + ADCredentialCollectionController* view = [ADCredentialCollectionController new]; + SAFE_ARC_AUTORELEASE(view); + [view.usernameLabel setStringValue:NSLocalizedString(@"Username", nil)]; + [view.passwordLabel setStringValue:NSLocalizedString(@"Password", nil)]; + [alert setAccessoryView:view.customView]; - completionHandler(username, password); - } - else - { - completionHandler(nil, nil); - } - }]; + [alert beginSheetModalForWindow:[NSApp keyWindow] completionHandler:^(NSModalResponse returnCode) + { + if (returnCode == 1000) + { + NSString* username = [view.usernameField stringValue]; + NSString* password = [view.passwordField stringValue]; + + completionHandler(username, password); + } + else + { + completionHandler(nil, nil); + } + }]; + }); } @end From 2d1249a1bd33da4f7ffd6b073399a87717bcfeca Mon Sep 17 00:00:00 2001 From: Ryan Pangrle Date: Mon, 10 Oct 2016 19:17:27 -0700 Subject: [PATCH 36/92] Bring over many iOS test app improvements to Mac --- .../MyTestMacOSApp.xcodeproj/project.pbxproj | 57 ++- ...> ADTestAppAcquireTokenWindowController.h} | 55 +- .../ADTestAppAcquireTokenWindowController.m | 343 +++++++++++++ .../{ADTestInstance.h => ADTestAppCache.h} | 29 +- .../MyTestMacOSApp/ADTestAppCache.m | 187 +++++++ .../ADTestAppCacheWindowController.h | 35 ++ .../ADTestAppCacheWindowController.m | 225 ++++++++ .../MyTestMacOSApp/ADTestAppDelegate.h | 29 +- .../MyTestMacOSApp/ADTestAppDelegate.m | 480 +----------------- .../MyTestMacOSApp/ADTestAppSettings.h | 28 +- .../MyTestMacOSApp/ADTestAppSettings.m | 152 ++++-- .../MyTestMacOSApp/AcquireTokenWindow.xib | 355 +++++++++++++ .../MyTestMacOSApp/Base.lproj/MainMenu.xib | 182 +------ .../MyTestMacOSApp/CacheWindow.xib | 367 +++++++++++++ .../MyTestMacOSApp/MyTestMacOSApp-Info.plist | 5 + .../ADTestAppProfileViewController.m | 1 - .../MyTestiOSApp/ADTestAppSettings.m | 1 + 17 files changed, 1787 insertions(+), 744 deletions(-) rename Samples/MyTestMacOSApp/MyTestMacOSApp/{ADTestInstance.m => ADTestAppAcquireTokenWindowController.h} (51%) create mode 100644 Samples/MyTestMacOSApp/MyTestMacOSApp/ADTestAppAcquireTokenWindowController.m rename Samples/MyTestMacOSApp/MyTestMacOSApp/{ADTestInstance.h => ADTestAppCache.h} (59%) create mode 100644 Samples/MyTestMacOSApp/MyTestMacOSApp/ADTestAppCache.m create mode 100644 Samples/MyTestMacOSApp/MyTestMacOSApp/ADTestAppCacheWindowController.h create mode 100644 Samples/MyTestMacOSApp/MyTestMacOSApp/ADTestAppCacheWindowController.m create mode 100644 Samples/MyTestMacOSApp/MyTestMacOSApp/AcquireTokenWindow.xib create mode 100644 Samples/MyTestMacOSApp/MyTestMacOSApp/CacheWindow.xib diff --git a/Samples/MyTestMacOSApp/MyTestMacOSApp.xcodeproj/project.pbxproj b/Samples/MyTestMacOSApp/MyTestMacOSApp.xcodeproj/project.pbxproj index a1ccc3c5c..2d5bab027 100644 --- a/Samples/MyTestMacOSApp/MyTestMacOSApp.xcodeproj/project.pbxproj +++ b/Samples/MyTestMacOSApp/MyTestMacOSApp.xcodeproj/project.pbxproj @@ -21,8 +21,13 @@ 8BD92F0518C93BE70026A014 /* Cocoa.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 8BD92EE118C93BE70026A014 /* Cocoa.framework */; }; 8BD92F0D18C93BE70026A014 /* InfoPlist.strings in Resources */ = {isa = PBXBuildFile; fileRef = 8BD92F0B18C93BE70026A014 /* InfoPlist.strings */; }; 94DD18C51C59FE9700F80C62 /* ADTestAppSettings.m in Sources */ = {isa = PBXBuildFile; fileRef = 94DD18C21C59FE9700F80C62 /* ADTestAppSettings.m */; }; - 94DD18C61C59FE9700F80C62 /* ADTestInstance.m in Sources */ = {isa = PBXBuildFile; fileRef = 94DD18C41C59FE9700F80C62 /* ADTestInstance.m */; }; 94DD18DC1C5ACF1900F80C62 /* TestData.plist in Resources */ = {isa = PBXBuildFile; fileRef = 94DD18DB1C5ACF1900F80C62 /* TestData.plist */; }; + D60534131DAC66B200210C8A /* Security.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = D60534121DAC66B200210C8A /* Security.framework */; }; + D623B1991D9F1188004D51F0 /* AcquireTokenWindow.xib in Resources */ = {isa = PBXBuildFile; fileRef = D623B1981D9F1188004D51F0 /* AcquireTokenWindow.xib */; }; + D623B1A21D9F1246004D51F0 /* ADTestAppAcquireTokenWindowController.m in Sources */ = {isa = PBXBuildFile; fileRef = D623B1A11D9F1246004D51F0 /* ADTestAppAcquireTokenWindowController.m */; }; + D669AE131DA47AE300763477 /* ADTestAppCacheWindowController.m in Sources */ = {isa = PBXBuildFile; fileRef = D669AE111DA47AE300763477 /* ADTestAppCacheWindowController.m */; }; + D669AE141DA47AE300763477 /* CacheWindow.xib in Resources */ = {isa = PBXBuildFile; fileRef = D669AE121DA47AE300763477 /* CacheWindow.xib */; }; + D669AE1D1DA584B600763477 /* ADTestAppCache.m in Sources */ = {isa = PBXBuildFile; fileRef = D669AE1C1DA584B600763477 /* ADTestAppCache.m */; }; /* End PBXBuildFile section */ /* Begin PBXContainerItemProxy section */ @@ -82,6 +87,13 @@ remoteGlobalIDString = 8BD92EDD18C93BE70026A014; remoteInfo = MyTestMacOSApp; }; + D605341B1DAC66B200210C8A /* PBXContainerItemProxy */ = { + isa = PBXContainerItemProxy; + containerPortal = 8B6B78E61D74F04700AA02E8 /* ADAL.xcodeproj */; + proxyType = 2; + remoteGlobalIDString = 04AB6D421D9D619B007E9A83; + remoteInfo = UnitTestHostApp; + }; /* End PBXContainerItemProxy section */ /* Begin PBXCopyFilesBuildPhase section */ @@ -121,10 +133,17 @@ 8BD92F0C18C93BE70026A014 /* en */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = en; path = en.lproj/InfoPlist.strings; sourceTree = ""; }; 94DD18C11C59FE9700F80C62 /* ADTestAppSettings.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ADTestAppSettings.h; sourceTree = ""; }; 94DD18C21C59FE9700F80C62 /* ADTestAppSettings.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ADTestAppSettings.m; sourceTree = ""; }; - 94DD18C31C59FE9700F80C62 /* ADTestInstance.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ADTestInstance.h; sourceTree = ""; }; - 94DD18C41C59FE9700F80C62 /* ADTestInstance.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ADTestInstance.m; sourceTree = ""; }; 94DD18DB1C5ACF1900F80C62 /* TestData.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = TestData.plist; sourceTree = ""; }; 9722233519A813BB00092E85 /* MyTestMacOSApp.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.xml; path = MyTestMacOSApp.entitlements; sourceTree = ""; }; + D60534121DAC66B200210C8A /* Security.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Security.framework; path = System/Library/Frameworks/Security.framework; sourceTree = SDKROOT; }; + D623B1981D9F1188004D51F0 /* AcquireTokenWindow.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = AcquireTokenWindow.xib; sourceTree = ""; }; + D623B1A01D9F1246004D51F0 /* ADTestAppAcquireTokenWindowController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ADTestAppAcquireTokenWindowController.h; sourceTree = ""; }; + D623B1A11D9F1246004D51F0 /* ADTestAppAcquireTokenWindowController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ADTestAppAcquireTokenWindowController.m; sourceTree = ""; }; + D669AE101DA47AE300763477 /* ADTestAppCacheWindowController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ADTestAppCacheWindowController.h; sourceTree = ""; }; + D669AE111DA47AE300763477 /* ADTestAppCacheWindowController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ADTestAppCacheWindowController.m; sourceTree = ""; }; + D669AE121DA47AE300763477 /* CacheWindow.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = CacheWindow.xib; sourceTree = ""; }; + D669AE1B1DA584B600763477 /* ADTestAppCache.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ADTestAppCache.h; sourceTree = ""; }; + D669AE1C1DA584B600763477 /* ADTestAppCache.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ADTestAppCache.m; sourceTree = ""; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -132,6 +151,7 @@ isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; files = ( + D60534131DAC66B200210C8A /* Security.framework in Frameworks */, 8B6B78FC1D74F04D00AA02E8 /* ADAL.framework in Frameworks */, 8BD92EE218C93BE70026A014 /* Cocoa.framework in Frameworks */, ); @@ -158,6 +178,7 @@ 8B6B78F71D74F04700AA02E8 /* ADALiOSTests.xctest */, 8B6B78F91D74F04700AA02E8 /* ADAL.framework */, 8B6B78FB1D74F04700AA02E8 /* ADAL Mac Tests.xctest */, + D605341C1DAC66B200210C8A /* UnitTestHostApp.app */, ); name = Products; sourceTree = ""; @@ -185,6 +206,7 @@ 8BD92EE018C93BE70026A014 /* Frameworks */ = { isa = PBXGroup; children = ( + D60534121DAC66B200210C8A /* Security.framework */, 8BD92EE118C93BE70026A014 /* Cocoa.framework */, 8BD92F0318C93BE70026A014 /* XCTest.framework */, 8BD92EE318C93BE70026A014 /* Other Frameworks */, @@ -208,10 +230,16 @@ 9722233519A813BB00092E85 /* MyTestMacOSApp.entitlements */, 94DD18C11C59FE9700F80C62 /* ADTestAppSettings.h */, 94DD18C21C59FE9700F80C62 /* ADTestAppSettings.m */, - 94DD18C31C59FE9700F80C62 /* ADTestInstance.h */, - 94DD18C41C59FE9700F80C62 /* ADTestInstance.m */, 8BD92EF318C93BE70026A014 /* ADTestAppDelegate.h */, 8BD92EF418C93BE70026A014 /* ADTestAppDelegate.m */, + D669AE1B1DA584B600763477 /* ADTestAppCache.h */, + D669AE1C1DA584B600763477 /* ADTestAppCache.m */, + D623B1A01D9F1246004D51F0 /* ADTestAppAcquireTokenWindowController.h */, + D623B1A11D9F1246004D51F0 /* ADTestAppAcquireTokenWindowController.m */, + D669AE101DA47AE300763477 /* ADTestAppCacheWindowController.h */, + D669AE111DA47AE300763477 /* ADTestAppCacheWindowController.m */, + D669AE121DA47AE300763477 /* CacheWindow.xib */, + D623B1981D9F1188004D51F0 /* AcquireTokenWindow.xib */, 8BD92EF618C93BE70026A014 /* MainMenu.xib */, 8BD92EFC18C93BE70026A014 /* Images.xcassets */, 8BD92EF918C93BE70026A014 /* MyTestMacOSApp.xcdatamodeld */, @@ -296,7 +324,7 @@ 8BD92ED618C93BE70026A014 /* Project object */ = { isa = PBXProject; attributes = { - CLASSPREFIX = BV; + CLASSPREFIX = ADTestApp; LastUpgradeCheck = 0500; ORGANIZATIONNAME = "Microsoft Open Technologies, Inc"; TargetAttributes = { @@ -381,6 +409,13 @@ remoteRef = 8B6B78FA1D74F04700AA02E8 /* PBXContainerItemProxy */; sourceTree = BUILT_PRODUCTS_DIR; }; + D605341C1DAC66B200210C8A /* UnitTestHostApp.app */ = { + isa = PBXReferenceProxy; + fileType = wrapper.application; + path = UnitTestHostApp.app; + remoteRef = D605341B1DAC66B200210C8A /* PBXContainerItemProxy */; + sourceTree = BUILT_PRODUCTS_DIR; + }; /* End PBXReferenceProxy section */ /* Begin PBXResourcesBuildPhase section */ @@ -391,7 +426,9 @@ 8BD92EEC18C93BE70026A014 /* InfoPlist.strings in Resources */, 8BD92EFD18C93BE70026A014 /* Images.xcassets in Resources */, 8BD92EF218C93BE70026A014 /* Credits.rtf in Resources */, + D669AE141DA47AE300763477 /* CacheWindow.xib in Resources */, 94DD18DC1C5ACF1900F80C62 /* TestData.plist in Resources */, + D623B1991D9F1188004D51F0 /* AcquireTokenWindow.xib in Resources */, 8BD92EF818C93BE70026A014 /* MainMenu.xib in Resources */, ); runOnlyForDeploymentPostprocessing = 0; @@ -411,9 +448,11 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( + D669AE131DA47AE300763477 /* ADTestAppCacheWindowController.m in Sources */, 94DD18C51C59FE9700F80C62 /* ADTestAppSettings.m in Sources */, + D623B1A21D9F1246004D51F0 /* ADTestAppAcquireTokenWindowController.m in Sources */, + D669AE1D1DA584B600763477 /* ADTestAppCache.m in Sources */, 8BD92EF518C93BE70026A014 /* ADTestAppDelegate.m in Sources */, - 94DD18C61C59FE9700F80C62 /* ADTestInstance.m in Sources */, 8BD92EEE18C93BE70026A014 /* main.m in Sources */, 8BD92EFB18C93BE70026A014 /* MyTestMacOSApp.xcdatamodeld in Sources */, ); @@ -484,6 +523,7 @@ ARCHS = "$(ARCHS_STANDARD_32_64_BIT)"; CLANG_CXX_LANGUAGE_STANDARD = "c++0x"; CLANG_CXX_LIBRARY = "libc++"; + CLANG_ENABLE_OBJC_ARC = YES; CLANG_WARN_BOOL_CONVERSION = YES; CLANG_WARN_CONSTANT_CONVERSION = YES; CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; @@ -509,6 +549,7 @@ MACOSX_DEPLOYMENT_TARGET = 10.8; ONLY_ACTIVE_ARCH = YES; SDKROOT = macosx; + USER_HEADER_SEARCH_PATHS = "../../ADAL/src/** $(HOME)/aadoverrides"; }; name = Debug; }; @@ -519,6 +560,7 @@ ARCHS = "$(ARCHS_STANDARD_32_64_BIT)"; CLANG_CXX_LANGUAGE_STANDARD = "c++0x"; CLANG_CXX_LIBRARY = "libc++"; + CLANG_ENABLE_OBJC_ARC = YES; CLANG_WARN_BOOL_CONVERSION = YES; CLANG_WARN_CONSTANT_CONVERSION = YES; CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; @@ -539,6 +581,7 @@ GCC_WARN_UNUSED_VARIABLE = YES; MACOSX_DEPLOYMENT_TARGET = 10.8; SDKROOT = macosx; + USER_HEADER_SEARCH_PATHS = "../../ADAL/src/** $(HOME)/aadoverrides"; }; name = Release; }; diff --git a/Samples/MyTestMacOSApp/MyTestMacOSApp/ADTestInstance.m b/Samples/MyTestMacOSApp/MyTestMacOSApp/ADTestAppAcquireTokenWindowController.h similarity index 51% rename from Samples/MyTestMacOSApp/MyTestMacOSApp/ADTestInstance.m rename to Samples/MyTestMacOSApp/MyTestMacOSApp/ADTestAppAcquireTokenWindowController.h index 0d15acdc7..a69a2ed66 100644 --- a/Samples/MyTestMacOSApp/MyTestMacOSApp/ADTestInstance.m +++ b/Samples/MyTestMacOSApp/MyTestMacOSApp/ADTestAppAcquireTokenWindowController.h @@ -21,38 +21,35 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN // THE SOFTWARE. -#import "ADTestInstance.h" +#import +#import +#import "ADAL_Internal.h" +#import "ADUserIdentifier.h" -@implementation ADTestInstance - -@synthesize authority = _authority; -@synthesize clientId = _clientId; -@synthesize resource = _resource; -@synthesize redirectUri = _redirectUri; -@synthesize userId = _userId; -@synthesize validateAuthority = _validateAuthority; -@synthesize extraQueryParameters = _extraQueryParameters; -@synthesize password = _password; - - --(id) initWithDictionary: (NSDictionary*) contents +@interface ADTestAppAcquireTokenWindowController : NSWindowController { - self = [super init]; - if (!self) - { - return nil; - } - self->_authority = [contents objectForKey:@"Authority"]; - self->_clientId = [contents objectForKey:@"ClientId"]; - self->_resource = [contents objectForKey:@"Resource"]; - self->_redirectUri = [contents objectForKey:@"RedirectUri"]; - self->_userId = [contents objectForKey:@"UserId"]; - self->_password = [contents objectForKey:@"Password"]; - NSString* va = [contents objectForKey:@"SupportsValidation"]; - self->_validateAuthority = [va boolValue]; - self->_extraQueryParameters = [contents objectForKey:@"extraQueryParameters"]; + IBOutlet NSView* _authView; + IBOutlet WebView* _webView; + + IBOutlet NSView* _acquireSettingsView; + IBOutlet NSTextField* _userIdField; + IBOutlet NSTextView* _resultView; + IBOutlet NSSegmentedControl* _validateAuthority; + IBOutlet NSSegmentedControl* _webViewType; - return self; + IBOutlet NSPopUpButton* _profiles; + + IBOutlet NSTextField* _authority; + IBOutlet NSTextField* _clientId; + IBOutlet NSTextField* _redirectUri; + IBOutlet NSTextField* _resource; + + ADUserIdentifierType _idType; + ADPromptBehavior _promptBehavior; + + BOOL _userIdEdited; } ++ (void)showWindow; + @end diff --git a/Samples/MyTestMacOSApp/MyTestMacOSApp/ADTestAppAcquireTokenWindowController.m b/Samples/MyTestMacOSApp/MyTestMacOSApp/ADTestAppAcquireTokenWindowController.m new file mode 100644 index 000000000..99bc29809 --- /dev/null +++ b/Samples/MyTestMacOSApp/MyTestMacOSApp/ADTestAppAcquireTokenWindowController.m @@ -0,0 +1,343 @@ +// Copyright (c) Microsoft Corporation. +// All rights reserved. +// +// This code is licensed under the MIT License. +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files(the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and / or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions : +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE. + +#import "ADTestAppAcquireTokenWindowController.h" +#import "ADAL_Internal.h" +#import "ADUserIdentifier.h" +#import "ADTestAppSettings.h" +#import "ADTokenCache.h" +#import "ADAuthenticationSettings.h" +#import "ADWebAuthController.h" + + + +@interface ADTestAppAcquireTokenWindowController () + +@end + +@implementation ADTestAppAcquireTokenWindowController + ++ (void)showWindow +{ + static ADTestAppAcquireTokenWindowController* controller = nil; + + static dispatch_once_t once; + + dispatch_once(&once, ^{ + controller = [[ADTestAppAcquireTokenWindowController alloc] init]; + + + }); + + [controller showWindow:nil]; +} + +- (id)init +{ + if (!(self = [super initWithWindowNibName:@"AcquireTokenWindow"])) + { + return nil; + } + + _idType = OptionalDisplayableId; + _promptBehavior = AD_PROMPT_ALWAYS; + + return self; +} + +- (void)populateProfiles +{ + [_profiles removeAllItems]; + [_profiles setTarget:self]; + [_profiles setAction:@selector(selectedProfileChanged:)]; + NSUInteger cProfiles = [ADTestAppSettings numberOfProfiles]; + for (NSUInteger i = 0; i < cProfiles; i++) + { + [_profiles addItemWithTitle:[ADTestAppSettings profileTitleForIndex:i]]; + } + + [_profiles selectItemAtIndex:[ADTestAppSettings currentProfileIdx]]; +} + +- (void)populateCurrentProfile +{ + ADTestAppSettings* settings = [ADTestAppSettings settings]; + + _authority.stringValue = settings.authority; + _clientId.stringValue = settings.clientId; + _redirectUri.stringValue = settings.redirectUri.absoluteString; + _resource.stringValue = settings.resource; +} + +- (IBAction)selectedProfileChanged:(id)sender +{ + [[ADTestAppSettings settings] setProfileFromIndex:[_profiles indexOfSelectedItem]]; + [self populateCurrentProfile]; +} + +- (void)windowDidLoad +{ + [super windowDidLoad]; + + [self.window.contentView addSubview:_acquireSettingsView]; + [_authView setHidden:YES]; + [self.window.contentView addSubview:_authView]; + + [self populateProfiles]; + [self populateCurrentProfile]; +} + +- (IBAction)setIdentifierType:(id)sender +{ + NSButton* button = (NSButton*)sender; + NSString* idType = button.title; + + if ([idType isEqualToString:@"OptionalDisplayableId"]) + { + _idType = OptionalDisplayableId; + } + else if ([idType isEqualToString:@"RequiredDisplayableId"]) + { + _idType = RequiredDisplayableId; + } + else if ([idType isEqualToString:@"UniqueId"]) + { + _idType = UniqueId; + } + else + { + @throw @"Unrecognized ID type"; + } +} + +- (IBAction)setPromptBehavior:(id)sender +{ + NSButton* button = (NSButton*)sender; + NSString* prompt = button.title; + + if ([prompt isEqualToString:@"Auto"]) + { + _promptBehavior = AD_PROMPT_AUTO; + } + else if ([prompt isEqualToString:@"Always"]) + { + _promptBehavior = AD_PROMPT_ALWAYS; + } + else + { + @throw @"Unrecognized prompt behavior"; + } +} + +- (void)textFieldChanged:(id)sender +{ + _userIdEdited = ![NSString adIsStringNilOrBlank:_userIdField.stringValue]; +} + +- (void)viewWillAppear:(BOOL)animated +{ + if (!_userIdEdited) + { + NSString* defaultUser = [[ADTestAppSettings settings] defaultUser]; + [_userIdField setStringValue:defaultUser]; + } +} + +- (ADUserIdentifier*)identifier +{ + NSString* userId = [_userIdField stringValue]; + + if (!userId || [userId isEqualToString:@""]) + { + return nil; + } + + return [ADUserIdentifier identifierWithId:userId type:_idType]; +} + +- (BOOL)embeddedWebView +{ + NSString* webViewType = [_webViewType labelForSegment:[_webViewType selectedSegment]]; + + if ([webViewType isEqualToString:@"ADAL"]) + { + return NO; + } + else if ([webViewType isEqualToString:@"Passed In"]) + { + return YES; + } + else + { + @throw @"unexpected webview type"; + } +} + +- (void)updateResultView:(ADAuthenticationResult*)result +{ + NSString* resultStatus = nil; + + switch (result.status) + { + case AD_SUCCEEDED : resultStatus = @"AD_SUCCEEDED"; break; + case AD_FAILED : resultStatus = @"AD_FAILED"; break; + case AD_USER_CANCELLED : resultStatus = @"AD_USER_CANCELLED"; break; + default: + resultStatus = [NSString stringWithFormat:@"Unknown (%d)", result.status]; + break; + } + + NSString* resultText = [NSString stringWithFormat:@"{\n\tstatus = %@;\n\terror = %@\n\tcorrelation ID = %@\n\ttokenCacheItem = %@\n}", resultStatus, result.error, result.correlationId, result.tokenCacheItem]; + + [_resultView setString:resultText]; + + printf("%s", [resultText UTF8String]); +} + +- (void)showMultipleHitAlert +{ + dispatch_async(dispatch_get_main_queue(), ^{ + NSAlert* alert = [NSAlert alertWithMessageText:@"Error!" + defaultButton:@"OK" + alternateButton:nil + otherButton:nil + informativeTextWithFormat:@"Completion block was hit multiple times!"]; + [alert beginSheetModalForWindow:self.window completionHandler:^(NSModalResponse returnCode) + { + (void)returnCode; + }]; + }); +} + +- (IBAction)acquireTokenInteractive:(id)sender +{ + ADTestAppSettings* settings = [ADTestAppSettings settings]; + NSString* authority = [settings authority]; + NSString* resource = [settings resource]; + NSString* clientId = [settings clientId]; + NSURL* redirectUri = [settings redirectUri]; + ADUserIdentifier* identifier = [self identifier]; + + BOOL validateAuthority = _validateAuthority.selectedSegment == 0; + + ADAuthenticationError* error = nil; + ADAuthenticationContext* context = [[ADAuthenticationContext alloc] initWithAuthority:authority + validateAuthority:validateAuthority + error:&error]; + if (!context) + { + NSString* resultText = [NSString stringWithFormat:@"Failed to create AuthenticationContext:\n%@", error]; + [_resultView setString:resultText]; + return; + } + + if ([self embeddedWebView]) + { + [_webView.mainFrame loadHTMLString:@"Loading..." baseURL:nil]; + [context setWebView:_webView]; + [_authView setFrame:self.window.contentView.frame]; + + [_acquireSettingsView setHidden:YES]; + [_authView setHidden:NO]; + } + + __block BOOL fBlockHit = NO; + + [context acquireTokenWithResource:resource + clientId:clientId + redirectUri:redirectUri + promptBehavior:_promptBehavior + userIdentifier:identifier + extraQueryParameters:nil + completionBlock:^(ADAuthenticationResult *result) + { + if (fBlockHit) + { + [self showMultipleHitAlert]; + return; + } + fBlockHit = YES; + + + + dispatch_async(dispatch_get_main_queue(), ^{ + [self updateResultView:result]; + + if ([_acquireSettingsView isHidden]) + { + [_webView.mainFrame loadHTMLString:@"done!" baseURL:nil]; + [_authView setHidden:YES]; + [_acquireSettingsView setHidden:NO]; + } + + [[NSNotificationCenter defaultCenter] postNotificationName:ADTestAppCacheChangeNotification object:self]; + }); + }]; + +} + +- (IBAction)cancelAuth:(id)sender +{ + [ADWebAuthController cancelCurrentWebAuthSession]; +} + +- (IBAction)acquireTokenSilent:(id)sender +{ + ADTestAppSettings* settings = [ADTestAppSettings settings]; + NSString* authority = [settings authority]; + NSString* resource = [settings resource]; + NSString* clientId = [settings clientId]; + NSURL* redirectUri = [settings redirectUri]; + ADUserIdentifier* identifier = [self identifier]; + BOOL validateAuthority = _validateAuthority.selectedSegment == 0; + + ADAuthenticationError* error = nil; + ADAuthenticationContext* context = [[ADAuthenticationContext alloc] initWithAuthority:authority validateAuthority:validateAuthority error:&error]; + if (!context) + { + NSString* resultText = [NSString stringWithFormat:@"Failed to create AuthenticationContext:\n%@", error]; + [_resultView setString:resultText]; + return; + } + + __block BOOL fBlockHit = NO; + + [context acquireTokenSilentWithResource:resource clientId:clientId redirectUri:redirectUri userId:identifier.userId completionBlock:^(ADAuthenticationResult *result) + { + if (fBlockHit) + { + [self showMultipleHitAlert]; + return; + } + fBlockHit = YES; + + dispatch_async(dispatch_get_main_queue(), ^{ + [self updateResultView:result]; + + [[NSNotificationCenter defaultCenter] postNotificationName:ADTestAppCacheChangeNotification object:self]; + }); + }]; +} + + +@end diff --git a/Samples/MyTestMacOSApp/MyTestMacOSApp/ADTestInstance.h b/Samples/MyTestMacOSApp/MyTestMacOSApp/ADTestAppCache.h similarity index 59% rename from Samples/MyTestMacOSApp/MyTestMacOSApp/ADTestInstance.h rename to Samples/MyTestMacOSApp/MyTestMacOSApp/ADTestAppCache.h index 0bb4ad42e..2952469c0 100644 --- a/Samples/MyTestMacOSApp/MyTestMacOSApp/ADTestInstance.h +++ b/Samples/MyTestMacOSApp/MyTestMacOSApp/ADTestAppCache.h @@ -22,32 +22,17 @@ // THE SOFTWARE. #import +#import "ADTokenCache.h" -//Identifies one testable instance, e.g. -//an AAD tenant with suitable user name password -//and a client accessing a resource -@interface ADTestInstance : NSObject +@interface ADTestAppCache : NSObject { -//@private: - NSString *_authority; - NSString *_clientId; - NSString *_resource; - NSString *_redirectUri; - NSString *_userId; - NSString *_password; - NSString *_extraQueryParameters; - BOOL _validateAuthority; + NSData* _data; + NSDate* _lastUpdated; } --(id) initWithDictionary: (NSDictionary*) contents; ++ (ADTestAppCache *)sharedCache; -@property (retain) NSString* authority; -@property BOOL validateAuthority; -@property (retain) NSString* clientId; -@property (retain) NSString* resource; -@property (retain) NSString* redirectUri; -@property (retain) NSString* userId; -@property (retain) NSString* password;//used for automation in the tests -@property (retain) NSString* extraQueryParameters;//Typically null and set by tests when needed +- (void)readFromFile:(NSString *)filePath; +- (void)writeToFile:(NSString *)filePath; @end diff --git a/Samples/MyTestMacOSApp/MyTestMacOSApp/ADTestAppCache.m b/Samples/MyTestMacOSApp/MyTestMacOSApp/ADTestAppCache.m new file mode 100644 index 000000000..71010e187 --- /dev/null +++ b/Samples/MyTestMacOSApp/MyTestMacOSApp/ADTestAppCache.m @@ -0,0 +1,187 @@ +// Copyright (c) Microsoft Corporation. +// All rights reserved. +// +// This code is licensed under the MIT License. +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files(the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and / or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions : +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE. + +#import "ADTestAppCache.h" +#import "ADAuthenticationSettings.h" +#import "ADAL_Internal.h" + +#define DEFAULT_KEYCHAIN_ATTRS \ + (id)kSecClass : (id)kSecClassGenericPassword, \ + (id)kSecAttrAccount : @"AdalTestApp", \ + (id)kSecAttrService : @"ADALCache" \ + +@implementation ADTestAppCache + ++ (void)load +{ + [self sharedCache]; +} + ++ (ADTestAppCache*)sharedCache +{ + static dispatch_once_t once; + static ADTestAppCache* cache = nil; + + dispatch_once(&once, ^{ + cache = [[ADTestAppCache alloc] init]; + [cache readFromFile:[self defaultSavePath]]; + + [[ADAuthenticationSettings sharedInstance] setDefaultStorageDelegate:cache]; + }); + + return cache; +} + ++ (NSString*)defaultSavePath +{ + static dispatch_once_t once; + static NSString* path = nil; + + dispatch_once(&once, ^{ + NSURL* homeDir = [[NSFileManager defaultManager] homeDirectoryForCurrentUser]; + path = [homeDir URLByAppendingPathComponent:@"TestApp.adalcache"].path; + }); + + return path; +} + +- (id)copyWithZone:(NSZone*)zone +{ + ADTestAppCache* cache = [[self.class allocWithZone:zone] init]; + cache->_data = [_data copyWithZone:zone]; + return cache; +} + +- (void)willAccessCache:(nonnull ADTokenCache *)cache +{ + @synchronized(self) + { + [self readFromKeychain]; + [cache deserialize:_data error:nil]; + } +} + +- (void)didAccessCache:(nonnull ADTokenCache *)cache +{ + // Nothing changed in the cache so no need to do anything. If you're implementing + // this with proper locking this is where you would let go of the lock. + (void)cache; +} + +- (void)willWriteCache:(nonnull ADTokenCache *)cache +{ + @synchronized(self) + { + [self readFromKeychain]; + [cache deserialize:_data error:nil]; + } +} + +- (void)didWriteCache:(nonnull ADTokenCache *)cache +{ + @synchronized(self) + { + SAFE_ARC_RELEASE(_data); + _data = [cache serialize]; + SAFE_ARC_RETAIN(_data); + //[self writeToFile:[ADTestAppCache defaultSavePath]]; + [self writeToKeychain]; + } +} + +- (void)readFromFile:(NSString *)filePath +{ + @synchronized (self) + { + SAFE_ARC_RELEASE(_data); + _data = [NSData dataWithContentsOfFile:filePath]; + SAFE_ARC_RETAIN(_data); + } +} + +- (void)writeToFile:(NSString *)filePath +{ + @synchronized (self) + { + // NOTE: This "implementation" does not provide any extra data security + // and is not recommended for production apps. + if (![_data writeToFile:filePath atomically:YES]) + { + NSLog(@"Failed to write cache to %@!", filePath); + } + } +} + +- (OSStatus)readFromKeychain +{ + @synchronized (self) + { + NSDictionary* readQuery = + @{ + DEFAULT_KEYCHAIN_ATTRS, + (id)kSecReturnData : @YES + }; + + CFDataRef data = NULL; + OSStatus status = SecItemCopyMatching((CFDictionaryRef)readQuery, (CFTypeRef *)&data); + + _data = (__bridge NSData*)data; + + return status; + } +} + +- (OSStatus)writeToKeychain +{ + @synchronized (self) + { + if (!_data) + { + return errSecItemNotFound; + } + + NSDictionary* updateQuery = + @{ + DEFAULT_KEYCHAIN_ATTRS + }; + + NSDictionary* attrToUpdate = + @{ + (id)kSecValueData : _data + }; + + OSStatus status = SecItemUpdate((CFDictionaryRef)updateQuery, (CFDictionaryRef)attrToUpdate); + if (status == errSecItemNotFound) + { + NSDictionary* writeQuery = + @{ + DEFAULT_KEYCHAIN_ATTRS, + (id)kSecValueData : _data, + }; + status = SecItemAdd((CFDictionaryRef)writeQuery, NULL); + } + return status; + } +} + +@end diff --git a/Samples/MyTestMacOSApp/MyTestMacOSApp/ADTestAppCacheWindowController.h b/Samples/MyTestMacOSApp/MyTestMacOSApp/ADTestAppCacheWindowController.h new file mode 100644 index 000000000..ceade24e9 --- /dev/null +++ b/Samples/MyTestMacOSApp/MyTestMacOSApp/ADTestAppCacheWindowController.h @@ -0,0 +1,35 @@ +// Copyright (c) Microsoft Corporation. +// All rights reserved. +// +// This code is licensed under the MIT License. +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files(the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and / or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions : +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE. + + +#import + +@interface ADTestAppCacheWindowController : NSWindowController +{ + IBOutlet NSTableView* _tableView; + NSArray* _allItems; +} + ++ (void)showWindow; + +@end diff --git a/Samples/MyTestMacOSApp/MyTestMacOSApp/ADTestAppCacheWindowController.m b/Samples/MyTestMacOSApp/MyTestMacOSApp/ADTestAppCacheWindowController.m new file mode 100644 index 000000000..e26b36f29 --- /dev/null +++ b/Samples/MyTestMacOSApp/MyTestMacOSApp/ADTestAppCacheWindowController.m @@ -0,0 +1,225 @@ +// Copyright (c) Microsoft Corporation. +// All rights reserved. +// +// This code is licensed under the MIT License. +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files(the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and / or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions : +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE. + +#import "ADTestAppCacheWindowController.h" +#import "ADTokenCache+Internal.h" +#import "ADTokenCacheItem.h" +#import "ADUserInformation.h" +#import "ADTestAppCache.h" +#import "ADLogger+Internal.h" + +@interface NSString (ADTestApp) + +- (NSString *)truncatedHash; + +@end + +@implementation NSString (ADTestApp) + +- (NSString *)truncatedHash +{ + return [[ADLogger getHash:self] substringToIndex:10]; +} + +@end + +@interface ADTestAppCacheWindowController () + +@end + +@implementation ADTestAppCacheWindowController + ++ (ADTestAppCacheWindowController*)controller +{ + static dispatch_once_t once; + static ADTestAppCacheWindowController* controller = nil; + + dispatch_once(&once, ^{ + controller = [self new]; + }); + + return controller; +} + ++ (void)showWindow +{ + [[self controller] showWindow:nil]; +} + +- (id)init +{ + if (!(self = [super initWithWindowNibName:@"CacheWindow"])) + { + return nil; + } + + [self reloadCache]; + + return self; +} + +- (void)windowDidLoad { + [super windowDidLoad]; + + // Implement this method to handle any initialization after your window controller's window has been loaded from its nib file. +} + +- (void)reloadCache +{ + _allItems = [[ADTokenCache defaultCache] allItems:nil]; + [_tableView reloadData]; +} + +- (IBAction)reload:(id)sender +{ + [self reloadCache]; + +} + +#pragma mark - +#pragma mark NSTableViewDataSource implementation + +- (NSInteger)numberOfRowsInTableView:(NSTableView *)tableView +{ + return [_allItems count]; +} + +- (NSString *)dataForTableColumn:(nullable NSTableColumn *)tableColumn row:(NSInteger)row +{ + ADTokenCacheItem* item = [_allItems objectAtIndex:row]; + + NSString* identifier = tableColumn.identifier; + if ([identifier isEqualToString:@"upn"]) + { + return item.userInformation.userId; + } + else if ([identifier isEqualToString:@"authority"]) + { + return item.authority; + } + else if ([identifier isEqualToString:@"clientId"]) + { + return item.clientId; + } + else if ([identifier isEqualToString:@"resource"]) + { + return item.resource; + } + else if ([identifier isEqualToString:@"accessToken"]) + { + return item.accessToken.truncatedHash; + } + else if ([identifier isEqualToString:@"expiresOn"]) + { + return [item.expiresOn description]; + } + else if ([identifier isEqualToString:@"refreshToken"]) + { + return item.refreshToken.truncatedHash; + } + else + { + @throw @"Unrecongized identifier"; + } +} + +/* View Based TableView: + Non-bindings: This method is required if you wish to turn on the use of NSViews instead of NSCells. The implementation of this method will usually call -[tableView makeViewWithIdentifier:[tableColumn identifier] owner:self] in order to reuse a previous view, or automatically unarchive an associated prototype view for that identifier. The -frame of the returned view is not important, and it will be automatically set by the table. 'tableColumn' will be nil if the row is a group row. Returning nil is acceptable, and a view will not be shown at that location. The view's properties should be properly set up before returning the result. + */ +- (nullable NSView *)tableView:(NSTableView *)tableView viewForTableColumn:(nullable NSTableColumn *)tableColumn row:(NSInteger)row +{ + + NSTextField* cell = [tableView makeViewWithIdentifier:@"CacheTextCell" owner:self]; + + if (!cell) + { + cell = [[NSTextField alloc] initWithFrame:NSMakeRect(0, 0, tableView.frame.size.width, 20)]; + cell.bordered = NO; + cell.drawsBackground = NO; + cell.identifier = @"CacheTextCell"; + } + + NSString* text = [self dataForTableColumn:tableColumn row:row]; + cell.stringValue = text ? text : @""; + return cell; +} + +- (IBAction)expire:(id)sender +{ + @synchronized (self) + { + NSIndexSet* rows = [_tableView selectedRowIndexes]; + + [rows enumerateIndexesUsingBlock:^(NSUInteger idx, BOOL * _Nonnull stop) + { + ADTokenCacheItem* item = _allItems[idx]; + if (item.expiresOn) + { + item.expiresOn = [NSDate dateWithTimeIntervalSinceNow:-1.0]; + } + + [[ADTokenCache defaultCache] addOrUpdateItem:item correlationId:nil error:nil]; + }]; + + [self reloadCache]; + } +} + +- (IBAction)delete:(id)sender +{ + @synchronized (self) + { + NSIndexSet* rows = [_tableView selectedRowIndexes]; + + [rows enumerateIndexesUsingBlock:^(NSUInteger idx, BOOL * _Nonnull stop) + { + ADTokenCacheItem* item = _allItems[idx]; + [[ADTokenCache defaultCache] removeItem:item error:nil]; + }]; + + [self reloadCache]; + } +} + +- (IBAction)invalidate:(id)sender +{ + @synchronized (self) + { + NSIndexSet* rows = [_tableView selectedRowIndexes]; + + [rows enumerateIndexesUsingBlock:^(NSUInteger idx, BOOL * _Nonnull stop) + { + ADTokenCacheItem* item = _allItems[idx]; + if (item.refreshToken) + { + item.refreshToken = @""; + } + + [[ADTokenCache defaultCache] addOrUpdateItem:item correlationId:nil error:nil]; + }]; + + [self reloadCache]; + } +} + +@end diff --git a/Samples/MyTestMacOSApp/MyTestMacOSApp/ADTestAppDelegate.h b/Samples/MyTestMacOSApp/MyTestMacOSApp/ADTestAppDelegate.h index 224231225..b96059e7b 100644 --- a/Samples/MyTestMacOSApp/MyTestMacOSApp/ADTestAppDelegate.h +++ b/Samples/MyTestMacOSApp/MyTestMacOSApp/ADTestAppDelegate.h @@ -29,31 +29,12 @@ @interface ADTestAppDelegate : NSObject { //@private: - IBOutlet NSWindow *_window; - IBOutlet NSTextView *_resultField; - IBOutlet NSTextView *_samlAssertionField; - NSPersistentStoreCoordinator *_persistentStoreCoordinator; - NSManagedObjectModel *_managedObjectModel; - NSManagedObjectContext *_managedObjectContext; - ADTestMemoryCache* _cacheDelegate; - ADTokenCache* _cache; } -@property (assign) IBOutlet NSWindow *window; -@property (assign) IBOutlet NSTextView *resultField; -@property (assign) IBOutlet NSTextView *samlAssertionField; - -@property (readonly, strong, nonatomic) NSPersistentStoreCoordinator *persistentStoreCoordinator; -@property (readonly, strong, nonatomic) NSManagedObjectModel *managedObjectModel; -@property (readonly, strong, nonatomic) NSManagedObjectContext *managedObjectContext; - -- (IBAction)saveAction:(id)sender; -- (IBAction)endToEndAction:(id)sender; -- (IBAction)showUsersAction:(id)sender; -- (IBAction)expireAllAction:(id)sender; -- (IBAction)clearCacheAndCookiesAction:(id)sender; -- (IBAction)acquireTokenSilentAction:(id)sender; -- (IBAction)promptAlwaysAction:(id)sender; -- (IBAction)samlAssertionAction:(id)sender; +- (IBAction)showAcquireToken:(id)sender; +- (IBAction)showConsoleLog:(id)sender; +- (IBAction)showCacheViewer:(id)sender; +- (IBAction)loadCacheFromFile:(id)sender; +- (IBAction)writeCacheToFile:(id)sender; @end diff --git a/Samples/MyTestMacOSApp/MyTestMacOSApp/ADTestAppDelegate.m b/Samples/MyTestMacOSApp/MyTestMacOSApp/ADTestAppDelegate.m index 3fe5fb8aa..ffa902966 100644 --- a/Samples/MyTestMacOSApp/MyTestMacOSApp/ADTestAppDelegate.m +++ b/Samples/MyTestMacOSApp/MyTestMacOSApp/ADTestAppDelegate.m @@ -23,8 +23,10 @@ #import "ADTestAppDelegate.h" #import "ADTestAppSettings.h" -#import "ADTestInstance.h" -#import +#import "ADAL_Internal.h" +#import "ADTokenCache.h" +#import "ADTestAppAcquireTokenWindowController.h" +#import "ADTestAppCacheWindowController.h" // These are not public APIs, however the test app is pulling // in things that can't be done with public APIs and shouldn't @@ -34,496 +36,38 @@ - (BOOL)addOrUpdateItem:(ADTokenCacheItem *)item error:(ADAuthenticationError * __autoreleasing *)error; @end -@interface ADTestMemoryCache : NSObject -{ - NSData* _data; -} - -@end - -@implementation ADTestMemoryCache - -- (id)copyWithZone:(NSZone*)zone -{ - ADTestMemoryCache* cache = [[self.class allocWithZone:zone] init]; - cache->_data = [_data copyWithZone:zone]; - return cache; -} - -- (void)willAccessCache:(nonnull ADTokenCache *)cache -{ - @synchronized(self) - { - [cache deserialize:_data error:nil]; - } -} - -- (void)didAccessCache:(nonnull ADTokenCache *)cache -{ - @synchronized(self) - { - [_data release]; - _data = [cache serialize]; - [_data retain]; - } -} - -- (void)willWriteCache:(nonnull ADTokenCache *)cache -{ - @synchronized(self) - { - [cache deserialize:_data error:nil]; - } -} - -- (void)didWriteCache:(nonnull ADTokenCache *)cache -{ - @synchronized(self) - { - [_data release]; - _data = [cache serialize]; - [_data retain]; - } -} - -@end @implementation ADTestAppDelegate -@synthesize window = _window; -@synthesize resultField = _resultField; -@synthesize samlAssertionField = _samlAssertionField; - -@synthesize persistentStoreCoordinator = _persistentStoreCoordinator; -@synthesize managedObjectModel = _managedObjectModel; -@synthesize managedObjectContext = _managedObjectContext; - (void)applicationDidFinishLaunching:(NSNotification *)aNotification { - [_resultField setString:@"Response goes here"]; - _cacheDelegate = [ADTestMemoryCache new]; - _cache = [ADTokenCache new]; - [_cache setDelegate:_cacheDelegate]; - - [[ADAuthenticationSettings sharedInstance] setDefaultStorageDelegate:_cacheDelegate]; + [self showAcquireToken:nil]; } - -- (void) setStatus:(NSString*) message +- (IBAction)showAcquireToken:(id)sender { - [_resultField setString:message]; - [_resultField displayIfNeeded]; -} - -- (void) appendStatus:(NSString*) message { - - NSMutableString* mutableString = [NSMutableString stringWithString:[[_resultField textStorage] string]]; - [mutableString appendString:message]; - [self setStatus:mutableString]; + [ADTestAppAcquireTokenWindowController showWindow]; } -- (IBAction)samlAssertionAction:(id)sender +- (IBAction)showConsoleLog:(id)sender { - ADTestAppSettings *testData = [ADTestAppSettings new]; - ADTestInstance *aadInstance = [[testData.testAuthorities objectForKey:sAADTestInstance] retain]; - - NSString* authority = aadInstance.authority;//params.authority; - NSString* clientId = aadInstance.clientId; - NSString* resourceString = aadInstance.resource; - ADAuthenticationError * error = nil; - ADAuthenticationContext* context = [ADAuthenticationContext authenticationContextWithAuthority:authority validateAuthority:aadInstance.validateAuthority error:&error]; - if (!context) - { - [self setStatus:error.errorDetails]; - return; - } - - [context acquireTokenForAssertion:[[_samlAssertionField textStorage] string] assertionType:AD_SAML1_1 resource:resourceString clientId:clientId userId:aadInstance.userId completionBlock:^(ADAuthenticationResult *result) { - if (result.status != AD_SUCCEEDED) - { - [self setStatus:result.error.errorDetails]; - return; - } - - [self setStatus:result.tokenCacheItem.accessToken]; - }]; -} - -- (IBAction)endToEndAction:(id)sender{ - // Do any additional setup after loading the view, typically from a nib. - //Log everything - [ADLogger setLevel:ADAL_LOG_LEVEL_VERBOSE]; - - [self setStatus:@"Running End-to-End\n"]; - ADTestAppSettings *testData = [ADTestAppSettings new]; - ADTestInstance *aadInstance = [[testData.testAuthorities objectForKey:sAADTestInstance] retain]; - - ADAuthenticationError *error = nil; - __block ADAuthenticationContext *context = [[ADAuthenticationContext authenticationContextWithAuthority:aadInstance.authority - validateAuthority: NO - error:&error] retain]; - [context acquireTokenWithResource:aadInstance.resource - clientId:aadInstance.clientId - redirectUri:[NSURL URLWithString:aadInstance.redirectUri] - promptBehavior:AD_PROMPT_AUTO - userId:aadInstance.userId - extraQueryParameters: aadInstance.extraQueryParameters - completionBlock:^(ADAuthenticationResult *result) - { - if (AD_SUCCEEDED == result.status) - { - [self setStatus: [NSString stringWithFormat:@"AcquireToken succeeded with access token: %@\n", result.accessToken]]; - } - else - { - [self setStatus: [NSString stringWithFormat:@"AcquireToken failed with access token: %@\n", result.error.errorDetails]]; - } - - [context release]; - }]; - - [aadInstance release]; - [testData release]; -} - - -- (IBAction)showUsersAction:(id)sender{ - - [self setStatus:@"Getting users from cache...\n"]; - ADAuthenticationError* error = nil; - NSArray* array = [_cache allItems:&error]; - if (error) - { - [self appendStatus:error.errorDetails]; - return; - } - NSMutableSet* users = [NSMutableSet new]; - NSMutableString* usersStr = [NSMutableString new]; - for(ADTokenCacheItem* item in array) - { - ADUserInformation *user = item.userInformation; - if (!item.userInformation) - { - if (![users containsObject:@""]) - { - [users addObject:@""]; - [usersStr appendString:@""]; - } - } - else if (![users containsObject:user.userId]) - { - //New user, add and print: - [users addObject:user.userId]; - [usersStr appendFormat:@"%@: %@ %@\n", user.userId, user.givenName, user.familyName]; - } - } - [self appendStatus:usersStr]; - [usersStr release]; } -- (IBAction)expireAllAction:(id)sender{ - ADAuthenticationError* error = nil; - [self setStatus:@"Attempt to expire...\n"]; - - NSArray* array = [_cache allItems:&error]; - if (error) - { - [self appendStatus:error.errorDetails]; - return; - } - - - [self appendStatus:[NSString stringWithFormat:@"Items found - %lu\n", (unsigned long)array.count]]; - for(ADTokenCacheItem* item in array) - { - item.expiresOn = [NSDate dateWithTimeIntervalSinceNow:0]; - [_cache addOrUpdateItem:item error:&error]; - } - if (error) - { - [self appendStatus:error.errorDetails]; - } - else - { - [self appendStatus:@"Done."]; - } -} - - -- (IBAction)clearCacheAndCookiesAction:(id)sender{ - ADAuthenticationError* error = nil; - [self setStatus:@"Clearing cache...\n"]; - NSArray* allItems = [_cache allItems:&error]; - if (error) - { - [self appendStatus:error.errorDetails]; - return; - } - - [self appendStatus:[NSString stringWithFormat: @"Total Items - %lu\n", (unsigned long)allItems.count]]; - NSString* status = @"Nothing in the cache.\n"; - if (allItems.count > 0) - { - for (ADTokenCacheItem* item in allItems) - { - [_cache removeItem:item error:&error]; - } - - if (error) - { - status = error.errorDetails; - } - else - { - status = @"Items removed.\n"; - } - } - [self appendStatus:status]; - - [self appendStatus:@"\nRemoving cookies..."]; - NSHTTPCookieStorage* cookieStorage = [NSHTTPCookieStorage sharedHTTPCookieStorage]; - NSArray* cookies = cookieStorage.cookies; - - [self appendStatus:[NSString stringWithFormat: @"Total Cookies - %lu\n", (unsigned long)cookies.count]]; - if (cookies.count) - { - for(NSHTTPCookie* cookie in cookies) - { - [cookieStorage deleteCookie:cookie]; - } - [self appendStatus:@"Cookies cleared.\n"]; - } -} - -- (IBAction)acquireTokenSilentAction:(id)sender{ - ADTestAppSettings *testData = [ADTestAppSettings new]; - ADTestInstance *aadInstance = [[testData.testAuthorities objectForKey:sAADTestInstance] retain]; - - [self setStatus:@"Setting prompt never..."]; - ADAuthenticationError* error = nil; - ADAuthenticationContext* context = [ADAuthenticationContext authenticationContextWithAuthority:aadInstance.authority error:&error]; - if (!context) - { - [self appendStatus:error.errorDetails]; - return; - } - - [context acquireTokenSilentWithResource:aadInstance.resource - clientId:aadInstance.clientId - redirectUri:[NSURL URLWithString:aadInstance.redirectUri] - completionBlock:^(ADAuthenticationResult *result) - { - if (result.status != AD_SUCCEEDED) - { - [self appendStatus:result.error.errorDetails]; - return; - } - - [self appendStatus:result.tokenCacheItem.accessToken]; - }]; - - [aadInstance release]; - [testData release]; -} - - -- (IBAction)promptAlwaysAction:(id)sender{ - - ADTestAppSettings *testData = [ADTestAppSettings new]; - ADTestInstance *aadInstance = [[testData.testAuthorities objectForKey:sAADTestInstance] retain]; - - [self setStatus:@"Setting prompt always..."]; - ADAuthenticationError* error = nil; - ADAuthenticationContext* context = [ADAuthenticationContext authenticationContextWithAuthority:aadInstance.authority error:&error]; - if (!context) - { - [self appendStatus:error.errorDetails]; - return; - } - - [context acquireTokenWithResource:aadInstance.resource - clientId:aadInstance.clientId - redirectUri:[NSURL URLWithString:aadInstance.redirectUri] - promptBehavior:AD_PROMPT_ALWAYS - userId:aadInstance.userId - extraQueryParameters: aadInstance.extraQueryParameters - completionBlock:^(ADAuthenticationResult *result) - { - if (result.status != AD_SUCCEEDED) - { - [self appendStatus:result.error.errorDetails]; - return; - } - - [self appendStatus:result.tokenCacheItem.accessToken]; - }]; - - [aadInstance release]; - [testData release]; - -} - -// Returns the directory the application uses to store the Core Data store file. This code uses a directory named "MSOpenTech.MyTestMacOSApp" in the user's Application Support directory. -- (NSURL *)applicationFilesDirectory -{ - NSFileManager *fileManager = [NSFileManager defaultManager]; - NSURL *appSupportURL = [[fileManager URLsForDirectory:NSApplicationSupportDirectory inDomains:NSUserDomainMask] lastObject]; - - return [appSupportURL URLByAppendingPathComponent:@"MSOpenTech.MyTestMacOSApp"]; -} - -// Creates if necessary and returns the managed object model for the application. -- (NSManagedObjectModel *)managedObjectModel -{ - if (_managedObjectModel) { - return _managedObjectModel; - } - - NSURL *modelURL = [[NSBundle mainBundle] URLForResource:@"MyTestMacOSApp" withExtension:@"momd"]; - _managedObjectModel = [[NSManagedObjectModel alloc] initWithContentsOfURL:modelURL]; - return _managedObjectModel; -} - -// Returns the persistent store coordinator for the application. This implementation creates and return a coordinator, having added the store for the application to it. (The directory for the store is created, if necessary.) -- (NSPersistentStoreCoordinator *)persistentStoreCoordinator -{ - if (_persistentStoreCoordinator) { - return _persistentStoreCoordinator; - } - - NSManagedObjectModel *mom = [self managedObjectModel]; - if (!mom) { - NSLog(@"%@:%@ No model to generate a store from", [self class], NSStringFromSelector(_cmd)); - return nil; - } - - NSFileManager *fileManager = [NSFileManager defaultManager]; - NSURL *applicationFilesDirectory = [self applicationFilesDirectory]; - NSError *error = nil; - - NSDictionary *properties = [applicationFilesDirectory resourceValuesForKeys:@[NSURLIsDirectoryKey] error:&error]; - - if (!properties) { - BOOL ok = NO; - if ([error code] == NSFileReadNoSuchFileError) { - ok = [fileManager createDirectoryAtPath:[applicationFilesDirectory path] withIntermediateDirectories:YES attributes:nil error:&error]; - } - if (!ok) { - [[NSApplication sharedApplication] presentError:error]; - return nil; - } - } else { - if (![[properties objectForKey:NSURLIsDirectoryKey] boolValue]) { - // Customize and localize this error. - NSString *failureDescription = [NSString stringWithFormat:@"Expected a folder to store application data, found a file (%@).", [applicationFilesDirectory path]]; - - NSMutableDictionary *dict = [NSMutableDictionary dictionary]; - [dict setValue:failureDescription forKey:NSLocalizedDescriptionKey]; - error = [NSError errorWithDomain:@"YOUR_ERROR_DOMAIN" code:101 userInfo:dict]; - - [[NSApplication sharedApplication] presentError:error]; - return nil; - } - } - - NSURL *url = [applicationFilesDirectory URLByAppendingPathComponent:@"MyTestMacOSApp.storedata"]; - NSPersistentStoreCoordinator *coordinator = [[NSPersistentStoreCoordinator alloc] initWithManagedObjectModel:mom]; - if (![coordinator addPersistentStoreWithType:NSXMLStoreType configuration:nil URL:url options:nil error:&error]) { - [[NSApplication sharedApplication] presentError:error]; - return nil; - } - _persistentStoreCoordinator = coordinator; - - return _persistentStoreCoordinator; -} - -// Returns the managed object context for the application (which is already bound to the persistent store coordinator for the application.) -- (NSManagedObjectContext *)managedObjectContext -{ - if (_managedObjectContext) { - return _managedObjectContext; - } - - NSPersistentStoreCoordinator *coordinator = [self persistentStoreCoordinator]; - if (!coordinator) { - NSMutableDictionary *dict = [NSMutableDictionary dictionary]; - [dict setValue:@"Failed to initialize the store" forKey:NSLocalizedDescriptionKey]; - [dict setValue:@"There was an error building up the data file." forKey:NSLocalizedFailureReasonErrorKey]; - NSError *error = [NSError errorWithDomain:@"YOUR_ERROR_DOMAIN" code:9999 userInfo:dict]; - [[NSApplication sharedApplication] presentError:error]; - return nil; - } - _managedObjectContext = [[NSManagedObjectContext alloc] init]; - [_managedObjectContext setPersistentStoreCoordinator:coordinator]; - - return _managedObjectContext; -} - -// Returns the NSUndoManager for the application. In this case, the manager returned is that of the managed object context for the application. -- (NSUndoManager *)windowWillReturnUndoManager:(NSWindow *)window +- (IBAction)showCacheViewer:(id)sender { - return [[self managedObjectContext] undoManager]; + [ADTestAppCacheWindowController showWindow]; } -// Performs the save action for the application, which is to send the save: message to the application's managed object context. Any encountered errors are presented to the user. -- (IBAction)saveAction:(id)sender +- (IBAction)loadCacheFromFile:(id)sender { - NSError *error = nil; - if (![[self managedObjectContext] commitEditing]) { - NSLog(@"%@:%@ unable to commit editing before saving", [self class], NSStringFromSelector(_cmd)); - } - - if (![[self managedObjectContext] save:&error]) { - [[NSApplication sharedApplication] presentError:error]; - } } -- (NSApplicationTerminateReply)applicationShouldTerminate:(NSApplication *)sender +- (IBAction)writeCacheToFile:(id)sender { - // Save changes in the application's managed object context before the application terminates. - - if (!_managedObjectContext) { - return NSTerminateNow; - } - - if (![[self managedObjectContext] commitEditing]) { - NSLog(@"%@:%@ unable to commit editing to terminate", [self class], NSStringFromSelector(_cmd)); - return NSTerminateCancel; - } - - if (![[self managedObjectContext] hasChanges]) { - return NSTerminateNow; - } - - NSError *error = nil; - if (![[self managedObjectContext] save:&error]) { - - // Customize this code block to include application-specific recovery steps. - BOOL result = [sender presentError:error]; - if (result) { - return NSTerminateCancel; - } - - NSString *question = NSLocalizedString(@"Could not save changes while quitting. Quit anyway?", @"Quit without saves error question message"); - NSString *info = NSLocalizedString(@"Quitting now will lose any changes you have made since the last successful save", @"Quit without saves error question info"); - NSString *quitButton = NSLocalizedString(@"Quit anyway", @"Quit anyway button title"); - NSString *cancelButton = NSLocalizedString(@"Cancel", @"Cancel button title"); - NSAlert *alert = [[NSAlert alloc] init]; - [alert setMessageText:question]; - [alert setInformativeText:info]; - [alert addButtonWithTitle:quitButton]; - [alert addButtonWithTitle:cancelButton]; - - NSInteger answer = [alert runModal]; - - if (answer == NSAlertAlternateReturn) { - return NSTerminateCancel; - } - } - return NSTerminateNow; } @end diff --git a/Samples/MyTestMacOSApp/MyTestMacOSApp/ADTestAppSettings.h b/Samples/MyTestMacOSApp/MyTestMacOSApp/ADTestAppSettings.h index 4f2f43266..90556cfee 100644 --- a/Samples/MyTestMacOSApp/MyTestMacOSApp/ADTestAppSettings.h +++ b/Samples/MyTestMacOSApp/MyTestMacOSApp/ADTestAppSettings.h @@ -23,17 +23,31 @@ #import -extern NSString* const sAADTestInstance; +extern NSString* ADTestAppCacheChangeNotification; -//A helper class for reading the test authorities, usernames, etc. -//Reads the authorities from the TestData.plist file. @interface ADTestAppSettings : NSObject { - NSMutableDictionary *_testAuthorities; + NSDictionary* _settings; + + NSString * _authority; + NSURL * _redirectUri; + NSString * _clientId; + NSString * _resource; + NSString * _defaultUser; } -//Returns a dictionary with the name of the test instances as keys. -//The values are instances of BVTestInstance class. -@property (readonly) NSDictionary* testAuthorities; +@property NSString * authority; +@property NSURL * redirectUri; +@property NSString * clientId; +@property NSString * resource; +@property NSString * defaultUser; + ++ (ADTestAppSettings *)settings; ++ (NSUInteger)numberOfProfiles; ++ (NSString *)profileTitleForIndex:(NSUInteger)idx; ++ (NSString *)currentProfileTitle; ++ (NSUInteger)currentProfileIdx; + +- (void)setProfileFromIndex:(NSInteger)idx; @end diff --git a/Samples/MyTestMacOSApp/MyTestMacOSApp/ADTestAppSettings.m b/Samples/MyTestMacOSApp/MyTestMacOSApp/ADTestAppSettings.m index 2a0f03e88..ef4090ecf 100644 --- a/Samples/MyTestMacOSApp/MyTestMacOSApp/ADTestAppSettings.m +++ b/Samples/MyTestMacOSApp/MyTestMacOSApp/ADTestAppSettings.m @@ -22,56 +22,150 @@ // THE SOFTWARE. #import "ADTestAppSettings.h" -#import "ADTestInstance.h" -NSString* const sAADTestInstance = @"AAD Instance"; +#if __has_include("ADAdditionalTestAppSettings.h") +#include "ADAdditionalTestAppSettings.h" +#else +// If you put a header file at ~/aadoverrides/ADAdditionalTestAppSettings.h with +// function named _addtionalProfiles() that returns an NSDictionary that will +// be folded into the profiles list without you having to constantly alter your +// github enlistment! +static NSDictionary* _additionalProfiles() +{ + return nil; +} +#endif +static NSDictionary* s_additionalProfiles = nil; + + +NSString* ADTestAppCacheChangeNotification = @"ADTestAppCacheChangeNotification"; + +static NSDictionary* s_profiles = nil; +static NSArray* s_profileTitles = nil; +static NSUInteger s_currentProfileIdx = 0; @implementation ADTestAppSettings -@synthesize testAuthorities = _testAuthorities; +@synthesize authority = _authority; +@synthesize redirectUri = _redirectUri; +@synthesize clientId = _clientId; +@synthesize resource = _resource; +@synthesize defaultUser = _defaultUser; --(id) init ++ (void)initialize { - self = [super init]; - if (!self) + s_profiles = + @{ @"Test App" : @{ @"authority" : @"https://login.microsoftonline.com/common", + @"resource" : @"https://graph.windows.net", + // NOTE: The settings below should come from your registered application on + // the azure management portal. + @"clientId" : @"b92e0ba5-f86e-4411-8e18-6b5f928d968a", + @"redirectUri" : @"x-msauth-adaltestapp-210://com.microsoft.adal.2.1.0.TestApp", + }, + @"Office" : @{ @"authority" : @"https://login.microsoftonline.com/common", + @"resource" : @"https://api.office.com/discovery", + @"clientId" : @"d3590ed6-52b3-4102-aeff-aad2292ab01c", + @"redirectUri" : @"urn:ietf:wg:oauth:2.0:oob", + }, + @"OneDrive" : @{ @"authority" : @"https://login.microsoftonline.com/common", + @"resource" : @"https://api.office.com/discovery", + @"clientId" : @"af124e86-4e96-495a-b70a-90f90ab96707", + @"redirectUri" : @"ms-onedrive://com.microsoft.skydrive", + }, + }; + + s_additionalProfiles = _additionalProfiles(); + + NSMutableArray* titles = [[NSMutableArray alloc] initWithCapacity:[s_profiles count] + [s_additionalProfiles count]]; + + for (NSString* profileTitle in s_profiles) { - return nil; + [titles addObject:profileTitle]; } - NSString* path = [[NSBundle mainBundle] pathForResource:@"TestData" ofType:@"plist"]; - if (!path || !path.length) + for (NSString* profileTitle in s_additionalProfiles) { - return nil; + [titles addObject:profileTitle]; } - NSDictionary* all = [NSDictionary dictionaryWithContentsOfFile:path]; - NSMutableDictionary* testAuthorities = [[NSMutableDictionary alloc] initWithCapacity:all.count]; + [titles sortUsingSelector:@selector(localizedCaseInsensitiveCompare:)]; - for(NSDictionary* instanceName in all.allKeys) + s_profileTitles = titles; + + NSString* currentProfile = [[NSUserDefaults standardUserDefaults] stringForKey:@"CurrentProfile"]; + if (!currentProfile) { - NSDictionary* instanceData = [all objectForKey:instanceName]; - if (!instanceData || ![instanceData isKindOfClass:[NSDictionary class]]) - { - NSLog(@"Bad data for the instance: '%@'. Contents: %@", instanceName, instanceData); - continue; - } - ADTestInstance* instance = [[ADTestInstance alloc] initWithDictionary:instanceData]; - [testAuthorities setObject:instance forKey:instanceName]; -#if !__has_feature(objc_arc) - [instance release]; -#endif + currentProfile = @"Test App"; + } + s_currentProfileIdx = [s_profileTitles indexOfObject:currentProfile]; + if (s_currentProfileIdx == NSNotFound) + { + s_currentProfileIdx = [s_profileTitles indexOfObject:@"Test App"]; + } + if (s_currentProfileIdx == NSNotFound) + { + s_currentProfileIdx = 0; } - _testAuthorities = testAuthorities; +} + ++ (NSUInteger)numberOfProfiles; +{ + return [s_profileTitles count]; +} + ++ (NSString*)profileTitleForIndex:(NSUInteger)idx +{ + return [s_profileTitles objectAtIndex:idx]; +} + ++ (NSString*)currentProfileTitle +{ + return [s_profileTitles objectAtIndex:s_currentProfileIdx]; +} + ++ (NSUInteger)currentProfileIdx +{ + return s_currentProfileIdx; +} + ++ (ADTestAppSettings*)settings +{ + static dispatch_once_t s_settingsOnce; + static ADTestAppSettings* s_settings = nil; + + dispatch_once(&s_settingsOnce,^{ s_settings = [ADTestAppSettings new]; }); + + return s_settings; +} + +- (id)init +{ + if (!(self = [super init])) + { + return nil; + } + + [self setProfileFromIndex:[ADTestAppSettings currentProfileIdx]]; return self; } -- (void)dealloc +- (void)setProfileFromIndex:(NSInteger)idx { - [_testAuthorities release]; - _testAuthorities = nil; + NSString* title = [s_profileTitles objectAtIndex:idx]; + s_currentProfileIdx = idx; + [[NSUserDefaults standardUserDefaults] setObject:title forKey:@"CurrentProfile"]; + NSDictionary* settings = [s_additionalProfiles objectForKey:title]; + if (!settings) + { + settings = [s_profiles objectForKey:title]; + } - [super dealloc]; + self.authority = [settings objectForKey:@"authority"]; + self.clientId = [settings objectForKey:@"clientId"]; + self.redirectUri = [NSURL URLWithString:[settings objectForKey:@"redirectUri"]]; + self.resource = [settings objectForKey:@"resource"]; + self.defaultUser = [settings objectForKey:@"defaultUser"]; } @end diff --git a/Samples/MyTestMacOSApp/MyTestMacOSApp/AcquireTokenWindow.xib b/Samples/MyTestMacOSApp/MyTestMacOSApp/AcquireTokenWindow.xib new file mode 100644 index 000000000..121388516 --- /dev/null +++ b/Samples/MyTestMacOSApp/MyTestMacOSApp/AcquireTokenWindow.xib @@ -0,0 +1,355 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Samples/MyTestMacOSApp/MyTestMacOSApp/Base.lproj/MainMenu.xib b/Samples/MyTestMacOSApp/MyTestMacOSApp/Base.lproj/MainMenu.xib index 735685316..73860f062 100644 --- a/Samples/MyTestMacOSApp/MyTestMacOSApp/Base.lproj/MainMenu.xib +++ b/Samples/MyTestMacOSApp/MyTestMacOSApp/Base.lproj/MainMenu.xib @@ -1,8 +1,8 @@ - - + + - + @@ -625,6 +625,27 @@ + + + + + + + + + + + + + + + + + + + + + @@ -647,160 +668,7 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + diff --git a/Samples/MyTestMacOSApp/MyTestMacOSApp/CacheWindow.xib b/Samples/MyTestMacOSApp/MyTestMacOSApp/CacheWindow.xib new file mode 100644 index 000000000..05dc2545c --- /dev/null +++ b/Samples/MyTestMacOSApp/MyTestMacOSApp/CacheWindow.xib @@ -0,0 +1,367 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Samples/MyTestMacOSApp/MyTestMacOSApp/MyTestMacOSApp-Info.plist b/Samples/MyTestMacOSApp/MyTestMacOSApp/MyTestMacOSApp-Info.plist index beec207c0..0d486ec0d 100644 --- a/Samples/MyTestMacOSApp/MyTestMacOSApp/MyTestMacOSApp-Info.plist +++ b/Samples/MyTestMacOSApp/MyTestMacOSApp/MyTestMacOSApp-Info.plist @@ -30,5 +30,10 @@ MainMenu NSPrincipalClass NSApplication + NSAppTransportSecurity + + NSAllowsArbitraryLoads + + diff --git a/Samples/MyTestiOSApp/MyTestiOSApp/ADTestAppProfileViewController.m b/Samples/MyTestiOSApp/MyTestiOSApp/ADTestAppProfileViewController.m index 7345ff778..fe14100bc 100644 --- a/Samples/MyTestiOSApp/MyTestiOSApp/ADTestAppProfileViewController.m +++ b/Samples/MyTestiOSApp/MyTestiOSApp/ADTestAppProfileViewController.m @@ -79,7 +79,6 @@ - (void)didReceiveMemoryWarning { - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { [[ADTestAppSettings settings] setProfileFromIndex:indexPath.row]; - [[NSUserDefaults standardUserDefaults] setObject:[ADTestAppSettings profileTitleForIndex:indexPath.row] forKey:@"CurrentProfile"]; [self.navigationController popViewControllerAnimated:YES]; } diff --git a/Samples/MyTestiOSApp/MyTestiOSApp/ADTestAppSettings.m b/Samples/MyTestiOSApp/MyTestiOSApp/ADTestAppSettings.m index 691a59e23..7b41c5f00 100644 --- a/Samples/MyTestiOSApp/MyTestiOSApp/ADTestAppSettings.m +++ b/Samples/MyTestiOSApp/MyTestiOSApp/ADTestAppSettings.m @@ -151,6 +151,7 @@ - (void)setProfileFromIndex:(NSInteger)idx { NSString* title = [s_profileTitles objectAtIndex:idx]; s_currentProfileIdx = idx; + [[NSUserDefaults standardUserDefaults] setObject:title forKey:@"CurrentProfile"]; NSDictionary* settings = [s_additionalProfiles objectForKey:title]; if (!settings) { From db10dd373d82749548b3c4860664e85c2c9f12eb Mon Sep 17 00:00:00 2001 From: Daniel Dobalian Date: Mon, 17 Oct 2016 10:25:56 -0700 Subject: [PATCH 37/92] Added reference documentation to README --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index b8b567d7a..a812c7d60 100644 --- a/README.md +++ b/README.md @@ -50,7 +50,7 @@ The ADAL SDK for iOS and Mac OS X gives you the ability to add support for Work ## Samples and Documentation -[We provide a full suite of sample applications and documentation on GitHub](https://github.com/AzureADSamples) to help you get started with learning the Azure Identity system. This includes tutorials for native clients such as Windows, Windows Phone, iOS, OSX, Android, and Linux. We also provide full walkthroughs for authentication flows such as OAuth2, OpenID Connect, Graph API, and other awesome features. +We provide a full suite of [sample applications](https://github.com/AzureADSamples) and [documentation](http://cocoadocs.org/docsets/ADAL/2.2.6/) on GitHub to help you get started with learning the Azure Identity system. This includes tutorials for native clients such as Windows, Windows Phone, iOS, OSX, Android, and Linux. We also provide full walkthroughs for authentication flows such as OAuth2, OpenID Connect, Graph API, and other awesome features. Azure Identity samples for iOS is here: [https://github.com/AzureADSamples/NativeClient-iOS](https://github.com/AzureADSamples/NativeClient-iOS) From 7857bafc2d8b65ce70ac255f1a632a5dffd661cc Mon Sep 17 00:00:00 2001 From: Ryan Pangrle Date: Tue, 18 Oct 2016 15:05:26 -0700 Subject: [PATCH 38/92] Update ADAL_Internal.h Add "-dev" to the version strings and set version to 2.2.8 --- ADAL/src/ADAL_Internal.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/ADAL/src/ADAL_Internal.h b/ADAL/src/ADAL_Internal.h index e543098d2..dad6a3c1a 100644 --- a/ADAL/src/ADAL_Internal.h +++ b/ADAL/src/ADAL_Internal.h @@ -27,7 +27,7 @@ // through build script. Don't change its format unless changing build script as well.) #define ADAL_VER_HIGH 2 #define ADAL_VER_LOW 2 -#define ADAL_VER_PATCH 7 +#define ADAL_VER_PATCH 8 #define STR_HELPER(x) #x #define STR(x) STR_HELPER(x) @@ -37,8 +37,8 @@ // Framework versions only support high and low for the double value, sadly. #define ADAL_VERSION_NUMBER INT_CONCAT(ADAL_VER_HIGH, ADAL_VER_LOW) -#define ADAL_VERSION_STRING STR(ADAL_VER_HIGH) "." STR(ADAL_VER_LOW) "." STR(ADAL_VER_PATCH) -#define ADAL_VERSION_NSSTRING @"" STR(ADAL_VER_HIGH) "." STR(ADAL_VER_LOW) "." STR(ADAL_VER_PATCH) +#define ADAL_VERSION_STRING STR(ADAL_VER_HIGH) "." STR(ADAL_VER_LOW) "." STR(ADAL_VER_PATCH) "-dev" +#define ADAL_VERSION_NSSTRING @"" STR(ADAL_VER_HIGH) "." STR(ADAL_VER_LOW) "." STR(ADAL_VER_PATCH) "-dev" #define ADAL_VERSION_HELPER(high, low, patch) adalVersion_ ## high ## _ ## low ## _ ## patch #define ADAL_VERSION_(high, low, patch) ADAL_VERSION_HELPER(high, low, patch) From 72e5037f0b1bb93c238a727ee0403c8d170c918f Mon Sep 17 00:00:00 2001 From: Ryan Pangrle Date: Wed, 19 Oct 2016 17:22:55 -0700 Subject: [PATCH 39/92] Update build script to build using the project file directly for the SampleSwiftApp --- .../xcshareddata/xcschemes/SampleSwiftApp.xcscheme | 2 +- build.py | 12 ++++++++++-- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/Samples/SampleSwiftApp/SampleSwiftApp.xcodeproj/xcshareddata/xcschemes/SampleSwiftApp.xcscheme b/Samples/SampleSwiftApp/SampleSwiftApp.xcodeproj/xcshareddata/xcschemes/SampleSwiftApp.xcscheme index 6fb25e365..7482b9960 100644 --- a/Samples/SampleSwiftApp/SampleSwiftApp.xcodeproj/xcshareddata/xcschemes/SampleSwiftApp.xcscheme +++ b/Samples/SampleSwiftApp/SampleSwiftApp.xcodeproj/xcshareddata/xcschemes/SampleSwiftApp.xcscheme @@ -4,7 +4,7 @@ version = "1.3"> + buildImplicitDependencies = "YES"> Date: Thu, 20 Oct 2016 18:56:16 -0700 Subject: [PATCH 40/92] Keychain and Result logging improvements I'm trying to clear up confusion over specific log line (i.e. "Nothing found in keychain" which simply meant none were found for the current query, not that they all disappeared...) Increased noise from the FoCI error fallback codepaths have made it more difficult to tell what the final result of an acquireToken call is, so I have added a definitive end log statement for acquireToken flows, as multiple errors can occur in a acquireToken flow, but it still can succeed. * Log clear acquireToken end messages so we have definitive ADAL logs for the eventual error that was sent to the developer * Move context information for keychain queries into the "info" section of the keychain logging --- ADAL/src/cache/ios/ADKeychainTokenCache.m | 20 +++++------ .../ADAuthenticationRequest+AcquireToken.m | 36 ++++++++++++++----- 2 files changed, 37 insertions(+), 19 deletions(-) diff --git a/ADAL/src/cache/ios/ADKeychainTokenCache.m b/ADAL/src/cache/ios/ADKeychainTokenCache.m index efd6e86d8..7cc2e4aeb 100644 --- a/ADAL/src/cache/ios/ADKeychainTokenCache.m +++ b/ADAL/src/cache/ios/ADKeychainTokenCache.m @@ -193,20 +193,16 @@ - (void)logItemRetrievalStatus:(NSArray *)items userId:(NSString *)userId correlationId:(NSUUID *)correlationId { + NSString* keyCtxStr = [NSString stringWithFormat:@"(resource <%@> + client <%@> + authority <%@>)", [key resource], [key clientId], [key authority]]; if (!items || [items count]<=0) { //if resource is nil, this request is intending to find MRRT - if ([NSString adIsStringNilOrBlank:[key resource]]) { - AD_LOG_INFO_F(@"No MRRT found", correlationId, @"resource <%@> + client <%@> + authority <%@>", [key resource], [key clientId], [key authority]); - } - else - { - AD_LOG_INFO_F(@"No AT was found", correlationId, @"resource <%@> + client <%@> + authority <%@>", [key resource], [key clientId], [key authority]); - } + NSString* logStr = [NSString stringWithFormat:@"No items were found for query: %@", keyCtxStr]; + AD_LOG_INFO(logStr, correlationId, nil); } else { - NSString* msg = [NSString stringWithFormat:@"Found %lu token(s)", (unsigned long)[items count]]; + NSString* msg = [NSString stringWithFormat:@"Found %lu token(s) for query: %@", (unsigned long)[items count], keyCtxStr]; AD_LOG_INFO_F(msg, correlationId, @"user <%@>", userId); } } @@ -241,9 +237,13 @@ - (NSString*)getTokenNameForLog:(ADTokenCacheItem *)item [tokenName stringByAppendingString:@"+RT"]; } } + else if ([item.clientId hasPrefix:@"foci-"]) + { + tokenName = @"FRT"; + } else if (![NSString adIsStringNilOrBlank:item.refreshToken] && [NSString adIsStringNilOrBlank:item.resource]) { - tokenName = @"MRRF"; + tokenName = @"MRRT"; } return tokenName; } @@ -267,8 +267,6 @@ - (NSArray *)keychainItemsWithKey:(ADTokenCacheKey*)key OSStatus status = SecItemCopyMatching((CFDictionaryRef)query, &items); if (status == errSecItemNotFound) { - // We don't want to print an error in this case as it's usually not actually an error. - AD_LOG_INFO(@"Nothing found in keychain.", nil, nil); return @[]; } else if (status != errSecSuccess) diff --git a/ADAL/src/request/ADAuthenticationRequest+AcquireToken.m b/ADAL/src/request/ADAuthenticationRequest+AcquireToken.m index 04c5e999f..7eb71066d 100644 --- a/ADAL/src/request/ADAuthenticationRequest+AcquireToken.m +++ b/ADAL/src/request/ADAuthenticationRequest+AcquireToken.m @@ -41,10 +41,30 @@ - (void)acquireToken:(ADAuthenticationCallback)completionBlock AD_REQUEST_CHECK_ARGUMENT(_resource); [self ensureRequest]; - NSString* log = [NSString stringWithFormat:@"acquireToken (authority = %@, resource = %@, clientId = %@, idtype = %@)", - _context.authority, _resource, _clientId, [_identifier typeAsString]]; + __block NSString* log = [NSString stringWithFormat:@"##### BEGIN acquireToken%@ (authority = %@, resource = %@, clientId = %@, idtype = %@) #####", + _silent ? @"Silent" : @"", _context.authority, _resource, _clientId, [_identifier typeAsString]]; AD_LOG_INFO_F(log, _correlationId, @"userId = %@", _identifier.userId); + ADAuthenticationCallback wrappedCallback = ^void(ADAuthenticationResult* result) + { + NSString* finalLog = nil; + if (result.status == AD_SUCCEEDED) + { + finalLog = [NSString stringWithFormat:@"##### END %@ succeeded. #####", log]; + } + else + { + ADAuthenticationError* error = result.error; + finalLog = [NSString stringWithFormat:@"##### END %@ failed { domain: %@ code: %ld protocolCode: %@ errorDetails: %@} #####", + log, error.domain, (long)error.code, error.protocolCode, error.errorDetails]; + } + + + AD_LOG_INFO(finalLog, _correlationId, nil); + + completionBlock(result); + }; + if (!_silent && ![NSThread isMainThread]) { ADAuthenticationError* error = @@ -53,7 +73,7 @@ - (void)acquireToken:(ADAuthenticationCallback)completionBlock errorDetails:@"Interactive authentication requests must originate from the main thread" correlationId:_correlationId]; - completionBlock([ADAuthenticationResult resultFromError:error]); + wrappedCallback([ADAuthenticationResult resultFromError:error]); return; } @@ -64,13 +84,13 @@ - (void)acquireToken:(ADAuthenticationCallback)completionBlock protocolCode:nil errorDetails:ADRedirectUriInvalidError correlationId:_correlationId]; - completionBlock([ADAuthenticationResult resultFromError:error correlationId:_correlationId]); + wrappedCallback([ADAuthenticationResult resultFromError:error correlationId:_correlationId]); return; } if (!_context.validateAuthority) { - [self validatedAcquireToken:completionBlock]; + [self validatedAcquireToken:wrappedCallback]; return; } @@ -81,14 +101,14 @@ - (void)acquireToken:(ADAuthenticationCallback)completionBlock (void)validated; if (error) { - completionBlock([ADAuthenticationResult resultFromError:error correlationId:_correlationId]); + wrappedCallback([ADAuthenticationResult resultFromError:error correlationId:_correlationId]); } else { - [self validatedAcquireToken:completionBlock]; + [self validatedAcquireToken:wrappedCallback]; } }]; - + } - (void)validatedAcquireToken:(ADAuthenticationCallback)completionBlock From 821b2e6e24e4a866251c723d91246dced54548fb Mon Sep 17 00:00:00 2001 From: Ryan Pangrle Date: Fri, 21 Oct 2016 14:33:44 -0700 Subject: [PATCH 41/92] Improve token logging A number of the token log statements don't provide useful context for what that line is for, and often are being logged at verbose, instead of info. Also, shorten the hashes we use to log. 40 character hashes aren't needed for logging purposes, the first 7 characters will be more then sufficient. --- ADAL/src/ADLogger+Internal.h | 9 +++--- ADAL/src/ADLogger.m | 30 +++++++++++++++---- ADAL/src/cache/ADTokenCacheItem+Internal.m | 13 ++++---- .../src/request/ADAcquireTokenSilentHandler.m | 17 +++++++---- 4 files changed, 49 insertions(+), 20 deletions(-) diff --git a/ADAL/src/ADLogger+Internal.h b/ADAL/src/ADLogger+Internal.h index b6c450811..2d6902a00 100644 --- a/ADAL/src/ADLogger+Internal.h +++ b/ADAL/src/ADLogger+Internal.h @@ -124,10 +124,11 @@ correlationId:(NSUUID *)correlationId @param correlationId: In case the token was just obtained from the server, the correlation id of the call. This parameter can be nil. */ -+ (void)logToken:(NSString*)token - tokenType:(NSString*)tokenType - expiresOn:(NSDate*)expiresOn - correlationId:(NSUUID*)correlationId; ++ (void)logToken:(NSString *)token + tokenType:(NSString *)tokenType + expiresOn:(NSDate *)expiresOn + context:(NSString *)context + correlationId:(NSUUID *)correlationId; + (void)setIdValue:(NSString*)value forKey:(NSString*)key; diff --git a/ADAL/src/ADLogger.m b/ADAL/src/ADLogger.m index 08af6c396..d17def8b0 100644 --- a/ADAL/src/ADLogger.m +++ b/ADAL/src/ADLogger.m @@ -277,7 +277,9 @@ + (NSString*)getHash:(NSString*)input { [toReturn appendFormat:@"%02x", hash[i]]; } - return toReturn; + + // 7 characters is sufficient to differentiate tokens in the log, otherwise the hashes start making log lines hard to read + return [toReturn substringToIndex:7]; } + (NSString*) getAdalVersion @@ -285,12 +287,28 @@ + (NSString*) getAdalVersion return ADAL_VERSION_NSSTRING; } -+ (void)logToken:(NSString*)token - tokenType:(NSString*)tokenType - expiresOn:(NSDate*)expiresOn - correlationId:(NSUUID*)correlationId ++ (void)logToken:(NSString *)token + tokenType:(NSString *)tokenType + expiresOn:(NSDate *)expiresOn + context:(NSString *)context + correlationId:(NSUUID *)correlationId { - AD_LOG_VERBOSE_F(@"Token returned", nil, @"Obtained %@ with hash %@, expiring on %@ and correlationId: %@", tokenType, [self getHash:token], expiresOn, [correlationId UUIDString]); + + NSMutableString* logString = nil; + + if (context) + { + [logString appendFormat:@"%@ ", context]; + } + + [logString appendFormat:@"%@ (%@)", tokenType, [self getHash:token]]; + + if (expiresOn) + { + [logString appendFormat:@" expires on %@", expiresOn]; + } + + AD_LOG_INFO(logString, correlationId, nil); } + (void)setIdValue:(NSString*)value diff --git a/ADAL/src/cache/ADTokenCacheItem+Internal.m b/ADAL/src/cache/ADTokenCacheItem+Internal.m index 003ce3cc6..b41fcb160 100644 --- a/ADAL/src/cache/ADTokenCacheItem+Internal.m +++ b/ADAL/src/cache/ADTokenCacheItem+Internal.m @@ -172,15 +172,16 @@ - (void)fillExpiration:(NSMutableDictionary*)responseDictionary } } -- (void)logWithCorrelationId:(NSString*)correlationId - mrrt:(BOOL)isMRRT +- (void)logMessage:(NSString *)message + correlationId:(NSString *)correlationId + mrrt:(BOOL)isMRRT { (void)isMRRT; NSUUID* correlationUUID = [[NSUUID alloc] initWithUUIDString:correlationId]; - [self logMessage:nil - level:ADAL_LOG_LEVEL_VERBOSE + [self logMessage:message + level:ADAL_LOG_LEVEL_INFO correlationId:correlationUUID]; SAFE_ARC_RELEASE(correlationUUID); @@ -221,7 +222,9 @@ - (BOOL)fillItemWithResponse:(NSDictionary*)response [self fillExpiration:responseDictionary]; - [self logWithCorrelationId:[responseDictionary objectForKey:OAUTH2_CORRELATION_ID_RESPONSE] mrrt:isMRRT]; + [self logMessage:@"Received" + correlationId:[responseDictionary objectForKey:OAUTH2_CORRELATION_ID_RESPONSE] + mrrt:isMRRT]; // Store what we haven't cached to _additionalServer SAFE_ARC_RELEASE(_additionalServer); diff --git a/ADAL/src/request/ADAcquireTokenSilentHandler.m b/ADAL/src/request/ADAcquireTokenSilentHandler.m index f04f6b231..3417d6c0d 100644 --- a/ADAL/src/request/ADAcquireTokenSilentHandler.m +++ b/ADAL/src/request/ADAcquireTokenSilentHandler.m @@ -75,8 +75,9 @@ + (void)acquireTokenSilentForAuthority:(NSString *)authority // give the stale token as result [ADLogger logToken:handler->_extendedLifetimeAccessTokenItem.accessToken - tokenType:@"access token (extended lifetime)" + tokenType:@"AT (extended lifetime)" expiresOn:handler->_extendedLifetimeAccessTokenItem.expiresOn + context:@"Returning" correlationId:handler->_correlationId]; result = [ADAuthenticationResult resultFromTokenCacheItem:handler->_extendedLifetimeAccessTokenItem @@ -133,9 +134,11 @@ - (void)acquireTokenByRefreshToken:(NSString*)refreshToken cacheItem:(ADTokenCacheItem*)cacheItem completionBlock:(ADAuthenticationCallback)completionBlock { - AD_LOG_VERBOSE_F(@"Attempting to acquire an access token from refresh token.", _correlationId, @"Resource: %@", _resource); - - [ADLogger logToken:refreshToken tokenType:@"refresh token" expiresOn:nil correlationId:_correlationId]; + [ADLogger logToken:refreshToken + tokenType:@"RT" + expiresOn:nil + context:[NSString stringWithFormat:@"Attempting to acquire for %@ using", _resource] + correlationId:_correlationId]; //Fill the data for the token refreshing: NSMutableDictionary *request_data = nil; @@ -323,7 +326,11 @@ - (void)getAccessToken:(ADAuthenticationCallback)completionBlock // If we have a good (non-expired) access token then return it right away if (item.accessToken && !item.isExpired) { - [ADLogger logToken:item.accessToken tokenType:@"access token" expiresOn:item.expiresOn correlationId:_correlationId]; + [ADLogger logToken:item.accessToken + tokenType:@"AT" + expiresOn:item.expiresOn + context:@"Returning" + correlationId:_correlationId]; ADAuthenticationResult* result = [ADAuthenticationResult resultFromTokenCacheItem:item multiResourceRefreshToken:NO correlationId:_correlationId]; completionBlock(result); return; From 2b30f30f7370d02392eefcf062af4f4be2f375df Mon Sep 17 00:00:00 2001 From: Ryan Pangrle Date: Wed, 26 Oct 2016 18:36:56 -0700 Subject: [PATCH 42/92] Bump "handling PKeyAuth Challenge" to INFO, add error log on explicit cancel --- ADAL/src/ui/ADWebAuthController.m | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ADAL/src/ui/ADWebAuthController.m b/ADAL/src/ui/ADWebAuthController.m index 33b68ccfb..2ca8fd231 100755 --- a/ADAL/src/ui/ADWebAuthController.m +++ b/ADAL/src/ui/ADWebAuthController.m @@ -163,8 +163,7 @@ - (void)dispatchCompletionBlock:(ADAuthenticationError *)error URL:(NSURL *)url - (void)handlePKeyAuthChallenge:(NSString *)challengeUrl { - - AD_LOG_VERBOSE(@"Handling PKeyAuth Challenge", nil, nil); + AD_LOG_INFO(@"Handling PKeyAuth Challenge", nil, nil); NSArray * parts = [challengeUrl componentsSeparatedByString:@"?"]; NSString *qp = [parts objectAtIndex:1]; @@ -531,6 +530,7 @@ + (ADWebAuthController *)sharedInstance - (BOOL)cancelCurrentWebAuthSessionWithError:(ADAuthenticationError*)error { + AD_LOG_ERROR_F(@"Application is cancelling current web auth session.", error.code, _correlationId, @"error = %@", error); return [self endWebAuthenticationWithError:error orURL:nil]; } From 7d6633546e97d7e9839e25fa29dd71b4681bf526 Mon Sep 17 00:00:00 2001 From: Ryan Pangrle Date: Wed, 26 Oct 2016 18:39:16 -0700 Subject: [PATCH 43/92] Add ADAL Automation Test app --- ADAL/ADAL.xcodeproj/project.pbxproj | 232 ++++++++++++++++++ ADAL/ADALAutomation/ADALAutomation.h | 21 ++ ADAL/ADALAutomation/ADAutoAppDelegate.h | 27 ++ ADAL/ADALAutomation/ADAutoAppDelegate.m | 61 +++++ .../ADAutoInputViewController.h | 31 +++ .../ADAutoInputViewController.m | 130 ++++++++++ .../ADALAutomation/ADAutoMainViewController.h | 25 ++ .../ADALAutomation/ADAutoMainViewController.m | 69 ++++++ .../ADAutoParameterViewController.h | 27 ++ .../ADAutoParameterViewController.m | 144 +++++++++++ .../AppIcon.appiconset/Contents.json | 93 +++++++ .../Base.lproj/LaunchScreen.storyboard | 17 ++ .../ADALAutomation/Base.lproj/Main.storyboard | 59 +++++ ADAL/ADALAutomation/Info.plist | 45 ++++ ADAL/ADALAutomation/main.m | 27 ++ 15 files changed, 1008 insertions(+) create mode 100644 ADAL/ADALAutomation/ADALAutomation.h create mode 100644 ADAL/ADALAutomation/ADAutoAppDelegate.h create mode 100644 ADAL/ADALAutomation/ADAutoAppDelegate.m create mode 100644 ADAL/ADALAutomation/ADAutoInputViewController.h create mode 100644 ADAL/ADALAutomation/ADAutoInputViewController.m create mode 100644 ADAL/ADALAutomation/ADAutoMainViewController.h create mode 100644 ADAL/ADALAutomation/ADAutoMainViewController.m create mode 100644 ADAL/ADALAutomation/ADAutoParameterViewController.h create mode 100644 ADAL/ADALAutomation/ADAutoParameterViewController.m create mode 100644 ADAL/ADALAutomation/Assets.xcassets/AppIcon.appiconset/Contents.json create mode 100644 ADAL/ADALAutomation/Base.lproj/LaunchScreen.storyboard create mode 100644 ADAL/ADALAutomation/Base.lproj/Main.storyboard create mode 100644 ADAL/ADALAutomation/Info.plist create mode 100644 ADAL/ADALAutomation/main.m diff --git a/ADAL/ADAL.xcodeproj/project.pbxproj b/ADAL/ADAL.xcodeproj/project.pbxproj index 89f60c8f6..a90aad73c 100755 --- a/ADAL/ADAL.xcodeproj/project.pbxproj +++ b/ADAL/ADAL.xcodeproj/project.pbxproj @@ -192,6 +192,15 @@ 97A522501A1A8999001D77CE /* ADClientMetricsTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 97A5224F1A1A8999001D77CE /* ADClientMetricsTests.m */; }; D60D8FE81D25C8D400F3E6C9 /* ADHelpersTests.m in Sources */ = {isa = PBXBuildFile; fileRef = D60D8FE71D25C8D400F3E6C9 /* ADHelpersTests.m */; }; D60D8FE91D25C8D400F3E6C9 /* ADHelpersTests.m in Sources */ = {isa = PBXBuildFile; fileRef = D60D8FE71D25C8D400F3E6C9 /* ADHelpersTests.m */; }; + D64C1F4C1DB9B05900850036 /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = D64C1F4B1DB9B05900850036 /* main.m */; }; + D64C1F4F1DB9B05900850036 /* ADAutoAppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = D64C1F4E1DB9B05900850036 /* ADAutoAppDelegate.m */; }; + D64C1F521DB9B05900850036 /* ADAutoMainViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = D64C1F511DB9B05900850036 /* ADAutoMainViewController.m */; }; + D64C1F551DB9B05900850036 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = D64C1F531DB9B05900850036 /* Main.storyboard */; }; + D64C1F571DB9B05A00850036 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = D64C1F561DB9B05A00850036 /* Assets.xcassets */; }; + D64C1F5A1DB9B05A00850036 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = D64C1F581DB9B05A00850036 /* LaunchScreen.storyboard */; }; + D64C1F621DB9B15800850036 /* ADAutoParameterViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = D64C1F611DB9B15800850036 /* ADAutoParameterViewController.m */; }; + D64C1F631DB9C64E00850036 /* libADAL-core.a in Frameworks */ = {isa = PBXBuildFile; fileRef = D664F1B41D302B9C0017B799 /* libADAL-core.a */; }; + D64C1F681DBAD90100850036 /* ADAutoInputViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = D64C1F671DBAD90100850036 /* ADAutoInputViewController.m */; }; D664F17A1D302B9C0017B799 /* ADWebAuthRequest.m in Sources */ = {isa = PBXBuildFile; fileRef = D6F095191CDC2BC300D28FC2 /* ADWebAuthRequest.m */; }; D664F17B1D302B9C0017B799 /* ADNTLMUIPrompt.m in Sources */ = {isa = PBXBuildFile; fileRef = 9453C4681C58709D006B9E79 /* ADNTLMUIPrompt.m */; }; D664F17C1D302B9C0017B799 /* ADOAuth2Constants.m in Sources */ = {isa = PBXBuildFile; fileRef = 8B7E6FC71856A1E8000DC3C8 /* ADOAuth2Constants.m */; }; @@ -312,6 +321,13 @@ remoteGlobalIDString = D664F16A1D302B9C0017B799; remoteInfo = "ADAL-core"; }; + D64C1F641DB9C65400850036 /* PBXContainerItemProxy */ = { + isa = PBXContainerItemProxy; + containerPortal = 8B0965A217F25770002BDFB8 /* Project object */; + proxyType = 1; + remoteGlobalIDString = D664F16A1D302B9C0017B799; + remoteInfo = "ADAL-core"; + }; D69A72091D4FEC4200E91DB3 /* PBXContainerItemProxy */ = { isa = PBXContainerItemProxy; containerPortal = 8B0965A217F25770002BDFB8 /* Project object */; @@ -537,6 +553,21 @@ 97A522511A1A89C4001D77CE /* ADClientMetrics.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ADClientMetrics.h; sourceTree = ""; }; 97EEE7B41A4C0D6000D003F8 /* QuartzCore.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = QuartzCore.framework; path = System/Library/Frameworks/QuartzCore.framework; sourceTree = SDKROOT; }; D60D8FE71D25C8D400F3E6C9 /* ADHelpersTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ADHelpersTests.m; sourceTree = ""; }; + D64C1F481DB9B05900850036 /* ADALAutomation.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = ADALAutomation.app; sourceTree = BUILT_PRODUCTS_DIR; }; + D64C1F4B1DB9B05900850036 /* main.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = ""; }; + D64C1F4D1DB9B05900850036 /* ADAutoAppDelegate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ADAutoAppDelegate.h; sourceTree = ""; }; + D64C1F4E1DB9B05900850036 /* ADAutoAppDelegate.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = ADAutoAppDelegate.m; sourceTree = ""; }; + D64C1F501DB9B05900850036 /* ADAutoMainViewController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ADAutoMainViewController.h; sourceTree = ""; }; + D64C1F511DB9B05900850036 /* ADAutoMainViewController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = ADAutoMainViewController.m; sourceTree = ""; }; + D64C1F541DB9B05900850036 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = ""; }; + D64C1F561DB9B05A00850036 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; + D64C1F591DB9B05A00850036 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = ""; }; + D64C1F5B1DB9B05A00850036 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; + D64C1F601DB9B15800850036 /* ADAutoParameterViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ADAutoParameterViewController.h; sourceTree = ""; }; + D64C1F611DB9B15800850036 /* ADAutoParameterViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ADAutoParameterViewController.m; sourceTree = ""; }; + D64C1F661DBAD90100850036 /* ADAutoInputViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ADAutoInputViewController.h; sourceTree = ""; }; + D64C1F671DBAD90100850036 /* ADAutoInputViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ADAutoInputViewController.m; sourceTree = ""; }; + D64C1F691DBADAF900850036 /* ADALAutomation.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ADALAutomation.h; sourceTree = ""; }; D664F1481D25FC4C0017B799 /* ADWorkPlaceJoinConstants.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ADWorkPlaceJoinConstants.h; sourceTree = ""; }; D664F1491D25FC4C0017B799 /* ADWorkPlaceJoinUtil.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ADWorkPlaceJoinUtil.h; sourceTree = ""; }; D664F1B41D302B9C0017B799 /* libADAL-core.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libADAL-core.a"; sourceTree = BUILT_PRODUCTS_DIR; }; @@ -607,6 +638,14 @@ ); runOnlyForDeploymentPostprocessing = 0; }; + D64C1F451DB9B05900850036 /* Frameworks */ = { + isa = PBXFrameworksBuildPhase; + buildActionMask = 2147483647; + files = ( + D64C1F631DB9C64E00850036 /* libADAL-core.a in Frameworks */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; D664F1AD1D302B9C0017B799 /* Frameworks */ = { isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; @@ -670,6 +709,7 @@ 9453C3151C57EE57006B9E79 /* resouces */, 94886EED1C63BE3800503C04 /* xcconfig */, 60967E191D76B62B00863853 /* tools */, + D64C1F491DB9B05900850036 /* ADALAutomation */, 8B0965AC17F25770002BDFB8 /* Frameworks */, 8B0965AB17F25770002BDFB8 /* Products */, ); @@ -687,6 +727,7 @@ 94DD18E11C5ACFBF00F80C62 /* ADAL Mac Tests.xctest */, D664F1B41D302B9C0017B799 /* libADAL-core.a */, 04AB6D421D9D619B007E9A83 /* UnitTestHostApp.app */, + D64C1F481DB9B05900850036 /* ADALAutomation.app */, ); name = Products; sourceTree = ""; @@ -1097,6 +1138,35 @@ path = mac; sourceTree = ""; }; + D64C1F491DB9B05900850036 /* ADALAutomation */ = { + isa = PBXGroup; + children = ( + D64C1F4D1DB9B05900850036 /* ADAutoAppDelegate.h */, + D64C1F661DBAD90100850036 /* ADAutoInputViewController.h */, + D64C1F671DBAD90100850036 /* ADAutoInputViewController.m */, + D64C1F4E1DB9B05900850036 /* ADAutoAppDelegate.m */, + D64C1F501DB9B05900850036 /* ADAutoMainViewController.h */, + D64C1F511DB9B05900850036 /* ADAutoMainViewController.m */, + D64C1F601DB9B15800850036 /* ADAutoParameterViewController.h */, + D64C1F611DB9B15800850036 /* ADAutoParameterViewController.m */, + D64C1F531DB9B05900850036 /* Main.storyboard */, + D64C1F561DB9B05A00850036 /* Assets.xcassets */, + D64C1F581DB9B05A00850036 /* LaunchScreen.storyboard */, + D64C1F5B1DB9B05A00850036 /* Info.plist */, + D64C1F4A1DB9B05900850036 /* Supporting Files */, + D64C1F691DBADAF900850036 /* ADALAutomation.h */, + ); + path = ADALAutomation; + sourceTree = ""; + }; + D64C1F4A1DB9B05900850036 /* Supporting Files */ = { + isa = PBXGroup; + children = ( + D64C1F4B1DB9B05900850036 /* main.m */, + ); + name = "Supporting Files"; + sourceTree = ""; + }; D6D8A83D1D4FD12300D20DE6 /* ios */ = { isa = PBXGroup; children = ( @@ -1305,6 +1375,24 @@ productReference = 94DD18E11C5ACFBF00F80C62 /* ADAL Mac Tests.xctest */; productType = "com.apple.product-type.bundle.unit-test"; }; + D64C1F471DB9B05900850036 /* ADALAutomation */ = { + isa = PBXNativeTarget; + buildConfigurationList = D64C1F5F1DB9B05A00850036 /* Build configuration list for PBXNativeTarget "ADALAutomation" */; + buildPhases = ( + D64C1F441DB9B05900850036 /* Sources */, + D64C1F451DB9B05900850036 /* Frameworks */, + D64C1F461DB9B05900850036 /* Resources */, + ); + buildRules = ( + ); + dependencies = ( + D64C1F651DB9C65400850036 /* PBXTargetDependency */, + ); + name = ADALAutomation; + productName = ADALAutomation; + productReference = D64C1F481DB9B05900850036 /* ADALAutomation.app */; + productType = "com.apple.product-type.application"; + }; D664F16A1D302B9C0017B799 /* ADAL-core */ = { isa = PBXNativeTarget; buildConfigurationList = D664F1B01D302B9C0017B799 /* Build configuration list for PBXNativeTarget "ADAL-core" */; @@ -1356,6 +1444,11 @@ 94DD18E01C5ACFBF00F80C62 = { CreatedOnToolsVersion = 7.2; }; + D64C1F471DB9B05900850036 = { + CreatedOnToolsVersion = 8.0; + DevelopmentTeam = UBF8T346G9; + ProvisioningStyle = Automatic; + }; }; }; buildConfigurationList = 8B0965A517F25770002BDFB8 /* Build configuration list for PBXProject "ADAL" */; @@ -1379,6 +1472,7 @@ 94DD18E01C5ACFBF00F80C62 /* ADAL Mac Tests */, 9453C4571C5866D0006B9E79 /* Build All */, 04AB6D411D9D619B007E9A83 /* UnitTestHostApp */, + D64C1F471DB9B05900850036 /* ADALAutomation */, ); }; /* End PBXProject section */ @@ -1423,6 +1517,16 @@ ); runOnlyForDeploymentPostprocessing = 0; }; + D64C1F461DB9B05900850036 /* Resources */ = { + isa = PBXResourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + D64C1F5A1DB9B05A00850036 /* LaunchScreen.storyboard in Resources */, + D64C1F571DB9B05A00850036 /* Assets.xcassets in Resources */, + D64C1F551DB9B05900850036 /* Main.storyboard in Resources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; /* End PBXResourcesBuildPhase section */ /* Begin PBXShellScriptBuildPhase section */ @@ -1623,6 +1727,18 @@ ); runOnlyForDeploymentPostprocessing = 0; }; + D64C1F441DB9B05900850036 /* Sources */ = { + isa = PBXSourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + D64C1F621DB9B15800850036 /* ADAutoParameterViewController.m in Sources */, + D64C1F681DBAD90100850036 /* ADAutoInputViewController.m in Sources */, + D64C1F521DB9B05900850036 /* ADAutoMainViewController.m in Sources */, + D64C1F4F1DB9B05900850036 /* ADAutoAppDelegate.m in Sources */, + D64C1F4C1DB9B05900850036 /* main.m in Sources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; D664F1791D302B9C0017B799 /* Sources */ = { isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; @@ -1715,6 +1831,11 @@ target = D664F16A1D302B9C0017B799 /* ADAL-core */; targetProxy = D61000E91D3984C20087AB81 /* PBXContainerItemProxy */; }; + D64C1F651DB9C65400850036 /* PBXTargetDependency */ = { + isa = PBXTargetDependency; + target = D664F16A1D302B9C0017B799 /* ADAL-core */; + targetProxy = D64C1F641DB9C65400850036 /* PBXContainerItemProxy */; + }; D69A720A1D4FEC4200E91DB3 /* PBXTargetDependency */ = { isa = PBXTargetDependency; target = D664F16A1D302B9C0017B799 /* ADAL-core */; @@ -1755,6 +1876,22 @@ name = InfoPlist.strings; sourceTree = ""; }; + D64C1F531DB9B05900850036 /* Main.storyboard */ = { + isa = PBXVariantGroup; + children = ( + D64C1F541DB9B05900850036 /* Base */, + ); + name = Main.storyboard; + sourceTree = ""; + }; + D64C1F581DB9B05A00850036 /* LaunchScreen.storyboard */ = { + isa = PBXVariantGroup; + children = ( + D64C1F591DB9B05A00850036 /* Base */, + ); + name = LaunchScreen.storyboard; + sourceTree = ""; + }; /* End PBXVariantGroup section */ /* Begin XCBuildConfiguration section */ @@ -2397,6 +2534,92 @@ }; name = Release; }; + D64C1F5C1DB9B05A00850036 /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; + CLANG_ANALYZER_NONNULL = YES; + CLANG_ENABLE_OBJC_ARC = YES; + CLANG_WARN_DOCUMENTATION_COMMENTS = YES; + CLANG_WARN_INFINITE_RECURSION = YES; + CLANG_WARN_SUSPICIOUS_MOVES = YES; + CLANG_WARN_UNREACHABLE_CODE = YES; + "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; + DEBUG_INFORMATION_FORMAT = dwarf; + DEVELOPMENT_TEAM = UBF8T346G9; + ENABLE_STRICT_OBJC_MSGSEND = YES; + GCC_NO_COMMON_BLOCKS = YES; + GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; + INFOPLIST_FILE = ADALAutomation/Info.plist; + IPHONEOS_DEPLOYMENT_TARGET = 10.0; + LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; + MTL_ENABLE_DEBUG_INFO = YES; + OTHER_LDFLAGS = "-ObjC"; + PRODUCT_BUNDLE_IDENTIFIER = com.microsoft.adal.automationapp; + PRODUCT_NAME = "$(TARGET_NAME)"; + TARGETED_DEVICE_FAMILY = "1,2"; + USER_HEADER_SEARCH_PATHS = "../src/** $(inherited)"; + }; + name = Debug; + }; + D64C1F5D1DB9B05A00850036 /* CodeCoverage */ = { + isa = XCBuildConfiguration; + buildSettings = { + ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; + CLANG_ANALYZER_NONNULL = YES; + CLANG_ENABLE_OBJC_ARC = YES; + CLANG_WARN_DOCUMENTATION_COMMENTS = YES; + CLANG_WARN_INFINITE_RECURSION = YES; + CLANG_WARN_SUSPICIOUS_MOVES = YES; + CLANG_WARN_UNREACHABLE_CODE = YES; + "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; + COPY_PHASE_STRIP = NO; + DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; + DEVELOPMENT_TEAM = UBF8T346G9; + ENABLE_STRICT_OBJC_MSGSEND = YES; + GCC_NO_COMMON_BLOCKS = YES; + GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; + INFOPLIST_FILE = ADALAutomation/Info.plist; + IPHONEOS_DEPLOYMENT_TARGET = 10.0; + LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; + MTL_ENABLE_DEBUG_INFO = NO; + OTHER_LDFLAGS = "-ObjC"; + PRODUCT_BUNDLE_IDENTIFIER = com.microsoft.adal.automationapp; + PRODUCT_NAME = "$(TARGET_NAME)"; + TARGETED_DEVICE_FAMILY = "1,2"; + USER_HEADER_SEARCH_PATHS = "../src/** $(inherited)"; + }; + name = CodeCoverage; + }; + D64C1F5E1DB9B05A00850036 /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; + CLANG_ANALYZER_NONNULL = YES; + CLANG_ENABLE_OBJC_ARC = YES; + CLANG_WARN_DOCUMENTATION_COMMENTS = YES; + CLANG_WARN_INFINITE_RECURSION = YES; + CLANG_WARN_SUSPICIOUS_MOVES = YES; + CLANG_WARN_UNREACHABLE_CODE = YES; + "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; + COPY_PHASE_STRIP = NO; + DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; + DEVELOPMENT_TEAM = UBF8T346G9; + ENABLE_STRICT_OBJC_MSGSEND = YES; + GCC_NO_COMMON_BLOCKS = YES; + GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; + INFOPLIST_FILE = ADALAutomation/Info.plist; + IPHONEOS_DEPLOYMENT_TARGET = 10.0; + LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; + MTL_ENABLE_DEBUG_INFO = NO; + OTHER_LDFLAGS = "-ObjC"; + PRODUCT_BUNDLE_IDENTIFIER = com.microsoft.adal.automationapp; + PRODUCT_NAME = "$(TARGET_NAME)"; + TARGETED_DEVICE_FAMILY = "1,2"; + USER_HEADER_SEARCH_PATHS = "../src/** $(inherited)"; + }; + name = Release; + }; D664F1B11D302B9C0017B799 /* Debug */ = { isa = XCBuildConfiguration; baseConfigurationReference = 946347851C644E13000A6DA1 /* adal__ios__staticlib.xcconfig */; @@ -2557,6 +2780,15 @@ defaultConfigurationIsVisible = 0; defaultConfigurationName = Debug; }; + D64C1F5F1DB9B05A00850036 /* Build configuration list for PBXNativeTarget "ADALAutomation" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + D64C1F5C1DB9B05A00850036 /* Debug */, + D64C1F5D1DB9B05A00850036 /* CodeCoverage */, + D64C1F5E1DB9B05A00850036 /* Release */, + ); + defaultConfigurationIsVisible = 0; + }; D664F1B01D302B9C0017B799 /* Build configuration list for PBXNativeTarget "ADAL-core" */ = { isa = XCConfigurationList; buildConfigurations = ( diff --git a/ADAL/ADALAutomation/ADALAutomation.h b/ADAL/ADALAutomation/ADALAutomation.h new file mode 100644 index 000000000..d1a5c8b1a --- /dev/null +++ b/ADAL/ADALAutomation/ADALAutomation.h @@ -0,0 +1,21 @@ +// Copyright © Microsoft Open Technologies, Inc. +// +// All Rights Reserved +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// THIS CODE IS PROVIDED *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS +// OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION +// ANY IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A +// PARTICULAR PURPOSE, MERCHANTABILITY OR NON-INFRINGEMENT. +// +// See the Apache License, Version 2.0 for the specific language +// governing permissions and limitations under the License. + +#pragma once + +typedef void (^ADAutoParamBlock)(NSDictionary * parameters); diff --git a/ADAL/ADALAutomation/ADAutoAppDelegate.h b/ADAL/ADALAutomation/ADAutoAppDelegate.h new file mode 100644 index 000000000..9fafe0107 --- /dev/null +++ b/ADAL/ADALAutomation/ADAutoAppDelegate.h @@ -0,0 +1,27 @@ +// Copyright © Microsoft Open Technologies, Inc. +// +// All Rights Reserved +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// THIS CODE IS PROVIDED *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS +// OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION +// ANY IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A +// PARTICULAR PURPOSE, MERCHANTABILITY OR NON-INFRINGEMENT. +// +// See the Apache License, Version 2.0 for the specific language +// governing permissions and limitations under the License. + +#import + +@interface ADAutoAppDelegate : UIResponder + +@property (strong, nonatomic) UIWindow *window; + + +@end + diff --git a/ADAL/ADALAutomation/ADAutoAppDelegate.m b/ADAL/ADALAutomation/ADAutoAppDelegate.m new file mode 100644 index 000000000..451d34c61 --- /dev/null +++ b/ADAL/ADALAutomation/ADAutoAppDelegate.m @@ -0,0 +1,61 @@ +// Copyright © Microsoft Open Technologies, Inc. +// +// All Rights Reserved +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// THIS CODE IS PROVIDED *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS +// OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION +// ANY IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A +// PARTICULAR PURPOSE, MERCHANTABILITY OR NON-INFRINGEMENT. +// +// See the Apache License, Version 2.0 for the specific language +// governing permissions and limitations under the License. + +#import "ADAutoAppDelegate.h" + +@interface ADAutoAppDelegate () + +@end + +@implementation ADAutoAppDelegate + + +- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { + // Override point for customization after application launch. + return YES; +} + + +- (void)applicationWillResignActive:(UIApplication *)application { + // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state. + // Use this method to pause ongoing tasks, disable timers, and invalidate graphics rendering callbacks. Games should use this method to pause the game. +} + + +- (void)applicationDidEnterBackground:(UIApplication *)application { + // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later. + // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits. +} + + +- (void)applicationWillEnterForeground:(UIApplication *)application { + // Called as part of the transition from the background to the active state; here you can undo many of the changes made on entering the background. +} + + +- (void)applicationDidBecomeActive:(UIApplication *)application { + // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface. +} + + +- (void)applicationWillTerminate:(UIApplication *)application { + // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:. +} + + +@end diff --git a/ADAL/ADALAutomation/ADAutoInputViewController.h b/ADAL/ADALAutomation/ADAutoInputViewController.h new file mode 100644 index 000000000..5feab4cf9 --- /dev/null +++ b/ADAL/ADALAutomation/ADAutoInputViewController.h @@ -0,0 +1,31 @@ +// Copyright (c) Microsoft Corporation. +// All rights reserved. +// +// This code is licensed under the MIT License. +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files(the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and / or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions : +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE. + +#import +#import "ADALAutomation.h" + +@interface ADAutoInputViewController : UIViewController + +- (id)initWithCompletionBlock:(ADAutoParamBlock)completionBlock; + +@end diff --git a/ADAL/ADALAutomation/ADAutoInputViewController.m b/ADAL/ADALAutomation/ADAutoInputViewController.m new file mode 100644 index 000000000..800647376 --- /dev/null +++ b/ADAL/ADALAutomation/ADAutoInputViewController.m @@ -0,0 +1,130 @@ +// Copyright (c) Microsoft Corporation. +// All rights reserved. +// +// This code is licensed under the MIT License. +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files(the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and / or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions : +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE. + +#import "ADAutoInputViewController.h" + +@interface ADAutoInputViewController () + +@end + +@implementation ADAutoInputViewController +{ + ADAutoParamBlock _completionBlock; + UITextView * _inputTextview; +} + +- (id)initWithCompletionBlock:(ADAutoParamBlock)completionBlock +{ + if (!(self = [super init])) + { + return nil; + } + + _completionBlock = completionBlock; + + return self; +} + +- (void)loadView +{ + UIView* rootView = [[UIView alloc] initWithFrame:UIScreen.mainScreen.bounds]; + rootView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight; + rootView.translatesAutoresizingMaskIntoConstraints = YES; + rootView.autoresizesSubviews = NO; + rootView.backgroundColor = UIColor.whiteColor; + self.view = rootView; + + UITextView* textView = [[UITextView alloc] init]; + textView.autocorrectionType = UITextAutocorrectionTypeNo; + textView.accessibilityIdentifier = @"inputTextview"; + textView.translatesAutoresizingMaskIntoConstraints = NO; + textView.editable = YES; + textView.layer.cornerRadius = 8.0; + textView.layer.borderWidth = 1.0; + textView.layer.borderColor = UIColor.lightGrayColor.CGColor; + + _inputTextview = textView; + + UIButton* goButton = [[UIButton alloc] init]; + [goButton setTitle:@"Go" forState:UIControlStateNormal]; + [goButton addTarget:self + action:@selector(go:) + forControlEvents:UIControlEventTouchUpInside]; + goButton.backgroundColor = UIColor.greenColor; + goButton.titleLabel.textColor = UIColor.whiteColor; + goButton.translatesAutoresizingMaskIntoConstraints = NO; + goButton.accessibilityIdentifier = @"GoButton"; + + [rootView addSubview:textView]; + [rootView addSubview:goButton]; + + UILayoutGuide* margins = self.view.layoutMarginsGuide; + [textView.topAnchor constraintEqualToAnchor:self.topLayoutGuide.bottomAnchor constant:8.0].active = YES; + [textView.leadingAnchor constraintEqualToAnchor:margins.leadingAnchor].active = YES; + [textView.trailingAnchor constraintEqualToAnchor:margins.trailingAnchor].active = YES; + [textView.bottomAnchor constraintEqualToAnchor:goButton.topAnchor constant:-8.0].active = YES; + [goButton.leadingAnchor constraintEqualToAnchor:margins.leadingAnchor].active = YES; + [goButton.trailingAnchor constraintEqualToAnchor:margins.trailingAnchor].active = YES; + [goButton.heightAnchor constraintEqualToConstant:20.0]; + [goButton.bottomAnchor constraintEqualToAnchor:self.bottomLayoutGuide.topAnchor constant:-8.0].active = YES; +} + +- (void)viewDidLoad { + [super viewDidLoad]; + // Do any additional setup after loading the view. +} + +- (void)didReceiveMemoryWarning { + [super didReceiveMemoryWarning]; + // Dispose of any resources that can be recreated. +} + +- (IBAction)go:(id)sender +{ + (void)sender; + + @synchronized (self) + { + NSString* text = _inputTextview.text; + NSError* error = nil; + NSDictionary* params = [NSJSONSerialization JSONObjectWithData:[text dataUsingEncoding:NSUTF8StringEncoding] options:0 error:&error]; + if (!params) + { + params = @{ @"error" : error }; + } + + _completionBlock(params); + } +} + +/* +#pragma mark - Navigation + +// In a storyboard-based application, you will often want to do a little preparation before navigation +- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender { + // Get the new view controller using [segue destinationViewController]. + // Pass the selected object to the new view controller. +} +*/ + +@end diff --git a/ADAL/ADALAutomation/ADAutoMainViewController.h b/ADAL/ADALAutomation/ADAutoMainViewController.h new file mode 100644 index 000000000..f07fc5680 --- /dev/null +++ b/ADAL/ADALAutomation/ADAutoMainViewController.h @@ -0,0 +1,25 @@ +// Copyright © Microsoft Open Technologies, Inc. +// +// All Rights Reserved +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// THIS CODE IS PROVIDED *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS +// OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION +// ANY IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A +// PARTICULAR PURPOSE, MERCHANTABILITY OR NON-INFRINGEMENT. +// +// See the Apache License, Version 2.0 for the specific language +// governing permissions and limitations under the License. + +#import + +@interface ADAutoMainViewController : UIViewController + + +@end + diff --git a/ADAL/ADALAutomation/ADAutoMainViewController.m b/ADAL/ADALAutomation/ADAutoMainViewController.m new file mode 100644 index 000000000..9ff5bad5b --- /dev/null +++ b/ADAL/ADALAutomation/ADAutoMainViewController.m @@ -0,0 +1,69 @@ +// Copyright © Microsoft Open Technologies, Inc. +// +// All Rights Reserved +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// THIS CODE IS PROVIDED *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS +// OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION +// ANY IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A +// PARTICULAR PURPOSE, MERCHANTABILITY OR NON-INFRINGEMENT. +// +// See the Apache License, Version 2.0 for the specific language +// governing permissions and limitations under the License. + +#import "ADAutoMainViewController.h" +#import "ADAutoParameterViewController.h" +#import "ADAutoInputViewController.h" +#import "ADAL_Internal.h" + +@interface ADAutoMainViewController () + +@end + +@implementation ADAutoMainViewController + +- (void)viewDidLoad { + [super viewDidLoad]; + // Do any additional setup after loading the view, typically from a nib. +} + + +- (void)didReceiveMemoryWarning { + [super didReceiveMemoryWarning]; + // Dispose of any resources that can be recreated. +} + + +- (IBAction)acquireToken:(id)sender +{ + /* ADAutoParameterViewController* paramController = + [[ADAutoParameterViewController alloc] initWithParameters:@[@"userId", @"authority", @"clientId", @"resource", @"redirectUri"] + completionBlock:^(NSDictionary *parameters)*/ + ADAutoInputViewController* inputController = + [[ADAutoInputViewController alloc] initWithCompletionBlock:^(NSDictionary *parameters) + { + ADAuthenticationContext* context = + [[ADAuthenticationContext alloc] initWithAuthority:parameters[@"authority"] + validateAuthority:YES + error:nil]; + + [context acquireTokenWithResource:parameters[@"resource"] + clientId:parameters[@"clientId"] + redirectUri:[NSURL URLWithString:parameters[@"redirectUri"]] + completionBlock:^(ADAuthenticationResult *result) + { + NSLog(@"Yay! %@", result); + }]; + }]; + + [self presentViewController:inputController animated:NO completion:^{ + NSLog(@"presented!"); + }]; +} + +@end diff --git a/ADAL/ADALAutomation/ADAutoParameterViewController.h b/ADAL/ADALAutomation/ADAutoParameterViewController.h new file mode 100644 index 000000000..b4a3826a1 --- /dev/null +++ b/ADAL/ADALAutomation/ADAutoParameterViewController.h @@ -0,0 +1,27 @@ +// Copyright © Microsoft Open Technologies, Inc. +// +// All Rights Reserved +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// THIS CODE IS PROVIDED *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS +// OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION +// ANY IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A +// PARTICULAR PURPOSE, MERCHANTABILITY OR NON-INFRINGEMENT. +// +// See the Apache License, Version 2.0 for the specific language +// governing permissions and limitations under the License. + +#import +#import "ADALAutomation.h" + +@interface ADAutoParameterViewController : UIViewController + +- (id)initWithParameters:(NSArray*)parameters + completionBlock:(ADAutoParamBlock)completionBlock; + +@end diff --git a/ADAL/ADALAutomation/ADAutoParameterViewController.m b/ADAL/ADALAutomation/ADAutoParameterViewController.m new file mode 100644 index 000000000..f46285e87 --- /dev/null +++ b/ADAL/ADALAutomation/ADAutoParameterViewController.m @@ -0,0 +1,144 @@ +// Copyright © Microsoft Open Technologies, Inc. +// +// All Rights Reserved +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// THIS CODE IS PROVIDED *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS +// OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION +// ANY IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A +// PARTICULAR PURPOSE, MERCHANTABILITY OR NON-INFRINGEMENT. +// +// See the Apache License, Version 2.0 for the specific language +// governing permissions and limitations under the License. + +#import "ADAutoParameterViewController.h" + +@interface ADAutoParameterViewController () + +@end + +@implementation ADAutoParameterViewController +{ + NSArray * _parameters; + ADAutoParamBlock _completion; + NSArray * _textFields; + UIStackView* _stackView; +} + +- (void)dealloc +{ + NSLog(@"dealloced"); +} + +- (void)loadView +{ + UIView* rootView = [[UIView alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; + rootView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight; + rootView.translatesAutoresizingMaskIntoConstraints = YES; + rootView.autoresizesSubviews = NO; + rootView.backgroundColor = UIColor.whiteColor; + self.view = rootView; + + UIStackView* stackView = [[UIStackView alloc] init]; + //stackView.autoresizingMask = UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleBottomMargin; + stackView.axis = UILayoutConstraintAxisVertical; + stackView.spacing = 4.0; + stackView.alignment = UIStackViewAlignmentFill; + stackView.translatesAutoresizingMaskIntoConstraints = NO; + stackView.backgroundColor = UIColor.whiteColor; + + NSMutableArray* fields = [[NSMutableArray alloc] initWithCapacity:_parameters.count]; + + for (NSString* param in _parameters) + { + UITextField* tf = [[UITextField alloc] init]; + tf.accessibilityIdentifier = param; + tf.placeholder = param; + tf.borderStyle = UITextBorderStyleLine; + tf.autocorrectionType = UITextAutocorrectionTypeNo; + [stackView addArrangedSubview:tf]; + [fields addObject:tf]; + } + + _textFields = fields; + + UIButton* goButton = [[UIButton alloc] init]; + [goButton setTitle:@"Go" forState:UIControlStateNormal]; + [goButton addTarget:self + action:@selector(go:) + forControlEvents:UIControlEventTouchUpInside]; + goButton.backgroundColor = UIColor.greenColor; + goButton.titleLabel.textColor = UIColor.whiteColor; + goButton.accessibilityIdentifier = @"GoButton"; + [stackView addArrangedSubview:goButton]; + + [rootView addSubview:stackView]; + + + UILayoutGuide* margins = self.view.layoutMarginsGuide; + [stackView.topAnchor constraintEqualToAnchor:self.topLayoutGuide.bottomAnchor].active = YES; + [stackView.leadingAnchor constraintEqualToAnchor:margins.leadingAnchor].active = YES; + [stackView.trailingAnchor constraintEqualToAnchor:margins.trailingAnchor constant:8.0].active = YES; + [stackView setNeedsLayout]; + + /*[rootView.leadingAnchor constraintEqualToAnchor:stackView.leadingAnchor constant:8.0].active = YES; + [rootView.trailingAnchor constraintEqualToAnchor:stackView.trailingAnchor constant:8.0].active = YES;*/ +} + +- (void)viewDidLoad { + [super viewDidLoad]; + // Do any additional setup after loading the view. +} + +- (void)didReceiveMemoryWarning { + [super didReceiveMemoryWarning]; + // Dispose of any resources that can be recreated. +} + +- (id)initWithParameters:(NSArray*)parameters + completionBlock:(ADAutoParamBlock)completionBlock +{ + if (!(self = [super init])) + { + return nil; + + } + + _parameters = parameters; + _completion = completionBlock; + + return self; +} + +- (IBAction)go:(id)sender +{ + (void)sender; + + @synchronized (self) + { + NSMutableDictionary* params = [NSMutableDictionary new]; + for (UITextField* field in _textFields) + { + params[field.accessibilityIdentifier] = field.text; + } + + _completion(params); + _completion = nil; + } +} +/* +#pragma mark - Navigation + +// In a storyboard-based application, you will often want to do a little preparation before navigation +- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender { + // Get the new view controller using [segue destinationViewController]. + // Pass the selected object to the new view controller. +} +*/ + +@end diff --git a/ADAL/ADALAutomation/Assets.xcassets/AppIcon.appiconset/Contents.json b/ADAL/ADALAutomation/Assets.xcassets/AppIcon.appiconset/Contents.json new file mode 100644 index 000000000..1d060ed28 --- /dev/null +++ b/ADAL/ADALAutomation/Assets.xcassets/AppIcon.appiconset/Contents.json @@ -0,0 +1,93 @@ +{ + "images" : [ + { + "idiom" : "iphone", + "size" : "20x20", + "scale" : "2x" + }, + { + "idiom" : "iphone", + "size" : "20x20", + "scale" : "3x" + }, + { + "idiom" : "iphone", + "size" : "29x29", + "scale" : "2x" + }, + { + "idiom" : "iphone", + "size" : "29x29", + "scale" : "3x" + }, + { + "idiom" : "iphone", + "size" : "40x40", + "scale" : "2x" + }, + { + "idiom" : "iphone", + "size" : "40x40", + "scale" : "3x" + }, + { + "idiom" : "iphone", + "size" : "60x60", + "scale" : "2x" + }, + { + "idiom" : "iphone", + "size" : "60x60", + "scale" : "3x" + }, + { + "idiom" : "ipad", + "size" : "20x20", + "scale" : "1x" + }, + { + "idiom" : "ipad", + "size" : "20x20", + "scale" : "2x" + }, + { + "idiom" : "ipad", + "size" : "29x29", + "scale" : "1x" + }, + { + "idiom" : "ipad", + "size" : "29x29", + "scale" : "2x" + }, + { + "idiom" : "ipad", + "size" : "40x40", + "scale" : "1x" + }, + { + "idiom" : "ipad", + "size" : "40x40", + "scale" : "2x" + }, + { + "idiom" : "ipad", + "size" : "76x76", + "scale" : "1x" + }, + { + "idiom" : "ipad", + "size" : "76x76", + "scale" : "2x" + }, + { + "idiom" : "ipad", + "size" : "83.5x83.5", + "scale" : "2x" + } + ], + "info" : { + "version" : 1, + "author" : "xcode" + } +} \ No newline at end of file diff --git a/ADAL/ADALAutomation/Base.lproj/LaunchScreen.storyboard b/ADAL/ADALAutomation/Base.lproj/LaunchScreen.storyboard new file mode 100644 index 000000000..3992c7fdf --- /dev/null +++ b/ADAL/ADALAutomation/Base.lproj/LaunchScreen.storyboard @@ -0,0 +1,17 @@ + + + + + + + + + + + + + + + + + diff --git a/ADAL/ADALAutomation/Base.lproj/Main.storyboard b/ADAL/ADALAutomation/Base.lproj/Main.storyboard new file mode 100644 index 000000000..f71de8aef --- /dev/null +++ b/ADAL/ADALAutomation/Base.lproj/Main.storyboard @@ -0,0 +1,59 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/ADAL/ADALAutomation/Info.plist b/ADAL/ADALAutomation/Info.plist new file mode 100644 index 000000000..d05247386 --- /dev/null +++ b/ADAL/ADALAutomation/Info.plist @@ -0,0 +1,45 @@ + + + + + CFBundleDevelopmentRegion + en + CFBundleExecutable + $(EXECUTABLE_NAME) + CFBundleIdentifier + $(PRODUCT_BUNDLE_IDENTIFIER) + CFBundleInfoDictionaryVersion + 6.0 + CFBundleName + $(PRODUCT_NAME) + CFBundlePackageType + APPL + CFBundleShortVersionString + 1.0 + CFBundleVersion + 1 + LSRequiresIPhoneOS + + UILaunchStoryboardName + LaunchScreen + UIMainStoryboardFile + Main + UIRequiredDeviceCapabilities + + armv7 + + UISupportedInterfaceOrientations + + UIInterfaceOrientationPortrait + UIInterfaceOrientationLandscapeLeft + UIInterfaceOrientationLandscapeRight + + UISupportedInterfaceOrientations~ipad + + UIInterfaceOrientationPortrait + UIInterfaceOrientationPortraitUpsideDown + UIInterfaceOrientationLandscapeLeft + UIInterfaceOrientationLandscapeRight + + + diff --git a/ADAL/ADALAutomation/main.m b/ADAL/ADALAutomation/main.m new file mode 100644 index 000000000..241ef6041 --- /dev/null +++ b/ADAL/ADALAutomation/main.m @@ -0,0 +1,27 @@ +// Copyright © Microsoft Open Technologies, Inc. +// +// All Rights Reserved +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// THIS CODE IS PROVIDED *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS +// OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION +// ANY IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A +// PARTICULAR PURPOSE, MERCHANTABILITY OR NON-INFRINGEMENT. +// +// See the Apache License, Version 2.0 for the specific language +// governing permissions and limitations under the License. + + +#import +#import "ADAutoAppDelegate.h" + +int main(int argc, char * argv[]) { + @autoreleasepool { + return UIApplicationMain(argc, argv, nil, NSStringFromClass([ADAutoAppDelegate class])); + } +} From 33f8dd52831079929e942d233d2720f2dbe3bdac Mon Sep 17 00:00:00 2001 From: Yong Zeng Date: Thu, 3 Nov 2016 15:34:19 -0700 Subject: [PATCH 44/92] error out when extraQueryParameters are not in good form --- .../ADAuthenticationRequest+WebRequest.h | 3 +- .../ADAuthenticationRequest+WebRequest.m | 48 ++++++++++++++----- ADAL/tests/ADAcquireTokenTests.m | 23 +++++++++ 3 files changed, 61 insertions(+), 13 deletions(-) diff --git a/ADAL/src/request/ADAuthenticationRequest+WebRequest.h b/ADAL/src/request/ADAuthenticationRequest+WebRequest.h index 335dfd9f1..6a2ce7db8 100644 --- a/ADAL/src/request/ADAuthenticationRequest+WebRequest.h +++ b/ADAL/src/request/ADAuthenticationRequest+WebRequest.h @@ -29,6 +29,7 @@ //Requests an OAuth2 code to be used for obtaining a token: - (void)requestCode:(ADAuthorizationCodeCallback)completionBlock; -- (NSString*)generateQueryStringForRequestType:(NSString*)requestType; +- (NSURL*)generateQueryUrlForRequestType:(NSString*)requestType + error:(ADAuthenticationError * __autoreleasing *)error; @end diff --git a/ADAL/src/request/ADAuthenticationRequest+WebRequest.m b/ADAL/src/request/ADAuthenticationRequest+WebRequest.m index e31f9382e..b4ba8f5c3 100755 --- a/ADAL/src/request/ADAuthenticationRequest+WebRequest.m +++ b/ADAL/src/request/ADAuthenticationRequest+WebRequest.m @@ -89,13 +89,14 @@ - (NSString *)encodeProtocolState adURLFormEncode] adBase64UrlEncode]; } -//Generates the query string, encoding the state: -- (NSString*)generateQueryStringForRequestType:(NSString*)requestType +//Generates the query url, encoding the state: +- (NSURL*)generateQueryUrlForRequestType:(NSString*)requestType + error:(ADAuthenticationError * __autoreleasing *)error { NSString* state = [self encodeProtocolState]; NSString* queryParams = nil; // Start the web navigation process for the Implicit grant profile. - NSMutableString* startUrl = [NSMutableString stringWithFormat:@"%@?%@=%@&%@=%@&%@=%@&%@=%@&%@=%@", + NSMutableString* startUrlStr = [NSMutableString stringWithFormat:@"%@?%@=%@&%@=%@&%@=%@&%@=%@&%@=%@", [_context.authority stringByAppendingString:OAUTH2_AUTHORIZE_SUFFIX], OAUTH2_RESPONSE_TYPE, requestType, OAUTH2_CLIENT_ID, [_clientId adUrlFormEncode], @@ -103,20 +104,31 @@ - (NSString*)generateQueryStringForRequestType:(NSString*)requestType OAUTH2_REDIRECT_URI, [_redirectUri adUrlFormEncode], OAUTH2_STATE, state]; - [startUrl appendFormat:@"&%@", [[ADLogger adalId] adURLFormEncode]]; + [startUrlStr appendFormat:@"&%@", [[ADLogger adalId] adURLFormEncode]]; if (_identifier && [_identifier isDisplayable] && ![NSString adIsStringNilOrBlank:_identifier.userId]) { - [startUrl appendFormat:@"&%@=%@", OAUTH2_LOGIN_HINT, [_identifier.userId adUrlFormEncode]]; + [startUrlStr appendFormat:@"&%@=%@", OAUTH2_LOGIN_HINT, [_identifier.userId adUrlFormEncode]]; } NSString* promptParam = [ADAuthenticationContext getPromptParameter:_promptBehavior]; if (promptParam) { //Force the server to ignore cookies, by specifying explicitly the prompt behavior: - [startUrl appendString:[NSString stringWithFormat:@"&prompt=%@", promptParam]]; + [startUrlStr appendString:[NSString stringWithFormat:@"&prompt=%@", promptParam]]; } - [startUrl appendString:@"&haschrome=1"]; //to hide back button in UI + [startUrlStr appendString:@"&haschrome=1"]; //to hide back button in UI + + NSURL* startUrl = [NSURL URLWithString:startUrlStr]; + if (!startUrl) + { + AD_LOG_ERROR_F(@"Failed to construct query URL before launching webview.", AD_ERROR_UNEXPECTED, _correlationId, @"URL String: %@", startUrlStr); + *error = [ADAuthenticationError errorFromAuthenticationError:AD_ERROR_UNEXPECTED + protocolCode:nil + errorDetails:@"Failed to construct query URL before launching webview." + correlationId:_correlationId]; + return startUrl; + } if (![NSString adIsStringNilOrBlank:_queryParams]) {//Append the additional query parameters if specified: @@ -125,21 +137,27 @@ - (NSString*)generateQueryStringForRequestType:(NSString*)requestType //Add the '&' for the additional params if not there already: if ([queryParams hasPrefix:@"&"]) { - [startUrl appendString:queryParams]; + [startUrlStr appendString:queryParams]; } else { - [startUrl appendFormat:@"&%@", queryParams]; + [startUrlStr appendFormat:@"&%@", queryParams]; } } + startUrl = [NSURL URLWithString:startUrlStr]; + if (!startUrl) + { + *error = [ADAuthenticationError errorFromArgument:_queryParams argumentName:@"extraQueryParameters" correlationId:_correlationId]; + } + return startUrl; } -- (void)launchWebView:(NSString*)startUrl +- (void)launchWebView:(NSURL*)startUrl completionBlock:(void (^)(ADAuthenticationError*, NSURL*))completionBlock { - [[ADWebAuthController sharedInstance] start:[NSURL URLWithString:startUrl] + [[ADWebAuthController sharedInstance] start:startUrl end:[NSURL URLWithString:_redirectUri] refreshCred:_refreshTokenCredential #if TARGET_OS_IPHONE @@ -159,7 +177,13 @@ - (void)requestCode:(ADAuthorizationCodeCallback)completionBlock AD_LOG_VERBOSE_F(@"Requesting authorization code.", _correlationId, @"Requesting authorization code for resource: %@", _resource); - NSString* startUrl = [self generateQueryStringForRequestType:OAUTH2_CODE]; + ADAuthenticationError* error = nil; + NSURL* startUrl = [self generateQueryUrlForRequestType:OAUTH2_CODE error:&error]; + if (error) + { + completionBlock(nil, error); + return; + } void(^requestCompletion)(ADAuthenticationError *error, NSURL *end) = ^void(ADAuthenticationError *error, NSURL *end) { diff --git a/ADAL/tests/ADAcquireTokenTests.m b/ADAL/tests/ADAcquireTokenTests.m index fddbd76a6..0cbd51f28 100644 --- a/ADAL/tests/ADAcquireTokenTests.m +++ b/ADAL/tests/ADAcquireTokenTests.m @@ -187,6 +187,29 @@ - (void)testInvalidBrokerRedirectURI TEST_WAIT; } +- (void)testBadExtraQueryParameters +{ + ADAuthenticationContext* context = [self getTestAuthenticationContext]; + + [context acquireTokenWithResource:TEST_RESOURCE + clientId:TEST_CLIENT_ID + redirectUri:TEST_REDIRECT_URL + userId:TEST_USER_ID + extraQueryParameters:@"login_hint=test1@馬克英家.com" + completionBlock:^(ADAuthenticationResult *result) + { + XCTAssertNotNil(result); + XCTAssertEqual(result.status, AD_FAILED); + XCTAssertNotNil(result.error); + XCTAssertEqual(result.error.code, AD_ERROR_DEVELOPER_INVALID_ARGUMENT); + ADTAssertContains(result.error.errorDetails, @"extraQueryParameters"); + + TEST_SIGNAL; + }]; + + TEST_WAIT; +} + - (void)testAssertionBadAssertion { ADAuthenticationContext* context = [self getTestAuthenticationContext]; From dec4d60cff1b26c0773788dbcb03e1eae75fe7bf Mon Sep 17 00:00:00 2001 From: Yong Zeng Date: Thu, 3 Nov 2016 18:09:24 -0700 Subject: [PATCH 45/92] error out earlier if bad extraQueryParameters --- .../ADAuthenticationRequest+AcquireToken.m | 28 +++++++++++ .../ADAuthenticationRequest+WebRequest.h | 3 +- .../ADAuthenticationRequest+WebRequest.m | 48 +++++-------------- 3 files changed, 41 insertions(+), 38 deletions(-) diff --git a/ADAL/src/request/ADAuthenticationRequest+AcquireToken.m b/ADAL/src/request/ADAuthenticationRequest+AcquireToken.m index 7eb71066d..7c7172ab3 100644 --- a/ADAL/src/request/ADAuthenticationRequest+AcquireToken.m +++ b/ADAL/src/request/ADAuthenticationRequest+AcquireToken.m @@ -77,6 +77,17 @@ - (void)acquireToken:(ADAuthenticationCallback)completionBlock return; } + if (![self checkExtraQueryParameters]) + { + ADAuthenticationError* error = + [ADAuthenticationError errorFromAuthenticationError:AD_ERROR_DEVELOPER_INVALID_ARGUMENT + protocolCode:nil + errorDetails:@"extraQueryParameters is not properly encoded. Please make sure it is URL encoded." + correlationId:_correlationId]; + wrappedCallback([ADAuthenticationResult resultFromError:error correlationId:_correlationId]); + return; + } + if (!_silent && _context.credentialsType == AD_CREDENTIALS_AUTO && ![ADAuthenticationRequest validBrokerRedirectUri:_redirectUri]) { ADAuthenticationError* error = @@ -111,6 +122,23 @@ - (void)acquireToken:(ADAuthenticationCallback)completionBlock } +- (BOOL)checkExtraQueryParameters +{ + if ([NSString adIsStringNilOrBlank:_queryParams]) + { + return YES; + } + + NSString* queryParams = _queryParams.adTrimmedString; + if ([queryParams hasPrefix:@"&"]) + { + queryParams = [queryParams substringFromIndex:1]; + } + NSURL* url = [NSURL URLWithString:[NSMutableString stringWithFormat:@"%@?%@", _context.authority, queryParams]]; + + return url!=nil; +} + - (void)validatedAcquireToken:(ADAuthenticationCallback)completionBlock { [self ensureRequest]; diff --git a/ADAL/src/request/ADAuthenticationRequest+WebRequest.h b/ADAL/src/request/ADAuthenticationRequest+WebRequest.h index 6a2ce7db8..335dfd9f1 100644 --- a/ADAL/src/request/ADAuthenticationRequest+WebRequest.h +++ b/ADAL/src/request/ADAuthenticationRequest+WebRequest.h @@ -29,7 +29,6 @@ //Requests an OAuth2 code to be used for obtaining a token: - (void)requestCode:(ADAuthorizationCodeCallback)completionBlock; -- (NSURL*)generateQueryUrlForRequestType:(NSString*)requestType - error:(ADAuthenticationError * __autoreleasing *)error; +- (NSString*)generateQueryStringForRequestType:(NSString*)requestType; @end diff --git a/ADAL/src/request/ADAuthenticationRequest+WebRequest.m b/ADAL/src/request/ADAuthenticationRequest+WebRequest.m index b4ba8f5c3..e31f9382e 100755 --- a/ADAL/src/request/ADAuthenticationRequest+WebRequest.m +++ b/ADAL/src/request/ADAuthenticationRequest+WebRequest.m @@ -89,14 +89,13 @@ - (NSString *)encodeProtocolState adURLFormEncode] adBase64UrlEncode]; } -//Generates the query url, encoding the state: -- (NSURL*)generateQueryUrlForRequestType:(NSString*)requestType - error:(ADAuthenticationError * __autoreleasing *)error +//Generates the query string, encoding the state: +- (NSString*)generateQueryStringForRequestType:(NSString*)requestType { NSString* state = [self encodeProtocolState]; NSString* queryParams = nil; // Start the web navigation process for the Implicit grant profile. - NSMutableString* startUrlStr = [NSMutableString stringWithFormat:@"%@?%@=%@&%@=%@&%@=%@&%@=%@&%@=%@", + NSMutableString* startUrl = [NSMutableString stringWithFormat:@"%@?%@=%@&%@=%@&%@=%@&%@=%@&%@=%@", [_context.authority stringByAppendingString:OAUTH2_AUTHORIZE_SUFFIX], OAUTH2_RESPONSE_TYPE, requestType, OAUTH2_CLIENT_ID, [_clientId adUrlFormEncode], @@ -104,31 +103,20 @@ - (NSURL*)generateQueryUrlForRequestType:(NSString*)requestType OAUTH2_REDIRECT_URI, [_redirectUri adUrlFormEncode], OAUTH2_STATE, state]; - [startUrlStr appendFormat:@"&%@", [[ADLogger adalId] adURLFormEncode]]; + [startUrl appendFormat:@"&%@", [[ADLogger adalId] adURLFormEncode]]; if (_identifier && [_identifier isDisplayable] && ![NSString adIsStringNilOrBlank:_identifier.userId]) { - [startUrlStr appendFormat:@"&%@=%@", OAUTH2_LOGIN_HINT, [_identifier.userId adUrlFormEncode]]; + [startUrl appendFormat:@"&%@=%@", OAUTH2_LOGIN_HINT, [_identifier.userId adUrlFormEncode]]; } NSString* promptParam = [ADAuthenticationContext getPromptParameter:_promptBehavior]; if (promptParam) { //Force the server to ignore cookies, by specifying explicitly the prompt behavior: - [startUrlStr appendString:[NSString stringWithFormat:@"&prompt=%@", promptParam]]; + [startUrl appendString:[NSString stringWithFormat:@"&prompt=%@", promptParam]]; } - [startUrlStr appendString:@"&haschrome=1"]; //to hide back button in UI - - NSURL* startUrl = [NSURL URLWithString:startUrlStr]; - if (!startUrl) - { - AD_LOG_ERROR_F(@"Failed to construct query URL before launching webview.", AD_ERROR_UNEXPECTED, _correlationId, @"URL String: %@", startUrlStr); - *error = [ADAuthenticationError errorFromAuthenticationError:AD_ERROR_UNEXPECTED - protocolCode:nil - errorDetails:@"Failed to construct query URL before launching webview." - correlationId:_correlationId]; - return startUrl; - } + [startUrl appendString:@"&haschrome=1"]; //to hide back button in UI if (![NSString adIsStringNilOrBlank:_queryParams]) {//Append the additional query parameters if specified: @@ -137,27 +125,21 @@ - (NSURL*)generateQueryUrlForRequestType:(NSString*)requestType //Add the '&' for the additional params if not there already: if ([queryParams hasPrefix:@"&"]) { - [startUrlStr appendString:queryParams]; + [startUrl appendString:queryParams]; } else { - [startUrlStr appendFormat:@"&%@", queryParams]; + [startUrl appendFormat:@"&%@", queryParams]; } } - startUrl = [NSURL URLWithString:startUrlStr]; - if (!startUrl) - { - *error = [ADAuthenticationError errorFromArgument:_queryParams argumentName:@"extraQueryParameters" correlationId:_correlationId]; - } - return startUrl; } -- (void)launchWebView:(NSURL*)startUrl +- (void)launchWebView:(NSString*)startUrl completionBlock:(void (^)(ADAuthenticationError*, NSURL*))completionBlock { - [[ADWebAuthController sharedInstance] start:startUrl + [[ADWebAuthController sharedInstance] start:[NSURL URLWithString:startUrl] end:[NSURL URLWithString:_redirectUri] refreshCred:_refreshTokenCredential #if TARGET_OS_IPHONE @@ -177,13 +159,7 @@ - (void)requestCode:(ADAuthorizationCodeCallback)completionBlock AD_LOG_VERBOSE_F(@"Requesting authorization code.", _correlationId, @"Requesting authorization code for resource: %@", _resource); - ADAuthenticationError* error = nil; - NSURL* startUrl = [self generateQueryUrlForRequestType:OAUTH2_CODE error:&error]; - if (error) - { - completionBlock(nil, error); - return; - } + NSString* startUrl = [self generateQueryStringForRequestType:OAUTH2_CODE]; void(^requestCompletion)(ADAuthenticationError *error, NSURL *end) = ^void(ADAuthenticationError *error, NSURL *end) { From 107bd0e6e8c5157ee71e1c4f7545e44734345f5a Mon Sep 17 00:00:00 2001 From: Ryan Pangrle Date: Fri, 4 Nov 2016 19:01:13 -0700 Subject: [PATCH 46/92] "Get the App" crash fix Rename -callBroker into -composeBrokerRequest so it can be better focused on a single scenario, and then call invokeBroker or promptBrokerInstall as appropriate. --- ADAL/src/ADAuthenticationError+Internal.h | 16 +++++ ADAL/src/broker/ADBrokerHelper.h | 5 +- ADAL/src/broker/ios/ADBrokerHelper.m | 35 +++++------ ADAL/src/public/ADErrorCodes.h | 3 + .../ADAuthenticationRequest+AcquireToken.m | 23 +++++++- .../request/ADAuthenticationRequest+Broker.h | 2 +- .../request/ADAuthenticationRequest+Broker.m | 58 +++++++------------ 7 files changed, 82 insertions(+), 60 deletions(-) diff --git a/ADAL/src/ADAuthenticationError+Internal.h b/ADAL/src/ADAuthenticationError+Internal.h index 49ecf25c9..fefbec4a5 100644 --- a/ADAL/src/ADAuthenticationError+Internal.h +++ b/ADAL/src/ADAuthenticationError+Internal.h @@ -31,6 +31,22 @@ correlationId:_CORRELATION]; \ if (error) { *error = adError; } + + +#define AUTH_ERROR_RETURN_IF_NIL(_VAL, _CODE, _DETAILS, _CORRELATION) \ + if (_VAL == nil) { \ + AUTH_ERROR(_CODE, _DETAILS, _CORRELATION); \ + return nil; \ + } + +#define ARG_RETURN_IF_NIL(_ARG, _CORRELATION) \ + if (_ARG == nil) { \ + AUTH_ERROR(AD_ERROR_DEVELOPER_INVALID_ARGUMENT, @#_ARG " should not be nil.", _CORRELATION); \ + return nil; \ + } + + + #define AUTH_ERROR_UNDERLYING(_CODE, _DETAILS, _UNDERLYING, _CORRELATION) \ ADAuthenticationError* adError = \ [ADAuthenticationError errorFromAuthenticationError:_CODE \ diff --git a/ADAL/src/broker/ADBrokerHelper.h b/ADAL/src/broker/ADBrokerHelper.h index ee229125b..a17c6d346 100644 --- a/ADAL/src/broker/ADBrokerHelper.h +++ b/ADAL/src/broker/ADBrokerHelper.h @@ -26,9 +26,10 @@ @interface ADBrokerHelper : NSObject + (BOOL)canUseBroker; -+ (void)invokeBroker:(NSDictionary *)brokerParams ++ (void)invokeBroker:(NSURL *)brokerURL completionHandler:(ADAuthenticationCallback)completion; -+ (void)promptBrokerInstall:(NSDictionary *)brokerParams ++ (void)promptBrokerInstall:(NSURL *)redirectURL + brokerRequest:(NSURL *)brokerURL completionHandler:(ADAuthenticationCallback)completion; + (ADAuthenticationCallback)copyAndClearCompletionBlock; diff --git a/ADAL/src/broker/ios/ADBrokerHelper.m b/ADAL/src/broker/ios/ADBrokerHelper.m index ffc918bbe..77b8ebddd 100644 --- a/ADAL/src/broker/ios/ADBrokerHelper.m +++ b/ADAL/src/broker/ios/ADBrokerHelper.m @@ -176,26 +176,26 @@ + (BOOL)canUseBroker } } -+ (void)invokeBroker:(NSDictionary *)brokerParams ++ (void)invokeBroker:(NSURL *)brokerURL completionHandler:(ADAuthenticationCallback)completion { if ([ADAppExtensionUtil isExecutingInAppExtension]) { // Ignore invocation in application extension hosts - completion(nil); + ADAuthenticationError* error = [ADAuthenticationError errorFromAuthenticationError:AD_ERROR_TOKENBROKER_NOT_SUPPORTED_IN_EXTENSION + protocolCode:nil + errorDetails:@"Calling to broker is not supported in app extensions" + correlationId:nil]; + completion([ADAuthenticationResult resultFromError:error]); return; } - - NSString* query = [brokerParams adURLFormEncode]; - - NSURL* appUrl = [[NSURL alloc] initWithString:[NSString stringWithFormat:@"%@://broker?%@", ADAL_BROKER_SCHEME, query]]; [[ADBrokerNotificationManager sharedInstance] enableNotifications:completion]; dispatch_async(dispatch_get_main_queue(), ^{ [[NSNotificationCenter defaultCenter] postNotificationName:ADWebAuthWillSwitchToBrokerApp object:nil]; - [ADAppExtensionUtil sharedApplicationOpenURL:appUrl]; + [ADAppExtensionUtil sharedApplicationOpenURL:brokerURL]; }); } @@ -208,7 +208,8 @@ + (void)saveToPasteBoard:(NSURL*) url [appPasteBoard setURL:url]; } -+ (void)promptBrokerInstall:(NSDictionary *)brokerParams ++ (void)promptBrokerInstall:(NSURL *)redirectURL + brokerRequest:(NSURL *)brokerRequest completionHandler:(ADAuthenticationCallback)completion { if ([ADAppExtensionUtil isExecutingInAppExtension]) @@ -217,20 +218,16 @@ + (void)promptBrokerInstall:(NSDictionary *)brokerParams completion(nil); return; } - - NSString* query = [brokerParams adURLFormEncode]; - - NSURL* appUrl = [[NSURL alloc] initWithString:[NSString stringWithFormat:@"%@://broker?%@", ADAL_BROKER_SCHEME, query]]; + NSString* query = [redirectURL query]; + NSDictionary* queryParams = [NSDictionary adURLFormDecode:query]; + NSString* appURLString = [queryParams objectForKey:@"app_link"]; + __block NSURL* appURL = [NSURL URLWithString:appURLString]; + [[ADBrokerNotificationManager sharedInstance] enableNotifications:completion]; - - //no broker installed. go to app store - NSString* qp = [appUrl query]; - NSDictionary* qpDict = [NSDictionary adURLFormDecode:qp]; - NSString* url = [qpDict valueForKey:@"app_link"]; - [self saveToPasteBoard:appUrl]; + [self saveToPasteBoard:brokerRequest]; dispatch_async(dispatch_get_main_queue(), ^{ - [ADAppExtensionUtil sharedApplicationOpenURL:[[NSURL alloc] initWithString:url]]; + [ADAppExtensionUtil sharedApplicationOpenURL:appURL]; }); } diff --git a/ADAL/src/public/ADErrorCodes.h b/ADAL/src/public/ADErrorCodes.h index 764696b85..12ea26079 100644 --- a/ADAL/src/public/ADErrorCodes.h +++ b/ADAL/src/public/ADErrorCodes.h @@ -174,6 +174,9 @@ typedef enum /*! The key hash was missing from the response */ AD_ERROR_TOKENBROKER_HASH_MISSING = 510, + /*! We can't call out to tokenbroker in an extension */ + AD_ERROR_TOKENBROKER_NOT_SUPPORTED_IN_EXTENSION = 511, + } ADErrorCode; /* HTTP status codes used by the library */ diff --git a/ADAL/src/request/ADAuthenticationRequest+AcquireToken.m b/ADAL/src/request/ADAuthenticationRequest+AcquireToken.m index 7eb71066d..0dd45e0c8 100644 --- a/ADAL/src/request/ADAuthenticationRequest+AcquireToken.m +++ b/ADAL/src/request/ADAuthenticationRequest+AcquireToken.m @@ -29,6 +29,7 @@ #import "ADUserIdentifier.h" #import "ADTokenCacheKey.h" #import "ADAcquireTokenSilentHandler.h" +#import "ADBrokerHelper.h" @implementation ADAuthenticationRequest (AcquireToken) @@ -210,7 +211,14 @@ - (void)requestTokenImpl:(ADAuthenticationCallback)completionBlock //call the broker. if ([self canUseBroker]) { - [self callBroker:completionBlock]; + ADAuthenticationError* error = nil; + NSURL* brokerURL = [self composeBrokerRequest:&error]; + if (!brokerURL) + { + completionBlock([ADAuthenticationResult resultFromError:error correlationId:_correlationId]); + return; + } + [ADBrokerHelper invokeBroker:brokerURL completionHandler:completionBlock]; return; } #endif @@ -237,7 +245,18 @@ - (void)requestTokenImpl:(ADAuthenticationCallback)completionBlock { if([code hasPrefix:@"msauth://"]) { - [self callBroker:completionBlock]; + ADAuthenticationError* error = nil; + NSURL* brokerRequestURL = [self composeBrokerRequest:&error]; + if (!brokerRequestURL) + { + completionBlock([ADAuthenticationResult resultFromError:error correlationId:_correlationId]); + return; + } + + [ADBrokerHelper promptBrokerInstall:[NSURL URLWithString:code] + brokerRequest:brokerRequestURL + completionHandler:completionBlock]; + return; } else { diff --git a/ADAL/src/request/ADAuthenticationRequest+Broker.h b/ADAL/src/request/ADAuthenticationRequest+Broker.h index 368dd920a..5ca5eb317 100644 --- a/ADAL/src/request/ADAuthenticationRequest+Broker.h +++ b/ADAL/src/request/ADAuthenticationRequest+Broker.h @@ -33,6 +33,6 @@ extern NSString* kAdalResumeDictionaryKey; - (BOOL)canUseBroker; -- (void)callBroker:(ADAuthenticationCallback)completionBlock; +- (NSURL *)composeBrokerRequest:(ADAuthenticationError* __autoreleasing *)error; @end diff --git a/ADAL/src/request/ADAuthenticationRequest+Broker.m b/ADAL/src/request/ADAuthenticationRequest+Broker.m index 8f23722d9..e279a9e2e 100644 --- a/ADAL/src/request/ADAuthenticationRequest+Broker.m +++ b/ADAL/src/request/ADAuthenticationRequest+Broker.m @@ -36,6 +36,8 @@ #import "ADWebAuthController+Internal.h" #import "ADAuthenticationResult.h" +#import "ADOAuth2Constants.h" + #if TARGET_OS_IPHONE #import "ADKeychainTokenCache+Internal.h" #import "ADBrokerKeyHelper.h" @@ -247,42 +249,29 @@ - (BOOL)canUseBroker return _context.credentialsType == AD_CREDENTIALS_AUTO && _context.validateAuthority == YES && [ADBrokerHelper canUseBroker]; } -- (void)callBroker:(ADAuthenticationCallback)completionBlock +- (NSURL *)composeBrokerRequest:(ADAuthenticationError* __autoreleasing *)error { - CHECK_FOR_NIL(_context.authority); - CHECK_FOR_NIL(_resource); - CHECK_FOR_NIL(_clientId); - CHECK_FOR_NIL(_correlationId); + ARG_RETURN_IF_NIL(_context.authority, _correlationId); + ARG_RETURN_IF_NIL(_resource, _correlationId); + ARG_RETURN_IF_NIL(_clientId, _correlationId); + ARG_RETURN_IF_NIL(_correlationId, _correlationId); - ADAuthenticationError* error = nil; - if(![ADAuthenticationRequest validBrokerRedirectUri:_redirectUri]) - { - error = [ADAuthenticationError errorFromAuthenticationError:AD_ERROR_TOKENBROKER_INVALID_REDIRECT_URI - protocolCode:nil - errorDetails:ADRedirectUriInvalidError - correlationId:_correlationId]; - completionBlock([ADAuthenticationResult resultFromError:error correlationId:_correlationId]); - return; - } + AUTH_ERROR(AD_ERROR_TOKENBROKER_INVALID_REDIRECT_URI, ADRedirectUriInvalidError, _correlationId); AD_LOG_INFO(@"Invoking broker for authentication", _correlationId, nil); #if TARGET_OS_IPHONE // Broker Message Encryption ADBrokerKeyHelper* brokerHelper = [[ADBrokerKeyHelper alloc] init]; - NSData* key = [brokerHelper getBrokerKey:&error]; - if (!key) - { - ADAuthenticationError* adError = [ADAuthenticationError unexpectedInternalError:@"Unable to retrieve broker key." correlationId:_correlationId]; - completionBlock([ADAuthenticationResult resultFromError:adError correlationId:_correlationId]); - return; - } + NSData* key = [brokerHelper getBrokerKey:error]; + AUTH_ERROR_RETURN_IF_NIL(key, AD_ERROR_UNEXPECTED, @"Unable to retrieve broker key.", _correlationId); NSString* base64Key = [NSString Base64EncodeData:key]; + AUTH_ERROR_RETURN_IF_NIL(base64Key, AD_ERROR_UNEXPECTED, @"Unable to base64 encode broker key.", _correlationId); NSString* base64UrlKey = [base64Key adUrlFormEncode]; - CHECK_FOR_NIL(base64UrlKey); + AUTH_ERROR_RETURN_IF_NIL(base64UrlKey, AD_ERROR_UNEXPECTED, @"Unable to URL encode broker key.", _correlationId); #endif // TARGET_OS_IPHONE Broker Message Encryption NSString* adalVersion = [ADLogger getAdalVersion]; - CHECK_FOR_NIL(adalVersion); + AUTH_ERROR_RETURN_IF_NIL(adalVersion, AD_ERROR_UNEXPECTED, @"Unable to retrieve ADAL version.", _correlationId); NSDictionary* queryDictionary = @{ @@ -308,11 +297,10 @@ - (void)callBroker:(ADAuthenticationCallback)completionBlock if (dataSource && [dataSource isKindOfClass:[ADKeychainTokenCache class]]) { NSString* keychainGroup = [(ADKeychainTokenCache*)dataSource sharedGroup]; - NSString* teamId = [ADKeychainUtil keychainTeamId:&error]; - if (!teamId && error) + NSString* teamId = [ADKeychainUtil keychainTeamId:error]; + if (!teamId) { - completionBlock([ADAuthenticationResult resultFromError:error]); - return; + return nil; } if (teamId && [keychainGroup hasPrefix:teamId]) { @@ -344,14 +332,12 @@ - (void)callBroker:(ADAuthenticationCallback)completionBlock [[NSUserDefaults standardUserDefaults] setObject:resumeDictionary forKey:kAdalResumeDictionaryKey]; [[NSUserDefaults standardUserDefaults] synchronize]; - if ([ADBrokerHelper canUseBroker]) - { - [ADBrokerHelper invokeBroker:queryDictionary completionHandler:completionBlock]; - } - else - { - [ADBrokerHelper promptBrokerInstall:queryDictionary completionHandler:completionBlock]; - } + NSString* query = [queryDictionary adURLFormEncode]; + + NSURL* brokerRequestURL = [[NSURL alloc] initWithString:[NSString stringWithFormat:@"%@://broker?%@", ADAL_BROKER_SCHEME, query]]; + AUTH_ERROR_RETURN_IF_NIL(brokerRequestURL, AD_ERROR_UNEXPECTED, @"Unable to encode broker request URL", _correlationId); + + return brokerRequestURL; } @end From 1cc8d41ec7e5f0bd20de76434425fda73ef08a05 Mon Sep 17 00:00:00 2001 From: Ryan Pangrle Date: Mon, 7 Nov 2016 12:24:01 -0800 Subject: [PATCH 47/92] ifdef out broker specific methods fon Mac --- ADAL/src/broker/ADBrokerHelper.h | 3 +++ ADAL/src/broker/mac/ADBrokerHelper.m | 24 ------------------- .../ADAuthenticationRequest+AcquireToken.m | 4 +++- 3 files changed, 6 insertions(+), 25 deletions(-) diff --git a/ADAL/src/broker/ADBrokerHelper.h b/ADAL/src/broker/ADBrokerHelper.h index a17c6d346..ece2c7835 100644 --- a/ADAL/src/broker/ADBrokerHelper.h +++ b/ADAL/src/broker/ADBrokerHelper.h @@ -26,6 +26,8 @@ @interface ADBrokerHelper : NSObject + (BOOL)canUseBroker; + +#if TARGET_OS_IPHONE + (void)invokeBroker:(NSURL *)brokerURL completionHandler:(ADAuthenticationCallback)completion; + (void)promptBrokerInstall:(NSURL *)redirectURL @@ -33,5 +35,6 @@ completionHandler:(ADAuthenticationCallback)completion; + (ADAuthenticationCallback)copyAndClearCompletionBlock; +#endif @end diff --git a/ADAL/src/broker/mac/ADBrokerHelper.m b/ADAL/src/broker/mac/ADBrokerHelper.m index dc7cacdfb..8c1d34bed 100644 --- a/ADAL/src/broker/mac/ADBrokerHelper.m +++ b/ADAL/src/broker/mac/ADBrokerHelper.m @@ -34,28 +34,4 @@ + (BOOL)canUseBroker return NO; } -+ (void)invokeBroker:(NSDictionary *)brokerParams - completionHandler:(ADAuthenticationCallback)completion -{ - (void)brokerParams; - (void)completion; - - AD_LOG_ERROR(@"invokeBroker is called on Mac! This code should be unreachable.", AD_ERROR_TOKENBROKER_UNKNOWN, nil, nil); -} - -+ (void)promptBrokerInstall:(NSDictionary *)brokerParams - completionHandler:(ADAuthenticationCallback)completion -{ - (void)brokerParams; - (void)completion; - - AD_LOG_ERROR(@"promptBrokerInstall is called on Mac! This code should be unreachable.", AD_ERROR_TOKENBROKER_UNKNOWN, nil, nil); -} - -+ (ADAuthenticationCallback)copyAndClearCompletionBlock -{ - AD_LOG_ERROR(@"copyAndClearCompletionBlock is called on Mac! This code should be unreachable.", AD_ERROR_TOKENBROKER_UNKNOWN, nil, nil); - return nil; -} - @end diff --git a/ADAL/src/request/ADAuthenticationRequest+AcquireToken.m b/ADAL/src/request/ADAuthenticationRequest+AcquireToken.m index 0dd45e0c8..1cbac55a4 100644 --- a/ADAL/src/request/ADAuthenticationRequest+AcquireToken.m +++ b/ADAL/src/request/ADAuthenticationRequest+AcquireToken.m @@ -207,7 +207,7 @@ - (void)requestToken:(ADAuthenticationCallback)completionBlock - (void)requestTokenImpl:(ADAuthenticationCallback)completionBlock { -#if !AD_BROKER +#if !AD_BROKER && TARGET_OS_IPHONE //call the broker. if ([self canUseBroker]) { @@ -243,6 +243,7 @@ - (void)requestTokenImpl:(ADAuthenticationCallback)completionBlock } else { +#if TARGET_OS_IPHONE if([code hasPrefix:@"msauth://"]) { ADAuthenticationError* error = nil; @@ -259,6 +260,7 @@ - (void)requestTokenImpl:(ADAuthenticationCallback)completionBlock return; } else +#endif { [self requestTokenByCode:code completionBlock:^(ADAuthenticationResult *result) From 228fd78467ddf1289d197af99b4598b223f7a799 Mon Sep 17 00:00:00 2001 From: Ryan Pangrle Date: Tue, 8 Nov 2016 15:05:24 -0800 Subject: [PATCH 48/92] Remove telemetry ifdefs, fix some code rot, deduplicate some code --- ADAL/src/ADAuthenticationContext.m | 222 ++---------------- ADAL/src/cache/ADTokenCacheAccessor.m | 59 +---- .../src/request/ADAcquireTokenSilentHandler.m | 7 +- .../ADAuthenticationRequest+AcquireToken.h | 4 +- .../ADAuthenticationRequest+AcquireToken.m | 66 +++--- .../ADAuthenticationRequest+WebRequest.m | 7 +- ADAL/src/request/ADAuthenticationRequest.h | 2 +- ADAL/src/request/ADWebRequest.m | 5 +- ADAL/src/telemetry/ADTelemetryBrokerEvent.m | 8 +- ADAL/src/telemetry/ADTelemetryDefaultEvent.h | 5 +- ADAL/src/telemetry/ADTelemetryDefaultEvent.m | 8 +- 11 files changed, 90 insertions(+), 303 deletions(-) diff --git a/ADAL/src/ADAuthenticationContext.m b/ADAL/src/ADAuthenticationContext.m index f284b51e6..eb7cf6754 100755 --- a/ADAL/src/ADAuthenticationContext.m +++ b/ADAL/src/ADAuthenticationContext.m @@ -284,29 +284,9 @@ - (void)acquireTokenForAssertion:(NSString*)assertion [request setSamlAssertion:assertion]; [request setAssertionType:assertionType]; -#if AD_TELEMETRY - //prepare telemetry for the acquire token call - [[ADTelemetry sharedInstance] startEvent:[request telemetryRequestId] - eventName:@"acquireTokenWithAssertion:assertionType:resource:clientId:userId:completionBlock:"]; -#endif - ADAuthenticationCallback requestCompletion = ^void(ADAuthenticationResult *result) - { -#if AD_TELEMETRY - ADTelemetryAPIEvent* event = [[ADTelemetryAPIEvent alloc] initWithName:@"acquireTokenWithAssertion:assertionType:resource:clientId:userId:completionBlock:" - requestId:[request telemetryRequestId] - correlationId:[request correlationId]]; - [event setApiId:@"6"]; - [self fillTelemetryForAcquireTokenCall:event request:request result:result]; - [[ADTelemetry sharedInstance] stopEvent:[request telemetryRequestId] event:event]; - SAFE_ARC_RELEASE(event); - //flush all events in the end of the acquireToken call - [[ADTelemetry sharedInstance] flush:[request telemetryRequestId]]; -#endif - - completionBlock(result); - }; - - [request acquireToken:requestCompletion]; + [request acquireToken:[NSString stringWithUTF8String:__FUNCTION__] + apiId:@"6" + completionBlock:completionBlock]; } @@ -319,29 +299,9 @@ - (void)acquireTokenWithResource:(NSString*)resource API_ENTRY; REQUEST_WITH_REDIRECT_URL(redirectUri, clientId, resource); -#if AD_TELEMETRY - //prepare telemetry for the acquire token call - [[ADTelemetry sharedInstance] startEvent:[request telemetryRequestId] - eventName:@"acquireTokenWithResource:clientId:redirectUri:completionBlock:"]; -#endif - ADAuthenticationCallback requestCompletion = ^void(ADAuthenticationResult *result) - { -#if AD_TELEMETRY - ADTelemetryAPIEvent* event = [[ADTelemetryAPIEvent alloc] initWithName:@"acquireTokenWithResource:clientId:redirectUri:completionBlock:" - requestId:[request telemetryRequestId] - correlationId:[request correlationId]]; - [event setApiId:@"118"]; - [self fillTelemetryForAcquireTokenCall:event request:request result:result]; - [[ADTelemetry sharedInstance] stopEvent:[request telemetryRequestId] event:event]; - SAFE_ARC_RELEASE(event); - //flush all events in the end of the acquireToken call - [[ADTelemetry sharedInstance] flush:[request telemetryRequestId]]; -#endif - - completionBlock(result); - }; - - [request acquireToken:requestCompletion]; + [request acquireToken:[NSString stringWithUTF8String:__FUNCTION__] + apiId:@"118" + completionBlock:completionBlock]; } - (void)acquireTokenWithResource:(NSString*)resource @@ -355,32 +315,11 @@ - (void)acquireTokenWithResource:(NSString*)resource [request setUserId:userId]; -#if AD_TELEMETRY - //prepare telemetry for the acquire token call - [[ADTelemetry sharedInstance] startEvent:[request telemetryRequestId] - eventName:@"acquireTokenWithResource:clientId:redirectUri:userId:completionBlock:"]; -#endif - ADAuthenticationCallback requestCompletion = ^void(ADAuthenticationResult *result) - { -#if AD_TELEMETRY - ADTelemetryAPIEvent* event = [[ADTelemetryAPIEvent alloc] initWithName:@"acquireTokenWithResource:clientId:redirectUri:userId:completionBlock:" - requestId:[request telemetryRequestId] - correlationId:[request correlationId]]; - [event setApiId:@"121"]; - [self fillTelemetryForAcquireTokenCall:event request:request result:result]; - [[ADTelemetry sharedInstance] stopEvent:[request telemetryRequestId] event:event]; - SAFE_ARC_RELEASE(event); - //flush all events in the end of the acquireToken call - [[ADTelemetry sharedInstance] flush:[request telemetryRequestId]]; -#endif - - completionBlock(result); - }; - - [request acquireToken:requestCompletion]; + [request acquireToken:[NSString stringWithUTF8String:__FUNCTION__] + apiId:@"121" + completionBlock:completionBlock]; } - - (void)acquireTokenWithResource:(NSString*)resource clientId:(NSString*)clientId redirectUri:(NSURL*)redirectUri @@ -394,28 +333,9 @@ - (void)acquireTokenWithResource:(NSString*)resource [request setUserId:userId]; [request setExtraQueryParameters:queryParams]; -#if AD_TELEMETRY - //prepare telemetry for the acquire token call - [[ADTelemetry sharedInstance] startEvent:[request telemetryRequestId] - eventName:@"acquireTokenWithResource:clientId:redirectUri:userId:extraQueryParameters:completionBlock:"]; -#endif - ADAuthenticationCallback requestCompletion = ^void(ADAuthenticationResult *result) - { -#if AD_TELEMETRY - ADTelemetryAPIEvent* event = [[ADTelemetryAPIEvent alloc] initWithName:@"acquireTokenWithResource:clientId:redirectUri:userId:extraQueryParameters:completionBlock:" - requestId:[request telemetryRequestId] - correlationId:[request correlationId]]; - [event setApiId:@"124"]; - [self fillTelemetryForAcquireTokenCall:event request:request result:result]; - [[ADTelemetry sharedInstance] stopEvent:[request telemetryRequestId] event:event]; - SAFE_ARC_RELEASE(event); - //flush all events in the end of the acquireToken call - [[ADTelemetry sharedInstance] flush:[request telemetryRequestId]]; -#endif - completionBlock(result); - }; - - [request acquireToken:requestCompletion]; + [request acquireToken:[NSString stringWithUTF8String:__FUNCTION__] + apiId:@"124" + completionBlock:completionBlock]; } - (void)acquireTokenSilentWithResource:(NSString*)resource @@ -427,28 +347,9 @@ - (void)acquireTokenSilentWithResource:(NSString*)resource REQUEST_WITH_REDIRECT_URL(redirectUri, clientId, resource); [request setSilent:YES]; -#if AD_TELEMETRY - //prepare telemetry for the acquire token call - [[ADTelemetry sharedInstance] startEvent:[request telemetryRequestId] - eventName:@"acquireTokenSilentWithResource:clientId:redirectId:redirectUri:completionBlock:"]; -#endif - ADAuthenticationCallback requestCompletion = ^void(ADAuthenticationResult *result) - { -#if AD_TELEMETRY - ADTelemetryAPIEvent* event = [[ADTelemetryAPIEvent alloc] initWithName:@"acquireTokenSilentWithResource:clientId:redirectId:redirectUri:completionBlock:" - requestId:[request telemetryRequestId] - correlationId:[request correlationId]]; - [event setApiId:@"7"]; - [self fillTelemetryForAcquireTokenCall:event request:request result:result]; - [[ADTelemetry sharedInstance] stopEvent:[request telemetryRequestId] event:event]; - SAFE_ARC_RELEASE(event); - //flush all events in the end of the acquireToken call - [[ADTelemetry sharedInstance] flush:[request telemetryRequestId]]; -#endif - completionBlock(result); - }; - - [request acquireToken:requestCompletion]; + [request acquireToken:[NSString stringWithUTF8String:__FUNCTION__] + apiId:@"7" + completionBlock:completionBlock]; } - (void)acquireTokenSilentWithResource:(NSString*)resource @@ -462,29 +363,9 @@ - (void)acquireTokenSilentWithResource:(NSString*)resource [request setUserId:userId]; [request setSilent:YES]; - -#if AD_TELEMETRY - //prepare telemetry for the acquire token call - [[ADTelemetry sharedInstance] startEvent:[request telemetryRequestId] - eventName:@"acquireTokenSilentWithResource:clientId:redirectId:redirectUri:userId:completionBlock:"]; -#endif - ADAuthenticationCallback requestCompletion = ^void(ADAuthenticationResult *result) - { -#if AD_TELEMETRY - ADTelemetryAPIEvent* event = [[ADTelemetryAPIEvent alloc] initWithName:@"acquireTokenSilentWithResource:clientId:redirectId:redirectUri:userId:completionBlock:" - requestId:[request telemetryRequestId] - correlationId:[request correlationId]]; - [event setApiId:@"8"]; - [self fillTelemetryForAcquireTokenCall:event request:request result:result]; - [[ADTelemetry sharedInstance] stopEvent:[request telemetryRequestId] event:event]; - SAFE_ARC_RELEASE(event); - //flush all events in the end of the acquireToken call - [[ADTelemetry sharedInstance] flush:[request telemetryRequestId]]; -#endif - completionBlock(result); - }; - - [request acquireToken:requestCompletion]; + [request acquireToken:[NSString stringWithUTF8String:__FUNCTION__] + apiId:@"8" + completionBlock:completionBlock]; } - (void)acquireTokenWithResource:(NSString*)resource @@ -501,29 +382,9 @@ - (void)acquireTokenWithResource:(NSString*)resource [request setUserId:userId]; [request setPromptBehavior:promptBehavior]; [request setExtraQueryParameters:queryParams]; - -#if AD_TELEMETRY - //prepare telemetry for the acquire token call - [[ADTelemetry sharedInstance] startEvent:[request telemetryRequestId] - eventName:@"acquireTokenWithResource:clientId:redirectUri:promptBehavior:userId:extraQueryParameters:completionBlock:"]; -#endif - ADAuthenticationCallback requestCompletion = ^void(ADAuthenticationResult *result) - { -#if AD_TELEMETRY - ADTelemetryAPIEvent* event = [[ADTelemetryAPIEvent alloc] initWithName:@"acquireTokenWithResource:clientId:redirectUri:promptBehavior:userId:extraQueryParameters:completionBlock:" - requestId:[request telemetryRequestId] - correlationId:[request correlationId]]; - [event setApiId:@"127"]; - [self fillTelemetryForAcquireTokenCall:event request:request result:result]; - [[ADTelemetry sharedInstance] stopEvent:[request telemetryRequestId] event:event]; - SAFE_ARC_RELEASE(event); - //flush all events in the end of the acquireToken call - [[ADTelemetry sharedInstance] flush:[request telemetryRequestId]]; -#endif - completionBlock(result); - }; - - [request acquireToken:requestCompletion]; + [request acquireToken:[NSString stringWithUTF8String:__FUNCTION__] + apiId:@"127" + completionBlock:completionBlock]; } - (void)acquireTokenWithResource:(NSString*)resource @@ -540,44 +401,9 @@ - (void)acquireTokenWithResource:(NSString*)resource [request setPromptBehavior:promptBehavior]; [request setUserIdentifier:userId]; [request setExtraQueryParameters:queryParams]; - -#if AD_TELEMETRY - //prepare telemetry for the acquire token call - [[ADTelemetry sharedInstance] startEvent:[request telemetryRequestId] - eventName:@"acquireTokenWithResource:clientId:redirectUri:promptBehavior:userIdentifier:extraQueryParameters:completionBlock:"]; -#endif - ADAuthenticationCallback requestCompletion = ^void(ADAuthenticationResult *result) - { -#if AD_TELEMETRY - ADTelemetryAPIEvent* event = [[ADTelemetryAPIEvent alloc] initWithName:@"acquireTokenWithResource:clientId:redirectUri:promptBehavior:userIdentifier:extraQueryParameters:completionBlock:" - requestId:[request telemetryRequestId] - correlationId:[request correlationId]]; - [event setApiId:@"130"]; - [self fillTelemetryForAcquireTokenCall:event request:request result:result]; - [[ADTelemetry sharedInstance] stopEvent:[request telemetryRequestId] event:event]; - SAFE_ARC_RELEASE(event); - //flush all events in the end of the acquireToken call - [[ADTelemetry sharedInstance] flush:[request telemetryRequestId]]; -#endif - completionBlock(result); - }; - - [request acquireToken:requestCompletion]; -} - -- (void)fillTelemetryForAcquireTokenCall:(ADTelemetryAPIEvent*)event - request:(ADAuthenticationRequest*)request - result:(ADAuthenticationResult*)result -{ - [event setCorrelationId:[request.requestParams correlationId]]; - [event setUserId:[[request.requestParams identifier] userId]]; - [event setClientId:[request.requestParams clientId]]; - [event setResultStatus:[result status]]; - [event setIsExtendedLifeTimeToken:[result extendedLifeTimeToken]? @"YES":@"NO"]; - [event setErrorCode:[NSString stringWithFormat:@"%ld",(long)[result.error code]]]; - [event setErrorDomain:[result.error domain]]; - [event setProtocolCode:[[result error] protocolCode]]; - [event setErrorDescription:[[result error] errorDetails]]; + [request acquireToken:[NSString stringWithUTF8String:__FUNCTION__] + apiId:@"130" + completionBlock:completionBlock]; } @end diff --git a/ADAL/src/cache/ADTokenCacheAccessor.m b/ADAL/src/cache/ADTokenCacheAccessor.m index 1ce7f1494..8f39b41b3 100644 --- a/ADAL/src/cache/ADTokenCacheAccessor.m +++ b/ADAL/src/cache/ADTokenCacheAccessor.m @@ -97,20 +97,15 @@ - (ADTokenCacheItem *)getATRTItemForUser:(ADUserIdentifier *)identifier context:(id)context error:(ADAuthenticationError * __autoreleasing *)error { -#if AD_TELEMETERY [[ADTelemetry sharedInstance] startEvent:[context telemetryRequestId] eventName:@"token_cache_lookup"]; -#endif ADTokenCacheItem* item = [self getItemForUser:identifier resource:resource clientId:clientId context:context error:error]; -#if AD_TELEMETRY ADTelemetryCacheEvent* event = [[ADTelemetryCacheEvent alloc] initWithName:@"token_cache_lookup" - requestId:[context telemetryRequestId] - correlationId:[context correlationId]]; + context:context]; [event setTokenType:@"access token"]; [event setStatus:item? @"succeeded" : @"failed"]; [[ADTelemetry sharedInstance] stopEvent:[context telemetryRequestId] event:event]; SAFE_ARC_RELEASE(event); -#endif return item; } @@ -123,11 +118,8 @@ - (ADTokenCacheItem *)getMRRTItemForUser:(ADUserIdentifier *)identifier context:(id)context error:(ADAuthenticationError * __autoreleasing *)error { -#if AD_TELEMETRY [[ADTelemetry sharedInstance] startEvent:[context telemetryRequestId] eventName:@"token_cache_lookup"]; -#endif ADTokenCacheItem* item = [self getItemForUser:identifier resource:nil clientId:clientId context:context error:error]; -#if AD_TELEMETRY ADTelemetryCacheEvent* event = [[ADTelemetryCacheEvent alloc] initWithName:@"token_cache_lookup" requestId:[context telemetryRequestId] correlationId:[context correlationId]]; @@ -135,7 +127,6 @@ - (ADTokenCacheItem *)getMRRTItemForUser:(ADUserIdentifier *)identifier [event setStatus:item? @"succeeded" : @"failed"]; [[ADTelemetry sharedInstance] stopEvent:[context telemetryRequestId] event:event]; SAFE_ARC_RELEASE(event); -#endif return item; } @@ -148,22 +139,17 @@ - (ADTokenCacheItem *)getFRTItemForUser:(ADUserIdentifier *)identifier context:(id)context error:(ADAuthenticationError * __autoreleasing *)error { -#if AD_TELEMETRY [[ADTelemetry sharedInstance] startEvent:context.telemetryRequestId eventName:@"token_cache_lookup"]; -#endif NSString* fociClientId = [ADTokenCacheAccessor familyClientId:familyId]; ADTokenCacheItem* item = [self getItemForUser:identifier resource:nil clientId:fociClientId context:context error:error]; -#if AD_TELEMETRY ADTelemetryCacheEvent* event = [[ADTelemetryCacheEvent alloc] initWithName:@"token_cache_lookup" - requestId:context.telemetryRequestId - correlationId:context.correlationId]; + context:context]; [event setTokenType:@"family refresh token"]; [event setStatus:item? @"succeeded" : @"failed"]; [[ADTelemetry sharedInstance] stopEvent:[context telemetryRequestId] event:event]; SAFE_ARC_RELEASE(event); -#endif return item; } @@ -185,19 +171,14 @@ - (ADTokenCacheItem*)getADFSUserTokenForResource:(NSString *)resource return nil; } -#if AD_TELEMETRY [[ADTelemetry sharedInstance] startEvent:[context telemetryRequestId] eventName:@"token_cache_lookup"]; -#endif ADTokenCacheItem* item = [_dataSource getItemWithKey:key userId:@"" correlationId:[context correlationId] error:error]; -#if AD_TELEMETRY ADTelemetryCacheEvent* event = [[ADTelemetryCacheEvent alloc] initWithName:@"token_cache_lookup" - requestId:[context telemetryRequestId] - correlationId:[context correlationId]]; + context:context]; [event setTokenType:@"ADFS access token/refresh token"]; [event setStatus:item? @"succeeded" : @"failed"]; [[ADTelemetry sharedInstance] stopEvent:[context telemetryRequestId] event:event]; SAFE_ARC_RELEASE(event); -#endif return item; } @@ -256,17 +237,14 @@ - (void)updateCacheToItem:(ADTokenCacheItem *)cacheItem context:(id)context { NSUUID* correlationId = [context correlationId]; -#if AD_TELEMETRY NSString* telemetryRequestId = [context telemetryRequestId]; -#endif NSString* savedRefreshToken = cacheItem.refreshToken; if (isMRRT) { AD_LOG_VERBOSE_F(@"Token cache store", correlationId, @"Storing multi-resource refresh token for authority: %@", _authority); -#if AD_TELEMETRY [[ADTelemetry sharedInstance] startEvent:telemetryRequestId eventName:@"token_cache_write"]; -#endif + //If the server returned a multi-resource refresh token, we break //the item into two: one with the access token and no refresh token and //another one with the broad refresh token and no access token and no resource. @@ -278,53 +256,43 @@ - (void)updateCacheToItem:(ADTokenCacheItem *)cacheItem multiRefreshTokenItem.resource = nil; multiRefreshTokenItem.expiresOn = nil; [_dataSource addOrUpdateItem:multiRefreshTokenItem correlationId:correlationId error:nil]; -#if AD_TELEMETRY ADTelemetryCacheEvent* event = [[ADTelemetryCacheEvent alloc] initWithName:@"token_cache_write" - requestId:telemetryRequestId - correlationId:correlationId]; + context:context]; [event setTokenType:@"multi-resource refresh token"]; [[ADTelemetry sharedInstance] stopEvent:telemetryRequestId event:event]; SAFE_ARC_RELEASE(event); -#endif + // If the item is also a Family Refesh Token (FRT) we update the FRT // as well so we have a guaranteed spot to look for the most recent FRT. NSString* familyId = cacheItem.familyId; if (familyId) { -#if AD_TELEMETRY [[ADTelemetry sharedInstance] startEvent:telemetryRequestId eventName:@"token_cache_write"]; -#endif + ADTokenCacheItem* frtItem = [multiRefreshTokenItem copy]; NSString* fociClientId = [ADTokenCacheAccessor familyClientId:familyId]; frtItem.clientId = fociClientId; [_dataSource addOrUpdateItem:frtItem correlationId:correlationId error:nil]; SAFE_ARC_RELEASE(frtItem); -#if AD_TELEMETRY + ADTelemetryCacheEvent* event = [[ADTelemetryCacheEvent alloc] initWithName:@"token_cache_write" - requestId:telemetryRequestId - correlationId:correlationId]; + context:context]; [event setTokenType:@"family refresh token"]; [[ADTelemetry sharedInstance] stopEvent:telemetryRequestId event:event]; SAFE_ARC_RELEASE(event); -#endif } SAFE_ARC_RELEASE(multiRefreshTokenItem); } AD_LOG_VERBOSE_F(@"Token cache store", correlationId, @"Storing access token for resource: %@", cacheItem.resource); -#if AD_TELEMETRY [[ADTelemetry sharedInstance] startEvent:telemetryRequestId eventName:@"token_cache_write"]; -#endif [_dataSource addOrUpdateItem:cacheItem correlationId:correlationId error:nil]; cacheItem.refreshToken = savedRefreshToken;//Restore for the result -#if AD_TELEMETRY ADTelemetryCacheEvent* event = [[ADTelemetryCacheEvent alloc] initWithName:@"token_cache_write" - requestId:telemetryRequestId - correlationId:correlationId]; + context:context]; [event setTokenType:@"access token"]; [[ADTelemetry sharedInstance] stopEvent:telemetryRequestId event:event]; SAFE_ARC_RELEASE(event); -#endif } - (void)removeItemFromCache:(ADTokenCacheItem *)cacheItem @@ -338,9 +306,7 @@ - (void)removeItemFromCache:(ADTokenCacheItem *)cacheItem } NSUUID* correlationId = [context correlationId]; -#if AD_TELEMETRY [[ADTelemetry sharedInstance] startEvent:[context telemetryRequestId] eventName:@"token_cache_delete_token"]; -#endif BOOL removed = NO; //The refresh token didn't work. We need to tombstone this refresh item in the cache. ADTokenCacheKey* exactKey = [cacheItem extractKey:nil]; @@ -380,13 +346,10 @@ - (void)removeItemFromCache:(ADTokenCacheItem *)cacheItem } } } -#if AD_TELEMETRY ADTelemetryCacheEvent* event = [[ADTelemetryCacheEvent alloc] initWithName:@"token_cache_delete_token" - requestId:[context telemetryRequestId] - correlationId:correlationId]; + context:context]; [[ADTelemetry sharedInstance] stopEvent:[context telemetryRequestId] event:event]; SAFE_ARC_RELEASE(event); -#endif } @end diff --git a/ADAL/src/request/ADAcquireTokenSilentHandler.m b/ADAL/src/request/ADAcquireTokenSilentHandler.m index f9b62d6cb..1da1c1b6a 100644 --- a/ADAL/src/request/ADAcquireTokenSilentHandler.m +++ b/ADAL/src/request/ADAcquireTokenSilentHandler.m @@ -209,22 +209,17 @@ - (void)acquireTokenWithItem:(ADTokenCacheItem *)item completionBlock:(ADAuthenticationCallback)completionBlock fallback:(ADAuthenticationCallback)fallback { -#if AD_TELEMETRY [[ADTelemetry sharedInstance] startEvent:[_requestParams telemetryRequestId] eventName:@"token_grant"]; -#endif [self acquireTokenByRefreshToken:item.refreshToken cacheItem:item completionBlock:^(ADAuthenticationResult *result) { -#if AD_TELEMETRY ADTelemetryAPIEvent* event = [[ADTelemetryAPIEvent alloc] initWithName:@"token_grant" - requestId:[_requestParams telemetryRequestId] - correlationId:[_requestParams correlationId]]; + context:_requestParams]; [event setGrantType:@"by refresh token"]; [event setResultStatus:[result status]]; [[ADTelemetry sharedInstance] stopEvent:[_requestParams telemetryRequestId] event:event]; SAFE_ARC_RELEASE(event); -#endif NSString* resultStatus = @"Succeded"; diff --git a/ADAL/src/request/ADAuthenticationRequest+AcquireToken.h b/ADAL/src/request/ADAuthenticationRequest+AcquireToken.h index cb950da1b..07bc87c9b 100644 --- a/ADAL/src/request/ADAuthenticationRequest+AcquireToken.h +++ b/ADAL/src/request/ADAuthenticationRequest+AcquireToken.h @@ -25,7 +25,9 @@ @interface ADAuthenticationRequest (AcquireToken) -- (void)acquireToken:(ADAuthenticationCallback)completionBlock; +- (void)acquireToken:(NSString *)eventName + apiId:(NSString *)apiId + completionBlock:(ADAuthenticationCallback)completionBlock; // For use after the authority has been validated - (void)validatedAcquireToken:(ADAuthenticationCallback)completionBlock; diff --git a/ADAL/src/request/ADAuthenticationRequest+AcquireToken.m b/ADAL/src/request/ADAuthenticationRequest+AcquireToken.m index e1de8890c..343413886 100644 --- a/ADAL/src/request/ADAuthenticationRequest+AcquireToken.m +++ b/ADAL/src/request/ADAuthenticationRequest+AcquireToken.m @@ -39,14 +39,17 @@ @implementation ADAuthenticationRequest (AcquireToken) #pragma mark - #pragma mark AcquireToken -- (void)acquireToken:(ADAuthenticationCallback)completionBlock +- (void)acquireToken:(NSString *)eventName + apiId:(NSString *)apiId + completionBlock:(ADAuthenticationCallback)completionBlock { THROW_ON_NIL_ARGUMENT(completionBlock); + [[ADTelemetry sharedInstance] startEvent:self.telemetryRequestId + eventName:eventName]; + AD_REQUEST_CHECK_ARGUMENT([_requestParams resource]); [self ensureRequest]; -#if AD_TELEMETRY NSString* telemetryRequestId = [_requestParams telemetryRequestId]; -#endif __block NSString* log = [NSString stringWithFormat:@"##### BEGIN acquireToken%@ (authority = %@, resource = %@, clientId = %@, idtype = %@) #####", _silent ? @"Silent" : @"", _requestParams.authority, _requestParams.resource, _requestParams.clientId, [_requestParams.identifier typeAsString]]; @@ -69,6 +72,25 @@ - (void)acquireToken:(ADAuthenticationCallback)completionBlock AD_LOG_INFO(finalLog, result.correlationId, nil); + ADTelemetryAPIEvent* event = [[ADTelemetryAPIEvent alloc] initWithName:eventName + context:self]; + [event setApiId:apiId]; + + [event setCorrelationId:self.correlationId]; + [event setUserId:_requestParams.identifier.userId]; + [event setClientId:_requestParams.clientId]; + [event setResultStatus:result.status]; + [event setIsExtendedLifeTimeToken:[result extendedLifeTimeToken]? @"YES":@"NO"]; + [event setErrorCode:[NSString stringWithFormat:@"%ld",(long)[result.error code]]]; + [event setErrorDomain:[result.error domain]]; + [event setProtocolCode:[[result error] protocolCode]]; + [event setErrorDescription:[[result error] errorDetails]]; + + [[ADTelemetry sharedInstance] stopEvent:self.telemetryRequestId event:event]; + SAFE_ARC_RELEASE(event); + //flush all events in the end of the acquireToken call + [[ADTelemetry sharedInstance] flush:self.telemetryRequestId]; + completionBlock(result); }; @@ -111,23 +133,19 @@ - (void)acquireToken:(ADAuthenticationCallback)completionBlock [self validatedAcquireToken:wrappedCallback]; return; } -#if AD_TELEMETRY + [[ADTelemetry sharedInstance] startEvent:telemetryRequestId eventName:@"authority_validation"]; -#endif [[ADInstanceDiscovery sharedInstance] validateAuthority:_context.authority requestParams:_requestParams completionBlock:^(BOOL validated, ADAuthenticationError *error) { (void)validated; -#if AD_TELEMETRY ADTelemetryAPIEvent* event = [[ADTelemetryAPIEvent alloc] initWithName:@"authority_validation" - requestId:telemetryRequestId - correlationId:correlationId]; + context:_requestParams]; [event setAuthorityValidationStatus:validated ? @"YES" : @"NO"]; [event setAuthority:_context.authority]; [[ADTelemetry sharedInstance] stopEvent:telemetryRequestId event:event]; SAFE_ARC_RELEASE(event); -#endif if (error) { wrappedCallback([ADAuthenticationResult resultFromError:error correlationId:_requestParams.correlationId]); @@ -163,19 +181,14 @@ - (void)validatedAcquireToken:(ADAuthenticationCallback)completionBlock if (![ADAuthenticationContext isForcedAuthorization:_promptBehavior] && [_context hasCacheStore]) { -#if AD_TELEMETRY [[ADTelemetry sharedInstance] startEvent:[self telemetryRequestId] eventName:@"acquire_token_silent_handler"]; -#endif ADAcquireTokenSilentHandler* request = [ADAcquireTokenSilentHandler requestWithParams:_requestParams]; [request getToken:^(ADAuthenticationResult *result) { -#if AD_TELEMETRY ADTelemetryAPIEvent* event = [[ADTelemetryAPIEvent alloc] initWithName:@"acquire_token_silent_handler" - requestId:[self telemetryRequestId] - correlationId:[self correlationId]]; + context:_requestParams]; [[ADTelemetry sharedInstance] stopEvent:[self telemetryRequestId] event:event]; SAFE_ARC_RELEASE(event); -#endif if ([ADAuthenticationContext isFinalResult:result]) { completionBlock(result); @@ -198,9 +211,6 @@ - (void)requestToken:(ADAuthenticationCallback)completionBlock { [self ensureRequest]; NSUUID* correlationId = [_requestParams correlationId]; -#if AD_TELEMETRY - NSString* telemetryRequestId = [_requestParams telemetryRequestId]; -#endif if (_samlAssertion) { @@ -277,17 +287,14 @@ - (void)requestTokenImpl:(ADAuthenticationCallback)completionBlock __block BOOL silentRequest = _allowSilent; + NSString* telemetryRequestId = [_requestParams telemetryRequestId]; + // Get the code first: -#if AD_TELEMETRY [[ADTelemetry sharedInstance] startEvent:telemetryRequestId eventName:@"authorization_code"]; -#endif [self requestCode:^(NSString * code, ADAuthenticationError *error) { -#if AD_TELEMETRY ADTelemetryAPIEvent* event = [[ADTelemetryAPIEvent alloc] initWithName:@"authorization_code" - requestId:telemetryRequestId - correlationId:_requestParams.correlationId]; -#endif + context:_requestParams]; if (error) { @@ -300,10 +307,8 @@ - (void)requestTokenImpl:(ADAuthenticationCallback)completionBlock ADAuthenticationResult* result = (AD_ERROR_UI_USER_CANCEL == error.code) ? [ADAuthenticationResult resultFromCancellation:_requestParams.correlationId] : [ADAuthenticationResult resultFromError:error correlationId:_requestParams.correlationId]; -#if AD_TELEMETRY [event setAPIStatus:(AD_ERROR_UI_USER_CANCEL == error.code) ? @"canceled":@"failed"]; [[ADTelemetry sharedInstance] stopEvent:_requestParams.telemetryRequestId event:event]; -#endif completionBlock(result); } else @@ -327,24 +332,19 @@ - (void)requestTokenImpl:(ADAuthenticationCallback)completionBlock else #endif { -#if AD_TELEMETRY [event setAPIStatus:@"succeeded"]; [[ADTelemetry sharedInstance] stopEvent:_requestParams.telemetryRequestId event:event]; [[ADTelemetry sharedInstance] startEvent:_requestParams.telemetryRequestId eventName:@"token_grant"]; -#endif [self requestTokenByCode:code completionBlock:^(ADAuthenticationResult *result) { -#if AD_TELEMETRY ADTelemetryAPIEvent* event = [[ADTelemetryAPIEvent alloc] initWithName:@"token_grant" - requestId:_requestParams.telemetryRequestId - correlationId:_requestParams.correlationId]; + context:_requestParams]; [event setGrantType:@"by code"]; [event setResultStatus:[result status]]; [[ADTelemetry sharedInstance] stopEvent:_requestParams.telemetryRequestId event:event]; SAFE_ARC_RELEASE(event); -#endif if (AD_SUCCEEDED == result.status) { [[_requestParams tokenCache] updateCacheToResult:result @@ -357,9 +357,7 @@ - (void)requestTokenImpl:(ADAuthenticationCallback)completionBlock }]; } } -#if AD_TELEMETRY SAFE_ARC_RELEASE(event); -#endif }]; } diff --git a/ADAL/src/request/ADAuthenticationRequest+WebRequest.m b/ADAL/src/request/ADAuthenticationRequest+WebRequest.m index d8cec6b87..47627b92a 100755 --- a/ADAL/src/request/ADAuthenticationRequest+WebRequest.m +++ b/ADAL/src/request/ADAuthenticationRequest+WebRequest.m @@ -143,18 +143,13 @@ - (NSString*)generateQueryStringForRequestType:(NSString*)requestType - (void)launchWebView:(NSString*)startUrl completionBlock:(void (^)(ADAuthenticationError*, NSURL*))completionBlock { -#if AD_TELEMETRY [[ADTelemetry sharedInstance] startEvent:[self telemetryRequestId] eventName:@"launch_web_view"]; -#endif void(^requestCompletion)(ADAuthenticationError *error, NSURL *end) = ^void(ADAuthenticationError *error, NSURL *end) { -#if AD_TELEMETRY ADTelemetryUIEvent* event = [[ADTelemetryUIEvent alloc] initWithName:@"launch_web_view" - requestId:[self telemetryRequestId] - correlationId:[self correlationId]]; + context:_requestParams]; [self fillTelemetryUIEvent:event]; [[ADTelemetry sharedInstance] stopEvent:[self telemetryRequestId] event:event]; -#endif completionBlock(error, end); }; diff --git a/ADAL/src/request/ADAuthenticationRequest.h b/ADAL/src/request/ADAuthenticationRequest.h index 998981872..f9b9a2e23 100644 --- a/ADAL/src/request/ADAuthenticationRequest.h +++ b/ADAL/src/request/ADAuthenticationRequest.h @@ -45,7 +45,7 @@ } \ } -@interface ADAuthenticationRequest : NSObject +@interface ADAuthenticationRequest : NSObject { @protected ADAuthenticationContext* _context; diff --git a/ADAL/src/request/ADWebRequest.m b/ADAL/src/request/ADWebRequest.m index 46233297f..dc62a34c4 100644 --- a/ADAL/src/request/ADWebRequest.m +++ b/ADAL/src/request/ADWebRequest.m @@ -150,9 +150,8 @@ - (void)completeWithError:(NSError *)error andResponse:(ADWebResponse *)response SAFE_ARC_RELEASE(_connection); _connection = nil; -#if AD_TELEMETRY + [self stopTelemetryEvent:error response:response]; -#endif _completionHandler(error, response); } @@ -181,9 +180,7 @@ - (void)resend - (void)send { -#if AD_TELEMETRY [[ADTelemetry sharedInstance] startEvent:_telemetryRequestId eventName:@"http_request"]; -#endif [_requestHeaders addEntriesFromDictionary:[ADLogger adalId]]; //Correlation id: if (_correlationId) diff --git a/ADAL/src/telemetry/ADTelemetryBrokerEvent.m b/ADAL/src/telemetry/ADTelemetryBrokerEvent.m index 915740e03..f4c1a5aa4 100644 --- a/ADAL/src/telemetry/ADTelemetryBrokerEvent.m +++ b/ADAL/src/telemetry/ADTelemetryBrokerEvent.m @@ -25,9 +25,11 @@ @implementation ADTelemetryBrokerEvent --(id) init +- (id)initWithName:(NSString*)eventName + requestId:(NSString*)requestId + correlationId:(NSUUID*)correlationId { - self = [super init]; + self = [super initWithName:eventName requestId:requestId correlationId:correlationId]; if(self) { //this is the only broker for iOS @@ -73,4 +75,4 @@ - (void)setBrokerApp:(NSString*)appName [self setProperty:@"broker_app" value:appName]; } -@end \ No newline at end of file +@end diff --git a/ADAL/src/telemetry/ADTelemetryDefaultEvent.h b/ADAL/src/telemetry/ADTelemetryDefaultEvent.h index 1338fdfbc..be018aed4 100644 --- a/ADAL/src/telemetry/ADTelemetryDefaultEvent.h +++ b/ADAL/src/telemetry/ADTelemetryDefaultEvent.h @@ -33,4 +33,7 @@ requestId:(NSString*)requestId correlationId:(NSUUID*)correlationId; -@end \ No newline at end of file +- (id)initWithName:(NSString*)eventName + context:(id)requestParams; + +@end diff --git a/ADAL/src/telemetry/ADTelemetryDefaultEvent.m b/ADAL/src/telemetry/ADTelemetryDefaultEvent.m index 4a7c22b7f..f3da9410f 100644 --- a/ADAL/src/telemetry/ADTelemetryDefaultEvent.m +++ b/ADAL/src/telemetry/ADTelemetryDefaultEvent.m @@ -68,6 +68,12 @@ - (id)initWithName:(NSString*)eventName return self; } +- (id)initWithName:(NSString*)eventName + context:(id)requestParams +{ + return [self initWithName:eventName requestId:requestParams.telemetryRequestId correlationId:requestParams.correlationId]; +} + - (void)setProperty:(NSString*)name value:(NSString*)value { // value can be empty but not nil @@ -197,4 +203,4 @@ void CopySerialNumber(CFStringRef *serialNumber) } #endif -@end \ No newline at end of file +@end From fa3b70d544c657c8e5574499b62693a777e0e47e Mon Sep 17 00:00:00 2001 From: Ryan Pangrle Date: Tue, 8 Nov 2016 17:52:27 -0800 Subject: [PATCH 49/92] Make resiliency APIs public --- ADAL/src/ADAuthenticationContext+Internal.h | 4 ---- ADAL/src/ADAuthenticationContext+Internal.m | 12 ------------ ADAL/src/ADAuthenticationContext.m | 2 +- ADAL/src/ADAuthenticationResult+Internal.h | 5 ----- ADAL/src/ADAuthenticationResult+Internal.m | 6 ------ ADAL/src/ADAuthenticationResult.m | 2 +- ADAL/src/public/ADAuthenticationContext.h | 3 +++ ADAL/src/public/ADAuthenticationResult.h | 4 ++++ 8 files changed, 9 insertions(+), 29 deletions(-) diff --git a/ADAL/src/ADAuthenticationContext+Internal.h b/ADAL/src/ADAuthenticationContext+Internal.h index 0b07287f3..611c88b59 100644 --- a/ADAL/src/ADAuthenticationContext+Internal.h +++ b/ADAL/src/ADAuthenticationContext+Internal.h @@ -84,10 +84,6 @@ extern NSString* const ADRedirectUriInvalidError; - (BOOL)hasCacheStore; -// ADAL_RESILIENCY_NOT_YET: Move back to public header -/*! Enable to return access token with extended lifetime during server outage. */ -@property BOOL extendedLifetimeEnabled; - @end @interface ADAuthenticationContext (CacheStorage) diff --git a/ADAL/src/ADAuthenticationContext+Internal.m b/ADAL/src/ADAuthenticationContext+Internal.m index ba390262f..d3564080a 100644 --- a/ADAL/src/ADAuthenticationContext+Internal.m +++ b/ADAL/src/ADAuthenticationContext+Internal.m @@ -62,18 +62,6 @@ - (id)initWithAuthority:(NSString *)authority return self; } -// ADAL_RESILIENCY_NOT_YET: Remove when feature goes into public API -- (BOOL)extendedLifetimeEnabled -{ - return _extendedLifetimeEnabled; -} - -// ADAL_RESILIENCY_NOT_YET: Remove when feature goes into public API -- (void)setExtendedLifetimeEnabled:(BOOL)extendedLifetimeEnabled -{ - _extendedLifetimeEnabled = extendedLifetimeEnabled; -} - /*! Verifies that the string parameter is not nil or empty. If it is, the method generates an error and set it to an authentication result. Then the method calls the callback with the result. diff --git a/ADAL/src/ADAuthenticationContext.m b/ADAL/src/ADAuthenticationContext.m index eb7cf6754..903ad1a44 100755 --- a/ADAL/src/ADAuthenticationContext.m +++ b/ADAL/src/ADAuthenticationContext.m @@ -48,7 +48,7 @@ @implementation ADAuthenticationContext @synthesize validateAuthority = _validateAuthority; @synthesize correlationId = _correlationId; @synthesize credentialsType = _credentialsType; -//@synthesize extendedLifetimeEnabled = _extendedLifetimeEnabled; ADAL_RESILIENCY_NOT_YET +@synthesize extendedLifetimeEnabled = _extendedLifetimeEnabled; @synthesize logComponent = _logComponent; @synthesize webView = _webView; diff --git a/ADAL/src/ADAuthenticationResult+Internal.h b/ADAL/src/ADAuthenticationResult+Internal.h index 53fa9d970..15e324279 100644 --- a/ADAL/src/ADAuthenticationResult+Internal.h +++ b/ADAL/src/ADAuthenticationResult+Internal.h @@ -52,9 +52,4 @@ /*! Internal method to set the extendedLifetimeToken flag. */ - (void)setExtendedLifeTimeToken:(BOOL)extendedLifeTimeToken; -// ADAL_RESILIENCY_NOT_YET: Move back to public header -/*! Some access tokens have extended lifetime when server is in an unavailable state. - This property indicates whether the access token is returned in such a state. */ -@property (readonly) BOOL extendedLifeTimeToken; - @end diff --git a/ADAL/src/ADAuthenticationResult+Internal.m b/ADAL/src/ADAuthenticationResult+Internal.m index 142455378..75f7066b1 100644 --- a/ADAL/src/ADAuthenticationResult+Internal.m +++ b/ADAL/src/ADAuthenticationResult+Internal.m @@ -30,12 +30,6 @@ @implementation ADAuthenticationResult (Internal) -// ADAL_RESILIENCY_NOT_YET: Remove when we add feature to public API -- (BOOL)extendedLifeTimeToken -{ - return _extendedLifeTimeToken; -} - - (id)initWithCancellation:(NSUUID*)correlationId { ADAuthenticationError* error = [ADAuthenticationError errorFromCancellation:correlationId]; diff --git a/ADAL/src/ADAuthenticationResult.m b/ADAL/src/ADAuthenticationResult.m index 6d1f8e193..47e30cdd5 100644 --- a/ADAL/src/ADAuthenticationResult.m +++ b/ADAL/src/ADAuthenticationResult.m @@ -34,7 +34,7 @@ @implementation ADAuthenticationResult @synthesize error = _error; @synthesize multiResourceRefreshToken = _multiResourceRefreshToken; @synthesize correlationId = _correlationId; -//@synthesize extendedLifeTimeToken = _extendedLifeTimeToken; ADAL_RESILIENCY_NOT_YET +@synthesize extendedLifeTimeToken = _extendedLifeTimeToken; - (id)init { diff --git a/ADAL/src/public/ADAuthenticationContext.h b/ADAL/src/public/ADAuthenticationContext.h index 5316ea976..e6ec98128 100644 --- a/ADAL/src/public/ADAuthenticationContext.h +++ b/ADAL/src/public/ADAuthenticationContext.h @@ -270,6 +270,9 @@ typedef enum when needed, leveraging the parentController property. */ @property (weak) WebViewType* webView; +/*! Enable to return access token with extended lifetime during server outage. */ +@property BOOL extendedLifetimeEnabled; + /*! Follows the OAuth2 protocol (RFC 6749). The function will first look at the cache and automatically check for token expiration. Additionally, if no suitable access token is found in the cache, but refresh token is available, the function will use the refresh token automatically. If neither of these attempts succeeds, the method will use the provided assertion to get an diff --git a/ADAL/src/public/ADAuthenticationResult.h b/ADAL/src/public/ADAuthenticationResult.h index c41f49d46..a3bea9e61 100644 --- a/ADAL/src/public/ADAuthenticationResult.h +++ b/ADAL/src/public/ADAuthenticationResult.h @@ -74,5 +74,9 @@ typedef enum /*! The correlation ID of the request(s) that get this result. */ @property (readonly) NSUUID* correlationId; +/*! Some access tokens have extended lifetime when server is in an unavailable state. + This property indicates whether the access token is returned in such a state. */ +@property (readonly) BOOL extendedLifeTimeToken; + @end From db53854f0937a3ee5bdc7b19445ce082117cfdcc Mon Sep 17 00:00:00 2001 From: Yong Zeng Date: Wed, 9 Nov 2016 09:15:00 -0800 Subject: [PATCH 50/92] update telemetry aggregated dispatcher to only output designated properties --- ADAL/src/public/ADWebAuthController.h | 4 +- .../ADAuthenticationRequest+WebRequest.m | 25 +------ ADAL/src/request/ADWebRequest.m | 1 + ADAL/src/telemetry/ADTelemetryEventStrings.h | 2 + ADAL/src/telemetry/ADTelemetryEventStrings.m | 2 + ADAL/src/telemetry/ADTelemetryHttpEvent.h | 1 + ADAL/src/telemetry/ADTelemetryHttpEvent.m | 5 ++ ADAL/src/telemetry/ADTelemetryUIEvent.h | 1 + ADAL/src/telemetry/ADTelemetryUIEvent.m | 8 ++- ADAL/src/ui/ADWebAuthController+Internal.h | 2 +- ADAL/src/ui/ADWebAuthController.m | 67 ++++++++++++------- ADAL/src/urlprotocol/ADURLProtocol.h | 4 +- ADAL/src/urlprotocol/ADURLProtocol.m | 12 ++++ ADAL/tests/ADTelemetryTests.m | 48 +++++++++---- ADAL/tests/ADWebAuthControllerTests.m | 12 +++- 15 files changed, 128 insertions(+), 66 deletions(-) diff --git a/ADAL/src/public/ADWebAuthController.h b/ADAL/src/public/ADWebAuthController.h index 3e6bc707a..6ff58971d 100755 --- a/ADAL/src/public/ADWebAuthController.h +++ b/ADAL/src/public/ADWebAuthController.h @@ -25,6 +25,7 @@ @class ADAuthenticationViewController; #import "ADAuthenticationContext.h" +#import "ADTelemetryUIEvent.h" /*! Fired at the start of a resource load in the webview. The URL of the load, if available, will be in the @"url" key in the userInfo dictionary */ extern NSString* ADWebAuthDidStartLoadNotification; @@ -62,7 +63,8 @@ extern NSString* ADWebAuthDidReceieveResponseFromBroker; BOOL _complete; - NSUUID * _correlationId; + ADRequestParameters* _requestParams; + ADTelemetryUIEvent* _telemetryEvent; void (^_completionBlock)( ADAuthenticationError *, NSURL *); } diff --git a/ADAL/src/request/ADAuthenticationRequest+WebRequest.m b/ADAL/src/request/ADAuthenticationRequest+WebRequest.m index 47627b92a..3a650ed2f 100755 --- a/ADAL/src/request/ADAuthenticationRequest+WebRequest.m +++ b/ADAL/src/request/ADAuthenticationRequest+WebRequest.m @@ -37,9 +37,6 @@ #import "ADAuthenticationRequest.h" #import "ADTokenCacheItem+Internal.h" #import "ADWebAuthRequest.h" -#import "ADTelemetry.h" -#import "ADTelemetry+Internal.h" -#import "ADTelemetryUIEvent.h" #import @@ -143,16 +140,6 @@ - (NSString*)generateQueryStringForRequestType:(NSString*)requestType - (void)launchWebView:(NSString*)startUrl completionBlock:(void (^)(ADAuthenticationError*, NSURL*))completionBlock { - [[ADTelemetry sharedInstance] startEvent:[self telemetryRequestId] eventName:@"launch_web_view"]; - void(^requestCompletion)(ADAuthenticationError *error, NSURL *end) = ^void(ADAuthenticationError *error, NSURL *end) - { - ADTelemetryUIEvent* event = [[ADTelemetryUIEvent alloc] initWithName:@"launch_web_view" - context:_requestParams]; - [self fillTelemetryUIEvent:event]; - [[ADTelemetry sharedInstance] stopEvent:[self telemetryRequestId] event:event]; - completionBlock(error, end); - }; - [[ADWebAuthController sharedInstance] start:[NSURL URLWithString:startUrl] end:[NSURL URLWithString:[_requestParams redirectUri]] refreshCred:_refreshTokenCredential @@ -161,8 +148,8 @@ - (void)launchWebView:(NSString*)startUrl fullScreen:[ADAuthenticationSettings sharedInstance].enableFullScreen #endif webView:_context.webView - correlationId:[_requestParams correlationId] - completion:requestCompletion]; + context:_requestParams + completion:completionBlock]; } //Requests an OAuth2 code to be used for obtaining a token: @@ -290,12 +277,4 @@ - (void)requestCode:(ADAuthorizationCodeCallback)completionBlock } } -- (void)fillTelemetryUIEvent:(ADTelemetryUIEvent*)event -{ - if ([_requestParams identifier] && [[_requestParams identifier] isDisplayable] && ![NSString adIsStringNilOrBlank:[_requestParams identifier].userId]) - { - [event setLoginHint:[_requestParams identifier].userId]; - } -} - @end diff --git a/ADAL/src/request/ADWebRequest.m b/ADAL/src/request/ADWebRequest.m index d0b532eb9..8b5d4fe6b 100644 --- a/ADAL/src/request/ADWebRequest.m +++ b/ADAL/src/request/ADWebRequest.m @@ -324,6 +324,7 @@ - (void)stopTelemetryEvent:(NSError *)error [event setHttpMethod:_isGetRequest ? @"GET" : @"POST"]; [event setHttpPath:[NSString stringWithFormat:@"%@://%@/%@", _requestURL.scheme, _requestURL.host, _requestURL.path]]; + [event setHttpRequestIdHeader:[response.headers objectForKey:OAUTH2_CORRELATION_ID_REQUEST_VALUE]]; if (error) { [event setOAuthErrorCode:[NSString stringWithFormat: @"%ld", (long)[error code]]]; diff --git a/ADAL/src/telemetry/ADTelemetryEventStrings.h b/ADAL/src/telemetry/ADTelemetryEventStrings.h index 45315fa3f..b7cf34d76 100644 --- a/ADAL/src/telemetry/ADTelemetryEventStrings.h +++ b/ADAL/src/telemetry/ADTelemetryEventStrings.h @@ -33,6 +33,7 @@ extern NSString *const TELEMETRY_TENANT_ID; extern NSString *const TELEMETRY_USER_ID; extern NSString *const TELEMETRY_RESPONSE_TIME; extern NSString *const TELEMETRY_LOGIN_HINT; +extern NSString *const TELEMETRY_NTLM_HANDLED; extern NSString *const TELEMETRY_UI_EVENT_COUNT; extern NSString *const TELEMETRY_BROKER_APP; extern NSString *const TELEMETRY_BROKER_VERSION; @@ -61,6 +62,7 @@ extern NSString *const TELEMETRY_ERROR_DESCRIPTION; extern NSString *const TELEMETRY_ERROR_DOMAIN; extern NSString *const TELEMETRY_HTTP_METHOD; extern NSString *const TELEMETRY_HTTP_PATH; +extern NSString *const TELEMETRY_HTTP_REQUEST_ID_HEADER; extern NSString *const TELEMETRY_HTTP_RESPONSE_CODE; extern NSString *const TELEMETRY_OAUTH_ERROR_CODE; extern NSString *const TELEMETRY_HTTP_RESPONSE_METHOD; diff --git a/ADAL/src/telemetry/ADTelemetryEventStrings.m b/ADAL/src/telemetry/ADTelemetryEventStrings.m index b4a7d7088..9c81bd8fc 100644 --- a/ADAL/src/telemetry/ADTelemetryEventStrings.m +++ b/ADAL/src/telemetry/ADTelemetryEventStrings.m @@ -33,6 +33,7 @@ NSString *const TELEMETRY_USER_ID = @"user_id"; NSString *const TELEMETRY_RESPONSE_TIME = @"response_time"; NSString *const TELEMETRY_LOGIN_HINT = @"login_hint"; +NSString *const TELEMETRY_NTLM_HANDLED = @"ntlm"; NSString *const TELEMETRY_UI_EVENT_COUNT = @"ui_event_count"; NSString *const TELEMETRY_BROKER_APP = @"broker_app"; NSString *const TELEMETRY_BROKER_VERSION = @"broker_version"; @@ -60,6 +61,7 @@ NSString *const TELEMETRY_ERROR_DOMAIN = @"error_domain"; NSString *const TELEMETRY_HTTP_METHOD = @"http_method"; NSString *const TELEMETRY_HTTP_PATH = @"http_path"; +NSString *const TELEMETRY_HTTP_REQUEST_ID_HEADER = @"x-ms-request-id"; NSString *const TELEMETRY_HTTP_RESPONSE_CODE = @"http_response_code"; NSString *const TELEMETRY_OAUTH_ERROR_CODE = @"oauth_error_code"; NSString *const TELEMETRY_HTTP_RESPONSE_METHOD = @"http_response_method"; diff --git a/ADAL/src/telemetry/ADTelemetryHttpEvent.h b/ADAL/src/telemetry/ADTelemetryHttpEvent.h index 688cc1627..8a90e5ea7 100644 --- a/ADAL/src/telemetry/ADTelemetryHttpEvent.h +++ b/ADAL/src/telemetry/ADTelemetryHttpEvent.h @@ -27,6 +27,7 @@ - (void)setHttpMethod:(NSString*)method; - (void)setHttpPath:(NSString*)path; +- (void)setHttpRequestIdHeader:(NSString*)requestIdHeader; - (void)setHttpResponseCode:(NSString*)code; - (void)setHttpResponseMethod:(NSString*)method; - (void)setHttpRequestQueryParams:(NSString*)params; diff --git a/ADAL/src/telemetry/ADTelemetryHttpEvent.m b/ADAL/src/telemetry/ADTelemetryHttpEvent.m index 167436319..ac4d6f185 100644 --- a/ADAL/src/telemetry/ADTelemetryHttpEvent.m +++ b/ADAL/src/telemetry/ADTelemetryHttpEvent.m @@ -36,6 +36,11 @@ - (void)setHttpPath:(NSString*)path [self setProperty:TELEMETRY_HTTP_PATH value:path]; } +- (void)setHttpRequestIdHeader:(NSString*)requestIdHeader +{ + [self setProperty:TELEMETRY_HTTP_REQUEST_ID_HEADER value:requestIdHeader]; +} + - (void)setHttpResponseCode:(NSString*)code { [self setProperty:TELEMETRY_HTTP_RESPONSE_CODE value:code]; diff --git a/ADAL/src/telemetry/ADTelemetryUIEvent.h b/ADAL/src/telemetry/ADTelemetryUIEvent.h index 1cd2cec01..a7385a762 100644 --- a/ADAL/src/telemetry/ADTelemetryUIEvent.h +++ b/ADAL/src/telemetry/ADTelemetryUIEvent.h @@ -26,5 +26,6 @@ @interface ADTelemetryUIEvent : ADTelemetryDefaultEvent - (void)setLoginHint:(NSString*)hint; +- (void)setNtlm:(NSString*)ntlmHandled; @end \ No newline at end of file diff --git a/ADAL/src/telemetry/ADTelemetryUIEvent.m b/ADAL/src/telemetry/ADTelemetryUIEvent.m index e35b31794..6612c1dd3 100644 --- a/ADAL/src/telemetry/ADTelemetryUIEvent.m +++ b/ADAL/src/telemetry/ADTelemetryUIEvent.m @@ -31,6 +31,11 @@ - (void)setLoginHint:(NSString*)hint [self setProperty:TELEMETRY_LOGIN_HINT value:[hint adComputeSHA256]]; } +- (void)setNtlm:(NSString*)ntlmHandled +{ + [self setProperty:TELEMETRY_NTLM_HANDLED value:ntlmHandled]; +} + - (void)processEvent:(NSMutableDictionary*)eventToBeDispatched { [super processEvent:eventToBeDispatched]; @@ -39,7 +44,8 @@ - (void)processEvent:(NSMutableDictionary*)eventToBeDispatched NSArray* properties = [self getProperties]; for (NSArray* property in properties) { - if ([property[0] isEqualToString:TELEMETRY_LOGIN_HINT]) + if ([property[0] isEqualToString:TELEMETRY_LOGIN_HINT] + ||[property[0] isEqualToString:TELEMETRY_NTLM_HANDLED]) { [eventToBeDispatched setObject:property[1] forKey:property[0]]; } diff --git a/ADAL/src/ui/ADWebAuthController+Internal.h b/ADAL/src/ui/ADWebAuthController+Internal.h index d500359a6..f2d956108 100644 --- a/ADAL/src/ui/ADWebAuthController+Internal.h +++ b/ADAL/src/ui/ADWebAuthController+Internal.h @@ -42,7 +42,7 @@ typedef void (^ADBrokerCallback)(ADAuthenticationError* error, NSURL*); fullScreen:(BOOL)fullScreen #endif webView:(WebViewType*)webView -correlationId:(NSUUID*)correlationId + context:(ADRequestParameters*)requestParams completion:(ADBrokerCallback)completionBlock; //Cancel the web authentication session which might be happening right now diff --git a/ADAL/src/ui/ADWebAuthController.m b/ADAL/src/ui/ADWebAuthController.m index 121dc3a70..dcdb104ac 100755 --- a/ADAL/src/ui/ADWebAuthController.m +++ b/ADAL/src/ui/ADWebAuthController.m @@ -39,6 +39,10 @@ #import "ADURLProtocol.h" #import "ADWebAuthDelegate.h" #import "ADWorkPlaceJoinConstants.h" +#import "ADUserIdentifier.h" +#import "ADTelemetry.h" +#import "ADTelemetry+Internal.h" +#import "ADTelemetryUIEvent.h" /*! Fired at the start of a resource load in the webview. */ NSString* ADWebAuthDidStartLoadNotification = @"ADWebAuthDidStartLoadNotification"; @@ -147,6 +151,9 @@ - (void)dispatchCompletionBlock:(ADAuthenticationError *)error URL:(NSURL *)url [ADURLProtocol unregisterProtocol]; + [self fillTelemetryUIEvent:_telemetryEvent]; + [[ADTelemetry sharedInstance] stopEvent:_requestParams.telemetryRequestId event:_telemetryEvent]; + if ( _completionBlock ) { void (^completionBlock)( ADAuthenticationError *, NSURL *) = _completionBlock; @@ -176,7 +183,7 @@ - (void)handlePKeyAuthChallenge:(NSString *)challengeUrl ADAuthenticationError* adError = nil; NSString* authHeader = [ADPkeyAuthHelper createDeviceAuthResponse:authority challengeData:queryParamsMap - correlationId:_correlationId + correlationId:_requestParams.correlationId error:&adError]; if (!authHeader) { @@ -185,7 +192,7 @@ - (void)handlePKeyAuthChallenge:(NSString *)challengeUrl } NSMutableURLRequest* responseUrl = [[NSMutableURLRequest alloc]initWithURL:[NSURL URLWithString:value]]; - [ADURLProtocol addCorrelationId:_correlationId toRequest:responseUrl]; + [ADURLProtocol addCorrelationId:_requestParams.correlationId toRequest:responseUrl]; [responseUrl setValue:pKeyAuthHeaderVersion forHTTPHeaderField: pKeyAuthHeader]; [responseUrl setValue:authHeader forHTTPHeaderField:@"Authorization"]; @@ -248,7 +255,7 @@ - (void)failWithTimeout NSError* error = [NSError errorWithDomain:NSURLErrorDomain code:NSURLErrorTimedOut userInfo:nil]; - ADAuthenticationError* adError = [ADAuthenticationError errorFromNSError:error errorDetails:@"WebView timed out" correlationId:_correlationId]; + ADAuthenticationError* adError = [ADAuthenticationError errorFromNSError:error errorDetails:@"WebView timed out" correlationId:_requestParams.correlationId]; [self dispatchCompletionBlock:adError URL:nil]; }]; } @@ -296,14 +303,14 @@ - (void)webAuthDidStartLoad:(NSURL*)url - (void)webAuthDidFinishLoad:(NSURL*)url { - AD_LOG_VERBOSE_F(@"-webAuthDidFinishLoad:", _correlationId, @"host: %@", url.host); + AD_LOG_VERBOSE_F(@"-webAuthDidFinishLoad:", _requestParams.correlationId, @"host: %@", url.host); [self stopSpinner]; [[NSNotificationCenter defaultCenter] postNotificationName:ADWebAuthDidFinishLoadNotification object:self userInfo:url ? @{ @"url" : url } : nil]; } - (BOOL)webAuthShouldStartLoadRequest:(NSURLRequest *)request { - AD_LOG_VERBOSE_F(@"-webAuthShouldStartLoadRequest:", _correlationId, @"host: %@", request.URL.host); + AD_LOG_VERBOSE_F(@"-webAuthShouldStartLoadRequest:", _requestParams.correlationId, @"host: %@", request.URL.host); if([ADNTLMHandler isChallengeCancelled]) { _complete = YES; @@ -336,7 +343,7 @@ - (BOOL)webAuthShouldStartLoadRequest:(NSURLRequest *)request } else { - AD_LOG_ERROR(@"unable to redirect to browser from extension", AD_ERROR_SERVER_UNSUPPORTED_REQUEST, _correlationId, nil); + AD_LOG_ERROR(@"unable to redirect to browser from extension", AD_ERROR_SERVER_UNSUPPORTED_REQUEST, _requestParams.correlationId, nil); } #else // !TARGET_OS_IPHONE AD_LOG_ERROR(@"server is redirecting us to browser, this behavior is not defined on Mac OS X yet", AD_ERROR_SERVER_UNSUPPORTED_REQUEST, _correlationId, nil); @@ -384,7 +391,7 @@ - (BOOL)webAuthShouldStartLoadRequest:(NSURLRequest *)request { AD_LOG_ERROR(@"Server is redirecting to a non-https url", AD_ERROR_SERVER_NON_HTTPS_REDIRECT, nil, nil); _complete = YES; - ADAuthenticationError* error = [ADAuthenticationError errorFromNonHttpsRedirect:_correlationId]; + ADAuthenticationError* error = [ADAuthenticationError errorFromNonHttpsRedirect:_requestParams.correlationId]; dispatch_async( dispatch_get_main_queue(), ^{[self endWebAuthenticationWithError:error orURL:nil];} ); return NO; @@ -392,7 +399,7 @@ - (BOOL)webAuthShouldStartLoadRequest:(NSURLRequest *)request if ([request isKindOfClass:[NSMutableURLRequest class]]) { - [ADURLProtocol addCorrelationId:_correlationId toRequest:(NSMutableURLRequest*)request]; + [ADURLProtocol addCorrelationId:_requestParams.correlationId toRequest:(NSMutableURLRequest*)request]; } return YES; @@ -401,18 +408,18 @@ - (BOOL)webAuthShouldStartLoadRequest:(NSURLRequest *)request // The user cancelled authentication - (void)webAuthDidCancel { - AD_LOG_INFO(@"-webAuthDidCancel", _correlationId, nil); + AD_LOG_INFO(@"-webAuthDidCancel", _requestParams.correlationId, nil); // Dispatch the completion block - ADAuthenticationError* error = [ADAuthenticationError errorFromCancellation:_correlationId]; + ADAuthenticationError* error = [ADAuthenticationError errorFromCancellation:_requestParams.correlationId]; [self endWebAuthenticationWithError:error orURL:nil]; } // Authentication completed at the end URL - (void)webAuthDidCompleteWithURL:(NSURL *)endURL { - AD_LOG_INFO_F(@"-webAuthDidCompleteWithURL:", _correlationId, @"%@", endURL); + AD_LOG_INFO_F(@"-webAuthDidCompleteWithURL:", _requestParams.correlationId, @"%@", endURL); [self endWebAuthenticationWithError:nil orURL:endURL]; [[NSNotificationCenter defaultCenter] postNotificationName:ADWebAuthDidCompleteNotification object:self userInfo:nil]; @@ -458,7 +465,7 @@ - (void)webAuthDidFailWithError:(NSError *)error if (error) { - AD_LOG_ERROR_F(@"-webAuthDidFailWithError:", error.code, _correlationId, @"error: %@", error); + AD_LOG_ERROR_F(@"-webAuthDidFailWithError:", error.code, _requestParams.correlationId, @"error: %@", error); [[NSNotificationCenter defaultCenter] postNotificationName:ADWebAuthDidFailNotification object:self @@ -489,12 +496,12 @@ - (void)webAuthDidFailWithError:(NSError *)error if (_complete == YES) { //We expect to get an error here, as we intentionally fail to navigate to the final redirect URL. - AD_LOG_VERBOSE(@"Expected error", _correlationId, [error localizedDescription]); + AD_LOG_VERBOSE(@"Expected error", _requestParams.correlationId, [error localizedDescription]); return; } // Dispatch the completion block - __block ADAuthenticationError* adError = [ADAuthenticationError errorFromNSError:error errorDetails:error.localizedDescription correlationId:_correlationId]; + __block ADAuthenticationError* adError = [ADAuthenticationError errorFromNSError:error errorDetails:error.localizedDescription correlationId:_requestParams.correlationId]; dispatch_async(dispatch_get_main_queue(), ^{ [self endWebAuthenticationWithError:adError orURL:nil]; }); } @@ -510,6 +517,14 @@ + (ADAuthenticationResult*)responseFromInterruptedBrokerSession } #endif // TARGET_OS_IPHONE +- (void)fillTelemetryUIEvent:(ADTelemetryUIEvent*)event +{ + if ([_requestParams identifier] && [[_requestParams identifier] isDisplayable] && ![NSString adIsStringNilOrBlank:[_requestParams identifier].userId]) + { + [event setLoginHint:[_requestParams identifier].userId]; + } +} + @end #pragma mark - Private Methods @@ -530,7 +545,7 @@ + (ADWebAuthController *)sharedInstance - (BOOL)cancelCurrentWebAuthSessionWithError:(ADAuthenticationError*)error { - AD_LOG_ERROR_F(@"Application is cancelling current web auth session.", error.code, _correlationId, @"error = %@", error); + AD_LOG_ERROR_F(@"Application is cancelling current web auth session.", error.code, _requestParams.correlationId, @"error = %@", error); return [self endWebAuthenticationWithError:error orURL:nil]; } @@ -549,12 +564,12 @@ - (void)start:(NSURL *)startURL fullScreen:(BOOL)fullScreen #endif webView:(WebViewType *)webView -correlationId:(NSUUID *)correlationId + context:(ADRequestParameters*)requestParams completion:(ADBrokerCallback)completionBlock { THROW_ON_NIL_ARGUMENT(startURL); THROW_ON_NIL_ARGUMENT(endURL); - THROW_ON_NIL_ARGUMENT(correlationId); + THROW_ON_NIL_ARGUMENT(requestParams.correlationId); THROW_ON_NIL_ARGUMENT(completionBlock); // If we're not on the main thread when trying to kick up the UI then @@ -570,31 +585,35 @@ - (void)start:(NSURL *)startURL fullScreen:fullScreen #endif webView:webView - correlationId:correlationId + context:requestParams completion:completionBlock]; }); return; } + [[ADTelemetry sharedInstance] startEvent:requestParams.telemetryRequestId eventName:@"launch_web_view"]; + SAFE_ARC_RELEASE(_telemetryEvent); + _telemetryEvent = [[ADTelemetryUIEvent alloc] initWithName:@"launch_web_view" + context:_requestParams]; _timeout = [[ADAuthenticationSettings sharedInstance] requestTimeOut]; - startURL = [self addToURL:startURL correlationId:correlationId];//Append the correlation id + startURL = [self addToURL:startURL correlationId:requestParams.correlationId];//Append the correlation id SAFE_ARC_RELEASE(_endURL); _endURL = [endURL absoluteString]; SAFE_ARC_RETAIN(_endURL); _complete = NO; - SAFE_ARC_RELEASE(_correlationId); - _correlationId = correlationId; - SAFE_ARC_RETAIN(_correlationId); + SAFE_ARC_RELEASE(_requestParams); + _requestParams = requestParams; + SAFE_ARC_RETAIN(_requestParams); // Save the completion block SAFE_ARC_RELEASE(_completionBlock); _completionBlock = [completionBlock copy]; ADAuthenticationError* error = nil; - [ADURLProtocol registerProtocol:[endURL absoluteString]]; + [ADURLProtocol registerProtocol:[endURL absoluteString] telemetryEvent:_telemetryEvent]; if(![NSString adIsStringNilOrBlank:refreshCred]) { @@ -618,7 +637,7 @@ - (void)start:(NSURL *)startURL } NSMutableURLRequest* request = [[NSMutableURLRequest alloc] initWithURL:[ADHelpers addClientVersionToURL:startURL]]; - [ADURLProtocol addCorrelationId:_correlationId toRequest:request]; + [ADURLProtocol addCorrelationId:_requestParams.correlationId toRequest:request]; [_authenticationViewController startRequest:request]; SAFE_ARC_RELEASE(request); } diff --git a/ADAL/src/urlprotocol/ADURLProtocol.h b/ADAL/src/urlprotocol/ADURLProtocol.h index 824b58ea1..1af7a11f0 100755 --- a/ADAL/src/urlprotocol/ADURLProtocol.h +++ b/ADAL/src/urlprotocol/ADURLProtocol.h @@ -25,6 +25,7 @@ @class ADAuthenticationError; @class ADURLProtocol; +@class ADTelemetryUIEvent; @protocol ADAuthMethodHandler @@ -46,7 +47,8 @@ + (void)registerHandler:(Class)handler authMethod:(NSString *)authMethod; -+ (BOOL)registerProtocol:(NSString*)endURL; ++ (BOOL)registerProtocol:(NSString*)endURL + telemetryEvent:(ADTelemetryUIEvent*)telemetryEvent; + (void)unregisterProtocol; + (void)addCorrelationId:(NSUUID *)correlationId diff --git a/ADAL/src/urlprotocol/ADURLProtocol.m b/ADAL/src/urlprotocol/ADURLProtocol.m index 5c9b71af1..4a0b4c188 100755 --- a/ADAL/src/urlprotocol/ADURLProtocol.m +++ b/ADAL/src/urlprotocol/ADURLProtocol.m @@ -26,9 +26,12 @@ #import "ADLogger.h" #import "ADNTLMHandler.h" #import "ADCustomHeaderHandler.h" +#import "ADTelemetryUIEvent.h" +#import "ADTelemetryEventStrings.h" static NSMutableDictionary* s_handlers = nil; static NSString* s_endURL = nil; +static ADTelemetryUIEvent* s_telemetryEvent = nil; static NSString* kADURLProtocolPropertyKey = @"ADURLProtocol"; @@ -64,12 +67,14 @@ + (void)registerHandler:(id)handler + (BOOL)registerProtocol:(NSString*)endURL + telemetryEvent:(ADTelemetryUIEvent*)telemetryEvent { if (s_endURL!=endURL) { s_endURL = endURL.lowercaseString; SAFE_ARC_RETAIN(s_endURL); } + s_telemetryEvent = telemetryEvent; return [NSURLProtocol registerClass:self]; } @@ -78,6 +83,7 @@ + (void)unregisterProtocol [NSURLProtocol unregisterClass:self]; SAFE_ARC_RELEASE(s_endURL); s_endURL = nil; + s_telemetryEvent = nil; @synchronized(self) { @@ -208,6 +214,12 @@ - (void)connection:(NSURLConnection *)connection { // Do default handling [challenge.sender performDefaultHandlingForAuthenticationChallenge:challenge]; + return; + } + + if ([authMethod isEqualToString:NSURLAuthenticationMethodNTLM]) + { + [s_telemetryEvent setNtlm:TELEMETRY_YES]; } } diff --git a/ADAL/tests/ADTelemetryTests.m b/ADAL/tests/ADTelemetryTests.m index aec7c60b8..be6af086e 100644 --- a/ADAL/tests/ADTelemetryTests.m +++ b/ADAL/tests/ADTelemetryTests.m @@ -207,6 +207,7 @@ - (void)testSequentialEventsWithAggregation { // new a dispatcher TestDispatcher* dispatcher = [TestDispatcher new]; NSMutableArray* receivedEvents = [NSMutableArray new]; + NSUUID* correlationId = [NSUUID UUID]; // the dispatcher will store the telemetry events it receives [dispatcher setTestCallback:^(NSArray* event) @@ -223,13 +224,13 @@ - (void)testSequentialEventsWithAggregation { [[ADTelemetry sharedInstance] stopEvent:requestId event:[[ADTelemetryAPIEvent alloc] initWithName:@"testEvent1" requestId:requestId - correlationId:nil]]; + correlationId:correlationId]]; // generate telemetry event 2 [[ADTelemetry sharedInstance] startEvent:requestId eventName:@"testEvent2"]; ADTelemetryDefaultEvent* event2 = [[ADTelemetryDefaultEvent alloc] initWithName:@"testEvent2" requestId:requestId - correlationId:nil]; + correlationId:correlationId]; [event2 setProperty:@"customized_property" value:@"customized_value"]; [[ADTelemetry sharedInstance] stopEvent:requestId event:event2]; @@ -239,7 +240,13 @@ - (void)testSequentialEventsWithAggregation { // there should be 1 telemetry event recorded as aggregation flag is on XCTAssertEqual([receivedEvents count], 1); - // the aggregated event only outputs some designated properties + // the aggregated event outputs the default properties like correlation_id, request_id, etc. + XCTAssertEqual([self getPropertyCount:[receivedEvents firstObject] + propertyName:@"correlation_id"], 1); + XCTAssertEqual([self getPropertyCount:[receivedEvents firstObject] + propertyName:@"request_id"], 1); + + // it will also outputs some designated properties like response_time, but not for event_name, etc. XCTAssertEqual([self getPropertyCount:[receivedEvents firstObject] propertyName:@"response_time"], 1); @@ -338,6 +345,7 @@ - (void)testNestedEventsWithAggregation { // new a dispatcher TestDispatcher* dispatcher = [TestDispatcher new]; NSMutableArray* receivedEvents = [NSMutableArray new]; + NSUUID* correlationId = [NSUUID UUID]; // the dispatcher will store the telemetry events it receives [dispatcher setTestCallback:^(NSArray* event) @@ -355,7 +363,7 @@ - (void)testNestedEventsWithAggregation { [[ADTelemetry sharedInstance] startEvent:requestId eventName:@"testEvent2"]; ADTelemetryDefaultEvent* event2 = [[ADTelemetryDefaultEvent alloc] initWithName:@"testEvent2" requestId:requestId - correlationId:nil]; + correlationId:correlationId]; [event2 setProperty:@"customized_property" value:@"customized_value"]; [[ADTelemetry sharedInstance] stopEvent:requestId event:event2]; @@ -363,19 +371,22 @@ - (void)testNestedEventsWithAggregation { [[ADTelemetry sharedInstance] stopEvent:requestId event:[[ADTelemetryAPIEvent alloc] initWithName:@"testEvent1" requestId:requestId - correlationId:nil]]; + correlationId:correlationId]]; [[ADTelemetry sharedInstance] flush:requestId]; // there should be 1 telemetry event recorded as aggregation flag is ON XCTAssertEqual([receivedEvents count], 1); - // the aggregated event only outputs some designated properties + // the aggregated event outputs the default properties like correlation_id, request_id, etc. XCTAssertEqual([self getPropertyCount:[receivedEvents firstObject] - propertyName:@"response_time"], 1); + propertyName:@"correlation_id"], 1); + XCTAssertEqual([self getPropertyCount:[receivedEvents firstObject] + propertyName:@"request_id"], 1); + // it will also outputs some designated properties like response_time, but not for event_name, etc. XCTAssertEqual([self getPropertyCount:[receivedEvents firstObject] - propertyName:@"customized_property"], 0); + propertyName:@"response_time"], 1); XCTAssertEqual([self getPropertyCount:[receivedEvents firstObject] propertyName:@"event_name"], 0); @@ -385,6 +396,9 @@ - (void)testNestedEventsWithAggregation { XCTAssertEqual([self getPropertyCount:[receivedEvents firstObject] propertyName:@"stop_time"], 0); + + XCTAssertEqual([self getPropertyCount:[receivedEvents firstObject] + propertyName:@"customized_property"], 0); } - (void)testComplexEvents { @@ -503,6 +517,7 @@ - (void)testComplexEventsWithAggregation { // new a dispatcher TestDispatcher* dispatcher = [TestDispatcher new]; NSMutableArray* receivedEvents = [NSMutableArray new]; + NSUUID* correlationId = [NSUUID UUID]; // the dispatcher will store the telemetry events it receives [dispatcher setTestCallback:^(NSArray* event) @@ -523,7 +538,7 @@ - (void)testComplexEventsWithAggregation { [[ADTelemetry sharedInstance] stopEvent:requestId event:[[ADTelemetryDefaultEvent alloc] initWithName:@"testEvent3" requestId:requestId - correlationId:nil]]; + correlationId:correlationId]]; [[ADTelemetry sharedInstance] stopEvent:requestId event:[[ADTelemetryDefaultEvent alloc] initWithName:@"testEvent2" @@ -533,20 +548,26 @@ - (void)testComplexEventsWithAggregation { [[ADTelemetry sharedInstance] stopEvent:requestId event:[[ADTelemetryAPIEvent alloc] initWithName:@"testEvent1" requestId:requestId - correlationId:nil]]; + correlationId:correlationId]]; [[ADTelemetry sharedInstance] startEvent:requestId eventName:@"testEvent4"]; [[ADTelemetry sharedInstance] stopEvent:requestId event:[[ADTelemetryDefaultEvent alloc] initWithName:@"testEvent4" requestId:requestId - correlationId:nil]]; + correlationId:correlationId]]; [[ADTelemetry sharedInstance] flush:requestId]; // there should be 1 telemetry events recorded as aggregation flag is ON XCTAssertEqual([receivedEvents count], 1); - // the aggregated event only outputs some designated properties + // the aggregated event outputs the default properties like correlation_id, request_id, etc. + XCTAssertEqual([self getPropertyCount:[receivedEvents firstObject] + propertyName:@"correlation_id"], 1); + XCTAssertEqual([self getPropertyCount:[receivedEvents firstObject] + propertyName:@"request_id"], 1); + + // it will also outputs some designated properties like response_time, but not for event_name, etc. XCTAssertEqual([self getPropertyCount:[receivedEvents firstObject] propertyName:@"response_time"], 1); @@ -558,6 +579,9 @@ - (void)testComplexEventsWithAggregation { XCTAssertEqual([self getPropertyCount:[receivedEvents firstObject] propertyName:@"stop_time"], 0); + + XCTAssertEqual([self getPropertyCount:[receivedEvents firstObject] + propertyName:@"customized_property"], 0); } - (NSString*)getPropertyFromEvent:(NSArray*)event diff --git a/ADAL/tests/ADWebAuthControllerTests.m b/ADAL/tests/ADWebAuthControllerTests.m index 9edfab4f9..72483782a 100644 --- a/ADAL/tests/ADWebAuthControllerTests.m +++ b/ADAL/tests/ADWebAuthControllerTests.m @@ -78,6 +78,9 @@ - (void)testAboutBlankWhitelistInWebView [ADTestAuthenticationViewController addDelegateCallWebAuthShouldStartLoadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"about:blank"]]]; [ADTestAuthenticationViewController addDelegateCallWebAuthShouldStartLoadRequest:[NSURLRequest requestWithURL:TEST_REDIRECT_URL]]; + ADRequestParameters* requestParams = [ADRequestParameters new]; + [requestParams setCorrelationId:[NSUUID new]]; + [controller start:[NSURL URLWithString:TEST_AUTHORITY] end:TEST_REDIRECT_URL refreshCred:nil @@ -85,8 +88,8 @@ - (void)testAboutBlankWhitelistInWebView parent:nil fullScreen:false #endif - webView:nil - correlationId:[NSUUID new] + webView:nil + context:requestParams completion:^(ADAuthenticationError *error, NSURL *url) { XCTAssertNil(error); @@ -108,6 +111,9 @@ - (void)testNonHttpsRedirectInWebView [ADTestAuthenticationViewController addDelegateCallWebAuthShouldStartLoadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:TEST_AUTHORITY]]]; [ADTestAuthenticationViewController addDelegateCallWebAuthShouldStartLoadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"http://abc.com"]]]; + ADRequestParameters* requestParams = [ADRequestParameters new]; + [requestParams setCorrelationId:[NSUUID new]]; + [controller start:[NSURL URLWithString:TEST_AUTHORITY] end:TEST_REDIRECT_URL refreshCred:nil @@ -116,7 +122,7 @@ - (void)testNonHttpsRedirectInWebView fullScreen:false #endif webView:nil - correlationId:[NSUUID new] + context:requestParams completion:^(ADAuthenticationError *error, NSURL *url) { //Should fail with AD_ERROR_NON_HTTPS_REDIRECT error From da6f1f1cd7fddb246f185edcc9a51f43beda7f63 Mon Sep 17 00:00:00 2001 From: Yong Zeng Date: Wed, 9 Nov 2016 09:29:07 -0800 Subject: [PATCH 51/92] convert more telemetry-related strings to constants --- ADAL/src/request/ADAuthenticationRequest.h | 1 - ADAL/src/request/ADAuthenticationRequest.m | 5 ----- ADAL/src/telemetry/ADTelemetry.m | 3 ++- ADAL/src/telemetry/ADTelemetryDefaultEvent.m | 4 ++-- ADAL/src/telemetry/ADTelemetryEventStrings.h | 4 +++- ADAL/src/telemetry/ADTelemetryEventStrings.m | 4 +++- ADAL/src/telemetry/ADTelemetryHttpEvent.m | 3 ++- 7 files changed, 12 insertions(+), 12 deletions(-) diff --git a/ADAL/src/request/ADAuthenticationRequest.h b/ADAL/src/request/ADAuthenticationRequest.h index 5369749bf..f9b9a2e23 100644 --- a/ADAL/src/request/ADAuthenticationRequest.h +++ b/ADAL/src/request/ADAuthenticationRequest.h @@ -100,7 +100,6 @@ - (void)setCorrelationId:(NSUUID*)correlationId; - (NSUUID*)correlationId; - (NSString*)telemetryRequestId; -- (ADPromptBehavior)promptBehavior; - (ADRequestParameters*)requestParams; #if AD_BROKER - (NSString*)redirectUri; diff --git a/ADAL/src/request/ADAuthenticationRequest.m b/ADAL/src/request/ADAuthenticationRequest.m index 5165c0338..483652404 100644 --- a/ADAL/src/request/ADAuthenticationRequest.m +++ b/ADAL/src/request/ADAuthenticationRequest.m @@ -290,11 +290,6 @@ - (NSString*)telemetryRequestId return [_requestParams telemetryRequestId]; } -- (ADPromptBehavior)promptBehavior -{ - return _promptBehavior; -} - - (ADRequestParameters*)requestParams { return _requestParams; diff --git a/ADAL/src/telemetry/ADTelemetry.m b/ADAL/src/telemetry/ADTelemetry.m index 9f7728bd1..8d7fc137e 100644 --- a/ADAL/src/telemetry/ADTelemetry.m +++ b/ADAL/src/telemetry/ADTelemetry.m @@ -26,6 +26,7 @@ #import "ADTelemetryEventInterface.h" #import "ADDefaultDispatcher.h" #import "ADAggregatedDispatcher.h" +#import "ADTelemetryEventStrings.h" static NSString* const s_delimiter = @"|"; @@ -114,7 +115,7 @@ - (void)stopEvent:(NSString*)requestId event:(id)event { NSDate* stopTime = [NSDate date]; - NSString* eventName = [self getPropertyFromEvent:event propertyName:@"event_name"]; + NSString* eventName = [self getPropertyFromEvent:event propertyName:TELEMETRY_EVENT_NAME]; if ([NSString adIsStringNilOrBlank:requestId] || [NSString adIsStringNilOrBlank:eventName] || !event) { diff --git a/ADAL/src/telemetry/ADTelemetryDefaultEvent.m b/ADAL/src/telemetry/ADTelemetryDefaultEvent.m index f4cd269fd..4896cbc8c 100644 --- a/ADAL/src/telemetry/ADTelemetryDefaultEvent.m +++ b/ADAL/src/telemetry/ADTelemetryDefaultEvent.m @@ -60,11 +60,11 @@ - (id)initWithName:(NSString*)eventName } _propertyMap = [[self defaultParameters] mutableCopy]; - SET_IF_NOT_NIL(_propertyMap, @"request_id", requestId); + SET_IF_NOT_NIL(_propertyMap, TELEMETRY_REQUEST_ID, requestId); SET_IF_NOT_NIL(_propertyMap, TELEMETRY_CORRELATION_ID, [correlationId UUIDString]); _defaultPropertyCount = [_propertyMap count]; - SET_IF_NOT_NIL(_propertyMap, @"event_name", eventName); + SET_IF_NOT_NIL(_propertyMap, TELEMETRY_EVENT_NAME, eventName); return self; } diff --git a/ADAL/src/telemetry/ADTelemetryEventStrings.h b/ADAL/src/telemetry/ADTelemetryEventStrings.h index b7cf34d76..15b5c5c27 100644 --- a/ADAL/src/telemetry/ADTelemetryEventStrings.h +++ b/ADAL/src/telemetry/ADTelemetryEventStrings.h @@ -73,4 +73,6 @@ extern NSString *const TELEMETRY_AUTHORITY; extern NSString *const TELEMETRY_AUTHORITY_AAD; extern NSString *const TELEMETRY_AUTHORITY_ADFS; extern NSString *const TELEMETRY_GRANT_TYPE; -extern NSString *const TELEMETRY_API_STATUS; \ No newline at end of file +extern NSString *const TELEMETRY_API_STATUS; +extern NSString *const TELEMETRY_EVENT_NAME; +extern NSString *const TELEMETRY_REQUEST_ID; \ No newline at end of file diff --git a/ADAL/src/telemetry/ADTelemetryEventStrings.m b/ADAL/src/telemetry/ADTelemetryEventStrings.m index 9c81bd8fc..54238904e 100644 --- a/ADAL/src/telemetry/ADTelemetryEventStrings.m +++ b/ADAL/src/telemetry/ADTelemetryEventStrings.m @@ -72,4 +72,6 @@ NSString *const TELEMETRY_AUTHORITY_AAD = @"aad"; NSString *const TELEMETRY_AUTHORITY_ADFS = @"adfs"; NSString *const TELEMETRY_GRANT_TYPE = @"grant_type"; -NSString *const TELEMETRY_API_STATUS = @"api_status"; \ No newline at end of file +NSString *const TELEMETRY_API_STATUS = @"api_status"; +NSString *const TELEMETRY_EVENT_NAME = @"event_name"; +NSString *const TELEMETRY_REQUEST_ID = @"request_id"; \ No newline at end of file diff --git a/ADAL/src/telemetry/ADTelemetryHttpEvent.m b/ADAL/src/telemetry/ADTelemetryHttpEvent.m index ac4d6f185..969706503 100644 --- a/ADAL/src/telemetry/ADTelemetryHttpEvent.m +++ b/ADAL/src/telemetry/ADTelemetryHttpEvent.m @@ -90,7 +90,8 @@ - (void)processEvent:(NSMutableDictionary*)eventToBeDispatched if ([property[0] isEqualToString:TELEMETRY_HTTP_RESPONSE_CODE] ||[property[0] isEqualToString:TELEMETRY_OAUTH_ERROR_CODE] ||[property[0] isEqualToString:TELEMETRY_HTTP_ERROR_DOMAIN] - ||[property[0] isEqualToString:TELEMETRY_HTTP_PATH]) + ||[property[0] isEqualToString:TELEMETRY_HTTP_PATH] + ||[property[0] isEqualToString:TELEMETRY_HTTP_REQUEST_ID_HEADER]) { [eventToBeDispatched setObject:property[1] forKey:property[0]]; } From 1a4b7ad2060c45b61406d38622f4b792fe0aa69d Mon Sep 17 00:00:00 2001 From: Ryan Pangrle Date: Wed, 9 Nov 2016 13:27:08 -0800 Subject: [PATCH 52/92] Even more attempts at making SampleSwiftApp build reliably in travis --- .../SampleSwiftApp.xcworkspace/contents.xcworkspacedata | 7 +++++++ build.py | 9 +++++++-- 2 files changed, 14 insertions(+), 2 deletions(-) create mode 100644 Samples/SampleSwiftApp/SampleSwiftApp.xcworkspace/contents.xcworkspacedata diff --git a/Samples/SampleSwiftApp/SampleSwiftApp.xcworkspace/contents.xcworkspacedata b/Samples/SampleSwiftApp/SampleSwiftApp.xcworkspace/contents.xcworkspacedata new file mode 100644 index 000000000..9d5522cee --- /dev/null +++ b/Samples/SampleSwiftApp/SampleSwiftApp.xcworkspace/contents.xcworkspacedata @@ -0,0 +1,7 @@ + + + + + diff --git a/build.py b/build.py index 58d588e35..c990f3d24 100755 --- a/build.py +++ b/build.py @@ -57,7 +57,7 @@ class tclr: "scheme" : "SampleSwiftApp", "operations" : [ "build" ], "platform" : "iOS", - "project" : "Samples/SampleSwiftApp/SampleSwiftApp.xcodeproj", + "workspace" : "Samples/SampleSwiftApp/SampleSwiftApp.xcworkspace", }, { "name" : "Mac Framework", @@ -96,6 +96,10 @@ def do_ios_build(target, operation) : name = target["name"] scheme = target["scheme"] project = target.get("project") + workspace = target.get("workspace") + + if (workspace == None) : + workspace = default_workspace print_operation_start(name, operation) @@ -103,7 +107,7 @@ def do_ios_build(target, operation) : if (project != None) : command += " -project " + project else : - command += " -workspace " + default_workspace + command += " -workspace " + workspace command += " -scheme \"" + scheme + "\" -configuration CodeCoverage " + ios_sim_flags + " " + ios_sim_dest + " | xcpretty" print command @@ -163,6 +167,7 @@ def check_dependencies(target) : # start by cleaning up any derived data that might be lying around if (clean) : subprocess.call("rm -rf ~/Library/Developer/Xcode/DerivedData/ADAL-*", shell=True) + subprocess.call("rm -rf ~/Library/Developer/Xcode/DerivedData/SampleSwiftApp-*", shell=True) for target in build_targets: exit_code = 0 From 05f55822475589f998d3c91cf9db75494e5e2898 Mon Sep 17 00:00:00 2001 From: Yong Zeng Date: Wed, 9 Nov 2016 22:09:14 -0800 Subject: [PATCH 53/92] fix build errors for mac --- ADAL/src/public/ADWebAuthController.h | 3 ++- ADAL/src/telemetry/ADTelemetryDefaultEvent.h | 1 + ADAL/src/ui/ADWebAuthController.m | 2 +- 3 files changed, 4 insertions(+), 2 deletions(-) diff --git a/ADAL/src/public/ADWebAuthController.h b/ADAL/src/public/ADWebAuthController.h index 6ff58971d..7b4e5b9c4 100755 --- a/ADAL/src/public/ADWebAuthController.h +++ b/ADAL/src/public/ADWebAuthController.h @@ -23,9 +23,10 @@ @class ADAuthenticationError; @class ADAuthenticationViewController; +@class ADTelemetryUIEvent; +@class ADRequestParameters; #import "ADAuthenticationContext.h" -#import "ADTelemetryUIEvent.h" /*! Fired at the start of a resource load in the webview. The URL of the load, if available, will be in the @"url" key in the userInfo dictionary */ extern NSString* ADWebAuthDidStartLoadNotification; diff --git a/ADAL/src/telemetry/ADTelemetryDefaultEvent.h b/ADAL/src/telemetry/ADTelemetryDefaultEvent.h index be018aed4..1eefb550f 100644 --- a/ADAL/src/telemetry/ADTelemetryDefaultEvent.h +++ b/ADAL/src/telemetry/ADTelemetryDefaultEvent.h @@ -22,6 +22,7 @@ // THE SOFTWARE. #import "ADTelemetryEventInterface.h" +#import "ADRequestContext.h" @interface ADTelemetryDefaultEvent : NSObject { diff --git a/ADAL/src/ui/ADWebAuthController.m b/ADAL/src/ui/ADWebAuthController.m index dcdb104ac..f1feec46f 100755 --- a/ADAL/src/ui/ADWebAuthController.m +++ b/ADAL/src/ui/ADWebAuthController.m @@ -346,7 +346,7 @@ - (BOOL)webAuthShouldStartLoadRequest:(NSURLRequest *)request AD_LOG_ERROR(@"unable to redirect to browser from extension", AD_ERROR_SERVER_UNSUPPORTED_REQUEST, _requestParams.correlationId, nil); } #else // !TARGET_OS_IPHONE - AD_LOG_ERROR(@"server is redirecting us to browser, this behavior is not defined on Mac OS X yet", AD_ERROR_SERVER_UNSUPPORTED_REQUEST, _correlationId, nil); + AD_LOG_ERROR(@"server is redirecting us to browser, this behavior is not defined on Mac OS X yet", AD_ERROR_SERVER_UNSUPPORTED_REQUEST, _requestParams.correlationId, nil); #endif // TARGET_OS_IPHONE return NO; } From cd5950476113d32e8a8583e6c7065866c80ff3f4 Mon Sep 17 00:00:00 2001 From: Yong Zeng Date: Thu, 10 Nov 2016 07:46:22 -0800 Subject: [PATCH 54/92] add back the broker telemetry hook which was deleted accidentally --- .../ADAuthenticationRequest+AcquireToken.m | 18 +++++++++++++++++- .../request/ADAuthenticationRequest+Broker.h | 2 ++ .../request/ADAuthenticationRequest+Broker.m | 4 ++-- 3 files changed, 21 insertions(+), 3 deletions(-) diff --git a/ADAL/src/request/ADAuthenticationRequest+AcquireToken.m b/ADAL/src/request/ADAuthenticationRequest+AcquireToken.m index 7cb81e889..8119ee816 100644 --- a/ADAL/src/request/ADAuthenticationRequest+AcquireToken.m +++ b/ADAL/src/request/ADAuthenticationRequest+AcquireToken.m @@ -32,6 +32,7 @@ #import "ADTelemetry.h" #import "ADTelemetry+Internal.h" #import "ADTelemetryAPIEvent.h" +#import "ADTelemetryBrokerEvent.h" #import "ADTelemetryEventStrings.h" #import "ADBrokerHelper.h" @@ -283,7 +284,19 @@ - (void)requestTokenImpl:(ADAuthenticationCallback)completionBlock completionBlock([ADAuthenticationResult resultFromError:error correlationId:_requestParams.correlationId]); return; } - [ADBrokerHelper invokeBroker:brokerURL completionHandler:completionBlock]; + + [[ADTelemetry sharedInstance] startEvent:[self telemetryRequestId] eventName:@"launch_broker"]; + [ADBrokerHelper invokeBroker:brokerURL completionHandler:^(ADAuthenticationResult* result) + { + ADTelemetryBrokerEvent* event = [[ADTelemetryBrokerEvent alloc] initWithName:@"launch_broker" + requestId:_requestParams.telemetryRequestId + correlationId:_requestParams.correlationId]; + [event setResultStatus:[result status]]; + [event setBrokerAppVersion:s_brokerAppVersion]; + [event setBrokerProtocolVersion:s_brokerProtocolVersion]; + [[ADTelemetry sharedInstance] stopEvent:[self telemetryRequestId] event:event]; + completionBlock(result); + }]; return; } #endif @@ -319,6 +332,9 @@ - (void)requestTokenImpl:(ADAuthenticationCallback)completionBlock #if TARGET_OS_IPHONE if([code hasPrefix:@"msauth://"]) { + [event setAPIStatus:@"try to prompt to install broker"]; + [[ADTelemetry sharedInstance] stopEvent:_requestParams.telemetryRequestId event:event]; + ADAuthenticationError* error = nil; NSURL* brokerRequestURL = [self composeBrokerRequest:&error]; if (!brokerRequestURL) diff --git a/ADAL/src/request/ADAuthenticationRequest+Broker.h b/ADAL/src/request/ADAuthenticationRequest+Broker.h index 5ca5eb317..2086f7cb1 100644 --- a/ADAL/src/request/ADAuthenticationRequest+Broker.h +++ b/ADAL/src/request/ADAuthenticationRequest+Broker.h @@ -24,6 +24,8 @@ typedef void(^ADAuthorizationCodeCallback)(NSString*, ADAuthenticationError*); extern NSString* kAdalResumeDictionaryKey; +extern NSString* s_brokerAppVersion; +extern NSString* s_brokerProtocolVersion; @interface ADAuthenticationRequest (Broker) diff --git a/ADAL/src/request/ADAuthenticationRequest+Broker.m b/ADAL/src/request/ADAuthenticationRequest+Broker.m index 2a212ca58..03ae43a4e 100644 --- a/ADAL/src/request/ADAuthenticationRequest+Broker.m +++ b/ADAL/src/request/ADAuthenticationRequest+Broker.m @@ -48,8 +48,8 @@ #import "ADKeychainUtil.h" #endif // TARGET_OS_IPHONE -static NSString* s_brokerAppVersion = nil; -static NSString* s_brokerProtocolVersion = nil; +NSString* s_brokerAppVersion = nil; +NSString* s_brokerProtocolVersion = nil; NSString* kAdalResumeDictionaryKey = @"adal-broker-resume-dictionary"; From 012db3f4d385fd764171002e721ceb529f5e54cd Mon Sep 17 00:00:00 2001 From: Yong Zeng Date: Thu, 10 Nov 2016 13:57:18 -0800 Subject: [PATCH 55/92] add prefix AD to all telemetry-related constants --- ADAL/src/cache/ADTokenCacheAccessor.m | 16 ++- .../ADAuthenticationRequest+AcquireToken.m | 6 +- ADAL/src/telemetry/ADTelemetry.m | 2 +- ADAL/src/telemetry/ADTelemetryAPIEvent.m | 82 +++++++------ ADAL/src/telemetry/ADTelemetryBrokerEvent.m | 10 +- ADAL/src/telemetry/ADTelemetryCacheEvent.h | 3 + ADAL/src/telemetry/ADTelemetryCacheEvent.m | 38 ++++-- ADAL/src/telemetry/ADTelemetryDefaultEvent.m | 8 +- ADAL/src/telemetry/ADTelemetryEventStrings.h | 112 +++++++++--------- ADAL/src/telemetry/ADTelemetryEventStrings.m | 110 +++++++++-------- ADAL/src/telemetry/ADTelemetryHttpEvent.m | 34 +++--- ADAL/src/telemetry/ADTelemetryUIEvent.m | 14 +-- ADAL/src/urlprotocol/ADURLProtocol.m | 4 +- 13 files changed, 238 insertions(+), 201 deletions(-) diff --git a/ADAL/src/cache/ADTokenCacheAccessor.m b/ADAL/src/cache/ADTokenCacheAccessor.m index ac0299657..51ff6148b 100644 --- a/ADAL/src/cache/ADTokenCacheAccessor.m +++ b/ADAL/src/cache/ADTokenCacheAccessor.m @@ -125,9 +125,11 @@ - (ADTokenCacheItem *)getMRRTItemForUser:(ADUserIdentifier *)identifier requestId:[context telemetryRequestId] correlationId:[context correlationId]]; [event setTokenType:@"multi-resource refresh token"]; + [event setMRRTStatus:AD_TELEMETRY_NOT_FOUND]; if (item) { - [event setIsMRRT:TELEMETRY_YES]; + [event setIsMRRT:AD_TELEMETRY_YES]; + [event setMRRTStatus:AD_TELEMETRY_TRIED]; } [event setStatus:item? @"succeeded" : @"failed"]; [[ADTelemetry sharedInstance] stopEvent:[context telemetryRequestId] event:event]; @@ -152,9 +154,11 @@ - (ADTokenCacheItem *)getFRTItemForUser:(ADUserIdentifier *)identifier ADTelemetryCacheEvent* event = [[ADTelemetryCacheEvent alloc] initWithName:@"token_cache_lookup" context:context]; [event setTokenType:@"family refresh token"]; + [event setFRTStatus:AD_TELEMETRY_NOT_FOUND]; if (item) { - [event setIsFRT:TELEMETRY_YES]; + [event setIsFRT:AD_TELEMETRY_YES]; + [event setFRTStatus:AD_TELEMETRY_TRIED]; } [event setStatus:item? @"succeeded" : @"failed"]; [[ADTelemetry sharedInstance] stopEvent:[context telemetryRequestId] event:event]; @@ -185,9 +189,11 @@ - (ADTokenCacheItem*)getADFSUserTokenForResource:(NSString *)resource ADTelemetryCacheEvent* event = [[ADTelemetryCacheEvent alloc] initWithName:@"token_cache_lookup" context:context]; [event setTokenType:@"ADFS access token/refresh token"]; + [event setRTStatus:AD_TELEMETRY_NOT_FOUND]; if ([item refreshToken]) { - [event setIsRT:TELEMETRY_YES]; + [event setIsRT:AD_TELEMETRY_YES]; + [event setRTStatus:AD_TELEMETRY_TRIED]; } [event setStatus:item? @"succeeded" : @"failed"]; [[ADTelemetry sharedInstance] stopEvent:[context telemetryRequestId] event:event]; @@ -271,7 +277,7 @@ - (void)updateCacheToItem:(ADTokenCacheItem *)cacheItem [_dataSource addOrUpdateItem:multiRefreshTokenItem correlationId:correlationId error:nil]; ADTelemetryCacheEvent* event = [[ADTelemetryCacheEvent alloc] initWithName:@"token_cache_write" context:context]; - [event setIsMRRT:TELEMETRY_YES]; + [event setIsMRRT:AD_TELEMETRY_YES]; [event setTokenType:@"multi-resource refresh token"]; [[ADTelemetry sharedInstance] stopEvent:telemetryRequestId event:event]; SAFE_ARC_RELEASE(event); @@ -291,7 +297,7 @@ - (void)updateCacheToItem:(ADTokenCacheItem *)cacheItem ADTelemetryCacheEvent* event = [[ADTelemetryCacheEvent alloc] initWithName:@"token_cache_write" context:context]; - [event setIsFRT:TELEMETRY_YES]; + [event setIsFRT:AD_TELEMETRY_YES]; [event setTokenType:@"family refresh token"]; [[ADTelemetry sharedInstance] stopEvent:telemetryRequestId event:event]; SAFE_ARC_RELEASE(event); diff --git a/ADAL/src/request/ADAuthenticationRequest+AcquireToken.m b/ADAL/src/request/ADAuthenticationRequest+AcquireToken.m index 8119ee816..2accc4917 100644 --- a/ADAL/src/request/ADAuthenticationRequest+AcquireToken.m +++ b/ADAL/src/request/ADAuthenticationRequest+AcquireToken.m @@ -80,11 +80,11 @@ - (void)acquireToken:(NSString *)eventName [event setCorrelationId:self.correlationId]; [event setClientId:_requestParams.clientId]; - [event setExtendedExpiresOnSetting:[_requestParams extendedLifetime]? TELEMETRY_YES:TELEMETRY_NO]; + [event setExtendedExpiresOnSetting:[_requestParams extendedLifetime]? AD_TELEMETRY_YES:AD_TELEMETRY_NO]; [event setPromptBehavior:_promptBehavior]; [event setUserInformation:[[result tokenCacheItem] userInformation]]; [event setResultStatus:result.status]; - [event setIsExtendedLifeTimeToken:[result extendedLifeTimeToken]? TELEMETRY_YES:TELEMETRY_NO]; + [event setIsExtendedLifeTimeToken:[result extendedLifeTimeToken]? AD_TELEMETRY_YES:AD_TELEMETRY_NO]; [event setErrorCode:[NSString stringWithFormat:@"%ld",(long)[result.error code]]]; [event setErrorDomain:[result.error domain]]; [event setProtocolCode:[[result error] protocolCode]]; @@ -146,7 +146,7 @@ - (void)acquireToken:(NSString *)eventName (void)validated; ADTelemetryAPIEvent* event = [[ADTelemetryAPIEvent alloc] initWithName:@"authority_validation" context:_requestParams]; - [event setAuthorityValidationStatus:validated ? TELEMETRY_YES:TELEMETRY_NO]; + [event setAuthorityValidationStatus:validated ? AD_TELEMETRY_YES:AD_TELEMETRY_NO]; [event setAuthority:_context.authority]; [[ADTelemetry sharedInstance] stopEvent:telemetryRequestId event:event]; SAFE_ARC_RELEASE(event); diff --git a/ADAL/src/telemetry/ADTelemetry.m b/ADAL/src/telemetry/ADTelemetry.m index 8d7fc137e..a0860cbbb 100644 --- a/ADAL/src/telemetry/ADTelemetry.m +++ b/ADAL/src/telemetry/ADTelemetry.m @@ -115,7 +115,7 @@ - (void)stopEvent:(NSString*)requestId event:(id)event { NSDate* stopTime = [NSDate date]; - NSString* eventName = [self getPropertyFromEvent:event propertyName:TELEMETRY_EVENT_NAME]; + NSString* eventName = [self getPropertyFromEvent:event propertyName:AD_TELEMETRY_EVENT_NAME]; if ([NSString adIsStringNilOrBlank:requestId] || [NSString adIsStringNilOrBlank:eventName] || !event) { diff --git a/ADAL/src/telemetry/ADTelemetryAPIEvent.m b/ADAL/src/telemetry/ADTelemetryAPIEvent.m index fb6ae2c7f..4769ec1b7 100644 --- a/ADAL/src/telemetry/ADTelemetryAPIEvent.m +++ b/ADAL/src/telemetry/ADTelemetryAPIEvent.m @@ -33,100 +33,100 @@ - (void)setResultStatus:(ADAuthenticationResultStatus)status NSString* statusStr = nil; switch (status) { case AD_SUCCEEDED: - statusStr = TELEMETRY_SUCCEEDED; + statusStr = AD_TELEMETRY_SUCCEEDED; break; case AD_FAILED: - statusStr = TELEMETRY_FAILED; + statusStr = AD_TELEMETRY_FAILED; break; case AD_USER_CANCELLED: - statusStr = TELEMETRY_USER_CANCELLED; - [self setProperty:TELEMETRY_USER_CANCEL value:TELEMETRY_YES]; + statusStr = AD_TELEMETRY_USER_CANCELLED; + [self setProperty:AD_TELEMETRY_USER_CANCEL value:AD_TELEMETRY_YES]; break; default: - statusStr = TELEMETRY_UNKNOWN; + statusStr = AD_TELEMETRY_UNKNOWN; } - [self setProperty:TELEMETRY_RESULT_STATUS value:statusStr]; + [self setProperty:AD_TELEMETRY_RESULT_STATUS value:statusStr]; } - (void)setCorrelationId:(NSUUID*)correlationId { - [self setProperty:TELEMETRY_CORRELATION_ID value:[correlationId UUIDString]]; + [self setProperty:AD_TELEMETRY_CORRELATION_ID value:[correlationId UUIDString]]; } - (void)setExtendedExpiresOnSetting:(NSString*)extendedExpiresOnSetting { - [self setProperty:TELEMETRY_EXTENDED_EXPIRES_ON_SETTING value:extendedExpiresOnSetting]; + [self setProperty:AD_TELEMETRY_EXTENDED_EXPIRES_ON_SETTING value:extendedExpiresOnSetting]; } - (void)setUserInformation:(ADUserInformation*)userInfo { - [self setProperty:TELEMETRY_USER_ID value:[[userInfo userId] adComputeSHA256]]; - [self setProperty:TELEMETRY_TENANT_ID value:[[userInfo tenantId] adComputeSHA256]]; - [self setProperty:TELEMETRY_IDP value:[userInfo identityProvider]]; + [self setProperty:AD_TELEMETRY_USER_ID value:[[userInfo userId] adComputeSHA256]]; + [self setProperty:AD_TELEMETRY_TENANT_ID value:[[userInfo tenantId] adComputeSHA256]]; + [self setProperty:AD_TELEMETRY_IDP value:[userInfo identityProvider]]; } - (void)setClientId:(NSString*)clientId { - [self setProperty:TELEMETRY_CLIENT_ID value:clientId]; + [self setProperty:AD_TELEMETRY_CLIENT_ID value:clientId]; } - (void)setIsExtendedLifeTimeToken:(NSString*)isExtendedLifeToken { - [self setProperty:TELEMETRY_IS_EXTENED_LIFE_TIME_TOKEN value:isExtendedLifeToken]; + [self setProperty:AD_TELEMETRY_IS_EXTENED_LIFE_TIME_TOKEN value:isExtendedLifeToken]; } - (void)setErrorCode:(NSString*)errorCode { - [self setProperty:TELEMETRY_ERROR_CODE value:errorCode]; + [self setProperty:AD_TELEMETRY_ERROR_CODE value:errorCode]; } - (void)setProtocolCode:(NSString*)protocolCode { - [self setProperty:TELEMETRY_PROTOCOL_CODE value:protocolCode]; + [self setProperty:AD_TELEMETRY_PROTOCOL_CODE value:protocolCode]; } - (void)setErrorDescription:(NSString*)errorDescription { - [self setProperty:TELEMETRY_ERROR_DESCRIPTION value:errorDescription]; + [self setProperty:AD_TELEMETRY_ERROR_DESCRIPTION value:errorDescription]; } - (void)setErrorDomain:(NSString*)errorDomain { - [self setProperty:TELEMETRY_ERROR_DOMAIN value:errorDomain]; + [self setProperty:AD_TELEMETRY_ERROR_DOMAIN value:errorDomain]; } - (void)setAuthorityValidationStatus:(NSString*)status { - [self setProperty:TELEMETRY_AUTHORITY_VALIDATION_STATUS value:status]; + [self setProperty:AD_TELEMETRY_AUTHORITY_VALIDATION_STATUS value:status]; } - (void)setAuthority:(NSString*)authority { - [self setProperty:TELEMETRY_AUTHORITY value:authority]; + [self setProperty:AD_TELEMETRY_AUTHORITY value:authority]; // set authority type - NSString* authorityType = TELEMETRY_AUTHORITY_AAD; + NSString* authorityType = AD_TELEMETRY_AUTHORITY_AAD; if ([ADHelpers isADFSInstance:authority]) { - authorityType = TELEMETRY_AUTHORITY_ADFS; + authorityType = AD_TELEMETRY_AUTHORITY_ADFS; } - [self setProperty:TELEMETRY_AUTHORITY_TYPE value:authorityType]; + [self setProperty:AD_TELEMETRY_AUTHORITY_TYPE value:authorityType]; } - (void)setGrantType:(NSString*)grantType { - [self setProperty:TELEMETRY_GRANT_TYPE value:grantType]; + [self setProperty:AD_TELEMETRY_GRANT_TYPE value:grantType]; } - (void)setAPIStatus:(NSString*)status { - [self setProperty:TELEMETRY_API_STATUS value:status]; + [self setProperty:AD_TELEMETRY_API_STATUS value:status]; } - (void)setApiId:(NSString*)apiId { - [self setProperty:TELEMETRY_API_ID value:apiId]; + [self setProperty:AD_TELEMETRY_API_ID value:apiId]; } - (void)setPromptBehavior:(ADPromptBehavior)promptBehavior @@ -146,10 +146,10 @@ - (void)setPromptBehavior:(ADPromptBehavior)promptBehavior promptBehaviorString = @"AD_FORCE_PROMPT"; break; default: - promptBehaviorString = TELEMETRY_UNKNOWN; + promptBehaviorString = AD_TELEMETRY_UNKNOWN; } - [self setProperty:TELEMETRY_PROMPT_BEHAVIOR value:promptBehaviorString]; + [self setProperty:AD_TELEMETRY_PROMPT_BEHAVIOR value:promptBehaviorString]; } - (void)processEvent:(NSMutableDictionary*)eventToBeDispatched @@ -159,18 +159,22 @@ - (void)processEvent:(NSMutableDictionary*)eventToBeDispatched NSArray* properties = [self getProperties]; for (NSArray* property in properties) { - if ([property[0] isEqualToString:TELEMETRY_AUTHORITY_TYPE] - ||[property[0] isEqualToString:TELEMETRY_AUTHORITY_VALIDATION_STATUS] - ||[property[0] isEqualToString:TELEMETRY_EXTENDED_EXPIRES_ON_SETTING] - ||[property[0] isEqualToString:TELEMETRY_PROMPT_BEHAVIOR] - ||[property[0] isEqualToString:TELEMETRY_RESULT_STATUS] - ||[property[0] isEqualToString:TELEMETRY_IDP] - ||[property[0] isEqualToString:TELEMETRY_TENANT_ID] - ||[property[0] isEqualToString:TELEMETRY_USER_ID] - ||[property[0] isEqualToString:TELEMETRY_RESPONSE_TIME] - ||[property[0] isEqualToString:TELEMETRY_CLIENT_ID] - ||[property[0] isEqualToString:TELEMETRY_API_ID] - ||[property[0] isEqualToString:TELEMETRY_USER_CANCEL]) + if ([property[0] isEqualToString:AD_TELEMETRY_AUTHORITY_TYPE] + ||[property[0] isEqualToString:AD_TELEMETRY_AUTHORITY_VALIDATION_STATUS] + ||[property[0] isEqualToString:AD_TELEMETRY_EXTENDED_EXPIRES_ON_SETTING] + ||[property[0] isEqualToString:AD_TELEMETRY_PROMPT_BEHAVIOR] + ||[property[0] isEqualToString:AD_TELEMETRY_RESULT_STATUS] + ||[property[0] isEqualToString:AD_TELEMETRY_IDP] + ||[property[0] isEqualToString:AD_TELEMETRY_TENANT_ID] + ||[property[0] isEqualToString:AD_TELEMETRY_USER_ID] + ||[property[0] isEqualToString:AD_TELEMETRY_RESPONSE_TIME] + ||[property[0] isEqualToString:AD_TELEMETRY_CLIENT_ID] + ||[property[0] isEqualToString:AD_TELEMETRY_API_ID] + ||[property[0] isEqualToString:AD_TELEMETRY_USER_CANCEL] + ||[property[0] isEqualToString:AD_TELEMETRY_ERROR_CODE] + ||[property[0] isEqualToString:AD_TELEMETRY_ERROR_DOMAIN] + ||[property[0] isEqualToString:AD_TELEMETRY_PROTOCOL_CODE] + ||[property[0] isEqualToString:AD_TELEMETRY_ERROR_DESCRIPTION]) { [eventToBeDispatched setObject:property[1] forKey:property[0]]; } diff --git a/ADAL/src/telemetry/ADTelemetryBrokerEvent.m b/ADAL/src/telemetry/ADTelemetryBrokerEvent.m index b800f0689..c475c7a0e 100644 --- a/ADAL/src/telemetry/ADTelemetryBrokerEvent.m +++ b/ADAL/src/telemetry/ADTelemetryBrokerEvent.m @@ -43,7 +43,7 @@ - (id)initWithName:(NSString*)eventName - (void)setBrokerAppVersion:(NSString*)version { - [self setProperty:TELEMETRY_BROKER_VERSION value:version]; + [self setProperty:AD_TELEMETRY_BROKER_VERSION value:version]; } - (void)setBrokerProtocolVersion:(NSString*)version @@ -73,7 +73,7 @@ - (void)setResultStatus:(ADAuthenticationResultStatus)status - (void)setBrokerApp:(NSString*)appName { - [self setProperty:TELEMETRY_BROKER_APP value:appName]; + [self setProperty:AD_TELEMETRY_BROKER_APP value:appName]; } - (void)processEvent:(NSMutableDictionary*)eventToBeDispatched @@ -84,13 +84,13 @@ - (void)processEvent:(NSMutableDictionary*)eventToBeDispatched NSArray* properties = [self getProperties]; for (NSArray* property in properties) { - if ([property[0] isEqualToString:TELEMETRY_BROKER_APP] - ||[property[0] isEqualToString:TELEMETRY_BROKER_VERSION]) + if ([property[0] isEqualToString:AD_TELEMETRY_BROKER_APP] + ||[property[0] isEqualToString:AD_TELEMETRY_BROKER_VERSION]) { [eventToBeDispatched setObject:property[1] forKey:property[0]]; } } - [eventToBeDispatched setObject:TELEMETRY_YES forKey:TELEMETRY_BROKER_APP_USED]; + [eventToBeDispatched setObject:AD_TELEMETRY_YES forKey:AD_TELEMETRY_BROKER_APP_USED]; } @end diff --git a/ADAL/src/telemetry/ADTelemetryCacheEvent.h b/ADAL/src/telemetry/ADTelemetryCacheEvent.h index f51ae3658..c7abf7fdc 100644 --- a/ADAL/src/telemetry/ADTelemetryCacheEvent.h +++ b/ADAL/src/telemetry/ADTelemetryCacheEvent.h @@ -30,5 +30,8 @@ - (void)setIsRT:(NSString*)isRT; - (void)setIsMRRT:(NSString*)isMRRT; - (void)setIsFRT:(NSString*)isFRT; +- (void)setRTStatus:(NSString*)status; +- (void)setMRRTStatus:(NSString*)status; +- (void)setFRTStatus:(NSString*)status; @end \ No newline at end of file diff --git a/ADAL/src/telemetry/ADTelemetryCacheEvent.m b/ADAL/src/telemetry/ADTelemetryCacheEvent.m index 931166253..b023c3723 100644 --- a/ADAL/src/telemetry/ADTelemetryCacheEvent.m +++ b/ADAL/src/telemetry/ADTelemetryCacheEvent.m @@ -28,7 +28,7 @@ @implementation ADTelemetryCacheEvent - (void)setTokenType:(NSString*)tokenType { - [self setProperty:TELEMETRY_TOKEN_TYPE value:tokenType]; + [self setProperty:AD_TELEMETRY_TOKEN_TYPE value:tokenType]; } - (void)setStatus:(NSString*)status @@ -38,17 +38,32 @@ - (void)setStatus:(NSString*)status - (void)setIsRT:(NSString*)isRT { - [self setProperty:TELEMETRY_IS_RT value:isRT]; + [self setProperty:AD_TELEMETRY_IS_RT value:isRT]; } - (void)setIsMRRT:(NSString*)isMRRT { - [self setProperty:TELEMETRY_IS_MRRT value:isMRRT]; + [self setProperty:AD_TELEMETRY_IS_MRRT value:isMRRT]; } - (void)setIsFRT:(NSString*)isFRT { - [self setProperty:TELEMETRY_IS_FRT value:isFRT]; + [self setProperty:AD_TELEMETRY_IS_FRT value:isFRT]; +} + +- (void)setRTStatus:(NSString*)status +{ + [self setProperty:AD_TELEMETRY_RT_STATUS value:status]; +} + +- (void)setMRRTStatus:(NSString*)status +{ + [self setProperty:AD_TELEMETRY_MRRT_STATUS value:status]; +} + +- (void)setFRTStatus:(NSString*)status +{ + [self setProperty:AD_TELEMETRY_FRT_STATUS value:status]; } - (void)processEvent:(NSMutableDictionary*)eventToBeDispatched @@ -59,23 +74,20 @@ - (void)processEvent:(NSMutableDictionary*)eventToBeDispatched NSArray* properties = [self getProperties]; for (NSArray* property in properties) { - if ([property[0] isEqualToString:TELEMETRY_IS_RT] - ||[property[0] isEqualToString:TELEMETRY_IS_MRRT] - ||[property[0] isEqualToString:TELEMETRY_IS_FRT]) + if ([property[0] isEqualToString:AD_TELEMETRY_RT_STATUS] + ||[property[0] isEqualToString:AD_TELEMETRY_FRT_STATUS] + ||[property[0] isEqualToString:AD_TELEMETRY_MRRT_STATUS]) { - [eventToBeDispatched removeObjectForKey:TELEMETRY_IS_RT]; - [eventToBeDispatched removeObjectForKey:TELEMETRY_IS_MRRT]; - [eventToBeDispatched removeObjectForKey:TELEMETRY_IS_FRT]; [eventToBeDispatched setObject:property[1] forKey:property[0]]; } } int cacheEventCount = 1; - if ([eventToBeDispatched objectForKey:TELEMETRY_CACHE_EVENT_COUNT]) + if ([eventToBeDispatched objectForKey:AD_TELEMETRY_CACHE_EVENT_COUNT]) { - cacheEventCount = [[eventToBeDispatched objectForKey:TELEMETRY_CACHE_EVENT_COUNT] intValue] + 1; + cacheEventCount = [[eventToBeDispatched objectForKey:AD_TELEMETRY_CACHE_EVENT_COUNT] intValue] + 1; } - [eventToBeDispatched setObject:[NSString stringWithFormat:@"%d", cacheEventCount] forKey:TELEMETRY_CACHE_EVENT_COUNT]; + [eventToBeDispatched setObject:[NSString stringWithFormat:@"%d", cacheEventCount] forKey:AD_TELEMETRY_CACHE_EVENT_COUNT]; } @end \ No newline at end of file diff --git a/ADAL/src/telemetry/ADTelemetryDefaultEvent.m b/ADAL/src/telemetry/ADTelemetryDefaultEvent.m index 4896cbc8c..fc12f2425 100644 --- a/ADAL/src/telemetry/ADTelemetryDefaultEvent.m +++ b/ADAL/src/telemetry/ADTelemetryDefaultEvent.m @@ -60,11 +60,11 @@ - (id)initWithName:(NSString*)eventName } _propertyMap = [[self defaultParameters] mutableCopy]; - SET_IF_NOT_NIL(_propertyMap, TELEMETRY_REQUEST_ID, requestId); - SET_IF_NOT_NIL(_propertyMap, TELEMETRY_CORRELATION_ID, [correlationId UUIDString]); + SET_IF_NOT_NIL(_propertyMap, AD_TELEMETRY_REQUEST_ID, requestId); + SET_IF_NOT_NIL(_propertyMap, AD_TELEMETRY_CORRELATION_ID, [correlationId UUIDString]); _defaultPropertyCount = [_propertyMap count]; - SET_IF_NOT_NIL(_propertyMap, TELEMETRY_EVENT_NAME, eventName); + SET_IF_NOT_NIL(_propertyMap, AD_TELEMETRY_EVENT_NAME, eventName); return self; } @@ -114,7 +114,7 @@ - (void)setStopTime:(NSDate*)time - (void)setResponseTime:(NSTimeInterval)responseTime { //the property is set in milliseconds - [_propertyMap addObject:@[TELEMETRY_RESPONSE_TIME, [NSString stringWithFormat:@"%f", responseTime*1000]]]; + [_propertyMap addObject:@[AD_TELEMETRY_RESPONSE_TIME, [NSString stringWithFormat:@"%f", responseTime*1000]]]; } - (NSString*)getStringFromDate:(NSDate*)date diff --git a/ADAL/src/telemetry/ADTelemetryEventStrings.h b/ADAL/src/telemetry/ADTelemetryEventStrings.h index 15b5c5c27..9906f2efb 100644 --- a/ADAL/src/telemetry/ADTelemetryEventStrings.h +++ b/ADAL/src/telemetry/ADTelemetryEventStrings.h @@ -23,56 +23,62 @@ #pragma once -extern NSString *const TELEMETRY_AUTHORITY_TYPE; -extern NSString *const TELEMETRY_AUTHORITY_VALIDATION_STATUS; -extern NSString *const TELEMETRY_EXTENDED_EXPIRES_ON_SETTING; -extern NSString *const TELEMETRY_PROMPT_BEHAVIOR; -extern NSString *const TELEMETRY_RESULT_STATUS; -extern NSString *const TELEMETRY_IDP; -extern NSString *const TELEMETRY_TENANT_ID; -extern NSString *const TELEMETRY_USER_ID; -extern NSString *const TELEMETRY_RESPONSE_TIME; -extern NSString *const TELEMETRY_LOGIN_HINT; -extern NSString *const TELEMETRY_NTLM_HANDLED; -extern NSString *const TELEMETRY_UI_EVENT_COUNT; -extern NSString *const TELEMETRY_BROKER_APP; -extern NSString *const TELEMETRY_BROKER_VERSION; -extern NSString *const TELEMETRY_BROKER_APP_USED; -extern NSString *const TELEMETRY_CLIENT_ID; -extern NSString *const TELEMETRY_HTTP_EVENT_COUNT; -extern NSString *const TELEMETRY_CACHE_EVENT_COUNT; -extern NSString *const TELEMETRY_API_ID; -extern NSString *const TELEMETRY_TOKEN_TYPE; -extern NSString *const TELEMETRY_USER_CANCEL; -extern NSString *const TELEMETRY_IS_RT; -extern NSString *const TELEMETRY_IS_MRRT; -extern NSString *const TELEMETRY_IS_FRT; -extern NSString *const TELEMETRY_YES; -extern NSString *const TELEMETRY_NO; -extern NSString *const TELEMETRY_SUCCEEDED; -extern NSString *const TELEMETRY_FAILED; -extern NSString *const TELEMETRY_USER_CANCELLED; -extern NSString *const TELEMETRY_UNKNOWN; -extern NSString *const TELEMETRY_CORRELATION_ID; -extern NSString *const TELEMETRY_CLIENT_ID; -extern NSString *const TELEMETRY_IS_EXTENED_LIFE_TIME_TOKEN; -extern NSString *const TELEMETRY_ERROR_CODE; -extern NSString *const TELEMETRY_PROTOCOL_CODE; -extern NSString *const TELEMETRY_ERROR_DESCRIPTION; -extern NSString *const TELEMETRY_ERROR_DOMAIN; -extern NSString *const TELEMETRY_HTTP_METHOD; -extern NSString *const TELEMETRY_HTTP_PATH; -extern NSString *const TELEMETRY_HTTP_REQUEST_ID_HEADER; -extern NSString *const TELEMETRY_HTTP_RESPONSE_CODE; -extern NSString *const TELEMETRY_OAUTH_ERROR_CODE; -extern NSString *const TELEMETRY_HTTP_RESPONSE_METHOD; -extern NSString *const TELEMETRY_REQUEST_QUERY_PARAMS; -extern NSString *const TELEMETRY_USER_AGENT; -extern NSString *const TELEMETRY_HTTP_ERROR_DOMAIN; -extern NSString *const TELEMETRY_AUTHORITY; -extern NSString *const TELEMETRY_AUTHORITY_AAD; -extern NSString *const TELEMETRY_AUTHORITY_ADFS; -extern NSString *const TELEMETRY_GRANT_TYPE; -extern NSString *const TELEMETRY_API_STATUS; -extern NSString *const TELEMETRY_EVENT_NAME; -extern NSString *const TELEMETRY_REQUEST_ID; \ No newline at end of file +extern NSString *const AD_TELEMETRY_AUTHORITY_TYPE; +extern NSString *const AD_TELEMETRY_AUTHORITY_VALIDATION_STATUS; +extern NSString *const AD_TELEMETRY_EXTENDED_EXPIRES_ON_SETTING; +extern NSString *const AD_TELEMETRY_PROMPT_BEHAVIOR; +extern NSString *const AD_TELEMETRY_RESULT_STATUS; +extern NSString *const AD_TELEMETRY_IDP; +extern NSString *const AD_TELEMETRY_TENANT_ID; +extern NSString *const AD_TELEMETRY_USER_ID; +extern NSString *const AD_TELEMETRY_RESPONSE_TIME; +extern NSString *const AD_TELEMETRY_LOGIN_HINT; +extern NSString *const AD_TELEMETRY_NTLM_HANDLED; +extern NSString *const AD_TELEMETRY_UI_EVENT_COUNT; +extern NSString *const AD_TELEMETRY_BROKER_APP; +extern NSString *const AD_TELEMETRY_BROKER_VERSION; +extern NSString *const AD_TELEMETRY_BROKER_APP_USED; +extern NSString *const AD_TELEMETRY_CLIENT_ID; +extern NSString *const AD_TELEMETRY_HTTP_EVENT_COUNT; +extern NSString *const AD_TELEMETRY_CACHE_EVENT_COUNT; +extern NSString *const AD_TELEMETRY_API_ID; +extern NSString *const AD_TELEMETRY_TOKEN_TYPE; +extern NSString *const AD_TELEMETRY_USER_CANCEL; +extern NSString *const AD_TELEMETRY_IS_RT; +extern NSString *const AD_TELEMETRY_IS_MRRT; +extern NSString *const AD_TELEMETRY_IS_FRT; +extern NSString *const AD_TELEMETRY_RT_STATUS; +extern NSString *const AD_TELEMETRY_MRRT_STATUS; +extern NSString *const AD_TELEMETRY_FRT_STATUS; +extern NSString *const AD_TELEMETRY_TRIED; +extern NSString *const AD_TELEMETRY_NOT_FOUND; +extern NSString *const AD_TELEMETRY_NO_NEED; +extern NSString *const AD_TELEMETRY_YES; +extern NSString *const AD_TELEMETRY_NO; +extern NSString *const AD_TELEMETRY_SUCCEEDED; +extern NSString *const AD_TELEMETRY_FAILED; +extern NSString *const AD_TELEMETRY_USER_CANCELLED; +extern NSString *const AD_TELEMETRY_UNKNOWN; +extern NSString *const AD_TELEMETRY_CORRELATION_ID; +extern NSString *const AD_TELEMETRY_CLIENT_ID; +extern NSString *const AD_TELEMETRY_IS_EXTENED_LIFE_TIME_TOKEN; +extern NSString *const AD_TELEMETRY_ERROR_CODE; +extern NSString *const AD_TELEMETRY_PROTOCOL_CODE; +extern NSString *const AD_TELEMETRY_ERROR_DESCRIPTION; +extern NSString *const AD_TELEMETRY_ERROR_DOMAIN; +extern NSString *const AD_TELEMETRY_HTTP_METHOD; +extern NSString *const AD_TELEMETRY_HTTP_PATH; +extern NSString *const AD_TELEMETRY_HTTP_REQUEST_ID_HEADER; +extern NSString *const AD_TELEMETRY_HTTP_RESPONSE_CODE; +extern NSString *const AD_TELEMETRY_OAUTH_ERROR_CODE; +extern NSString *const AD_TELEMETRY_HTTP_RESPONSE_METHOD; +extern NSString *const AD_TELEMETRY_REQUEST_QUERY_PARAMS; +extern NSString *const AD_TELEMETRY_USER_AGENT; +extern NSString *const AD_TELEMETRY_HTTP_ERROR_DOMAIN; +extern NSString *const AD_TELEMETRY_AUTHORITY; +extern NSString *const AD_TELEMETRY_AUTHORITY_AAD; +extern NSString *const AD_TELEMETRY_AUTHORITY_ADFS; +extern NSString *const AD_TELEMETRY_GRANT_TYPE; +extern NSString *const AD_TELEMETRY_API_STATUS; +extern NSString *const AD_TELEMETRY_EVENT_NAME; +extern NSString *const AD_TELEMETRY_REQUEST_ID; \ No newline at end of file diff --git a/ADAL/src/telemetry/ADTelemetryEventStrings.m b/ADAL/src/telemetry/ADTelemetryEventStrings.m index 54238904e..7694da98a 100644 --- a/ADAL/src/telemetry/ADTelemetryEventStrings.m +++ b/ADAL/src/telemetry/ADTelemetryEventStrings.m @@ -23,55 +23,61 @@ #import "ADTelemetryEventStrings.h" -NSString *const TELEMETRY_AUTHORITY_TYPE = @"authority_type"; -NSString *const TELEMETRY_AUTHORITY_VALIDATION_STATUS = @"authority_validation_status"; -NSString *const TELEMETRY_EXTENDED_EXPIRES_ON_SETTING = @"extended_expires_on_setting"; -NSString *const TELEMETRY_PROMPT_BEHAVIOR = @"prompt_behavior"; -NSString *const TELEMETRY_RESULT_STATUS = @"status"; -NSString *const TELEMETRY_IDP = @"idp"; -NSString *const TELEMETRY_TENANT_ID = @"tenant_id"; -NSString *const TELEMETRY_USER_ID = @"user_id"; -NSString *const TELEMETRY_RESPONSE_TIME = @"response_time"; -NSString *const TELEMETRY_LOGIN_HINT = @"login_hint"; -NSString *const TELEMETRY_NTLM_HANDLED = @"ntlm"; -NSString *const TELEMETRY_UI_EVENT_COUNT = @"ui_event_count"; -NSString *const TELEMETRY_BROKER_APP = @"broker_app"; -NSString *const TELEMETRY_BROKER_VERSION = @"broker_version"; -NSString *const TELEMETRY_BROKER_APP_USED = @"broker_app_used"; -NSString *const TELEMETRY_CLIENT_ID = @"client_id"; -NSString *const TELEMETRY_HTTP_EVENT_COUNT = @"http_event_count"; -NSString *const TELEMETRY_CACHE_EVENT_COUNT = @"cache_event_count"; -NSString *const TELEMETRY_API_ID = @"api_id"; -NSString *const TELEMETRY_TOKEN_TYPE = @"token_type"; -NSString *const TELEMETRY_USER_CANCEL = @"user_cancel"; -NSString *const TELEMETRY_IS_RT = @"is_rt"; -NSString *const TELEMETRY_IS_MRRT = @"is_mrrt"; -NSString *const TELEMETRY_IS_FRT = @"is_frt"; -NSString *const TELEMETRY_YES = @"yes"; -NSString *const TELEMETRY_NO = @"no"; -NSString *const TELEMETRY_SUCCEEDED = @"succeeded"; -NSString *const TELEMETRY_FAILED = @"failed"; -NSString *const TELEMETRY_USER_CANCELLED = @"user_cancelled"; -NSString *const TELEMETRY_UNKNOWN = @"unknown"; -NSString *const TELEMETRY_CORRELATION_ID = @"correlation_id"; -NSString *const TELEMETRY_IS_EXTENED_LIFE_TIME_TOKEN = @"is_extended_life_time_token"; -NSString *const TELEMETRY_ERROR_CODE = @"error_code"; -NSString *const TELEMETRY_PROTOCOL_CODE = @"protocol_code"; -NSString *const TELEMETRY_ERROR_DESCRIPTION = @"error_description"; -NSString *const TELEMETRY_ERROR_DOMAIN = @"error_domain"; -NSString *const TELEMETRY_HTTP_METHOD = @"http_method"; -NSString *const TELEMETRY_HTTP_PATH = @"http_path"; -NSString *const TELEMETRY_HTTP_REQUEST_ID_HEADER = @"x-ms-request-id"; -NSString *const TELEMETRY_HTTP_RESPONSE_CODE = @"http_response_code"; -NSString *const TELEMETRY_OAUTH_ERROR_CODE = @"oauth_error_code"; -NSString *const TELEMETRY_HTTP_RESPONSE_METHOD = @"http_response_method"; -NSString *const TELEMETRY_REQUEST_QUERY_PARAMS = @"request_query_params"; -NSString *const TELEMETRY_USER_AGENT = @"user_agent"; -NSString *const TELEMETRY_HTTP_ERROR_DOMAIN = @"http_error_domain"; -NSString *const TELEMETRY_AUTHORITY = @"authority"; -NSString *const TELEMETRY_AUTHORITY_AAD = @"aad"; -NSString *const TELEMETRY_AUTHORITY_ADFS = @"adfs"; -NSString *const TELEMETRY_GRANT_TYPE = @"grant_type"; -NSString *const TELEMETRY_API_STATUS = @"api_status"; -NSString *const TELEMETRY_EVENT_NAME = @"event_name"; -NSString *const TELEMETRY_REQUEST_ID = @"request_id"; \ No newline at end of file +NSString *const AD_TELEMETRY_AUTHORITY_TYPE = @"authority_type"; +NSString *const AD_TELEMETRY_AUTHORITY_VALIDATION_STATUS = @"authority_validation_status"; +NSString *const AD_TELEMETRY_EXTENDED_EXPIRES_ON_SETTING = @"extended_expires_on_setting"; +NSString *const AD_TELEMETRY_PROMPT_BEHAVIOR = @"prompt_behavior"; +NSString *const AD_TELEMETRY_RESULT_STATUS = @"status"; +NSString *const AD_TELEMETRY_IDP = @"idp"; +NSString *const AD_TELEMETRY_TENANT_ID = @"tenant_id"; +NSString *const AD_TELEMETRY_USER_ID = @"user_id"; +NSString *const AD_TELEMETRY_RESPONSE_TIME = @"response_time"; +NSString *const AD_TELEMETRY_LOGIN_HINT = @"login_hint"; +NSString *const AD_TELEMETRY_NTLM_HANDLED = @"ntlm"; +NSString *const AD_TELEMETRY_UI_EVENT_COUNT = @"ui_event_count"; +NSString *const AD_TELEMETRY_BROKER_APP = @"broker_app"; +NSString *const AD_TELEMETRY_BROKER_VERSION = @"broker_version"; +NSString *const AD_TELEMETRY_BROKER_APP_USED = @"broker_app_used"; +NSString *const AD_TELEMETRY_CLIENT_ID = @"client_id"; +NSString *const AD_TELEMETRY_HTTP_EVENT_COUNT = @"http_event_count"; +NSString *const AD_TELEMETRY_CACHE_EVENT_COUNT = @"cache_event_count"; +NSString *const AD_TELEMETRY_API_ID = @"api_id"; +NSString *const AD_TELEMETRY_TOKEN_TYPE = @"token_type"; +NSString *const AD_TELEMETRY_USER_CANCEL = @"user_cancel"; +NSString *const AD_TELEMETRY_IS_RT = @"is_rt"; +NSString *const AD_TELEMETRY_IS_MRRT = @"is_mrrt"; +NSString *const AD_TELEMETRY_IS_FRT = @"is_frt"; +NSString *const AD_TELEMETRY_RT_STATUS = @"token_rt_status"; +NSString *const AD_TELEMETRY_MRRT_STATUS = @"token_mrrt_status"; +NSString *const AD_TELEMETRY_FRT_STATUS = @"token_frt_status"; +NSString *const AD_TELEMETRY_TRIED = @"tried"; +NSString *const AD_TELEMETRY_NOT_FOUND = @"not_found"; +NSString *const AD_TELEMETRY_NO_NEED = @"no_need"; +NSString *const AD_TELEMETRY_YES = @"yes"; +NSString *const AD_TELEMETRY_NO = @"no"; +NSString *const AD_TELEMETRY_SUCCEEDED = @"succeeded"; +NSString *const AD_TELEMETRY_FAILED = @"failed"; +NSString *const AD_TELEMETRY_USER_CANCELLED = @"user_cancelled"; +NSString *const AD_TELEMETRY_UNKNOWN = @"unknown"; +NSString *const AD_TELEMETRY_CORRELATION_ID = @"correlation_id"; +NSString *const AD_TELEMETRY_IS_EXTENED_LIFE_TIME_TOKEN = @"is_extended_life_time_token"; +NSString *const AD_TELEMETRY_ERROR_CODE = @"error_code"; +NSString *const AD_TELEMETRY_PROTOCOL_CODE = @"protocol_code"; +NSString *const AD_TELEMETRY_ERROR_DESCRIPTION = @"error_description"; +NSString *const AD_TELEMETRY_ERROR_DOMAIN = @"error_domain"; +NSString *const AD_TELEMETRY_HTTP_METHOD = @"http_method"; +NSString *const AD_TELEMETRY_HTTP_PATH = @"http_path"; +NSString *const AD_TELEMETRY_HTTP_REQUEST_ID_HEADER = @"x-ms-request-id"; +NSString *const AD_TELEMETRY_HTTP_RESPONSE_CODE = @"http_response_code"; +NSString *const AD_TELEMETRY_OAUTH_ERROR_CODE = @"oauth_error_code"; +NSString *const AD_TELEMETRY_HTTP_RESPONSE_METHOD = @"http_response_method"; +NSString *const AD_TELEMETRY_REQUEST_QUERY_PARAMS = @"request_query_params"; +NSString *const AD_TELEMETRY_USER_AGENT = @"user_agent"; +NSString *const AD_TELEMETRY_HTTP_ERROR_DOMAIN = @"http_error_domain"; +NSString *const AD_TELEMETRY_AUTHORITY = @"authority"; +NSString *const AD_TELEMETRY_AUTHORITY_AAD = @"aad"; +NSString *const AD_TELEMETRY_AUTHORITY_ADFS = @"adfs"; +NSString *const AD_TELEMETRY_GRANT_TYPE = @"grant_type"; +NSString *const AD_TELEMETRY_API_STATUS = @"api_status"; +NSString *const AD_TELEMETRY_EVENT_NAME = @"event_name"; +NSString *const AD_TELEMETRY_REQUEST_ID = @"request_id"; \ No newline at end of file diff --git a/ADAL/src/telemetry/ADTelemetryHttpEvent.m b/ADAL/src/telemetry/ADTelemetryHttpEvent.m index 969706503..9a93b9d67 100644 --- a/ADAL/src/telemetry/ADTelemetryHttpEvent.m +++ b/ADAL/src/telemetry/ADTelemetryHttpEvent.m @@ -28,47 +28,47 @@ @implementation ADTelemetryHttpEvent - (void)setHttpMethod:(NSString*)method { - [self setProperty:TELEMETRY_HTTP_METHOD value:method]; + [self setProperty:AD_TELEMETRY_HTTP_METHOD value:method]; } - (void)setHttpPath:(NSString*)path { - [self setProperty:TELEMETRY_HTTP_PATH value:path]; + [self setProperty:AD_TELEMETRY_HTTP_PATH value:path]; } - (void)setHttpRequestIdHeader:(NSString*)requestIdHeader { - [self setProperty:TELEMETRY_HTTP_REQUEST_ID_HEADER value:requestIdHeader]; + [self setProperty:AD_TELEMETRY_HTTP_REQUEST_ID_HEADER value:requestIdHeader]; } - (void)setHttpResponseCode:(NSString*)code { - [self setProperty:TELEMETRY_HTTP_RESPONSE_CODE value:code]; + [self setProperty:AD_TELEMETRY_HTTP_RESPONSE_CODE value:code]; } - (void)setOAuthErrorCode:(NSString*)code { - [self setProperty:TELEMETRY_OAUTH_ERROR_CODE value:code]; + [self setProperty:AD_TELEMETRY_OAUTH_ERROR_CODE value:code]; } - (void)setHttpResponseMethod:(NSString*)method { - [self setProperty:TELEMETRY_HTTP_RESPONSE_METHOD value:method]; + [self setProperty:AD_TELEMETRY_HTTP_RESPONSE_METHOD value:method]; } - (void)setHttpRequestQueryParams:(NSString*)params { - [self setProperty:TELEMETRY_REQUEST_QUERY_PARAMS value:params]; + [self setProperty:AD_TELEMETRY_REQUEST_QUERY_PARAMS value:params]; } - (void)setHttpUserAgent:(NSString*)userAgent { - [self setProperty:TELEMETRY_USER_AGENT value:userAgent]; + [self setProperty:AD_TELEMETRY_USER_AGENT value:userAgent]; } - (void)setHttpErrorDomain:(NSString*)errorDomain { - [self setProperty:TELEMETRY_HTTP_ERROR_DOMAIN value:errorDomain]; + [self setProperty:AD_TELEMETRY_HTTP_ERROR_DOMAIN value:errorDomain]; } - (void)processEvent:(NSMutableDictionary*)eventToBeDispatched @@ -78,20 +78,20 @@ - (void)processEvent:(NSMutableDictionary*)eventToBeDispatched (void)eventToBeDispatched; int httpEventCount = 1; - if ([eventToBeDispatched objectForKey:TELEMETRY_HTTP_EVENT_COUNT]) + if ([eventToBeDispatched objectForKey:AD_TELEMETRY_HTTP_EVENT_COUNT]) { - httpEventCount = [[eventToBeDispatched objectForKey:TELEMETRY_HTTP_EVENT_COUNT] intValue] + 1; + httpEventCount = [[eventToBeDispatched objectForKey:AD_TELEMETRY_HTTP_EVENT_COUNT] intValue] + 1; } - [eventToBeDispatched setObject:[NSString stringWithFormat:@"%d", httpEventCount] forKey:TELEMETRY_HTTP_EVENT_COUNT]; + [eventToBeDispatched setObject:[NSString stringWithFormat:@"%d", httpEventCount] forKey:AD_TELEMETRY_HTTP_EVENT_COUNT]; NSArray* properties = [self getProperties]; for (NSArray* property in properties) { - if ([property[0] isEqualToString:TELEMETRY_HTTP_RESPONSE_CODE] - ||[property[0] isEqualToString:TELEMETRY_OAUTH_ERROR_CODE] - ||[property[0] isEqualToString:TELEMETRY_HTTP_ERROR_DOMAIN] - ||[property[0] isEqualToString:TELEMETRY_HTTP_PATH] - ||[property[0] isEqualToString:TELEMETRY_HTTP_REQUEST_ID_HEADER]) + if ([property[0] isEqualToString:AD_TELEMETRY_HTTP_RESPONSE_CODE] + ||[property[0] isEqualToString:AD_TELEMETRY_OAUTH_ERROR_CODE] + ||[property[0] isEqualToString:AD_TELEMETRY_HTTP_ERROR_DOMAIN] + ||[property[0] isEqualToString:AD_TELEMETRY_HTTP_PATH] + ||[property[0] isEqualToString:AD_TELEMETRY_HTTP_REQUEST_ID_HEADER]) { [eventToBeDispatched setObject:property[1] forKey:property[0]]; } diff --git a/ADAL/src/telemetry/ADTelemetryUIEvent.m b/ADAL/src/telemetry/ADTelemetryUIEvent.m index 6612c1dd3..bb4d29109 100644 --- a/ADAL/src/telemetry/ADTelemetryUIEvent.m +++ b/ADAL/src/telemetry/ADTelemetryUIEvent.m @@ -28,12 +28,12 @@ @implementation ADTelemetryUIEvent - (void)setLoginHint:(NSString*)hint { - [self setProperty:TELEMETRY_LOGIN_HINT value:[hint adComputeSHA256]]; + [self setProperty:AD_TELEMETRY_LOGIN_HINT value:[hint adComputeSHA256]]; } - (void)setNtlm:(NSString*)ntlmHandled { - [self setProperty:TELEMETRY_NTLM_HANDLED value:ntlmHandled]; + [self setProperty:AD_TELEMETRY_NTLM_HANDLED value:ntlmHandled]; } - (void)processEvent:(NSMutableDictionary*)eventToBeDispatched @@ -44,19 +44,19 @@ - (void)processEvent:(NSMutableDictionary*)eventToBeDispatched NSArray* properties = [self getProperties]; for (NSArray* property in properties) { - if ([property[0] isEqualToString:TELEMETRY_LOGIN_HINT] - ||[property[0] isEqualToString:TELEMETRY_NTLM_HANDLED]) + if ([property[0] isEqualToString:AD_TELEMETRY_LOGIN_HINT] + ||[property[0] isEqualToString:AD_TELEMETRY_NTLM_HANDLED]) { [eventToBeDispatched setObject:property[1] forKey:property[0]]; } } int UIEventCount = 1; - if ([eventToBeDispatched objectForKey:TELEMETRY_UI_EVENT_COUNT]) + if ([eventToBeDispatched objectForKey:AD_TELEMETRY_UI_EVENT_COUNT]) { - UIEventCount = [[eventToBeDispatched objectForKey:TELEMETRY_UI_EVENT_COUNT] intValue] + 1; + UIEventCount = [[eventToBeDispatched objectForKey:AD_TELEMETRY_UI_EVENT_COUNT] intValue] + 1; } - [eventToBeDispatched setObject:[NSString stringWithFormat:@"%d", UIEventCount] forKey:TELEMETRY_UI_EVENT_COUNT]; + [eventToBeDispatched setObject:[NSString stringWithFormat:@"%d", UIEventCount] forKey:AD_TELEMETRY_UI_EVENT_COUNT]; } @end \ No newline at end of file diff --git a/ADAL/src/urlprotocol/ADURLProtocol.m b/ADAL/src/urlprotocol/ADURLProtocol.m index 4a0b4c188..55954495e 100755 --- a/ADAL/src/urlprotocol/ADURLProtocol.m +++ b/ADAL/src/urlprotocol/ADURLProtocol.m @@ -217,9 +217,9 @@ - (void)connection:(NSURLConnection *)connection return; } - if ([authMethod isEqualToString:NSURLAuthenticationMethodNTLM]) + if ([authMethod caseInsensitiveCompare:NSURLAuthenticationMethodNTLM] == NSOrderedSame) { - [s_telemetryEvent setNtlm:TELEMETRY_YES]; + [s_telemetryEvent setNtlm:AD_TELEMETRY_YES]; } } From 6cabea1ec93d681d98d82f70df086a5406ccd558 Mon Sep 17 00:00:00 2001 From: Yong Zeng Date: Thu, 10 Nov 2016 17:57:05 -0800 Subject: [PATCH 56/92] rename function processEvent, add class ADTelemetryProperty --- ADAL/src/telemetry/ADAggregatedDispatcher.m | 4 +- ADAL/src/telemetry/ADTelemetry.h | 22 +++++++++- ADAL/src/telemetry/ADTelemetry.m | 27 ++++++++++-- ADAL/src/telemetry/ADTelemetryAPIEvent.m | 41 ++++++++++--------- ADAL/src/telemetry/ADTelemetryBrokerEvent.m | 13 +++--- ADAL/src/telemetry/ADTelemetryCacheEvent.m | 15 +++---- ADAL/src/telemetry/ADTelemetryDefaultEvent.m | 18 ++++---- .../src/telemetry/ADTelemetryEventInterface.h | 2 +- ADAL/src/telemetry/ADTelemetryHttpEvent.m | 19 +++++---- ADAL/src/telemetry/ADTelemetryUIEvent.m | 13 +++--- ADAL/tests/ADTelemetryTests.m | 10 ++--- 11 files changed, 116 insertions(+), 68 deletions(-) diff --git a/ADAL/src/telemetry/ADAggregatedDispatcher.m b/ADAL/src/telemetry/ADAggregatedDispatcher.m index 81eed3171..02fc015ed 100644 --- a/ADAL/src/telemetry/ADAggregatedDispatcher.m +++ b/ADAL/src/telemetry/ADAggregatedDispatcher.m @@ -50,7 +50,7 @@ - (void)flush:(NSString*)requestId NSMutableDictionary* aggregatedEventMap = [NSMutableDictionary new]; for (id event in eventsToBeDispatched) { - [event processEvent:aggregatedEventMap]; + [event addAggregatedPropertiesToDictionary:aggregatedEventMap]; } // convert the aggregated event from a map to a list @@ -58,7 +58,7 @@ - (void)flush:(NSString*)requestId SAFE_ARC_AUTORELEASE(aggregatedEvent); for (NSString* key in aggregatedEventMap) { - [aggregatedEvent addObject:@[key, [aggregatedEventMap objectForKey:key]]]; + [aggregatedEvent addObject:[[ADTelemetryProperty alloc] initWithName:key value:[aggregatedEventMap objectForKey:key]]]; } [_dispatcher dispatchEvent:aggregatedEvent]; } diff --git a/ADAL/src/telemetry/ADTelemetry.h b/ADAL/src/telemetry/ADTelemetry.h index b75153dc4..26a83c052 100644 --- a/ADAL/src/telemetry/ADTelemetry.h +++ b/ADAL/src/telemetry/ADTelemetry.h @@ -34,13 +34,31 @@ /*! Callback function that will be called by ADAL when telemetry events are flushed. - @param event An array of property-value pairs. Each pair is also stored in an array whose size is 2. - So event is a two-dimentional array. + @param event An event is represented by an array of ADTelemetryProperty. */ - (void)dispatchEvent:(NSArray*)event; @end +/*! + @class ADTelemetryProperty + + Each telemetry event dispatched to the above callback function is represented by an array of ADTelemetryProperty. + It includes property name and property value. + */ +@interface ADTelemetryProperty : NSObject +{ + NSString* _name; + NSString* _value; +} + +@property (readonly) NSString* name; +@property (readonly) NSString* value; + +- (id)initWithName:(NSString*)name value:(NSString*)value; + +@end + /*! @class ADTelemetry diff --git a/ADAL/src/telemetry/ADTelemetry.m b/ADAL/src/telemetry/ADTelemetry.m index a0860cbbb..7339cf595 100644 --- a/ADAL/src/telemetry/ADTelemetry.m +++ b/ADAL/src/telemetry/ADTelemetry.m @@ -158,11 +158,11 @@ - (NSString*)getPropertyFromEvent:(id)event propertyName:(NSString*)propertyName { NSArray* properties = [event getProperties]; - for (NSArray* propertyValuePair in properties) + for (ADTelemetryProperty* property in properties) { - if ([[propertyValuePair objectAtIndex:0] isEqualToString:propertyName]) + if ([property.name isEqualToString:propertyName]) { - return [propertyValuePair objectAtIndex:1]; + return [property value]; } } return nil; @@ -179,4 +179,25 @@ - (void)flush:(NSString*)requestId } } +@end + +@implementation ADTelemetryProperty + +@synthesize name = _name; +@synthesize value = _value; + +- (id)initWithName:(NSString*)name + value:(NSString*)value +{ + if (!(self = [super init])) + { + return nil; + } + + _name = name; + _value = value; + + return self; +} + @end \ No newline at end of file diff --git a/ADAL/src/telemetry/ADTelemetryAPIEvent.m b/ADAL/src/telemetry/ADTelemetryAPIEvent.m index 4769ec1b7..6de57dc4c 100644 --- a/ADAL/src/telemetry/ADTelemetryAPIEvent.m +++ b/ADAL/src/telemetry/ADTelemetryAPIEvent.m @@ -21,6 +21,7 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN // THE SOFTWARE. +#import "ADTelemetry.h" #import "ADTelemetryAPIEvent.h" #import "ADUserInformation.h" #import "ADTelemetryEventStrings.h" @@ -152,31 +153,31 @@ - (void)setPromptBehavior:(ADPromptBehavior)promptBehavior [self setProperty:AD_TELEMETRY_PROMPT_BEHAVIOR value:promptBehaviorString]; } -- (void)processEvent:(NSMutableDictionary*)eventToBeDispatched +- (void)addAggregatedPropertiesToDictionary:(NSMutableDictionary*)eventToBeDispatched { - [super processEvent:eventToBeDispatched]; + [super addAggregatedPropertiesToDictionary:eventToBeDispatched]; NSArray* properties = [self getProperties]; - for (NSArray* property in properties) + for (ADTelemetryProperty* property in properties) { - if ([property[0] isEqualToString:AD_TELEMETRY_AUTHORITY_TYPE] - ||[property[0] isEqualToString:AD_TELEMETRY_AUTHORITY_VALIDATION_STATUS] - ||[property[0] isEqualToString:AD_TELEMETRY_EXTENDED_EXPIRES_ON_SETTING] - ||[property[0] isEqualToString:AD_TELEMETRY_PROMPT_BEHAVIOR] - ||[property[0] isEqualToString:AD_TELEMETRY_RESULT_STATUS] - ||[property[0] isEqualToString:AD_TELEMETRY_IDP] - ||[property[0] isEqualToString:AD_TELEMETRY_TENANT_ID] - ||[property[0] isEqualToString:AD_TELEMETRY_USER_ID] - ||[property[0] isEqualToString:AD_TELEMETRY_RESPONSE_TIME] - ||[property[0] isEqualToString:AD_TELEMETRY_CLIENT_ID] - ||[property[0] isEqualToString:AD_TELEMETRY_API_ID] - ||[property[0] isEqualToString:AD_TELEMETRY_USER_CANCEL] - ||[property[0] isEqualToString:AD_TELEMETRY_ERROR_CODE] - ||[property[0] isEqualToString:AD_TELEMETRY_ERROR_DOMAIN] - ||[property[0] isEqualToString:AD_TELEMETRY_PROTOCOL_CODE] - ||[property[0] isEqualToString:AD_TELEMETRY_ERROR_DESCRIPTION]) + if ([property.name isEqualToString:AD_TELEMETRY_AUTHORITY_TYPE] + ||[property.name isEqualToString:AD_TELEMETRY_AUTHORITY_VALIDATION_STATUS] + ||[property.name isEqualToString:AD_TELEMETRY_EXTENDED_EXPIRES_ON_SETTING] + ||[property.name isEqualToString:AD_TELEMETRY_PROMPT_BEHAVIOR] + ||[property.name isEqualToString:AD_TELEMETRY_RESULT_STATUS] + ||[property.name isEqualToString:AD_TELEMETRY_IDP] + ||[property.name isEqualToString:AD_TELEMETRY_TENANT_ID] + ||[property.name isEqualToString:AD_TELEMETRY_USER_ID] + ||[property.name isEqualToString:AD_TELEMETRY_RESPONSE_TIME] + ||[property.name isEqualToString:AD_TELEMETRY_CLIENT_ID] + ||[property.name isEqualToString:AD_TELEMETRY_API_ID] + ||[property.name isEqualToString:AD_TELEMETRY_USER_CANCEL] + ||[property.name isEqualToString:AD_TELEMETRY_ERROR_CODE] + ||[property.name isEqualToString:AD_TELEMETRY_ERROR_DOMAIN] + ||[property.name isEqualToString:AD_TELEMETRY_PROTOCOL_CODE] + ||[property.name isEqualToString:AD_TELEMETRY_ERROR_DESCRIPTION]) { - [eventToBeDispatched setObject:property[1] forKey:property[0]]; + [eventToBeDispatched setObject:property.value forKey:property.name]; } } } diff --git a/ADAL/src/telemetry/ADTelemetryBrokerEvent.m b/ADAL/src/telemetry/ADTelemetryBrokerEvent.m index c475c7a0e..c16922403 100644 --- a/ADAL/src/telemetry/ADTelemetryBrokerEvent.m +++ b/ADAL/src/telemetry/ADTelemetryBrokerEvent.m @@ -21,6 +21,7 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN // THE SOFTWARE. +#import "ADTelemetry.h" #import "ADTelemetryBrokerEvent.h" #import "ADTelemetryEventStrings.h" @@ -76,18 +77,18 @@ - (void)setBrokerApp:(NSString*)appName [self setProperty:AD_TELEMETRY_BROKER_APP value:appName]; } -- (void)processEvent:(NSMutableDictionary*)eventToBeDispatched +- (void)addAggregatedPropertiesToDictionary:(NSMutableDictionary*)eventToBeDispatched { - [super processEvent:eventToBeDispatched]; + [super addAggregatedPropertiesToDictionary:eventToBeDispatched]; (void)eventToBeDispatched; NSArray* properties = [self getProperties]; - for (NSArray* property in properties) + for (ADTelemetryProperty* property in properties) { - if ([property[0] isEqualToString:AD_TELEMETRY_BROKER_APP] - ||[property[0] isEqualToString:AD_TELEMETRY_BROKER_VERSION]) + if ([property.name isEqualToString:AD_TELEMETRY_BROKER_APP] + ||[property.name isEqualToString:AD_TELEMETRY_BROKER_VERSION]) { - [eventToBeDispatched setObject:property[1] forKey:property[0]]; + [eventToBeDispatched setObject:property.value forKey:property.name]; } } [eventToBeDispatched setObject:AD_TELEMETRY_YES forKey:AD_TELEMETRY_BROKER_APP_USED]; diff --git a/ADAL/src/telemetry/ADTelemetryCacheEvent.m b/ADAL/src/telemetry/ADTelemetryCacheEvent.m index b023c3723..2af78358d 100644 --- a/ADAL/src/telemetry/ADTelemetryCacheEvent.m +++ b/ADAL/src/telemetry/ADTelemetryCacheEvent.m @@ -21,6 +21,7 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN // THE SOFTWARE. +#import "ADTelemetry.h" #import "ADTelemetryCacheEvent.h" #import "ADTelemetryEventStrings.h" @@ -66,19 +67,19 @@ - (void)setFRTStatus:(NSString*)status [self setProperty:AD_TELEMETRY_FRT_STATUS value:status]; } -- (void)processEvent:(NSMutableDictionary*)eventToBeDispatched +- (void)addAggregatedPropertiesToDictionary:(NSMutableDictionary*)eventToBeDispatched { - [super processEvent:eventToBeDispatched]; + [super addAggregatedPropertiesToDictionary:eventToBeDispatched]; (void)eventToBeDispatched; NSArray* properties = [self getProperties]; - for (NSArray* property in properties) + for (ADTelemetryProperty* property in properties) { - if ([property[0] isEqualToString:AD_TELEMETRY_RT_STATUS] - ||[property[0] isEqualToString:AD_TELEMETRY_FRT_STATUS] - ||[property[0] isEqualToString:AD_TELEMETRY_MRRT_STATUS]) + if ([property.name isEqualToString:AD_TELEMETRY_RT_STATUS] + ||[property.name isEqualToString:AD_TELEMETRY_FRT_STATUS] + ||[property.name isEqualToString:AD_TELEMETRY_MRRT_STATUS]) { - [eventToBeDispatched setObject:property[1] forKey:property[0]]; + [eventToBeDispatched setObject:property.value forKey:property.name]; } } diff --git a/ADAL/src/telemetry/ADTelemetryDefaultEvent.m b/ADAL/src/telemetry/ADTelemetryDefaultEvent.m index fc12f2425..4e5695648 100644 --- a/ADAL/src/telemetry/ADTelemetryDefaultEvent.m +++ b/ADAL/src/telemetry/ADTelemetryDefaultEvent.m @@ -21,6 +21,7 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN // THE SOFTWARE. +#import "ADTelemetry.h" #import "ADTelemetryDefaultEvent.h" #import "ADTelemetryEventInterface.h" #import "ADTelemetryEventStrings.h" @@ -35,7 +36,7 @@ { \ if (OBJECT) \ { \ -[(DICT) addObject:@[(NAME), (OBJECT)]]; \ +[(DICT) addObject:[[ADTelemetryProperty alloc] initWithName:(NAME) value:(OBJECT)]]; \ } \ } @@ -83,7 +84,7 @@ - (void)setProperty:(NSString*)name value:(NSString*)value return; } - [_propertyMap addObject:@[name, value]]; + [_propertyMap addObject:[[ADTelemetryProperty alloc] initWithName:name value:value]]; } - (NSArray*)getProperties @@ -98,7 +99,7 @@ - (void)setStartTime:(NSDate*)time return; } - [_propertyMap addObject:@[@"start_time", [self getStringFromDate:time]]]; + [_propertyMap addObject:[[ADTelemetryProperty alloc] initWithName:@"start_time" value:[self getStringFromDate:time]]]; } - (void)setStopTime:(NSDate*)time @@ -108,13 +109,14 @@ - (void)setStopTime:(NSDate*)time return; } - [_propertyMap addObject:@[@"stop_time", [self getStringFromDate:time]]]; + [_propertyMap addObject:[[ADTelemetryProperty alloc] initWithName:@"stop_time" value:[self getStringFromDate:time]]]; } - (void)setResponseTime:(NSTimeInterval)responseTime { //the property is set in milliseconds - [_propertyMap addObject:@[AD_TELEMETRY_RESPONSE_TIME, [NSString stringWithFormat:@"%f", responseTime*1000]]]; + [_propertyMap addObject:[[ADTelemetryProperty alloc] initWithName:AD_TELEMETRY_RESPONSE_TIME + value:[NSString stringWithFormat:@"%f", responseTime*1000]]]; } - (NSString*)getStringFromDate:(NSDate*)date @@ -131,11 +133,13 @@ - (NSString*)getStringFromDate:(NSDate*)date return [s_dateFormatter stringFromDate:date]; } -- (void)processEvent:(NSMutableDictionary*)eventToBeDispatched +- (void)addAggregatedPropertiesToDictionary:(NSMutableDictionary*)eventToBeDispatched { for (int i=0; i<[self getDefaultPropertyCount]; i++) { - [eventToBeDispatched setObject:_propertyMap[i][1] forKey:_propertyMap[i][0]]; + NSString* propertyName = [(ADTelemetryProperty*)_propertyMap[i] name]; + NSString* propertyValue = [(ADTelemetryProperty*)_propertyMap[i] value]; + [eventToBeDispatched setObject:propertyValue forKey:propertyName]; } } diff --git a/ADAL/src/telemetry/ADTelemetryEventInterface.h b/ADAL/src/telemetry/ADTelemetryEventInterface.h index dd7bb4fae..f9d85246a 100644 --- a/ADAL/src/telemetry/ADTelemetryEventInterface.h +++ b/ADAL/src/telemetry/ADTelemetryEventInterface.h @@ -31,6 +31,6 @@ - (void)setStartTime:(NSDate*)time; - (void)setStopTime:(NSDate*)time; - (void)setResponseTime:(NSTimeInterval)responseTime; -- (void)processEvent:(NSMutableDictionary*)eventToBeDispatched; +- (void)addAggregatedPropertiesToDictionary:(NSMutableDictionary*)eventToBeDispatched; @end \ No newline at end of file diff --git a/ADAL/src/telemetry/ADTelemetryHttpEvent.m b/ADAL/src/telemetry/ADTelemetryHttpEvent.m index 9a93b9d67..3798f9c7e 100644 --- a/ADAL/src/telemetry/ADTelemetryHttpEvent.m +++ b/ADAL/src/telemetry/ADTelemetryHttpEvent.m @@ -21,6 +21,7 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN // THE SOFTWARE. +#import "ADTelemetry.h" #import "ADTelemetryHttpEvent.h" #import "ADTelemetryEventStrings.h" @@ -71,9 +72,9 @@ - (void)setHttpErrorDomain:(NSString*)errorDomain [self setProperty:AD_TELEMETRY_HTTP_ERROR_DOMAIN value:errorDomain]; } -- (void)processEvent:(NSMutableDictionary*)eventToBeDispatched +- (void)addAggregatedPropertiesToDictionary:(NSMutableDictionary*)eventToBeDispatched { - [super processEvent:eventToBeDispatched]; + [super addAggregatedPropertiesToDictionary:eventToBeDispatched]; (void)eventToBeDispatched; @@ -85,15 +86,15 @@ - (void)processEvent:(NSMutableDictionary*)eventToBeDispatched [eventToBeDispatched setObject:[NSString stringWithFormat:@"%d", httpEventCount] forKey:AD_TELEMETRY_HTTP_EVENT_COUNT]; NSArray* properties = [self getProperties]; - for (NSArray* property in properties) + for (ADTelemetryProperty* property in properties) { - if ([property[0] isEqualToString:AD_TELEMETRY_HTTP_RESPONSE_CODE] - ||[property[0] isEqualToString:AD_TELEMETRY_OAUTH_ERROR_CODE] - ||[property[0] isEqualToString:AD_TELEMETRY_HTTP_ERROR_DOMAIN] - ||[property[0] isEqualToString:AD_TELEMETRY_HTTP_PATH] - ||[property[0] isEqualToString:AD_TELEMETRY_HTTP_REQUEST_ID_HEADER]) + if ([property.name isEqualToString:AD_TELEMETRY_HTTP_RESPONSE_CODE] + ||[property.name isEqualToString:AD_TELEMETRY_OAUTH_ERROR_CODE] + ||[property.name isEqualToString:AD_TELEMETRY_HTTP_ERROR_DOMAIN] + ||[property.name isEqualToString:AD_TELEMETRY_HTTP_PATH] + ||[property.name isEqualToString:AD_TELEMETRY_HTTP_REQUEST_ID_HEADER]) { - [eventToBeDispatched setObject:property[1] forKey:property[0]]; + [eventToBeDispatched setObject:property.value forKey:property.name]; } } } diff --git a/ADAL/src/telemetry/ADTelemetryUIEvent.m b/ADAL/src/telemetry/ADTelemetryUIEvent.m index bb4d29109..6f1cbda87 100644 --- a/ADAL/src/telemetry/ADTelemetryUIEvent.m +++ b/ADAL/src/telemetry/ADTelemetryUIEvent.m @@ -21,6 +21,7 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN // THE SOFTWARE. +#import "ADTelemetry.h" #import "ADTelemetryUIEvent.h" #import "ADTelemetryEventStrings.h" @@ -36,18 +37,18 @@ - (void)setNtlm:(NSString*)ntlmHandled [self setProperty:AD_TELEMETRY_NTLM_HANDLED value:ntlmHandled]; } -- (void)processEvent:(NSMutableDictionary*)eventToBeDispatched +- (void)addAggregatedPropertiesToDictionary:(NSMutableDictionary*)eventToBeDispatched { - [super processEvent:eventToBeDispatched]; + [super addAggregatedPropertiesToDictionary:eventToBeDispatched]; (void)eventToBeDispatched; NSArray* properties = [self getProperties]; - for (NSArray* property in properties) + for (ADTelemetryProperty* property in properties) { - if ([property[0] isEqualToString:AD_TELEMETRY_LOGIN_HINT] - ||[property[0] isEqualToString:AD_TELEMETRY_NTLM_HANDLED]) + if ([property.name isEqualToString:AD_TELEMETRY_LOGIN_HINT] + ||[property.name isEqualToString:AD_TELEMETRY_NTLM_HANDLED]) { - [eventToBeDispatched setObject:property[1] forKey:property[0]]; + [eventToBeDispatched setObject:property.value forKey:property.name]; } } diff --git a/ADAL/tests/ADTelemetryTests.m b/ADAL/tests/ADTelemetryTests.m index be6af086e..c1101e765 100644 --- a/ADAL/tests/ADTelemetryTests.m +++ b/ADAL/tests/ADTelemetryTests.m @@ -587,11 +587,11 @@ - (void)testComplexEventsWithAggregation { - (NSString*)getPropertyFromEvent:(NSArray*)event propertyName:(NSString*)propertyName { - for (NSArray* propertyValuePair in event) + for (ADTelemetryProperty* property in event) { - if ([[propertyValuePair objectAtIndex:0] isEqualToString:propertyName]) + if ([property.name isEqualToString:propertyName]) { - return [propertyValuePair objectAtIndex:1]; + return property.value; } } return nil; @@ -601,9 +601,9 @@ - (NSInteger)getPropertyCount:(NSArray*)event propertyName:(NSString*)propertyName { NSInteger count = 0; - for (NSArray* propertyValuePair in event) + for (ADTelemetryProperty* property in event) { - if ([[propertyValuePair objectAtIndex:0] isEqualToString:propertyName]) + if ([property.name isEqualToString:propertyName]) { count++; } From b39dd743e72991b5320f30a8a1d94df29a846848 Mon Sep 17 00:00:00 2001 From: Yong Zeng Date: Sun, 13 Nov 2016 20:42:59 -0800 Subject: [PATCH 57/92] nil out _authenticationViewController after web view timeout, execute completion block for raw response case --- ADAL/src/request/ADWebAuthResponse.m | 1 + ADAL/src/ui/ADWebAuthController.m | 2 ++ 2 files changed, 3 insertions(+) diff --git a/ADAL/src/request/ADWebAuthResponse.m b/ADAL/src/request/ADWebAuthResponse.m index 97871f3b8..17a04e0cd 100644 --- a/ADAL/src/request/ADWebAuthResponse.m +++ b/ADAL/src/request/ADWebAuthResponse.m @@ -106,6 +106,7 @@ - (void)handleResponse:(ADWebResponse *)webResponse [_responseDictionary setObject:rawResponse forKey:@"raw_response"]; SAFE_ARC_RELEASE(rawResponse); + completionBlock(_responseDictionary); break; } case 400: diff --git a/ADAL/src/ui/ADWebAuthController.m b/ADAL/src/ui/ADWebAuthController.m index f1feec46f..476a7152c 100755 --- a/ADAL/src/ui/ADWebAuthController.m +++ b/ADAL/src/ui/ADWebAuthController.m @@ -258,6 +258,8 @@ - (void)failWithTimeout ADAuthenticationError* adError = [ADAuthenticationError errorFromNSError:error errorDetails:@"WebView timed out" correlationId:_requestParams.correlationId]; [self dispatchCompletionBlock:adError URL:nil]; }]; + SAFE_ARC_RELEASE(_authenticationViewController); + _authenticationViewController = nil; } #pragma mark - ADWebAuthDelegate From 098aa43ed6ab7cc27e33374426860b0b6a159e0c Mon Sep 17 00:00:00 2001 From: Yong Zeng Date: Mon, 14 Nov 2016 15:45:30 -0800 Subject: [PATCH 58/92] change break to return for safety --- ADAL/src/request/ADWebAuthResponse.m | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ADAL/src/request/ADWebAuthResponse.m b/ADAL/src/request/ADWebAuthResponse.m index 17a04e0cd..e2d860949 100644 --- a/ADAL/src/request/ADWebAuthResponse.m +++ b/ADAL/src/request/ADWebAuthResponse.m @@ -107,7 +107,7 @@ - (void)handleResponse:(ADWebResponse *)webResponse forKey:@"raw_response"]; SAFE_ARC_RELEASE(rawResponse); completionBlock(_responseDictionary); - break; + return; } case 400: case 401: From a23e2950b1dbc5fa8dcc585a73b70a5de2e3d47d Mon Sep 17 00:00:00 2001 From: Ryan Pangrle Date: Tue, 15 Nov 2016 17:25:04 -0800 Subject: [PATCH 59/92] Separate out the text-and-button view This little bit of view code is going to be used in other viewcontrollers in our app, so in proper MVC fashion I'm splitting it out. I also rewrote the layout constraints code to use APIs available in iOS 8 --- ADAL/ADAL.xcodeproj/project.pbxproj | 19 ++-- .../ADAutoInputViewController.m | 64 +++++------ ADAL/ADALAutomation/ADTextAndButtonView.h | 31 ++++++ ADAL/ADALAutomation/ADTextAndButtonView.m | 101 ++++++++++++++++++ 4 files changed, 171 insertions(+), 44 deletions(-) create mode 100644 ADAL/ADALAutomation/ADTextAndButtonView.h create mode 100644 ADAL/ADALAutomation/ADTextAndButtonView.m diff --git a/ADAL/ADAL.xcodeproj/project.pbxproj b/ADAL/ADAL.xcodeproj/project.pbxproj index 34081471d..ab5b1c082 100755 --- a/ADAL/ADAL.xcodeproj/project.pbxproj +++ b/ADAL/ADAL.xcodeproj/project.pbxproj @@ -64,9 +64,9 @@ 605C16821D8FD0AC0097DBA0 /* ADTelemetryEventStrings.m in Sources */ = {isa = PBXBuildFile; fileRef = 605C16801D8FD0AC0097DBA0 /* ADTelemetryEventStrings.m */; }; 605C16831D8FD1AC0097DBA0 /* ADTelemetryEventStrings.m in Sources */ = {isa = PBXBuildFile; fileRef = 605C16801D8FD0AC0097DBA0 /* ADTelemetryEventStrings.m */; }; 6071B5E41C14C0B0006F6CC2 /* ADTestURLConnection.m in Sources */ = {isa = PBXBuildFile; fileRef = 6071B5E31C14C0B0006F6CC2 /* ADTestURLConnection.m */; }; + 60C351BA1DA0D588006C8435 /* ADAL.m in Sources */ = {isa = PBXBuildFile; fileRef = 60C351B91DA0D588006C8435 /* ADAL.m */; }; 60D2F3FF1D524F7A008725D9 /* ADRequestParameters.h in Headers */ = {isa = PBXBuildFile; fileRef = 60D2F3FE1D524F7A008725D9 /* ADRequestParameters.h */; }; 60D2F4021D531F16008725D9 /* ADRequestParameters.m in Sources */ = {isa = PBXBuildFile; fileRef = 60D2F4001D531F16008725D9 /* ADRequestParameters.m */; }; - 60C351BA1DA0D588006C8435 /* ADAL.m in Sources */ = {isa = PBXBuildFile; fileRef = 60C351B91DA0D588006C8435 /* ADAL.m */; }; 8B0965AE17F25770002BDFB8 /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 8B0965AD17F25770002BDFB8 /* Foundation.framework */; }; 8B0965BC17F25770002BDFB8 /* XCTest.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 8B0965BB17F25770002BDFB8 /* XCTest.framework */; }; 8B0965BD17F25770002BDFB8 /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 8B0965AD17F25770002BDFB8 /* Foundation.framework */; }; @@ -175,6 +175,7 @@ 9453C46E1C5872B0006B9E79 /* ADJwtHelper.m in Sources */ = {isa = PBXBuildFile; fileRef = 9453C46C1C5872AD006B9E79 /* ADJwtHelper.m */; }; 9453C4741C5874FB006B9E79 /* ADBrokerHelper.m in Sources */ = {isa = PBXBuildFile; fileRef = 9453C4731C5874FB006B9E79 /* ADBrokerHelper.m */; }; 946818A71C59B7F200CA0378 /* ADWebAuthController.m in Sources */ = {isa = PBXBuildFile; fileRef = 946818A41C59B7EE00CA0378 /* ADWebAuthController.m */; }; + 947135881DDBD01C001BBD60 /* ADTextAndButtonView.m in Sources */ = {isa = PBXBuildFile; fileRef = 947135871DDBD01C001BBD60 /* ADTextAndButtonView.m */; }; 94DD18CA1C5A00BC00F80C62 /* ADAuthenticationViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 94DD18C91C5A00BC00F80C62 /* ADAuthenticationViewController.m */; }; 94DD18CF1C5AC8DE00F80C62 /* ADAL.h in Headers */ = {isa = PBXBuildFile; fileRef = 9453C3B71C583AE6006B9E79 /* ADAL.h */; settings = {ATTRIBUTES = (Public, ); }; }; 94DD18D01C5AC8DE00F80C62 /* ADAuthenticationContext.h in Headers */ = {isa = PBXBuildFile; fileRef = 9453C3B81C583AE6006B9E79 /* ADAuthenticationContext.h */; settings = {ATTRIBUTES = (Public, ); }; }; @@ -424,10 +425,10 @@ 605C16801D8FD0AC0097DBA0 /* ADTelemetryEventStrings.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ADTelemetryEventStrings.m; sourceTree = ""; }; 6071B5E21C14C0B0006F6CC2 /* ADTestURLConnection.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ADTestURLConnection.h; sourceTree = ""; }; 6071B5E31C14C0B0006F6CC2 /* ADTestURLConnection.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ADTestURLConnection.m; sourceTree = ""; }; - 60D2F3FE1D524F7A008725D9 /* ADRequestParameters.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ADRequestParameters.h; sourceTree = ""; }; - 60D2F4001D531F16008725D9 /* ADRequestParameters.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ADRequestParameters.m; sourceTree = ""; }; 60967E191D76B62B00863853 /* tools */ = {isa = PBXFileReference; lastKnownFileType = folder; path = tools; sourceTree = SOURCE_ROOT; }; 60C351B91DA0D588006C8435 /* ADAL.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ADAL.m; sourceTree = ""; }; + 60D2F3FE1D524F7A008725D9 /* ADRequestParameters.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ADRequestParameters.h; sourceTree = ""; }; + 60D2F4001D531F16008725D9 /* ADRequestParameters.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ADRequestParameters.m; sourceTree = ""; }; 8B0965AA17F25770002BDFB8 /* libADALiOS.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = libADALiOS.a; sourceTree = BUILT_PRODUCTS_DIR; }; 8B0965AD17F25770002BDFB8 /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = System/Library/Frameworks/Foundation.framework; sourceTree = SDKROOT; }; 8B0965BA17F25770002BDFB8 /* ADALiOSTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = ADALiOSTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; @@ -576,6 +577,8 @@ 946818A41C59B7EE00CA0378 /* ADWebAuthController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = ADWebAuthController.m; sourceTree = ""; }; 946818A51C59B7EE00CA0378 /* ADWebAuthController+Internal.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "ADWebAuthController+Internal.h"; sourceTree = ""; }; 946818A81C59B80800CA0378 /* ADAuthenticationViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ADAuthenticationViewController.m; sourceTree = ""; }; + 947135861DDBD01C001BBD60 /* ADTextAndButtonView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ADTextAndButtonView.h; sourceTree = ""; }; + 947135871DDBD01C001BBD60 /* ADTextAndButtonView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ADTextAndButtonView.m; sourceTree = ""; }; 94A0BDE61D779AB0007BEB63 /* ADRequestContext.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ADRequestContext.h; sourceTree = ""; }; 94DD18C91C5A00BC00F80C62 /* ADAuthenticationViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ADAuthenticationViewController.m; sourceTree = ""; }; 94DD18E11C5ACFBF00F80C62 /* ADAL Mac Tests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = "ADAL Mac Tests.xctest"; sourceTree = BUILT_PRODUCTS_DIR; }; @@ -1195,6 +1198,8 @@ D64C1F4D1DB9B05900850036 /* ADAutoAppDelegate.h */, D64C1F661DBAD90100850036 /* ADAutoInputViewController.h */, D64C1F671DBAD90100850036 /* ADAutoInputViewController.m */, + 947135861DDBD01C001BBD60 /* ADTextAndButtonView.h */, + 947135871DDBD01C001BBD60 /* ADTextAndButtonView.m */, D64C1F4E1DB9B05900850036 /* ADAutoAppDelegate.m */, D64C1F501DB9B05900850036 /* ADAutoMainViewController.h */, D64C1F511DB9B05900850036 /* ADAutoMainViewController.m */, @@ -1796,6 +1801,7 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( + 947135881DDBD01C001BBD60 /* ADTextAndButtonView.m in Sources */, D64C1F621DB9B15800850036 /* ADAutoParameterViewController.m in Sources */, D64C1F681DBAD90100850036 /* ADAutoInputViewController.m in Sources */, D64C1F521DB9B05900850036 /* ADAutoMainViewController.m in Sources */, @@ -2623,7 +2629,7 @@ GCC_NO_COMMON_BLOCKS = YES; GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; INFOPLIST_FILE = ADALAutomation/Info.plist; - IPHONEOS_DEPLOYMENT_TARGET = 10.0; + IPHONEOS_DEPLOYMENT_TARGET = 9.0; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; MTL_ENABLE_DEBUG_INFO = YES; OTHER_LDFLAGS = "-ObjC"; @@ -2652,7 +2658,7 @@ GCC_NO_COMMON_BLOCKS = YES; GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; INFOPLIST_FILE = ADALAutomation/Info.plist; - IPHONEOS_DEPLOYMENT_TARGET = 10.0; + IPHONEOS_DEPLOYMENT_TARGET = 9.0; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; MTL_ENABLE_DEBUG_INFO = NO; OTHER_LDFLAGS = "-ObjC"; @@ -2681,7 +2687,7 @@ GCC_NO_COMMON_BLOCKS = YES; GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; INFOPLIST_FILE = ADALAutomation/Info.plist; - IPHONEOS_DEPLOYMENT_TARGET = 10.0; + IPHONEOS_DEPLOYMENT_TARGET = 9.0; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; MTL_ENABLE_DEBUG_INFO = NO; OTHER_LDFLAGS = "-ObjC"; @@ -2860,6 +2866,7 @@ D64C1F5E1DB9B05A00850036 /* Release */, ); defaultConfigurationIsVisible = 0; + defaultConfigurationName = Debug; }; D664F1B01D302B9C0017B799 /* Build configuration list for PBXNativeTarget "ADAL-core" */ = { isa = XCConfigurationList; diff --git a/ADAL/ADALAutomation/ADAutoInputViewController.m b/ADAL/ADALAutomation/ADAutoInputViewController.m index 800647376..3f82b7569 100644 --- a/ADAL/ADALAutomation/ADAutoInputViewController.m +++ b/ADAL/ADALAutomation/ADAutoInputViewController.m @@ -22,6 +22,7 @@ // THE SOFTWARE. #import "ADAutoInputViewController.h" +#import "ADTextAndButtonView.h" @interface ADAutoInputViewController () @@ -30,7 +31,7 @@ @interface ADAutoInputViewController () @implementation ADAutoInputViewController { ADAutoParamBlock _completionBlock; - UITextView * _inputTextview; + ADTextAndButtonView* _textAndButtonView; } - (id)initWithCompletionBlock:(ADAutoParamBlock)completionBlock @@ -47,46 +48,33 @@ - (id)initWithCompletionBlock:(ADAutoParamBlock)completionBlock - (void)loadView { - UIView* rootView = [[UIView alloc] initWithFrame:UIScreen.mainScreen.bounds]; - rootView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight; - rootView.translatesAutoresizingMaskIntoConstraints = YES; - rootView.autoresizesSubviews = NO; - rootView.backgroundColor = UIColor.whiteColor; - self.view = rootView; + UIView* contentView = [[UIView alloc] initWithFrame:UIScreen.mainScreen.bounds]; + contentView.backgroundColor = UIColor.whiteColor; + self.view = contentView; + _textAndButtonView = [[ADTextAndButtonView alloc] initWithFrame:UIScreen.mainScreen.bounds]; + [contentView addSubview:_textAndButtonView]; + [_textAndButtonView.actionButton addTarget:self + action:@selector(go:) + forControlEvents:UIControlEventTouchUpInside]; - UITextView* textView = [[UITextView alloc] init]; - textView.autocorrectionType = UITextAutocorrectionTypeNo; - textView.accessibilityIdentifier = @"inputTextview"; - textView.translatesAutoresizingMaskIntoConstraints = NO; - textView.editable = YES; - textView.layer.cornerRadius = 8.0; - textView.layer.borderWidth = 1.0; - textView.layer.borderColor = UIColor.lightGrayColor.CGColor; - - _inputTextview = textView; + NSDictionary* views = @{ @"textAndButtonView" : _textAndButtonView, + @"topLayoutGuide" : self.topLayoutGuide, + @"bottomLayoutGuide" : self.bottomLayoutGuide }; - UIButton* goButton = [[UIButton alloc] init]; - [goButton setTitle:@"Go" forState:UIControlStateNormal]; - [goButton addTarget:self - action:@selector(go:) - forControlEvents:UIControlEventTouchUpInside]; - goButton.backgroundColor = UIColor.greenColor; - goButton.titleLabel.textColor = UIColor.whiteColor; - goButton.translatesAutoresizingMaskIntoConstraints = NO; - goButton.accessibilityIdentifier = @"GoButton"; + NSArray* verticalConstraints = + [NSLayoutConstraint constraintsWithVisualFormat:@"V:[topLayoutGuide]-[textAndButtonView]-[bottomLayoutGuide]" + options:0 + metrics:nil + views:views]; - [rootView addSubview:textView]; - [rootView addSubview:goButton]; + NSArray* horizontalConstraints = + [NSLayoutConstraint constraintsWithVisualFormat:@"H:|-[textAndButtonView]-|" + options:0 + metrics:nil + views:views]; - UILayoutGuide* margins = self.view.layoutMarginsGuide; - [textView.topAnchor constraintEqualToAnchor:self.topLayoutGuide.bottomAnchor constant:8.0].active = YES; - [textView.leadingAnchor constraintEqualToAnchor:margins.leadingAnchor].active = YES; - [textView.trailingAnchor constraintEqualToAnchor:margins.trailingAnchor].active = YES; - [textView.bottomAnchor constraintEqualToAnchor:goButton.topAnchor constant:-8.0].active = YES; - [goButton.leadingAnchor constraintEqualToAnchor:margins.leadingAnchor].active = YES; - [goButton.trailingAnchor constraintEqualToAnchor:margins.trailingAnchor].active = YES; - [goButton.heightAnchor constraintEqualToConstant:20.0]; - [goButton.bottomAnchor constraintEqualToAnchor:self.bottomLayoutGuide.topAnchor constant:-8.0].active = YES; + [self.view addConstraints:verticalConstraints]; + [self.view addConstraints:horizontalConstraints]; } - (void)viewDidLoad { @@ -105,7 +93,7 @@ - (IBAction)go:(id)sender @synchronized (self) { - NSString* text = _inputTextview.text; + NSString* text = _textAndButtonView.textView.text; NSError* error = nil; NSDictionary* params = [NSJSONSerialization JSONObjectWithData:[text dataUsingEncoding:NSUTF8StringEncoding] options:0 error:&error]; if (!params) diff --git a/ADAL/ADALAutomation/ADTextAndButtonView.h b/ADAL/ADALAutomation/ADTextAndButtonView.h new file mode 100644 index 000000000..b626064d8 --- /dev/null +++ b/ADAL/ADALAutomation/ADTextAndButtonView.h @@ -0,0 +1,31 @@ +// Copyright (c) Microsoft Corporation. +// All rights reserved. +// +// This code is licensed under the MIT License. +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files(the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and / or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions : +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE. + +#import + +@interface ADTextAndButtonView : UIView + +@property (readonly) UIButton* actionButton; +@property (readonly) UITextView* textView; + +@end diff --git a/ADAL/ADALAutomation/ADTextAndButtonView.m b/ADAL/ADALAutomation/ADTextAndButtonView.m new file mode 100644 index 000000000..86761651a --- /dev/null +++ b/ADAL/ADALAutomation/ADTextAndButtonView.m @@ -0,0 +1,101 @@ +// Copyright (c) Microsoft Corporation. +// All rights reserved. +// +// This code is licensed under the MIT License. +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files(the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and / or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions : +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE. + +#import "ADTextAndButtonView.h" + +@implementation ADTextAndButtonView + +- (id)initWithFrame:(CGRect)frame +{ + if (!(self = [super initWithFrame:frame])) + { + return nil; + } + + [self loadView]; + + return self; +} + +- (void)loadView +{ + self.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight; + self.translatesAutoresizingMaskIntoConstraints = NO; + self.autoresizesSubviews = NO; + self.backgroundColor = UIColor.whiteColor; + + UITextView* textView = [[UITextView alloc] init]; + textView.autocorrectionType = UITextAutocorrectionTypeNo; + textView.accessibilityIdentifier = @"inputTextview"; + textView.translatesAutoresizingMaskIntoConstraints = NO; + textView.editable = YES; + textView.layer.cornerRadius = 8.0; + textView.layer.borderWidth = 1.0; + textView.layer.borderColor = UIColor.lightGrayColor.CGColor; + + _textView = textView; + + UIButton* goButton = [[UIButton alloc] init]; + [goButton setTitle:@"Go" forState:UIControlStateNormal]; + goButton.backgroundColor = UIColor.greenColor; + goButton.titleLabel.textColor = UIColor.whiteColor; + goButton.translatesAutoresizingMaskIntoConstraints = NO; + goButton.accessibilityIdentifier = @"GoButton"; + _actionButton = goButton; + + [self addSubview:textView]; + [self addSubview:goButton]; + + + NSDictionary* views = @{@"textView" : textView, @"actionButton" : goButton }; + NSArray* veritcalConstraints = + [NSLayoutConstraint constraintsWithVisualFormat:@"V:|[textView]-[actionButton]|" + options:0 + metrics:NULL + views:views]; + NSArray* horizConstraints1 = + [NSLayoutConstraint constraintsWithVisualFormat:@"H:|[textView]|" + options:0 + metrics:nil + views:views]; + + NSArray* horizConstraints2 = + [NSLayoutConstraint constraintsWithVisualFormat:@"H:|[actionButton]|" + options:0 + metrics:nil + views:views]; + + [self addConstraints:veritcalConstraints]; + [self addConstraints:horizConstraints1]; + [self addConstraints:horizConstraints2]; +} + +/* +// Only override drawRect: if you perform custom drawing. +// An empty implementation adversely affects performance during animation. +- (void)drawRect:(CGRect)rect { + // Drawing code +} +*/ + +@end From c7479488b84578dbe253b9fb0d7052f8da0ab903 Mon Sep 17 00:00:00 2001 From: Ryan Pangrle Date: Tue, 15 Nov 2016 23:03:27 -0800 Subject: [PATCH 60/92] Update README.md with more explicit information on versioning and releases --- README.md | 57 +++++++++++++++++++------------------------------------ 1 file changed, 19 insertions(+), 38 deletions(-) diff --git a/README.md b/README.md index a812c7d60..8782f9478 100644 --- a/README.md +++ b/README.md @@ -2,38 +2,13 @@ #Microsoft Azure Active Directory Authentication Library (ADAL) for iOS and OSX ===================================== -## URGENT: iOS 10 NOTICE +## Release Versions -**If you are using ADAL versions <= 1.2.8 or <= 2.2.4 you need to immediately upgrade your application to the latest version of our SDKs. Without this step, your users will not be able to sign-in once iOS 10 is released.** If a user is already signed in to your application it will continue to work temporarily, but the next time they need to sign in again they will experience this issue. +We recommend remaining up-to-date with the latest version of ADAL. The best place to check what the most recent version is is the [releases page][https://github.com/AzureAD/azure-activedirectory-library-for-objc/releases] on GitHub, you can also subscribe the the [Atom Feed][https://github.com/AzureAD/azure-activedirectory-library-for-objc/releases.atom] from GitHub, or use a 3rd party tool like [Sibbell][https://sibbell.com/about/] to receive emails when a new version is released. -To update your application, you may use cocoapods or manually download the SDK from source on GitHub. Once you’ve update your SDK to the latest version your application will continue to work, there is no further code changes required for your application to continue working. - -## How to Update Your Application with Cocoapods (recommended) - -If you are using the 2.x version of our library, ensure the following line is in your `Podfile` in the root directory of your application: - -``` -pod 'ADAL', '~> 2.2' -``` -If you are using the 1.2 version of our library, ensure the following line is in your `Podfile` in the root directory of your application: - -``` -pod 'ADALiOS', '~> 1.2' -``` -Once this is complete, run the `pod update` command to update your application. - - -## How to Update Your Application with source - -1. Download the latest code from the task you require, either 2.2.5 or 1.2.9 -2. In your XCode 8 or higher project, Click File -> Add Files -3. In the Finder that appears, navigate to where you downloaded the ADAL source. Go to the ADAL folder, and select `ADAL.xcodeproj` and click Add. -4. You’ll see you have another Project in your Project list to the left called `ADAL.xcodeproj` -5. Under “Linked Frameworks and Libraries” in your application’s General project settings, ensure ADALiOS.a is listed and not in red color font. Red color font means XCode can’t find the library and you need to update the location by removing the entry and adding it again. -6. If it isn’t there or in red color, press the “+” icon. You should see ADALiOS.a in your available libraries. Select it and click OK. -7. OPTIONAL: You may also select the .framework version if you would rather use the framework. Make sure that you are selecting the iOS Target and not the Mac Target for the framework. -8. Compile as and test your application. +The only approved way to get the latest version is through a tagged release on GitHub, or a tool that relies on that data. Tools like [CocoaPods][https://cocoapods.org] can make it easier to set up your project dependencies and update to the latest release. ADAL follows the [GitFlow branching model][http://danielkummer.github.io/git-flow-cheatsheet/]. You should never pull an ADAL version for release from any branch other then master, any other branch is for versions of ADAL still in development or testing, and are subject to change. +NOTE: To work with iOS 10 you must have at least version 2.2.5, or 1.2.9. ===================================== @@ -81,28 +56,34 @@ We've made it easy for you to have multiple options to use this library in your ###Option 1: Git Submodule -If your project is managed in a git repository you can include ADAL as a git submodule: + If your project is managed in a git repository you can include ADAL as a git submodule. First check the [GitHub Releases Page][https://github.com/AzureAD/azure-activedirectory-library-for-objc/releases] for the latest release tag. Replace `` with that version. git submodule add https://github.com/AzureAD/azure-activedirectory-library-for-objc adal cd adal - git checkout tags/2.1.0 + git checkout tags/ cd .. git add adal - git commit -m "Use ADAL git submodule at 2.1.0" + git commit -m "Use ADAL git submodule at " git push -We recommend only syncing to specific release tags to make sure you're at a known spot in the code. - -###Option 2: Source Zip +We recommend only syncing to specific release tags to make sure you're at a known good point. We will not support versions of ADAL between release tags. -To download a copy of the source code, click "Download ZIP" on the right side of the page or click [here](https://github.com/AzureAD/azure-activedirectory-library-for-objc/archive/1.2.5.tar.gz). +###Option 2: Cocoapods -###Option 3: Cocoapods +You can use CocoaPods to remain up to date with ADAL within a specific major version. Include the following line in your podfile: - pod 'ADAL', '~> 2.1.0' + pod 'ADAL', '~> 2.2' + +You then you can run either `pod install` (if it's a new PodFile) or `pod update` (if it's an existing PodFile) to get the latest version of ADAL. Subsequent calls to `pod update` will update to the latest released version of ADAL as well. See [CocoaPods](https://cocoapods.org) for more information on setting up a PodFile +###Option 3: Source Zip + +To download a copy of the source code, first make sure you're on the "master" branch and click "Clone or download" then "Download ZIP" in the upper right hand corner, or you can download it [here][https://github.com/AzureAD/azure-activedirectory-library-for-objc/archive/master.zip] + +This is not recommended, as it leaves no infrastructure in place for being able to easily update to the latest version. + ## Usage ### Caching From 50baf8bb80af63496166fa191555d2d5f5e9afdd Mon Sep 17 00:00:00 2001 From: Ryan Pangrle Date: Tue, 15 Nov 2016 23:05:21 -0800 Subject: [PATCH 61/92] Update for Carthage compatibility Including ADAL as a subproject in the the SampleSwiftApp project confused the carthage tool, combined with xcodebuild bugs it would block Carthage from working. --- ADAL.xcworkspace/contents.xcworkspacedata | 3 - .../SampleSwiftApp.xcodeproj/project.pbxproj | 146 ------------------ .../contents.xcworkspacedata | 3 + 3 files changed, 3 insertions(+), 149 deletions(-) diff --git a/ADAL.xcworkspace/contents.xcworkspacedata b/ADAL.xcworkspace/contents.xcworkspacedata index 3b62a971b..f1cf7b876 100644 --- a/ADAL.xcworkspace/contents.xcworkspacedata +++ b/ADAL.xcworkspace/contents.xcworkspacedata @@ -10,7 +10,4 @@ - - diff --git a/Samples/SampleSwiftApp/SampleSwiftApp.xcodeproj/project.pbxproj b/Samples/SampleSwiftApp/SampleSwiftApp.xcodeproj/project.pbxproj index 6e060c196..c669ce026 100644 --- a/Samples/SampleSwiftApp/SampleSwiftApp.xcodeproj/project.pbxproj +++ b/Samples/SampleSwiftApp/SampleSwiftApp.xcodeproj/project.pbxproj @@ -7,8 +7,6 @@ objects = { /* Begin PBXBuildFile section */ - 8BD644461D74EFA900EE0AB4 /* ADAL.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 8BD6443F1D74EFA400EE0AB4 /* ADAL.framework */; }; - 8BD644471D74EFA900EE0AB4 /* ADAL.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 8BD6443F1D74EFA400EE0AB4 /* ADAL.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; D664F1571D3014F70017B799 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = D664F1561D3014F70017B799 /* AppDelegate.swift */; }; D664F1591D3014F70017B799 /* ViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = D664F1581D3014F70017B799 /* ViewController.swift */; }; D664F15C1D3014F70017B799 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = D664F15A1D3014F70017B799 /* Main.storyboard */; }; @@ -16,65 +14,6 @@ D664F1611D3014F70017B799 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = D664F15F1D3014F70017B799 /* LaunchScreen.storyboard */; }; /* End PBXBuildFile section */ -/* Begin PBXContainerItemProxy section */ - 04AB6D7D1D9D91FD007E9A83 /* PBXContainerItemProxy */ = { - isa = PBXContainerItemProxy; - containerPortal = 8BD644301D74EFA400EE0AB4 /* ADAL.xcodeproj */; - proxyType = 2; - remoteGlobalIDString = 04AB6D421D9D619B007E9A83; - remoteInfo = UnitTestHostApp; - }; - 8BD6443A1D74EFA400EE0AB4 /* PBXContainerItemProxy */ = { - isa = PBXContainerItemProxy; - containerPortal = 8BD644301D74EFA400EE0AB4 /* ADAL.xcodeproj */; - proxyType = 2; - remoteGlobalIDString = 8B0965AA17F25770002BDFB8; - remoteInfo = ADALiOS; - }; - 8BD6443C1D74EFA400EE0AB4 /* PBXContainerItemProxy */ = { - isa = PBXContainerItemProxy; - containerPortal = 8BD644301D74EFA400EE0AB4 /* ADAL.xcodeproj */; - proxyType = 2; - remoteGlobalIDString = D664F1B41D302B9C0017B799; - remoteInfo = "ADAL-core"; - }; - 8BD6443E1D74EFA400EE0AB4 /* PBXContainerItemProxy */ = { - isa = PBXContainerItemProxy; - containerPortal = 8BD644301D74EFA400EE0AB4 /* ADAL.xcodeproj */; - proxyType = 2; - remoteGlobalIDString = 9453C3CC1C583E07006B9E79; - remoteInfo = ADAL; - }; - 8BD644401D74EFA400EE0AB4 /* PBXContainerItemProxy */ = { - isa = PBXContainerItemProxy; - containerPortal = 8BD644301D74EFA400EE0AB4 /* ADAL.xcodeproj */; - proxyType = 2; - remoteGlobalIDString = 8B0965BA17F25770002BDFB8; - remoteInfo = ADALiOSTests; - }; - 8BD644421D74EFA400EE0AB4 /* PBXContainerItemProxy */ = { - isa = PBXContainerItemProxy; - containerPortal = 8BD644301D74EFA400EE0AB4 /* ADAL.xcodeproj */; - proxyType = 2; - remoteGlobalIDString = 9453C3FD1C586425006B9E79; - remoteInfo = "ADAL Mac"; - }; - 8BD644441D74EFA400EE0AB4 /* PBXContainerItemProxy */ = { - isa = PBXContainerItemProxy; - containerPortal = 8BD644301D74EFA400EE0AB4 /* ADAL.xcodeproj */; - proxyType = 2; - remoteGlobalIDString = 94DD18E11C5ACFBF00F80C62; - remoteInfo = "ADAL Mac Tests"; - }; - 8BD644481D74EFA900EE0AB4 /* PBXContainerItemProxy */ = { - isa = PBXContainerItemProxy; - containerPortal = 8BD644301D74EFA400EE0AB4 /* ADAL.xcodeproj */; - proxyType = 1; - remoteGlobalIDString = 9453C3CB1C583E07006B9E79; - remoteInfo = ADAL; - }; -/* End PBXContainerItemProxy section */ - /* Begin PBXCopyFilesBuildPhase section */ D63948921D6CCB05002D53D6 /* Embed Frameworks */ = { isa = PBXCopyFilesBuildPhase; @@ -82,7 +21,6 @@ dstPath = ""; dstSubfolderSpec = 10; files = ( - 8BD644471D74EFA900EE0AB4 /* ADAL.framework in Embed Frameworks */, ); name = "Embed Frameworks"; runOnlyForDeploymentPostprocessing = 0; @@ -90,7 +28,6 @@ /* End PBXCopyFilesBuildPhase section */ /* Begin PBXFileReference section */ - 8BD644301D74EFA400EE0AB4 /* ADAL.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = ADAL.xcodeproj; path = ../../ADAL/ADAL.xcodeproj; sourceTree = ""; }; D664F1531D3014F60017B799 /* SampleSwiftApp.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = SampleSwiftApp.app; sourceTree = BUILT_PRODUCTS_DIR; }; D664F1561D3014F70017B799 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = ""; }; D664F1581D3014F70017B799 /* ViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ViewController.swift; sourceTree = ""; }; @@ -105,31 +42,15 @@ isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; files = ( - 8BD644461D74EFA900EE0AB4 /* ADAL.framework in Frameworks */, ); runOnlyForDeploymentPostprocessing = 0; }; /* End PBXFrameworksBuildPhase section */ /* Begin PBXGroup section */ - 8BD644311D74EFA400EE0AB4 /* Products */ = { - isa = PBXGroup; - children = ( - 8BD6443B1D74EFA400EE0AB4 /* libADALiOS.a */, - 8BD6443D1D74EFA400EE0AB4 /* libADAL-core.a */, - 8BD6443F1D74EFA400EE0AB4 /* ADAL.framework */, - 8BD644411D74EFA400EE0AB4 /* ADALiOSTests.xctest */, - 8BD644431D74EFA400EE0AB4 /* ADAL.framework */, - 8BD644451D74EFA400EE0AB4 /* ADAL Mac Tests.xctest */, - 04AB6D7E1D9D91FD007E9A83 /* UnitTestHostApp.app */, - ); - name = Products; - sourceTree = ""; - }; D664F14A1D3014F60017B799 = { isa = PBXGroup; children = ( - 8BD644301D74EFA400EE0AB4 /* ADAL.xcodeproj */, D664F1551D3014F70017B799 /* SampleSwiftApp */, D664F1541D3014F60017B799 /* Products */, ); @@ -171,7 +92,6 @@ buildRules = ( ); dependencies = ( - 8BD644491D74EFA900EE0AB4 /* PBXTargetDependency */, ); name = SampleSwiftApp; productName = SampleSwiftApp; @@ -205,12 +125,6 @@ mainGroup = D664F14A1D3014F60017B799; productRefGroup = D664F1541D3014F60017B799 /* Products */; projectDirPath = ""; - projectReferences = ( - { - ProductGroup = 8BD644311D74EFA400EE0AB4 /* Products */; - ProjectRef = 8BD644301D74EFA400EE0AB4 /* ADAL.xcodeproj */; - }, - ); projectRoot = ""; targets = ( D664F1521D3014F60017B799 /* SampleSwiftApp */, @@ -218,58 +132,6 @@ }; /* End PBXProject section */ -/* Begin PBXReferenceProxy section */ - 04AB6D7E1D9D91FD007E9A83 /* UnitTestHostApp.app */ = { - isa = PBXReferenceProxy; - fileType = wrapper.application; - path = UnitTestHostApp.app; - remoteRef = 04AB6D7D1D9D91FD007E9A83 /* PBXContainerItemProxy */; - sourceTree = BUILT_PRODUCTS_DIR; - }; - 8BD6443B1D74EFA400EE0AB4 /* libADALiOS.a */ = { - isa = PBXReferenceProxy; - fileType = archive.ar; - path = libADALiOS.a; - remoteRef = 8BD6443A1D74EFA400EE0AB4 /* PBXContainerItemProxy */; - sourceTree = BUILT_PRODUCTS_DIR; - }; - 8BD6443D1D74EFA400EE0AB4 /* libADAL-core.a */ = { - isa = PBXReferenceProxy; - fileType = archive.ar; - path = "libADAL-core.a"; - remoteRef = 8BD6443C1D74EFA400EE0AB4 /* PBXContainerItemProxy */; - sourceTree = BUILT_PRODUCTS_DIR; - }; - 8BD6443F1D74EFA400EE0AB4 /* ADAL.framework */ = { - isa = PBXReferenceProxy; - fileType = wrapper.framework; - path = ADAL.framework; - remoteRef = 8BD6443E1D74EFA400EE0AB4 /* PBXContainerItemProxy */; - sourceTree = BUILT_PRODUCTS_DIR; - }; - 8BD644411D74EFA400EE0AB4 /* ADALiOSTests.xctest */ = { - isa = PBXReferenceProxy; - fileType = wrapper.cfbundle; - path = ADALiOSTests.xctest; - remoteRef = 8BD644401D74EFA400EE0AB4 /* PBXContainerItemProxy */; - sourceTree = BUILT_PRODUCTS_DIR; - }; - 8BD644431D74EFA400EE0AB4 /* ADAL.framework */ = { - isa = PBXReferenceProxy; - fileType = wrapper.framework; - path = ADAL.framework; - remoteRef = 8BD644421D74EFA400EE0AB4 /* PBXContainerItemProxy */; - sourceTree = BUILT_PRODUCTS_DIR; - }; - 8BD644451D74EFA400EE0AB4 /* ADAL Mac Tests.xctest */ = { - isa = PBXReferenceProxy; - fileType = wrapper.cfbundle; - path = "ADAL Mac Tests.xctest"; - remoteRef = 8BD644441D74EFA400EE0AB4 /* PBXContainerItemProxy */; - sourceTree = BUILT_PRODUCTS_DIR; - }; -/* End PBXReferenceProxy section */ - /* Begin PBXResourcesBuildPhase section */ D664F1511D3014F60017B799 /* Resources */ = { isa = PBXResourcesBuildPhase; @@ -295,14 +157,6 @@ }; /* End PBXSourcesBuildPhase section */ -/* Begin PBXTargetDependency section */ - 8BD644491D74EFA900EE0AB4 /* PBXTargetDependency */ = { - isa = PBXTargetDependency; - name = ADAL; - targetProxy = 8BD644481D74EFA900EE0AB4 /* PBXContainerItemProxy */; - }; -/* End PBXTargetDependency section */ - /* Begin PBXVariantGroup section */ D664F15A1D3014F70017B799 /* Main.storyboard */ = { isa = PBXVariantGroup; diff --git a/Samples/SampleSwiftApp/SampleSwiftApp.xcworkspace/contents.xcworkspacedata b/Samples/SampleSwiftApp/SampleSwiftApp.xcworkspace/contents.xcworkspacedata index 9d5522cee..c65348143 100644 --- a/Samples/SampleSwiftApp/SampleSwiftApp.xcworkspace/contents.xcworkspacedata +++ b/Samples/SampleSwiftApp/SampleSwiftApp.xcworkspace/contents.xcworkspacedata @@ -1,6 +1,9 @@ + + From 8bd3db6a0390d5d1ea70e036ec766e6bf29000c5 Mon Sep 17 00:00:00 2001 From: Ryan Pangrle Date: Wed, 16 Nov 2016 13:37:10 -0800 Subject: [PATCH 62/92] Rename to ADAutoTextAndButtonView --- ADAL/ADAL.xcodeproj/project.pbxproj | 12 ++++++------ ADAL/ADALAutomation/ADAutoInputViewController.m | 6 +++--- ...TextAndButtonView.h => ADAutoTextAndButtonView.h} | 2 +- ...TextAndButtonView.m => ADAutoTextAndButtonView.m} | 2 +- 4 files changed, 11 insertions(+), 11 deletions(-) rename ADAL/ADALAutomation/{ADTextAndButtonView.h => ADAutoTextAndButtonView.h} (96%) rename ADAL/ADALAutomation/{ADTextAndButtonView.m => ADAutoTextAndButtonView.m} (98%) diff --git a/ADAL/ADAL.xcodeproj/project.pbxproj b/ADAL/ADAL.xcodeproj/project.pbxproj index ab5b1c082..874d1ff38 100755 --- a/ADAL/ADAL.xcodeproj/project.pbxproj +++ b/ADAL/ADAL.xcodeproj/project.pbxproj @@ -175,7 +175,7 @@ 9453C46E1C5872B0006B9E79 /* ADJwtHelper.m in Sources */ = {isa = PBXBuildFile; fileRef = 9453C46C1C5872AD006B9E79 /* ADJwtHelper.m */; }; 9453C4741C5874FB006B9E79 /* ADBrokerHelper.m in Sources */ = {isa = PBXBuildFile; fileRef = 9453C4731C5874FB006B9E79 /* ADBrokerHelper.m */; }; 946818A71C59B7F200CA0378 /* ADWebAuthController.m in Sources */ = {isa = PBXBuildFile; fileRef = 946818A41C59B7EE00CA0378 /* ADWebAuthController.m */; }; - 947135881DDBD01C001BBD60 /* ADTextAndButtonView.m in Sources */ = {isa = PBXBuildFile; fileRef = 947135871DDBD01C001BBD60 /* ADTextAndButtonView.m */; }; + 947135881DDBD01C001BBD60 /* ADAutoTextAndButtonView.m in Sources */ = {isa = PBXBuildFile; fileRef = 947135871DDBD01C001BBD60 /* ADAutoTextAndButtonView.m */; }; 94DD18CA1C5A00BC00F80C62 /* ADAuthenticationViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 94DD18C91C5A00BC00F80C62 /* ADAuthenticationViewController.m */; }; 94DD18CF1C5AC8DE00F80C62 /* ADAL.h in Headers */ = {isa = PBXBuildFile; fileRef = 9453C3B71C583AE6006B9E79 /* ADAL.h */; settings = {ATTRIBUTES = (Public, ); }; }; 94DD18D01C5AC8DE00F80C62 /* ADAuthenticationContext.h in Headers */ = {isa = PBXBuildFile; fileRef = 9453C3B81C583AE6006B9E79 /* ADAuthenticationContext.h */; settings = {ATTRIBUTES = (Public, ); }; }; @@ -577,8 +577,8 @@ 946818A41C59B7EE00CA0378 /* ADWebAuthController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = ADWebAuthController.m; sourceTree = ""; }; 946818A51C59B7EE00CA0378 /* ADWebAuthController+Internal.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "ADWebAuthController+Internal.h"; sourceTree = ""; }; 946818A81C59B80800CA0378 /* ADAuthenticationViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ADAuthenticationViewController.m; sourceTree = ""; }; - 947135861DDBD01C001BBD60 /* ADTextAndButtonView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ADTextAndButtonView.h; sourceTree = ""; }; - 947135871DDBD01C001BBD60 /* ADTextAndButtonView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ADTextAndButtonView.m; sourceTree = ""; }; + 947135861DDBD01C001BBD60 /* ADAutoTextAndButtonView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ADAutoTextAndButtonView.h; sourceTree = ""; }; + 947135871DDBD01C001BBD60 /* ADAutoTextAndButtonView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ADAutoTextAndButtonView.m; sourceTree = ""; }; 94A0BDE61D779AB0007BEB63 /* ADRequestContext.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ADRequestContext.h; sourceTree = ""; }; 94DD18C91C5A00BC00F80C62 /* ADAuthenticationViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ADAuthenticationViewController.m; sourceTree = ""; }; 94DD18E11C5ACFBF00F80C62 /* ADAL Mac Tests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = "ADAL Mac Tests.xctest"; sourceTree = BUILT_PRODUCTS_DIR; }; @@ -1198,8 +1198,8 @@ D64C1F4D1DB9B05900850036 /* ADAutoAppDelegate.h */, D64C1F661DBAD90100850036 /* ADAutoInputViewController.h */, D64C1F671DBAD90100850036 /* ADAutoInputViewController.m */, - 947135861DDBD01C001BBD60 /* ADTextAndButtonView.h */, - 947135871DDBD01C001BBD60 /* ADTextAndButtonView.m */, + 947135861DDBD01C001BBD60 /* ADAutoTextAndButtonView.h */, + 947135871DDBD01C001BBD60 /* ADAutoTextAndButtonView.m */, D64C1F4E1DB9B05900850036 /* ADAutoAppDelegate.m */, D64C1F501DB9B05900850036 /* ADAutoMainViewController.h */, D64C1F511DB9B05900850036 /* ADAutoMainViewController.m */, @@ -1801,7 +1801,7 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( - 947135881DDBD01C001BBD60 /* ADTextAndButtonView.m in Sources */, + 947135881DDBD01C001BBD60 /* ADAutoTextAndButtonView.m in Sources */, D64C1F621DB9B15800850036 /* ADAutoParameterViewController.m in Sources */, D64C1F681DBAD90100850036 /* ADAutoInputViewController.m in Sources */, D64C1F521DB9B05900850036 /* ADAutoMainViewController.m in Sources */, diff --git a/ADAL/ADALAutomation/ADAutoInputViewController.m b/ADAL/ADALAutomation/ADAutoInputViewController.m index 3f82b7569..18c79a9a0 100644 --- a/ADAL/ADALAutomation/ADAutoInputViewController.m +++ b/ADAL/ADALAutomation/ADAutoInputViewController.m @@ -22,7 +22,7 @@ // THE SOFTWARE. #import "ADAutoInputViewController.h" -#import "ADTextAndButtonView.h" +#import "ADAutoTextAndButtonView.h" @interface ADAutoInputViewController () @@ -31,7 +31,7 @@ @interface ADAutoInputViewController () @implementation ADAutoInputViewController { ADAutoParamBlock _completionBlock; - ADTextAndButtonView* _textAndButtonView; + ADAutoTextAndButtonView* _textAndButtonView; } - (id)initWithCompletionBlock:(ADAutoParamBlock)completionBlock @@ -51,7 +51,7 @@ - (void)loadView UIView* contentView = [[UIView alloc] initWithFrame:UIScreen.mainScreen.bounds]; contentView.backgroundColor = UIColor.whiteColor; self.view = contentView; - _textAndButtonView = [[ADTextAndButtonView alloc] initWithFrame:UIScreen.mainScreen.bounds]; + _textAndButtonView = [[ADAutoTextAndButtonView alloc] initWithFrame:UIScreen.mainScreen.bounds]; [contentView addSubview:_textAndButtonView]; [_textAndButtonView.actionButton addTarget:self action:@selector(go:) diff --git a/ADAL/ADALAutomation/ADTextAndButtonView.h b/ADAL/ADALAutomation/ADAutoTextAndButtonView.h similarity index 96% rename from ADAL/ADALAutomation/ADTextAndButtonView.h rename to ADAL/ADALAutomation/ADAutoTextAndButtonView.h index b626064d8..cf7c5aac2 100644 --- a/ADAL/ADALAutomation/ADTextAndButtonView.h +++ b/ADAL/ADALAutomation/ADAutoTextAndButtonView.h @@ -23,7 +23,7 @@ #import -@interface ADTextAndButtonView : UIView +@interface ADAutoTextAndButtonView : UIView @property (readonly) UIButton* actionButton; @property (readonly) UITextView* textView; diff --git a/ADAL/ADALAutomation/ADTextAndButtonView.m b/ADAL/ADALAutomation/ADAutoTextAndButtonView.m similarity index 98% rename from ADAL/ADALAutomation/ADTextAndButtonView.m rename to ADAL/ADALAutomation/ADAutoTextAndButtonView.m index 86761651a..b4203f15f 100644 --- a/ADAL/ADALAutomation/ADTextAndButtonView.m +++ b/ADAL/ADALAutomation/ADAutoTextAndButtonView.m @@ -23,7 +23,7 @@ #import "ADTextAndButtonView.h" -@implementation ADTextAndButtonView +@implementation ADAutoTextAndButtonView - (id)initWithFrame:(CGRect)frame { From 5aa5ed8b4b6a62836869a15b20c0ca909a65b0b8 Mon Sep 17 00:00:00 2001 From: Ryan Pangrle Date: Thu, 17 Nov 2016 10:12:09 -0800 Subject: [PATCH 63/92] Update README.md --- README.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 8782f9478..dc84527ed 100644 --- a/README.md +++ b/README.md @@ -4,9 +4,9 @@ ## Release Versions -We recommend remaining up-to-date with the latest version of ADAL. The best place to check what the most recent version is is the [releases page][https://github.com/AzureAD/azure-activedirectory-library-for-objc/releases] on GitHub, you can also subscribe the the [Atom Feed][https://github.com/AzureAD/azure-activedirectory-library-for-objc/releases.atom] from GitHub, or use a 3rd party tool like [Sibbell][https://sibbell.com/about/] to receive emails when a new version is released. +We recommend remaining up-to-date with the latest version of ADAL. The best place to check what the most recent version is is the [releases page](https://github.com/AzureAD/azure-activedirectory-library-for-objc/releases) on GitHub, you can also subscribe the the [Atom Feed](https://github.com/AzureAD/azure-activedirectory-library-for-objc/releases.atom) from GitHub, or use a 3rd party tool like [Sibbell](https://sibbell.com/about/) to receive emails when a new version is released. -The only approved way to get the latest version is through a tagged release on GitHub, or a tool that relies on that data. Tools like [CocoaPods][https://cocoapods.org] can make it easier to set up your project dependencies and update to the latest release. ADAL follows the [GitFlow branching model][http://danielkummer.github.io/git-flow-cheatsheet/]. You should never pull an ADAL version for release from any branch other then master, any other branch is for versions of ADAL still in development or testing, and are subject to change. +The only approved way to get the latest version is through a tagged release on GitHub, or a tool that relies on that data. Tools like [CocoaPods](https://cocoapods.org) can make it easier to set up your project dependencies and update to the latest release. ADAL follows the [GitFlow branching model](http://danielkummer.github.io/git-flow-cheatsheet/). You should never pull an ADAL version for release from any branch other then master, any other branch is for versions of ADAL still in development or testing, and are subject to change. NOTE: To work with iOS 10 you must have at least version 2.2.5, or 1.2.9. @@ -56,7 +56,7 @@ We've made it easy for you to have multiple options to use this library in your ###Option 1: Git Submodule - If your project is managed in a git repository you can include ADAL as a git submodule. First check the [GitHub Releases Page][https://github.com/AzureAD/azure-activedirectory-library-for-objc/releases] for the latest release tag. Replace `` with that version. + If your project is managed in a git repository you can include ADAL as a git submodule. First check the [GitHub Releases Page](https://github.com/AzureAD/azure-activedirectory-library-for-objc/releases) for the latest release tag. Replace `` with that version. git submodule add https://github.com/AzureAD/azure-activedirectory-library-for-objc adal cd adal @@ -80,7 +80,7 @@ See [CocoaPods](https://cocoapods.org) for more information on setting up a PodF ###Option 3: Source Zip -To download a copy of the source code, first make sure you're on the "master" branch and click "Clone or download" then "Download ZIP" in the upper right hand corner, or you can download it [here][https://github.com/AzureAD/azure-activedirectory-library-for-objc/archive/master.zip] +To download a copy of the source code, first make sure you're on the "master" branch and click "Clone or download" then "Download ZIP" in the upper right hand corner, or you can download it [here](https://github.com/AzureAD/azure-activedirectory-library-for-objc/archive/master.zip) This is not recommended, as it leaves no infrastructure in place for being able to easily update to the latest version. From fb203757c000498ec0d9c03e766c432fa6f11742 Mon Sep 17 00:00:00 2001 From: Ryan Pangrle Date: Thu, 17 Nov 2016 10:36:29 -0800 Subject: [PATCH 64/92] Switch Travis to Xcode 8.1 --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index e7b669a7f..b5a934ca2 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,5 +1,5 @@ language: objective-c -osx_image: xcode8 +osx_image: xcode8.1 # Set up our rubygems (slather and xcpretty, namely) install: From e3e76fcb7b0305c6b24e0e5d4d6ca6ba606298b0 Mon Sep 17 00:00:00 2001 From: Anisimov Vasiliy Date: Wed, 23 Nov 2016 18:38:30 +0300 Subject: [PATCH 65/92] fix AzureAD/azure-activedirectory-library-for-objc#840 --- ADAL/src/ui/ios/ADAuthenticationViewController.m | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/ADAL/src/ui/ios/ADAuthenticationViewController.m b/ADAL/src/ui/ios/ADAuthenticationViewController.m index 88a4d6cef..9a4275913 100644 --- a/ADAL/src/ui/ios/ADAuthenticationViewController.m +++ b/ADAL/src/ui/ios/ADAuthenticationViewController.m @@ -32,7 +32,6 @@ @interface ADAuthenticationViewController ( ) { UIActivityIndicatorView* _activityIndicator; - UINavigationController* _navController; } @end @@ -91,14 +90,10 @@ - (BOOL)loadView:(ADAuthenticationError * __autoreleasing *)error self.view = rootView; - _navController = [[UINavigationController alloc] init]; - _navController.navigationBar.hidden = NO; - UIBarButtonItem* cancelButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCancel target:self action:@selector(onCancel:)]; self.navigationItem.leftBarButtonItem = cancelButton; - [_navController pushViewController:self animated:NO]; return YES; } @@ -170,18 +165,20 @@ - (void)stop:(void (^)(void))completion - (void)startRequest:(NSURLRequest *)request { [self loadRequest:request]; - + + UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:self]; + if (_fullScreen) { - [_navController setModalPresentationStyle:UIModalPresentationFullScreen]; + [navController setModalPresentationStyle:UIModalPresentationFullScreen]; } else { - [_navController setModalPresentationStyle:UIModalPresentationFormSheet]; + [navController setModalPresentationStyle:UIModalPresentationFormSheet]; } dispatch_async(dispatch_get_main_queue(), ^{ - [_parentController presentViewController:_navController animated:YES completion:nil]; + [_parentController presentViewController:navController animated:YES completion:nil]; }); } From f6faca6cc7f7aeb0fcc48bf9d12c4d7e8e3cd9f4 Mon Sep 17 00:00:00 2001 From: Ryan Pangrle Date: Tue, 29 Nov 2016 19:57:03 -0800 Subject: [PATCH 66/92] Print hashes in the token item description This causes hashes to show up in our results box which makes it a lot easier to quickly verify that a new token indeed came back. --- ADAL/src/cache/ADTokenCacheItem.m | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ADAL/src/cache/ADTokenCacheItem.m b/ADAL/src/cache/ADTokenCacheItem.m index acf47e7e4..515a085a6 100644 --- a/ADAL/src/cache/ADTokenCacheItem.m +++ b/ADAL/src/cache/ADTokenCacheItem.m @@ -240,8 +240,8 @@ - (NSString*)description { return [NSString stringWithFormat:@"(authority=%@ clientId=%@ accessToken=%@ accessTokenType=%@ refreshToken=%@ resource=%@)", _authority, _clientId, - [NSString adIsStringNilOrBlank:_accessToken] ? @"(nil)" : @"(present)", _accessTokenType, - [NSString adIsStringNilOrBlank:_refreshToken] ? @"(nil)" : @"(present)", _resource]; + [NSString adIsStringNilOrBlank:_accessToken] ? @"(nil)" : [ADLogger getHash:_accessToken], _accessTokenType, + [NSString adIsStringNilOrBlank:_refreshToken] ? @"(nil)" : [ADLogger getHash:_refreshToken], _resource]; } - (NSString *)clientId From c9a65bf2d3a30992c32aaa74fc551f6eb5d5f488 Mon Sep 17 00:00:00 2001 From: Ryan Pangrle Date: Tue, 29 Nov 2016 19:58:32 -0800 Subject: [PATCH 67/92] Mac test app improvements Expanded out the cache window Set better truncation settings on cache columns Added clear cache and clear cookies buttons to the acquire token window --- .../ADTestAppAcquireTokenWindowController.m | 21 +++- .../MyTestMacOSApp/ADTestAppCache.h | 2 + .../MyTestMacOSApp/ADTestAppCache.m | 14 ++- .../ADTestAppCacheWindowController.m | 25 +++- .../MyTestMacOSApp/AcquireTokenWindow.xib | 107 +++++++++++------- .../MyTestMacOSApp/CacheWindow.xib | 57 +++++----- 6 files changed, 151 insertions(+), 75 deletions(-) diff --git a/Samples/MyTestMacOSApp/MyTestMacOSApp/ADTestAppAcquireTokenWindowController.m b/Samples/MyTestMacOSApp/MyTestMacOSApp/ADTestAppAcquireTokenWindowController.m index 99bc29809..58233d295 100644 --- a/Samples/MyTestMacOSApp/MyTestMacOSApp/ADTestAppAcquireTokenWindowController.m +++ b/Samples/MyTestMacOSApp/MyTestMacOSApp/ADTestAppAcquireTokenWindowController.m @@ -28,7 +28,7 @@ #import "ADTokenCache.h" #import "ADAuthenticationSettings.h" #import "ADWebAuthController.h" - +#import "ADTestAppCache.h" @interface ADTestAppAcquireTokenWindowController () @@ -301,6 +301,25 @@ - (IBAction)cancelAuth:(id)sender [ADWebAuthController cancelCurrentWebAuthSession]; } +- (IBAction)clearCache:(id)sender +{ + OSStatus status = [[ADTestAppCache sharedCache] deleteFromKeychain]; + + [_resultView setString:[NSString stringWithFormat:@"Cache cleared (%d)", (int)status]]; +} + +- (IBAction)clearCookies:(id)sender +{ + NSHTTPCookieStorage* cookieStore = [NSHTTPCookieStorage sharedHTTPCookieStorage]; + NSArray* cookies = cookieStore.cookies; + for (NSHTTPCookie* cookie in cookies) + { + [cookieStore deleteCookie:cookie]; + } + + [_resultView setString:[NSString stringWithFormat:@"Cleared %lu cookies.", (unsigned long)cookies.count]]; +} + - (IBAction)acquireTokenSilent:(id)sender { ADTestAppSettings* settings = [ADTestAppSettings settings]; diff --git a/Samples/MyTestMacOSApp/MyTestMacOSApp/ADTestAppCache.h b/Samples/MyTestMacOSApp/MyTestMacOSApp/ADTestAppCache.h index 2952469c0..90e4925ee 100644 --- a/Samples/MyTestMacOSApp/MyTestMacOSApp/ADTestAppCache.h +++ b/Samples/MyTestMacOSApp/MyTestMacOSApp/ADTestAppCache.h @@ -35,4 +35,6 @@ - (void)readFromFile:(NSString *)filePath; - (void)writeToFile:(NSString *)filePath; +- (OSStatus)deleteFromKeychain; + @end diff --git a/Samples/MyTestMacOSApp/MyTestMacOSApp/ADTestAppCache.m b/Samples/MyTestMacOSApp/MyTestMacOSApp/ADTestAppCache.m index 71010e187..d4bdec9bf 100644 --- a/Samples/MyTestMacOSApp/MyTestMacOSApp/ADTestAppCache.m +++ b/Samples/MyTestMacOSApp/MyTestMacOSApp/ADTestAppCache.m @@ -44,8 +44,8 @@ + (ADTestAppCache*)sharedCache dispatch_once(&once, ^{ cache = [[ADTestAppCache alloc] init]; - [cache readFromFile:[self defaultSavePath]]; - + //[cache readFromFile:[self defaultSavePath]]; + [cache readFromKeychain]; [[ADAuthenticationSettings sharedInstance] setDefaultStorageDelegate:cache]; }); @@ -58,7 +58,7 @@ + (NSString*)defaultSavePath static NSString* path = nil; dispatch_once(&once, ^{ - NSURL* homeDir = [[NSFileManager defaultManager] homeDirectoryForCurrentUser]; + NSURL* homeDir = [NSURL fileURLWithPath:NSHomeDirectory()]; path = [homeDir URLByAppendingPathComponent:@"TestApp.adalcache"].path; }); @@ -184,4 +184,12 @@ - (OSStatus)writeToKeychain } } +- (OSStatus)deleteFromKeychain +{ + @synchronized (self) + { + return SecItemDelete((CFDictionaryRef)@{ DEFAULT_KEYCHAIN_ATTRS }); + } +} + @end diff --git a/Samples/MyTestMacOSApp/MyTestMacOSApp/ADTestAppCacheWindowController.m b/Samples/MyTestMacOSApp/MyTestMacOSApp/ADTestAppCacheWindowController.m index e26b36f29..2eb6deedc 100644 --- a/Samples/MyTestMacOSApp/MyTestMacOSApp/ADTestAppCacheWindowController.m +++ b/Samples/MyTestMacOSApp/MyTestMacOSApp/ADTestAppCacheWindowController.m @@ -38,7 +38,7 @@ @implementation NSString (ADTestApp) - (NSString *)truncatedHash { - return [[ADLogger getHash:self] substringToIndex:10]; + return [ADLogger getHash:self]; } @end @@ -135,6 +135,11 @@ - (NSString *)dataForTableColumn:(nullable NSTableColumn *)tableColumn row:(NSIn } else if ([identifier isEqualToString:@"refreshToken"]) { + NSString* refreshToken = item.refreshToken; + if ([refreshToken isEqualToString:@""]) + { + return @""; + } return item.refreshToken.truncatedHash; } else @@ -143,6 +148,23 @@ - (NSString *)dataForTableColumn:(nullable NSTableColumn *)tableColumn row:(NSIn } } +static NSLineBreakMode linebreakForColumn(NSTableColumn* tableColumn) +{ + if (!tableColumn) + { + return NSLineBreakByTruncatingMiddle; + } + + NSString* identifier = tableColumn.identifier; + + if ([identifier isEqualToString:@"upn"] || [identifier isEqualToString:@"expiresOn"]) + { + return NSLineBreakByTruncatingTail; + } + + return NSLineBreakByTruncatingMiddle; +} + /* View Based TableView: Non-bindings: This method is required if you wish to turn on the use of NSViews instead of NSCells. The implementation of this method will usually call -[tableView makeViewWithIdentifier:[tableColumn identifier] owner:self] in order to reuse a previous view, or automatically unarchive an associated prototype view for that identifier. The -frame of the returned view is not important, and it will be automatically set by the table. 'tableColumn' will be nil if the row is a group row. Returning nil is acceptable, and a view will not be shown at that location. The view's properties should be properly set up before returning the result. */ @@ -157,6 +179,7 @@ - (nullable NSView *)tableView:(NSTableView *)tableView viewForTableColumn:(null cell.bordered = NO; cell.drawsBackground = NO; cell.identifier = @"CacheTextCell"; + cell.lineBreakMode = linebreakForColumn(tableColumn); } NSString* text = [self dataForTableColumn:tableColumn row:row]; diff --git a/Samples/MyTestMacOSApp/MyTestMacOSApp/AcquireTokenWindow.xib b/Samples/MyTestMacOSApp/MyTestMacOSApp/AcquireTokenWindow.xib index 121388516..487c855d5 100644 --- a/Samples/MyTestMacOSApp/MyTestMacOSApp/AcquireTokenWindow.xib +++ b/Samples/MyTestMacOSApp/MyTestMacOSApp/AcquireTokenWindow.xib @@ -1,9 +1,10 @@ - + - - + + + @@ -28,20 +29,20 @@ - + - + - + - + @@ -52,7 +53,7 @@ - + @@ -61,7 +62,7 @@ - + @@ -70,7 +71,7 @@ - + @@ -79,7 +80,7 @@ - + @@ -90,7 +91,7 @@ - + @@ -99,7 +100,7 @@ - + @@ -108,7 +109,7 @@ - + @@ -150,7 +151,7 @@ - + @@ -181,7 +182,7 @@ - + @@ -190,7 +191,7 @@ - + @@ -199,7 +200,7 @@ - + @@ -208,7 +209,7 @@ - + @@ -217,7 +218,7 @@ - + @@ -226,7 +227,7 @@ - + @@ -235,7 +236,7 @@ - + @@ -244,7 +245,7 @@ - + @@ -253,7 +254,7 @@ - + @@ -268,21 +269,21 @@ - + - + - + - + - + @@ -294,12 +295,34 @@ - + + + - + - + - + - + diff --git a/Samples/MyTestMacOSApp/MyTestMacOSApp/CacheWindow.xib b/Samples/MyTestMacOSApp/MyTestMacOSApp/CacheWindow.xib index 05dc2545c..6890b1efd 100644 --- a/Samples/MyTestMacOSApp/MyTestMacOSApp/CacheWindow.xib +++ b/Samples/MyTestMacOSApp/MyTestMacOSApp/CacheWindow.xib @@ -1,8 +1,9 @@ - + - + + @@ -16,26 +17,26 @@ - + - + - + - + - + - + @@ -49,11 +50,11 @@ - + - + @@ -82,7 +83,7 @@ - + @@ -101,7 +102,7 @@ - + @@ -115,11 +116,11 @@ - + - + @@ -134,7 +135,7 @@ - + @@ -148,11 +149,11 @@ - + - + @@ -181,7 +182,7 @@ - + @@ -200,7 +201,7 @@ - + @@ -214,11 +215,11 @@ - + - + @@ -247,7 +248,7 @@ - + @@ -274,8 +275,8 @@ - - + - + - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/Samples/MyTestiOSApp/MyTestiOSApp/ADTestAppAcquireTokenViewController.m b/Samples/MyTestiOSApp/MyTestiOSApp/ADTestAppAcquireTokenViewController.m index b44ae4bc4..cbfdb3e81 100644 --- a/Samples/MyTestiOSApp/MyTestiOSApp/ADTestAppAcquireTokenViewController.m +++ b/Samples/MyTestiOSApp/MyTestiOSApp/ADTestAppAcquireTokenViewController.m @@ -23,18 +23,147 @@ #import "ADTestAppAcquireTokenViewController.h" #import "ADTestAppSettings.h" +#import "ADKeychainTokenCache+Internal.h" @interface ADTestAppAcquireTokenViewController () @end +// Apple provides a lot of this in UIStackView in iOS 9, but prior to that we need to build it by hand +@interface ADTestAppSettingsLayoutBuilder : NSObject +{ + UIView* _contentView; + NSMutableDictionary* _views; + NSMutableArray* _keys; + CGRect _screenRect; +} + +- (void)addControl:(UIControl *)control + title:(NSString *)title; + +- (void)addView:(UIView*)view key:(NSString *)key; + +- (void)addCenteredView:(UIView *)view + key:(NSString *)key; + +- (UIView*)contentView; + +@end + +@implementation ADTestAppSettingsLayoutBuilder + +- (id)init +{ + if (!(self = [super init])) + return nil; + + _screenRect = UIScreen.mainScreen.bounds; + _contentView = [[UIView alloc] initWithFrame:_screenRect]; + _contentView.autoresizingMask = UIViewAutoresizingFlexibleWidth; + + _views = [NSMutableDictionary new]; + _keys = [NSMutableArray new]; + + return self; +} + +- (void)addControl:(UIControl *)control + title:(NSString *)title +{ + UIView* view = [[UIView alloc] init]; + UILabel* label = [[UILabel alloc] init]; + label.textColor = UIColor.blackColor; + label.text = title; + label.font = [UIFont systemFontOfSize:12.0]; + label.translatesAutoresizingMaskIntoConstraints = NO; + label.textAlignment = NSTextAlignmentRight; + + [view addSubview:label]; + + control.translatesAutoresizingMaskIntoConstraints = NO; + [view addSubview:control]; + + NSDictionary* views = @{ @"label" : label, @"control" : control }; + NSArray* verticalConstraints1 = [NSLayoutConstraint constraintsWithVisualFormat:@"V:|[label]|" options:0 metrics:NULL views:views]; + NSArray* verticalConstraints2 = [NSLayoutConstraint constraintsWithVisualFormat:@"V:|[control(29)]|" options:0 metrics:NULL views:views]; + NSArray* horizontalConstraints = [NSLayoutConstraint constraintsWithVisualFormat:@"H:|[label(60)]-[control]|" options:NSLayoutFormatAlignAllCenterY metrics:NULL views:views]; + + [view addConstraints:verticalConstraints1]; + [view addConstraints:verticalConstraints2]; + [view addConstraints:horizontalConstraints]; + + [self addView:view key:title]; +} + +- (void)addViewInternal:(UIView*)view key:(NSString *)key +{ + view.translatesAutoresizingMaskIntoConstraints = NO; + [_contentView addSubview:view]; + [_views setObject:view forKey:key]; + [_keys addObject:key]; +} + +- (void)addView:(UIView*)view key:(NSString *)key +{ + [self addViewInternal:view key:key]; + + NSString* horizontalConstraint = [NSString stringWithFormat:@"H:|-6-[%@]-6-|", key]; + NSArray* horizontalConstraints2 = [NSLayoutConstraint constraintsWithVisualFormat:horizontalConstraint options:0 metrics:NULL views:_views]; + [_contentView addConstraints:horizontalConstraints2]; +} + +- (void)addCenteredView:(UIView *)view key:(NSString *)key +{ + [self addViewInternal:view key:key]; + + NSLayoutConstraint* centerConstraint = + [NSLayoutConstraint constraintWithItem:view + attribute:NSLayoutAttributeCenterX + relatedBy:NSLayoutRelationEqual + toItem:_contentView + attribute:NSLayoutAttributeCenterX + multiplier:1.0 + constant:0.0]; + [_contentView addConstraint:centerConstraint]; +} + +- (UIView*)contentView +{ + if (_keys.count == 0) + { + return _contentView; + } + + NSMutableString* verticalConstraint = [NSMutableString new]; + [verticalConstraint appendString:@"V:|-24-"]; + + for (int i = 0; i < _keys.count - 1; i++) + { + NSString* key = _keys[i]; + [verticalConstraint appendFormat:@"[%@]-", key]; + } + + NSString* lastKey = _keys.lastObject; + [verticalConstraint appendFormat:@"[%@(>=200)]-36-|", lastKey]; + + //[verticalConstraint appendString:@"-|"]; + NSArray* verticalConstraints = [NSLayoutConstraint constraintsWithVisualFormat:verticalConstraint options:0 metrics:NULL views:_views]; + [_contentView addConstraints:verticalConstraints]; + + return _contentView; +} + +@end + @implementation ADTestAppAcquireTokenViewController { IBOutlet UIView* _acquireSettingsView; IBOutlet UITextField* _userIdField; IBOutlet UISegmentedControl* _userIdType; + + UISegmentedControl* _promptBehavior; - IBOutlet UISegmentedControl* _credentialsType; + IBOutlet UISegmentedControl* _brokerEnabled; IBOutlet UISegmentedControl* _webViewType; IBOutlet UISegmentedControl* _fullScreen; IBOutlet UISegmentedControl* _validateAuthority; @@ -44,12 +173,15 @@ @implementation ADTestAppAcquireTokenViewController IBOutlet UIView* _authView; IBOutlet UIWebView* _webView; + NSLayoutConstraint* _bottomConstraint; + NSLayoutConstraint* _bottomConstraint2; + BOOL _userIdEdited; } - (id)init { - if (!(self = [super initWithNibName:@"ADTestAppAcquireTokenView" bundle:nil])) + if (!(self = [super init])) { return nil; } @@ -62,22 +194,207 @@ - (id)init return self; } +- (UIView*)createTwoItemLayoutView:(UIView*)item1 + item2:(UIView*)item2 +{ + item1.translatesAutoresizingMaskIntoConstraints = NO; + item2.translatesAutoresizingMaskIntoConstraints = NO; + + UIView* view = [[UIView alloc] init]; + view.translatesAutoresizingMaskIntoConstraints = NO; + [view addSubview:item1]; + [view addSubview:item2]; + + NSDictionary* views = @{@"item1" : item1, @"item2" : item2 }; + NSArray* verticalConstraints1 = [NSLayoutConstraint constraintsWithVisualFormat:@"V:|[item1(20)]|" options:0 metrics:NULL views:views]; + NSArray* verticalConstraints2 = [NSLayoutConstraint constraintsWithVisualFormat:@"V:|[item2(20)]|" options:0 metrics:NULL views:views]; + NSArray* horizontalConstraints = [NSLayoutConstraint constraintsWithVisualFormat:@"H:|[item1]-[item2]|" options:0 metrics:NULL views:views]; + + [view addConstraints:verticalConstraints1]; + [view addConstraints:verticalConstraints2]; + [view addConstraints:horizontalConstraints]; + + return view; +} + +- (UIView*)createSettingsAndResultView +{ + CGRect screenFrame = UIScreen.mainScreen.bounds; + UIScrollView* scrollView = [[UIScrollView alloc] initWithFrame:screenFrame]; + scrollView.translatesAutoresizingMaskIntoConstraints = NO; + scrollView.scrollEnabled = YES; + scrollView.showsVerticalScrollIndicator = YES; + scrollView.showsHorizontalScrollIndicator = NO; + scrollView.userInteractionEnabled = YES; + ADTestAppSettingsLayoutBuilder* layout = [ADTestAppSettingsLayoutBuilder new]; + + _userIdField = [[UITextField alloc] initWithFrame:CGRectMake(0, 0, 400, 20)]; + _userIdField.borderStyle = UITextBorderStyleRoundedRect; + [layout addControl:_userIdField title:@"userId"]; + + _userIdType = [[UISegmentedControl alloc] initWithItems:@[@"Optional", @"Required", @"Unique"]]; + _userIdType.selectedSegmentIndex = 0; + [layout addControl:_userIdType title:@"idType"]; + + _promptBehavior = [[UISegmentedControl alloc] initWithItems:@[@"Always", @"Auto"]]; + _promptBehavior.selectedSegmentIndex = 0; + [layout addControl:_promptBehavior title:@"prompt"]; + + _webViewType = [[UISegmentedControl alloc] initWithItems:@[@"Passed In", @"ADAL"]]; + _webViewType.selectedSegmentIndex = 1; + [layout addControl:_webViewType title:@"webView"]; + + _fullScreen = [[UISegmentedControl alloc] initWithItems:@[@"Yes", @"No"]]; + _fullScreen.selectedSegmentIndex = 0; + [layout addControl:_fullScreen title:@"fullScreen"]; + + _brokerEnabled = [[UISegmentedControl alloc] initWithItems:@[@"Disabled", @"Auto"]]; + [_brokerEnabled setSelectedSegmentIndex:0]; + [layout addControl:_brokerEnabled title:@"broker"]; + + _validateAuthority = [[UISegmentedControl alloc] initWithItems:@[@"Yes", @"No"]]; + [layout addControl:_validateAuthority title:@"valAuth"]; + + UIButton* clearCookies = [UIButton buttonWithType:UIButtonTypeSystem]; + [clearCookies setTitle:@"Clear Cookies" forState:UIControlStateNormal]; + [clearCookies addTarget:self action:@selector(clearCookies:) forControlEvents:UIControlEventTouchUpInside]; + + UIButton* clearCache = [UIButton buttonWithType:UIButtonTypeSystem]; + [clearCache setTitle:@"Clear Cache" forState:UIControlStateNormal]; + [clearCache addTarget:self action:@selector(clearCache:) forControlEvents:UIControlEventTouchUpInside]; + + UIView* clearButtonsView = [self createTwoItemLayoutView:clearCookies item2:clearCache]; + [layout addCenteredView:clearButtonsView key:@"clearButtons"]; + + _resultView = [[UITextView alloc] init]; + _resultView.layer.borderWidth = 1.0f; + _resultView.layer.borderColor = [UIColor colorWithRed:0.9f green:0.9f blue:0.9f alpha:1.0f].CGColor; + _resultView.layer.cornerRadius = 8.0f; + _resultView.backgroundColor = [UIColor colorWithRed:0.96f green:0.96f blue:0.96f alpha:1.0f]; + _resultView.editable = NO; + [layout addView:_resultView key:@"result"]; + + UIView* contentView = [layout contentView]; + [scrollView addSubview:contentView]; + scrollView.contentSize = contentView.bounds.size; + + return scrollView; +} + + +- (void)loadView +{ + CGRect screenFrame = UIScreen.mainScreen.bounds; + UIView* mainView = [[UIView alloc] initWithFrame:screenFrame]; + + UIView* settingsView = [self createSettingsAndResultView]; + [mainView addSubview:settingsView]; + + UIButton* acquireButton = [UIButton buttonWithType:UIButtonTypeSystem]; + [acquireButton setTitle:@"acquire" forState:UIControlStateNormal]; + [acquireButton addTarget:self action:@selector(acquireTokenInteractive:) forControlEvents:UIControlEventTouchUpInside]; + + UIButton* acquireSilentButton = [UIButton buttonWithType:UIButtonTypeSystem]; + [acquireSilentButton setTitle:@"acquireSilent" forState:UIControlStateNormal]; + [acquireSilentButton addTarget:self action:@selector(acquireTokenSilent:) forControlEvents:UIControlEventTouchUpInside]; + + UIView* acquireButtonsView = [self createTwoItemLayoutView:acquireButton item2:acquireSilentButton]; + UIVisualEffect* blurEffect = [UIBlurEffect effectWithStyle:UIBlurEffectStyleLight]; + UIVisualEffectView* acquireBlurView = [[UIVisualEffectView alloc] initWithEffect:blurEffect]; + acquireBlurView.translatesAutoresizingMaskIntoConstraints = NO; + [acquireBlurView.contentView addSubview:acquireButtonsView]; + + NSDictionary* views = @{ @"settings" : settingsView, @"acquire" : acquireBlurView, @"buttons" : acquireButtonsView }; + + // Constraint to center the acquire buttons in the blur view + [acquireBlurView addConstraint:[NSLayoutConstraint constraintWithItem:acquireButtonsView + attribute:NSLayoutAttributeCenterX + relatedBy:NSLayoutRelationEqual + toItem:acquireBlurView + attribute:NSLayoutAttributeCenterX + multiplier:1.0 + constant:0.0]]; + [acquireBlurView addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:|-6-[buttons]-6-|" options:0 metrics:nil views:views]]; + + + [mainView addSubview:acquireBlurView]; + + self.view = mainView; + + // Set up constraints to make the settings scroll view take up the whole screen + [mainView addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:|[settings]|" options:0 metrics:nil views:views]]; + [mainView addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:|[settings(>=200)]" options:0 metrics:nil views:views]]; + _bottomConstraint2 = [NSLayoutConstraint constraintWithItem:settingsView + attribute:NSLayoutAttributeBottom + relatedBy:NSLayoutRelationEqual + toItem:self.bottomLayoutGuide + attribute:NSLayoutAttributeTop + multiplier:1.0 + constant:0]; + [mainView addConstraint:_bottomConstraint2]; + + + // And more constraints to make the acquire buttons view float on top + [mainView addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:|[acquire]|" options:0 metrics:nil views:views]]; + + // This constraint is the one that gets adjusted when the keyboard hides or shows. It moves the acquire buttons to make sure + // they remain in view above the keyboard + _bottomConstraint = [NSLayoutConstraint constraintWithItem:acquireBlurView + attribute:NSLayoutAttributeBottom + relatedBy:NSLayoutRelationEqual + toItem:self.bottomLayoutGuide + attribute:NSLayoutAttributeTop + multiplier:1.0 + constant:0]; + [mainView addConstraint:_bottomConstraint]; +} + - (void)viewDidLoad { [super viewDidLoad]; - // Do any additional setup after loading the view. - [self.view addSubview:_acquireSettingsView]; - [_authView setHidden:YES]; - [self.view addSubview:_authView]; + [[NSNotificationCenter defaultCenter] addObserver:self + selector:@selector(keyboardWillShow:) + name:UIKeyboardWillShowNotification + object:nil]; - [_userIdField addTarget:self action:@selector(textFieldChanged:) forControlEvents:UIControlEventEditingChanged]; + [[NSNotificationCenter defaultCenter] addObserver:self + selector:@selector(keyboardWillHide:) + name:UIKeyboardWillHideNotification + object:nil]; + [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent]; } -- (void)textFieldChanged:(id)sender +- (void)keyboardWillShow:(NSNotification *)aNotification { - _userIdEdited = ![NSString adIsStringNilOrBlank:_userIdField.text]; + NSDictionary* userInfo = aNotification.userInfo; + NSTimeInterval duration = [userInfo[UIKeyboardAnimationDurationUserInfoKey] doubleValue]; + UIViewAnimationCurve curve = [userInfo[UIKeyboardAnimationCurveUserInfoKey] integerValue]; + + CGRect keyboardFrameEnd = [userInfo[UIKeyboardFrameEndUserInfoKey] CGRectValue]; + keyboardFrameEnd = [self.view convertRect:keyboardFrameEnd fromView:nil]; + + [UIView animateWithDuration:duration delay:0 options:UIViewAnimationOptionBeginFromCurrentState | curve animations:^{ + _bottomConstraint.constant = -keyboardFrameEnd.size.height + 49.0; // 49.0 is the height of a tab bar + _bottomConstraint2.constant = -keyboardFrameEnd.size.height + 49.0; + [self.view layoutIfNeeded]; + } completion:nil]; +} + +- (void)keyboardWillHide:(NSNotification *)note { + NSDictionary *userInfo = note.userInfo; + NSTimeInterval duration = [userInfo[UIKeyboardAnimationDurationUserInfoKey] doubleValue]; + UIViewAnimationCurve curve = [userInfo[UIKeyboardAnimationCurveUserInfoKey] integerValue]; + + CGRect keyboardFrameEnd = [userInfo[UIKeyboardFrameEndUserInfoKey] CGRectValue]; + keyboardFrameEnd = [self.view convertRect:keyboardFrameEnd fromView:nil]; + + [UIView animateWithDuration:duration delay:0 options:UIViewAnimationOptionBeginFromCurrentState | curve animations:^{ + _bottomConstraint.constant = 0; + _bottomConstraint2.constant = 0; + [self.view layoutIfNeeded]; + } completion:nil]; } - (void)viewWillAppear:(BOOL)animated @@ -89,7 +406,7 @@ - (void)viewWillAppear:(BOOL)animated } [_validateAuthority setSelectedSegmentIndex:settings.validateAuthority ? 0 : 1]; - [_credentialsType setSelectedSegmentIndex:settings.enableBroker ? 1 : 0]; + [_brokerEnabled setSelectedSegmentIndex:settings.enableBroker ? 1 : 0]; } - (void)didReceiveMemoryWarning { @@ -111,15 +428,15 @@ - (ADUserIdentifier*)identifier ADUserIdentifierType idType = OptionalDisplayableId; - if ([userIdType isEqualToString:@"O"]) + if ([userIdType isEqualToString:@"Optional"]) { idType = OptionalDisplayableId; } - else if ([userIdType isEqualToString:@"R"]) + else if ([userIdType isEqualToString:@"Required"]) { idType = RequiredDisplayableId; } - else if ([userIdType isEqualToString:@"U"]) + else if ([userIdType isEqualToString:@"Unique"]) { idType = UniqueId; } @@ -133,7 +450,7 @@ - (ADUserIdentifier*)identifier - (ADCredentialsType)credType { - NSString* credType = [_credentialsType titleForSegmentAtIndex:[_credentialsType selectedSegmentIndex]]; + NSString* credType = [_brokerEnabled titleForSegmentAtIndex:[_brokerEnabled selectedSegmentIndex]]; if ([credType isEqualToString:@"Disabled"]) { @@ -153,7 +470,7 @@ - (BOOL)embeddedWebView { NSString* webViewType = [_webViewType titleForSegmentAtIndex:[_webViewType selectedSegmentIndex]]; - if ([webViewType isEqualToString:@"ADAL UI"]) + if ([webViewType isEqualToString:@"ADAL"]) { return NO; } @@ -167,16 +484,6 @@ - (BOOL)embeddedWebView } } -- (IBAction)acquireTokenPromptAlways:(id)sender -{ - [self acquireTokenInteractive:AD_PROMPT_ALWAYS]; -} - -- (IBAction)acquireTokenPromptAuto:(id)sender -{ - [self acquireTokenInteractive:AD_PROMPT_AUTO]; -} - - (void)updateResultView:(ADAuthenticationResult*)result { NSString* resultStatus = nil; @@ -198,7 +505,19 @@ - (void)updateResultView:(ADAuthenticationResult*)result printf("%s", [resultText UTF8String]); } -- (void)acquireTokenInteractive:(ADPromptBehavior)promptBehavior +- (ADPromptBehavior)promptBehavior +{ + NSString* label = [_promptBehavior titleForSegmentAtIndex:_promptBehavior.selectedSegmentIndex]; + + if ([label isEqualToString:@"Always"]) + return AD_PROMPT_ALWAYS; + if ([label isEqualToString:@"Auto"]) + return AD_PROMPT_AUTO; + + @throw @"Do not recognize prompt behavior"; +} + +- (void)acquireTokenInteractive:(id)sender { ADTestAppSettings* settings = [ADTestAppSettings settings]; NSString* authority = [settings authority]; @@ -239,7 +558,7 @@ - (void)acquireTokenInteractive:(ADPromptBehavior)promptBehavior [context acquireTokenWithResource:resource clientId:clientId redirectUri:redirectUri - promptBehavior:promptBehavior + promptBehavior:[self promptBehavior] userIdentifier:identifier extraQueryParameters:nil completionBlock:^(ADAuthenticationResult *result) @@ -326,4 +645,24 @@ - (IBAction)acquireTokenSilent:(id)sender }]; } +- (IBAction)clearCache:(id)sender +{ + NSDictionary* query = [[ADKeychainTokenCache defaultKeychainCache] defaultKeychainQuery]; + OSStatus status = SecItemDelete((CFDictionaryRef)query); + + _resultView.text = [NSString stringWithFormat:@"Deleted keychain items (%d)", (int)status]; +} + +- (IBAction)clearCookies:(id)sender +{ + NSHTTPCookieStorage* cookieStore = [NSHTTPCookieStorage sharedHTTPCookieStorage]; + NSArray* cookies = cookieStore.cookies; + for (NSHTTPCookie* cookie in cookies) + { + [cookieStore deleteCookie:cookie]; + } + + _resultView.text = [NSString stringWithFormat:@"Cleared %lu cookies.", (unsigned long)cookies.count]; +} + @end diff --git a/Samples/MyTestiOSApp/MyTestiOSApp/ADTestAppCacheViewController.m b/Samples/MyTestiOSApp/MyTestiOSApp/ADTestAppCacheViewController.m index d8214d98a..911e70ee8 100644 --- a/Samples/MyTestiOSApp/MyTestiOSApp/ADTestAppCacheViewController.m +++ b/Samples/MyTestiOSApp/MyTestiOSApp/ADTestAppCacheViewController.m @@ -426,5 +426,10 @@ - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(N } } +- (void)tableView:(UITableView*)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath*)indexPath +{ + // All tasks are handled by blocks defined in editActionsForRowAtIndexPath, however iOS8 requires this method to enable editing +} + @end diff --git a/Samples/MyTestiOSApp/MyTestiOSApp/ADTestAppSettingsView.xib b/Samples/MyTestiOSApp/MyTestiOSApp/ADTestAppSettingsView.xib deleted file mode 100644 index 61ae23544..000000000 --- a/Samples/MyTestiOSApp/MyTestiOSApp/ADTestAppSettingsView.xib +++ /dev/null @@ -1,156 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/Samples/MyTestiOSApp/MyTestiOSApp/ADTestAppSettingsViewController.m b/Samples/MyTestiOSApp/MyTestiOSApp/ADTestAppSettingsViewController.m index 2878993e0..2f8e342a3 100644 --- a/Samples/MyTestiOSApp/MyTestiOSApp/ADTestAppSettingsViewController.m +++ b/Samples/MyTestiOSApp/MyTestiOSApp/ADTestAppSettingsViewController.m @@ -30,22 +30,58 @@ #import "ADKeychainUtil.h" #import "ADRegistrationInformation.h" +static NSArray* s_profileRows = nil; +static NSArray* s_deviceRows = nil; -@interface ADTestAppSettingsViewController () +@interface ADTestAppSettingsRow : NSObject + +@property (nonatomic, retain) NSString* title; +@property (nonatomic, copy) NSString*(^valueBlock)(); +@property (nonatomic, copy) void(^action)(); + ++ (ADTestAppSettingsRow*)rowWithTitle:(NSString *)title; + +@end + +@implementation ADTestAppSettingsRow + ++ (ADTestAppSettingsRow*)rowWithTitle:(NSString *)title +{ + ADTestAppSettingsRow* row = [ADTestAppSettingsRow new]; + row.title = title; + return row; +} + ++ (ADTestAppSettingsRow*)rowWithTitle:(NSString *)title + value:(NSString*(^)())value +{ + ADTestAppSettingsRow* row = [ADTestAppSettingsRow new]; + row.title = title; + row.valueBlock = value; + return row; +} + +@end + +@interface ADTestAppSettingsViewController () @end @implementation ADTestAppSettingsViewController { - IBOutlet UIButton* _profile; - IBOutlet UIButton* _authority; - IBOutlet UILabel* _clientId; - IBOutlet UILabel* _redirectUri; - IBOutlet UIButton* _resource; - IBOutlet UILabel* _keychainId; - IBOutlet UILabel* _workplaceJoin; + UITableView* _tableView; + + NSArray* _profileRows; + NSArray* _deviceRows; + + NSString* _keychainId; + NSString* _wpjState; } +#define SETTING_ROW(_SETTING) \ + ADTestAppSettingsRow* _SETTING = [ADTestAppSettingsRow rowWithTitle:@#_SETTING]; \ + _SETTING.valueBlock = ^NSString *{ return ADTestAppSettings.settings._SETTING; } + - (id)init { if (!(self = [super init])) @@ -58,20 +94,47 @@ - (id)init image:[UIImage imageNamed:@"Settings"] tag:0]; + + NSString* teamId = [ADKeychainUtil keychainTeamId:nil]; + _keychainId = teamId ? teamId : @""; + + ADTestAppSettingsRow* profileRow = [ADTestAppSettingsRow rowWithTitle:@"profile"]; + profileRow.valueBlock = ^NSString *{ return ADTestAppSettings.currentProfileTitle; }; + profileRow.action = ^{ [self gotoProfile:nil]; }; + SETTING_ROW(authority); + SETTING_ROW(clientId); + SETTING_ROW(resource); + ADTestAppSettingsRow* redirectUri = [ADTestAppSettingsRow rowWithTitle:@"redirectUri"]; + redirectUri.valueBlock = ^NSString *{ return [ADTestAppSettings.settings.redirectUri absoluteString]; }; + + _profileRows = @[ profileRow, authority, clientId, redirectUri, resource]; + + + + _deviceRows = @[ [ADTestAppSettingsRow rowWithTitle:@"TeamID" value:^NSString *{ return _keychainId; }], + [ADTestAppSettingsRow rowWithTitle:@"WPJ State" value:^NSString *{ return _wpjState; }]]; + return self; } +- (void)loadView +{ + CGRect screenFrame = UIScreen.mainScreen.bounds; + _tableView = [[UITableView alloc] initWithFrame:screenFrame]; + _tableView.delegate = self; + _tableView.dataSource = self; + _tableView.allowsSelection = YES; + + self.view = _tableView; +} + - (void)viewDidLoad { [super viewDidLoad]; - - NSString* teamId = [ADKeychainUtil keychainTeamId:nil]; - - [_keychainId setText: teamId ? teamId : @"" ]; - - [self refreshProfileSettings]; } + + - (void)viewWillAppear:(BOOL)animated { ADRegistrationInformation* regInfo = @@ -88,24 +151,97 @@ - (void)viewWillAppear:(BOOL)animated wpjLabel = @"WPJ Registration Found"; } - [_workplaceJoin setText:wpjLabel]; + _wpjState = wpjLabel; - [self refreshProfileSettings]; + [_tableView reloadData]; } -- (IBAction)gotoProfile:(id)sender +- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { - [self.navigationController pushViewController:[ADTestAppProfileViewController sharedProfileViewController] animated:YES]; + if (section == 0) + return _profileRows.count; + if (section == 1) + return _deviceRows.count; + + return 0; } -- (void)refreshProfileSettings +- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView; { - ADTestAppSettings* settings = [ADTestAppSettings settings]; - [_authority setTitle:settings.authority forState:UIControlStateNormal]; - [_clientId setText:settings.clientId]; - [_redirectUri setText:settings.redirectUri.absoluteString]; - [_resource setTitle:settings.resource forState:UIControlStateNormal]; - [_profile setTitle:[ADTestAppSettings currentProfileTitle] forState:UIControlStateNormal]; + return 2; +} + +- (nullable NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section +{ + if (section == 0) + return @"Authentication Settings"; + if (section == 1) + return @"Device State"; + + return nil; +} + + +- (ADTestAppSettingsRow*)rowForIndexPath:(NSIndexPath *)indexPath +{ + NSInteger section = [indexPath indexAtPosition:0]; + NSInteger row = [indexPath indexAtPosition:1]; + + if (section == 0) + { + return _profileRows[row]; + } + + if (section == 1) + { + return _deviceRows[row]; + } + + return nil; +} + +- (nullable NSIndexPath *)tableView:(UITableView *)tableView willSelectRowAtIndexPath:(NSIndexPath *)indexPath +{ + ADTestAppSettingsRow* row = [self rowForIndexPath:indexPath]; + if (!row.action) + return nil; + + row.action(); + return nil; +} + +// Row display. Implementers should *always* try to reuse cells by setting each cell's reuseIdentifier and querying for available reusable cells with dequeueReusableCellWithIdentifier: +// Cell gets various attributes set automatically based on table (separators) and data source (accessory views, editing controls) + +- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath +{ + UITableViewCell* cell = [tableView dequeueReusableCellWithIdentifier:@"settingsCell"]; + if (!cell) + { + cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:@"settingsCell"]; + } + + ADTestAppSettingsRow* row = [self rowForIndexPath:indexPath]; + cell.textLabel.text = row.title; + cell.detailTextLabel.text = row.valueBlock(); + + if (row.action) + { + cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator; + } + + return cell; +} + +- (void)tableView:(UITableView *)tableView accessoryButtonTappedForRowWithIndexPath:(NSIndexPath *)indexPath +{ + ADTestAppSettingsRow* row = [self rowForIndexPath:indexPath]; + row.action(); +} + +- (IBAction)gotoProfile:(id)sender +{ + [self.navigationController pushViewController:[ADTestAppProfileViewController sharedProfileViewController] animated:YES]; } @end From f3ca7e7acba3261c18744b7f55d560661ac6ff9f Mon Sep 17 00:00:00 2001 From: Ryan Pangrle Date: Thu, 1 Dec 2016 14:49:14 -0800 Subject: [PATCH 69/92] Separate out the layout builder into its own class, add back passed in webview --- .../MyTestiOSApp.xcodeproj/project.pbxproj | 6 + .../ADTestAppAcquireLayoutBuilder.h | 45 ++++ .../ADTestAppAcquireLayoutBuilder.m | 129 +++++++++++ .../ADTestAppAcquireTokenViewController.m | 200 ++++++------------ 4 files changed, 242 insertions(+), 138 deletions(-) create mode 100644 Samples/MyTestiOSApp/MyTestiOSApp/ADTestAppAcquireLayoutBuilder.h create mode 100644 Samples/MyTestiOSApp/MyTestiOSApp/ADTestAppAcquireLayoutBuilder.m diff --git a/Samples/MyTestiOSApp/MyTestiOSApp.xcodeproj/project.pbxproj b/Samples/MyTestiOSApp/MyTestiOSApp.xcodeproj/project.pbxproj index 1eefd4d4e..9d9a93c2d 100644 --- a/Samples/MyTestiOSApp/MyTestiOSApp.xcodeproj/project.pbxproj +++ b/Samples/MyTestiOSApp/MyTestiOSApp.xcodeproj/project.pbxproj @@ -24,6 +24,7 @@ 8BA42B2717E3C150002D206E /* CoreData.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 8BA42AFF17E3C150002D206E /* CoreData.framework */; }; 8BA42B2F17E3C150002D206E /* InfoPlist.strings in Resources */ = {isa = PBXBuildFile; fileRef = 8BA42B2D17E3C150002D206E /* InfoPlist.strings */; }; 8BA42B3117E3C150002D206E /* MyTestiOSAppTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 8BA42B3017E3C150002D206E /* MyTestiOSAppTests.m */; }; + D6119CE61DF0D86A004EC0E0 /* ADTestAppAcquireLayoutBuilder.m in Sources */ = {isa = PBXBuildFile; fileRef = D6119CE51DF0D86A004EC0E0 /* ADTestAppAcquireLayoutBuilder.m */; }; D68ACD301CD42710008EFA17 /* ADTestAppProfileViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = D68ACD2F1CD42710008EFA17 /* ADTestAppProfileViewController.m */; }; D68B4A2B1CB5A80700758FB3 /* ADTestAppAcquireTokenViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = D68B4A2A1CB5A80700758FB3 /* ADTestAppAcquireTokenViewController.m */; }; D68B4A311CB5A85D00758FB3 /* ADTestAppCacheViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = D68B4A301CB5A85D00758FB3 /* ADTestAppCacheViewController.m */; }; @@ -163,6 +164,8 @@ 8BA42B2C17E3C150002D206E /* MyTestiOSAppTests-Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = "MyTestiOSAppTests-Info.plist"; sourceTree = ""; }; 8BA42B2E17E3C150002D206E /* en */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = en; path = en.lproj/InfoPlist.strings; sourceTree = ""; }; 8BA42B3017E3C150002D206E /* MyTestiOSAppTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = MyTestiOSAppTests.m; sourceTree = ""; }; + D6119CE41DF0D86A004EC0E0 /* ADTestAppAcquireLayoutBuilder.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ADTestAppAcquireLayoutBuilder.h; sourceTree = ""; }; + D6119CE51DF0D86A004EC0E0 /* ADTestAppAcquireLayoutBuilder.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ADTestAppAcquireLayoutBuilder.m; sourceTree = ""; }; D68ACD2E1CD42710008EFA17 /* ADTestAppProfileViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ADTestAppProfileViewController.h; sourceTree = ""; }; D68ACD2F1CD42710008EFA17 /* ADTestAppProfileViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ADTestAppProfileViewController.m; sourceTree = ""; }; D68B4A291CB5A80700758FB3 /* ADTestAppAcquireTokenViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ADTestAppAcquireTokenViewController.h; sourceTree = ""; }; @@ -276,6 +279,8 @@ 8BA42B0217E3C150002D206E /* Supporting Files */, D68B4A291CB5A80700758FB3 /* ADTestAppAcquireTokenViewController.h */, D68B4A2A1CB5A80700758FB3 /* ADTestAppAcquireTokenViewController.m */, + D6119CE41DF0D86A004EC0E0 /* ADTestAppAcquireLayoutBuilder.h */, + D6119CE51DF0D86A004EC0E0 /* ADTestAppAcquireLayoutBuilder.m */, D6D034841CB6D74E00406721 /* ADTestAppSettingsViewController.h */, D6D034851CB6D74E00406721 /* ADTestAppSettingsViewController.m */, D68B4A2F1CB5A85D00758FB3 /* ADTestAppCacheViewController.h */, @@ -539,6 +544,7 @@ 8BA42B0C17E3C150002D206E /* ADTestAppDelegate.m in Sources */, D68B4A2B1CB5A80700758FB3 /* ADTestAppAcquireTokenViewController.m in Sources */, D68ACD301CD42710008EFA17 /* ADTestAppProfileViewController.m in Sources */, + D6119CE61DF0D86A004EC0E0 /* ADTestAppAcquireLayoutBuilder.m in Sources */, D6D034871CB6D74E00406721 /* ADTestAppSettingsViewController.m in Sources */, D68B4A311CB5A85D00758FB3 /* ADTestAppCacheViewController.m in Sources */, 8B87548C189978350061999F /* ADTestAppSettings.m in Sources */, diff --git a/Samples/MyTestiOSApp/MyTestiOSApp/ADTestAppAcquireLayoutBuilder.h b/Samples/MyTestiOSApp/MyTestiOSApp/ADTestAppAcquireLayoutBuilder.h new file mode 100644 index 000000000..37f390657 --- /dev/null +++ b/Samples/MyTestiOSApp/MyTestiOSApp/ADTestAppAcquireLayoutBuilder.h @@ -0,0 +1,45 @@ +// Copyright (c) Microsoft Corporation. +// All rights reserved. +// +// This code is licensed under the MIT License. +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files(the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and / or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions : +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE. + +#import + +// Apple provides a lot of this in UIStackView in iOS 9, but prior to that we need to build it by hand +@interface ADTestAppAcquireLayoutBuilder : NSObject +{ + UIView* _contentView; + NSMutableDictionary* _views; + NSMutableArray* _keys; + CGRect _screenRect; +} + +- (void)addControl:(UIControl *)control + title:(NSString *)title; + +- (void)addView:(UIView*)view key:(NSString *)key; + +- (void)addCenteredView:(UIView *)view + key:(NSString *)key; + +- (UIView*)contentView; + +@end diff --git a/Samples/MyTestiOSApp/MyTestiOSApp/ADTestAppAcquireLayoutBuilder.m b/Samples/MyTestiOSApp/MyTestiOSApp/ADTestAppAcquireLayoutBuilder.m new file mode 100644 index 000000000..2cd6526d0 --- /dev/null +++ b/Samples/MyTestiOSApp/MyTestiOSApp/ADTestAppAcquireLayoutBuilder.m @@ -0,0 +1,129 @@ +// Copyright (c) Microsoft Corporation. +// All rights reserved. +// +// This code is licensed under the MIT License. +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files(the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and / or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions : +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE. + +#import "ADTestAppAcquireLayoutBuilder.h" + +@implementation ADTestAppAcquireLayoutBuilder + +- (id)init +{ + if (!(self = [super init])) + return nil; + + _screenRect = UIScreen.mainScreen.bounds; + _contentView = [[UIView alloc] initWithFrame:_screenRect]; + _contentView.autoresizingMask = UIViewAutoresizingFlexibleWidth; + + _views = [NSMutableDictionary new]; + _keys = [NSMutableArray new]; + + return self; +} + +- (void)addControl:(UIControl *)control + title:(NSString *)title +{ + UIView* view = [[UIView alloc] init]; + UILabel* label = [[UILabel alloc] init]; + label.textColor = UIColor.blackColor; + label.text = title; + label.font = [UIFont systemFontOfSize:12.0]; + label.translatesAutoresizingMaskIntoConstraints = NO; + label.textAlignment = NSTextAlignmentRight; + + [view addSubview:label]; + + control.translatesAutoresizingMaskIntoConstraints = NO; + [view addSubview:control]; + + NSDictionary* views = @{ @"label" : label, @"control" : control }; + NSArray* verticalConstraints1 = [NSLayoutConstraint constraintsWithVisualFormat:@"V:|[label]|" options:0 metrics:NULL views:views]; + NSArray* verticalConstraints2 = [NSLayoutConstraint constraintsWithVisualFormat:@"V:|[control(29)]|" options:0 metrics:NULL views:views]; + NSArray* horizontalConstraints = [NSLayoutConstraint constraintsWithVisualFormat:@"H:|[label(60)]-[control]|" options:NSLayoutFormatAlignAllCenterY metrics:NULL views:views]; + + [view addConstraints:verticalConstraints1]; + [view addConstraints:verticalConstraints2]; + [view addConstraints:horizontalConstraints]; + + [self addView:view key:title]; +} + +- (void)addViewInternal:(UIView*)view key:(NSString *)key +{ + view.translatesAutoresizingMaskIntoConstraints = NO; + [_contentView addSubview:view]; + [_views setObject:view forKey:key]; + [_keys addObject:key]; +} + +- (void)addView:(UIView*)view key:(NSString *)key +{ + [self addViewInternal:view key:key]; + + NSString* horizontalConstraint = [NSString stringWithFormat:@"H:|-6-[%@]-6-|", key]; + NSArray* horizontalConstraints2 = [NSLayoutConstraint constraintsWithVisualFormat:horizontalConstraint options:0 metrics:NULL views:_views]; + [_contentView addConstraints:horizontalConstraints2]; +} + +- (void)addCenteredView:(UIView *)view key:(NSString *)key +{ + [self addViewInternal:view key:key]; + + NSLayoutConstraint* centerConstraint = + [NSLayoutConstraint constraintWithItem:view + attribute:NSLayoutAttributeCenterX + relatedBy:NSLayoutRelationEqual + toItem:_contentView + attribute:NSLayoutAttributeCenterX + multiplier:1.0 + constant:0.0]; + [_contentView addConstraint:centerConstraint]; +} + +- (UIView*)contentView +{ + if (_keys.count == 0) + { + return _contentView; + } + + NSMutableString* verticalConstraint = [NSMutableString new]; + [verticalConstraint appendString:@"V:|-24-"]; + + for (int i = 0; i < _keys.count - 1; i++) + { + NSString* key = _keys[i]; + [verticalConstraint appendFormat:@"[%@]-", key]; + } + + NSString* lastKey = _keys.lastObject; + [verticalConstraint appendFormat:@"[%@(>=200)]-36-|", lastKey]; + + //[verticalConstraint appendString:@"-|"]; + NSArray* verticalConstraints = [NSLayoutConstraint constraintsWithVisualFormat:verticalConstraint options:0 metrics:NULL views:_views]; + [_contentView addConstraints:verticalConstraints]; + + return _contentView; +} + +@end diff --git a/Samples/MyTestiOSApp/MyTestiOSApp/ADTestAppAcquireTokenViewController.m b/Samples/MyTestiOSApp/MyTestiOSApp/ADTestAppAcquireTokenViewController.m index cbfdb3e81..8c676ce9b 100644 --- a/Samples/MyTestiOSApp/MyTestiOSApp/ADTestAppAcquireTokenViewController.m +++ b/Samples/MyTestiOSApp/MyTestiOSApp/ADTestAppAcquireTokenViewController.m @@ -24,137 +24,12 @@ #import "ADTestAppAcquireTokenViewController.h" #import "ADTestAppSettings.h" #import "ADKeychainTokenCache+Internal.h" +#import "ADTestAppAcquireLayoutBuilder.h" @interface ADTestAppAcquireTokenViewController () @end -// Apple provides a lot of this in UIStackView in iOS 9, but prior to that we need to build it by hand -@interface ADTestAppSettingsLayoutBuilder : NSObject -{ - UIView* _contentView; - NSMutableDictionary* _views; - NSMutableArray* _keys; - CGRect _screenRect; -} - -- (void)addControl:(UIControl *)control - title:(NSString *)title; - -- (void)addView:(UIView*)view key:(NSString *)key; - -- (void)addCenteredView:(UIView *)view - key:(NSString *)key; - -- (UIView*)contentView; - -@end - -@implementation ADTestAppSettingsLayoutBuilder - -- (id)init -{ - if (!(self = [super init])) - return nil; - - _screenRect = UIScreen.mainScreen.bounds; - _contentView = [[UIView alloc] initWithFrame:_screenRect]; - _contentView.autoresizingMask = UIViewAutoresizingFlexibleWidth; - - _views = [NSMutableDictionary new]; - _keys = [NSMutableArray new]; - - return self; -} - -- (void)addControl:(UIControl *)control - title:(NSString *)title -{ - UIView* view = [[UIView alloc] init]; - UILabel* label = [[UILabel alloc] init]; - label.textColor = UIColor.blackColor; - label.text = title; - label.font = [UIFont systemFontOfSize:12.0]; - label.translatesAutoresizingMaskIntoConstraints = NO; - label.textAlignment = NSTextAlignmentRight; - - [view addSubview:label]; - - control.translatesAutoresizingMaskIntoConstraints = NO; - [view addSubview:control]; - - NSDictionary* views = @{ @"label" : label, @"control" : control }; - NSArray* verticalConstraints1 = [NSLayoutConstraint constraintsWithVisualFormat:@"V:|[label]|" options:0 metrics:NULL views:views]; - NSArray* verticalConstraints2 = [NSLayoutConstraint constraintsWithVisualFormat:@"V:|[control(29)]|" options:0 metrics:NULL views:views]; - NSArray* horizontalConstraints = [NSLayoutConstraint constraintsWithVisualFormat:@"H:|[label(60)]-[control]|" options:NSLayoutFormatAlignAllCenterY metrics:NULL views:views]; - - [view addConstraints:verticalConstraints1]; - [view addConstraints:verticalConstraints2]; - [view addConstraints:horizontalConstraints]; - - [self addView:view key:title]; -} - -- (void)addViewInternal:(UIView*)view key:(NSString *)key -{ - view.translatesAutoresizingMaskIntoConstraints = NO; - [_contentView addSubview:view]; - [_views setObject:view forKey:key]; - [_keys addObject:key]; -} - -- (void)addView:(UIView*)view key:(NSString *)key -{ - [self addViewInternal:view key:key]; - - NSString* horizontalConstraint = [NSString stringWithFormat:@"H:|-6-[%@]-6-|", key]; - NSArray* horizontalConstraints2 = [NSLayoutConstraint constraintsWithVisualFormat:horizontalConstraint options:0 metrics:NULL views:_views]; - [_contentView addConstraints:horizontalConstraints2]; -} - -- (void)addCenteredView:(UIView *)view key:(NSString *)key -{ - [self addViewInternal:view key:key]; - - NSLayoutConstraint* centerConstraint = - [NSLayoutConstraint constraintWithItem:view - attribute:NSLayoutAttributeCenterX - relatedBy:NSLayoutRelationEqual - toItem:_contentView - attribute:NSLayoutAttributeCenterX - multiplier:1.0 - constant:0.0]; - [_contentView addConstraint:centerConstraint]; -} - -- (UIView*)contentView -{ - if (_keys.count == 0) - { - return _contentView; - } - - NSMutableString* verticalConstraint = [NSMutableString new]; - [verticalConstraint appendString:@"V:|-24-"]; - - for (int i = 0; i < _keys.count - 1; i++) - { - NSString* key = _keys[i]; - [verticalConstraint appendFormat:@"[%@]-", key]; - } - - NSString* lastKey = _keys.lastObject; - [verticalConstraint appendFormat:@"[%@(>=200)]-36-|", lastKey]; - - //[verticalConstraint appendString:@"-|"]; - NSArray* verticalConstraints = [NSLayoutConstraint constraintsWithVisualFormat:verticalConstraint options:0 metrics:NULL views:_views]; - [_contentView addConstraints:verticalConstraints]; - - return _contentView; -} - -@end - @implementation ADTestAppAcquireTokenViewController { IBOutlet UIView* _acquireSettingsView; @@ -226,7 +101,7 @@ - (UIView*)createSettingsAndResultView scrollView.showsVerticalScrollIndicator = YES; scrollView.showsHorizontalScrollIndicator = NO; scrollView.userInteractionEnabled = YES; - ADTestAppSettingsLayoutBuilder* layout = [ADTestAppSettingsLayoutBuilder new]; + ADTestAppAcquireLayoutBuilder* layout = [ADTestAppAcquireLayoutBuilder new]; _userIdField = [[UITextField alloc] initWithFrame:CGRectMake(0, 0, 400, 20)]; _userIdField.borderStyle = UITextBorderStyleRoundedRect; @@ -281,15 +156,8 @@ - (UIView*)createSettingsAndResultView return scrollView; } - -- (void)loadView +- (UIView *)createAcquireButtonsView { - CGRect screenFrame = UIScreen.mainScreen.bounds; - UIView* mainView = [[UIView alloc] initWithFrame:screenFrame]; - - UIView* settingsView = [self createSettingsAndResultView]; - [mainView addSubview:settingsView]; - UIButton* acquireButton = [UIButton buttonWithType:UIButtonTypeSystem]; [acquireButton setTitle:@"acquire" forState:UIControlStateNormal]; [acquireButton addTarget:self action:@selector(acquireTokenInteractive:) forControlEvents:UIControlEventTouchUpInside]; @@ -304,8 +172,6 @@ - (void)loadView acquireBlurView.translatesAutoresizingMaskIntoConstraints = NO; [acquireBlurView.contentView addSubview:acquireButtonsView]; - NSDictionary* views = @{ @"settings" : settingsView, @"acquire" : acquireBlurView, @"buttons" : acquireButtonsView }; - // Constraint to center the acquire buttons in the blur view [acquireBlurView addConstraint:[NSLayoutConstraint constraintWithItem:acquireButtonsView attribute:NSLayoutAttributeCenterX @@ -314,13 +180,71 @@ - (void)loadView attribute:NSLayoutAttributeCenterX multiplier:1.0 constant:0.0]]; + NSDictionary* views = @{ @"buttons" : acquireButtonsView }; [acquireBlurView addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:|-6-[buttons]-6-|" options:0 metrics:nil views:views]]; + return acquireBlurView; +} + +- (UIView *)createWebOverlay +{ + UIVisualEffect* blurEffect = [UIBlurEffect effectWithStyle:UIBlurEffectStyleLight]; + UIVisualEffectView* blurView = [[UIVisualEffectView alloc] initWithEffect:blurEffect]; + blurView.translatesAutoresizingMaskIntoConstraints = NO; + blurView.layer.borderWidth = 1.0f; + blurView.layer.borderColor = [UIColor colorWithRed:0.9f green:0.9f blue:0.9f alpha:1.0f].CGColor; + blurView.layer.cornerRadius = 8.0f; + blurView.clipsToBounds = YES; + + UIView* contentView = blurView.contentView; + + _webView = [[UIWebView alloc] init]; + _webView.translatesAutoresizingMaskIntoConstraints = NO; + [contentView addSubview:_webView]; + + UIButton* cancelButton = [UIButton buttonWithType:UIButtonTypeSystem]; + cancelButton.translatesAutoresizingMaskIntoConstraints = NO; + [cancelButton setTitle:@"Cancel" forState:UIControlStateNormal]; + [cancelButton addTarget:self action:@selector(cancelAuth:) forControlEvents:UIControlEventTouchUpInside]; + [contentView addSubview:cancelButton]; + + NSDictionary* views = @{ @"webView" : _webView, @"cancelButton" : cancelButton }; + [contentView addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:|-8-[webView]-[cancelButton]-8-|" options:0 metrics:nil views:views]]; + [contentView addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:|-8-[webView]-|" options:0 metrics:nil views:views]]; + [contentView addConstraint:[NSLayoutConstraint constraintWithItem:cancelButton + attribute:NSLayoutAttributeCenterX + relatedBy:NSLayoutRelationEqual + toItem:contentView + attribute:NSLayoutAttributeCenterX + multiplier:1.0 + constant:0.0]]; + + return blurView; +} + + +- (void)loadView +{ + CGRect screenFrame = UIScreen.mainScreen.bounds; + UIView* mainView = [[UIView alloc] initWithFrame:screenFrame]; + + UIView* settingsView = [self createSettingsAndResultView]; + [mainView addSubview:settingsView]; + UIView* acquireBlurView = [self createAcquireButtonsView]; [mainView addSubview:acquireBlurView]; + _authView = [self createWebOverlay]; + _authView.hidden = YES; + [mainView addSubview:_authView]; + self.view = mainView; + NSDictionary* views = @{ @"settings" : settingsView, @"acquire" : acquireBlurView, @"authView" : _authView }; + // Set up constraints for the web overlay + [mainView addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:|-34-[authView]-10-|" options:0 metrics:nil views:views]]; + [mainView addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:|-10-[authView]-10-|" options:0 metrics:nil views:views]]; + // Set up constraints to make the settings scroll view take up the whole screen [mainView addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:|[settings]|" options:0 metrics:nil views:views]]; [mainView addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:|[settings(>=200)]" options:0 metrics:nil views:views]]; @@ -545,7 +469,7 @@ - (void)acquireTokenInteractive:(id)sender if ([self embeddedWebView]) { [context setWebView:_webView]; - [_authView setFrame:self.view.frame]; + //[_authView setFrame:self.view.frame]; [UIView animateWithDuration:0.5 animations:^{ [_acquireSettingsView setHidden:YES]; From 1a50fc9679c8b4eeabf16b60b5d76a29c16f5c61 Mon Sep 17 00:00:00 2001 From: Ryan Pangrle Date: Thu, 1 Dec 2016 14:53:18 -0800 Subject: [PATCH 70/92] Remove the isHidden check, we aren't hiding the acquire settings anymore --- .../MyTestiOSApp/ADTestAppAcquireTokenViewController.m | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/Samples/MyTestiOSApp/MyTestiOSApp/ADTestAppAcquireTokenViewController.m b/Samples/MyTestiOSApp/MyTestiOSApp/ADTestAppAcquireTokenViewController.m index 8c676ce9b..a8f55cbc4 100644 --- a/Samples/MyTestiOSApp/MyTestiOSApp/ADTestAppAcquireTokenViewController.m +++ b/Samples/MyTestiOSApp/MyTestiOSApp/ADTestAppAcquireTokenViewController.m @@ -506,13 +506,9 @@ - (void)acquireTokenInteractive:(id)sender dispatch_async(dispatch_get_main_queue(), ^{ [self updateResultView:result]; - if ([_acquireSettingsView isHidden]) - { - [_webView loadHTMLString:@"done!" baseURL:nil]; - [_authView setHidden:YES]; - [_acquireSettingsView setHidden:NO]; - [self.view setNeedsDisplay]; - } + [_webView loadHTMLString:@"done!" baseURL:nil]; + [_authView setHidden:YES]; + [self.view setNeedsDisplay]; [[NSNotificationCenter defaultCenter] postNotificationName:ADTestAppCacheChangeNotification object:self]; }); From 890ab317416efac9240c9d3d44d7e87d718d7912 Mon Sep 17 00:00:00 2001 From: Ryan Pangrle Date: Fri, 2 Dec 2016 15:10:33 -0800 Subject: [PATCH 71/92] Add "--no-xcpretty" switch Sometimes xcpretty doesn't print out output, which can make things difficult to debug. --- build.py | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/build.py b/build.py index c990f3d24..84453a905 100755 --- a/build.py +++ b/build.py @@ -31,6 +31,8 @@ default_workspace = "ADAL.xcworkspace" +use_xcpretty = True + class tclr: HDR = '\033[1m' OK = '\033[32m\033[1m' @@ -109,7 +111,10 @@ def do_ios_build(target, operation) : else : command += " -workspace " + workspace - command += " -scheme \"" + scheme + "\" -configuration CodeCoverage " + ios_sim_flags + " " + ios_sim_dest + " | xcpretty" + command += " -scheme \"" + scheme + "\" -configuration CodeCoverage " + ios_sim_flags + " " + ios_sim_dest + if (use_xcpretty) : + commanmd += " | xcpretty" + print command exit_code = subprocess.call("set -o pipefail;" + command, shell = True) @@ -126,9 +131,10 @@ def do_mac_build(target, operation) : command = "xcodebuild " + operation + " -workspace " + default_workspace + " -scheme \"" + scheme + "\"" if (arch != None) : - command = command + " -destination 'arch=" + arch + "'" + command += " -destination 'arch=" + arch + "'" - command = command + " | xcpretty" + if (use_xcpretty) : + command += " | xcpretty" print command exit_code = subprocess.call("set -o pipefail;" + command, shell = True) @@ -163,6 +169,8 @@ def check_dependencies(target) : for arg in sys.argv : if (arg == "--no-clean") : clean = False + if (arg == "--no-xcpretty") : + use_xcpretty = False # start by cleaning up any derived data that might be lying around if (clean) : From 5ca465cc7518743166cb06dd4e65c4e1fdcb8c10 Mon Sep 17 00:00:00 2001 From: Ryan Pangrle Date: Fri, 2 Dec 2016 17:08:33 -0800 Subject: [PATCH 72/92] misspelled "command" --- build.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.py b/build.py index 84453a905..e88bcd27f 100755 --- a/build.py +++ b/build.py @@ -113,7 +113,7 @@ def do_ios_build(target, operation) : command += " -scheme \"" + scheme + "\" -configuration CodeCoverage " + ios_sim_flags + " " + ios_sim_dest if (use_xcpretty) : - commanmd += " | xcpretty" + command += " | xcpretty" print command exit_code = subprocess.call("set -o pipefail;" + command, shell = True) From 7052acadc56ea81a5c71e6d0ac2e63634beeac71 Mon Sep 17 00:00:00 2001 From: Ryan Pangrle Date: Fri, 2 Dec 2016 20:57:11 -0800 Subject: [PATCH 73/92] Dispatch to the main thread first and create the alert The associated object call created some memory management issues when the server is misbehaving. --- ADAL/src/ui/ios/UIAlertView+Additions.m | 29 ++++++++++--------------- 1 file changed, 11 insertions(+), 18 deletions(-) diff --git a/ADAL/src/ui/ios/UIAlertView+Additions.m b/ADAL/src/ui/ios/UIAlertView+Additions.m index 5c9a70e49..fa1157694 100755 --- a/ADAL/src/ui/ios/UIAlertView+Additions.m +++ b/ADAL/src/ui/ios/UIAlertView+Additions.m @@ -11,15 +11,21 @@ @implementation UIAlertView (Additions) + (void)presentCredentialAlert:(void (^)(NSUInteger))handler { - if (![ADAppExtensionUtil isExecutingInAppExtension]) + if ([ADAppExtensionUtil isExecutingInAppExtension]) { + handler(0); + return; + } + + + dispatch_async(dispatch_get_main_queue(), ^{ NSBundle* bundle = [ADALFrameworkUtils frameworkBundle]; if (!bundle) { bundle = [NSBundle mainBundle]; } - + alert = [[UIAlertView alloc] initWithFrame:CGRectZero]; alert.title = NSLocalizedStringFromTableInBundle(@"Enter your credentials", nil, bundle, nil); alert.alertViewStyle = UIAlertViewStyleLoginAndPasswordInput; @@ -29,21 +35,8 @@ + (void)presentCredentialAlert:(void (^)(NSUInteger))handler [alert setCancelButtonIndex:0]; [alert setDelegate:alert]; - - if (handler) - { - objc_setAssociatedObject(alert, HANDLER_KEY, handler, OBJC_ASSOCIATION_COPY_NONATOMIC); - } - - dispatch_async(dispatch_get_main_queue(), ^(void){ - [alert show]; - }); - } - else - { - // Show nothing - handler(0); - } + [alert show]; + }); } - (void)alertView:(UIAlertView*)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex @@ -62,4 +55,4 @@ + (id)getAlertInstance return alert; } -@end \ No newline at end of file +@end From c1c924143194e125d9465f5178abd5835693ba85 Mon Sep 17 00:00:00 2001 From: Ryan Pangrle Date: Mon, 5 Dec 2016 18:37:20 -0800 Subject: [PATCH 74/92] Replace UIAlertView with UIAlertController UIAlertView was deprecated with iOS 9, UIAlertController has been available since iOS 8, as iOS 8 is our min OS we can move to it. Our previous code using UIAlertView had some suspect memory management in it that caused crashes in edge cases. The UIAlertController code does not have that issue. --- ADAL/ADAL.xcodeproj/project.pbxproj | 6 --- ADAL/src/ui/ios/ADNTLMUIPrompt.m | 60 +++++++++++++++++++------ ADAL/src/ui/ios/UIAlertView+Additions.h | 8 ---- ADAL/src/ui/ios/UIAlertView+Additions.m | 58 ------------------------ 4 files changed, 47 insertions(+), 85 deletions(-) delete mode 100644 ADAL/src/ui/ios/UIAlertView+Additions.h delete mode 100755 ADAL/src/ui/ios/UIAlertView+Additions.m diff --git a/ADAL/ADAL.xcodeproj/project.pbxproj b/ADAL/ADAL.xcodeproj/project.pbxproj index 874d1ff38..a3cb5dfc8 100755 --- a/ADAL/ADAL.xcodeproj/project.pbxproj +++ b/ADAL/ADAL.xcodeproj/project.pbxproj @@ -249,7 +249,6 @@ D664F1911D302B9C0017B799 /* ADHelpers.m in Sources */ = {isa = PBXBuildFile; fileRef = 9453C3611C580157006B9E79 /* ADHelpers.m */; }; D664F1921D302B9C0017B799 /* ADAuthenticationParameters.m in Sources */ = {isa = PBXBuildFile; fileRef = 8BB8346118074CFA007F9F0D /* ADAuthenticationParameters.m */; }; D664F1931D302B9C0017B799 /* ADWebAuthController.m in Sources */ = {isa = PBXBuildFile; fileRef = 946818A41C59B7EE00CA0378 /* ADWebAuthController.m */; }; - D664F1941D302B9C0017B799 /* UIAlertView+Additions.m in Sources */ = {isa = PBXBuildFile; fileRef = 9453C31F1C57FBCB006B9E79 /* UIAlertView+Additions.m */; }; D664F1951D302B9C0017B799 /* ADBrokerKeyHelper.m in Sources */ = {isa = PBXBuildFile; fileRef = 9453C37A1C5801CB006B9E79 /* ADBrokerKeyHelper.m */; }; D664F1961D302B9C0017B799 /* ADAuthenticationViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 946818A81C59B80800CA0378 /* ADAuthenticationViewController.m */; }; D664F1971D302B9C0017B799 /* ADAcquireTokenSilentHandler.m in Sources */ = {isa = PBXBuildFile; fileRef = D6F095141CDC072200D28FC2 /* ADAcquireTokenSilentHandler.m */; }; @@ -481,8 +480,6 @@ 9430C3551C55862A00D6506D /* ADAuthorityValidationTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ADAuthorityValidationTests.m; sourceTree = ""; }; 9434C3361BF6B72E0095E122 /* ADLogger+Internal.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "ADLogger+Internal.h"; sourceTree = ""; }; 9453C3011C57149A006B9E79 /* ADRegistrationInformation.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ADRegistrationInformation.h; sourceTree = ""; }; - 9453C31E1C57FBCB006B9E79 /* UIAlertView+Additions.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "UIAlertView+Additions.h"; sourceTree = ""; }; - 9453C31F1C57FBCB006B9E79 /* UIAlertView+Additions.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "UIAlertView+Additions.m"; sourceTree = ""; }; 9453C3201C57FBCB006B9E79 /* UIApplication+ADExtensions.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "UIApplication+ADExtensions.h"; sourceTree = ""; }; 9453C3211C57FBCB006B9E79 /* UIApplication+ADExtensions.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "UIApplication+ADExtensions.m"; sourceTree = ""; }; 9453C3371C57FC2A006B9E79 /* ADTokenCache.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ADTokenCache.m; sourceTree = ""; }; @@ -996,8 +993,6 @@ children = ( 946818A81C59B80800CA0378 /* ADAuthenticationViewController.m */, 9453C4681C58709D006B9E79 /* ADNTLMUIPrompt.m */, - 9453C31E1C57FBCB006B9E79 /* UIAlertView+Additions.h */, - 9453C31F1C57FBCB006B9E79 /* UIAlertView+Additions.m */, 9453C3201C57FBCB006B9E79 /* UIApplication+ADExtensions.h */, 9453C3211C57FBCB006B9E79 /* UIApplication+ADExtensions.m */, ); @@ -1849,7 +1844,6 @@ D664F1911D302B9C0017B799 /* ADHelpers.m in Sources */, D664F1921D302B9C0017B799 /* ADAuthenticationParameters.m in Sources */, D664F1931D302B9C0017B799 /* ADWebAuthController.m in Sources */, - D664F1941D302B9C0017B799 /* UIAlertView+Additions.m in Sources */, D664F1951D302B9C0017B799 /* ADBrokerKeyHelper.m in Sources */, D664F1961D302B9C0017B799 /* ADAuthenticationViewController.m in Sources */, D664F1971D302B9C0017B799 /* ADAcquireTokenSilentHandler.m in Sources */, diff --git a/ADAL/src/ui/ios/ADNTLMUIPrompt.m b/ADAL/src/ui/ios/ADNTLMUIPrompt.m index cb9bfe9f3..4ef1d2bb8 100644 --- a/ADAL/src/ui/ios/ADNTLMUIPrompt.m +++ b/ADAL/src/ui/ios/ADNTLMUIPrompt.m @@ -21,26 +21,60 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN // THE SOFTWARE. -#import "UIAlertView+Additions.h" #import "ADNTLMUIPrompt.h" +#import "ADAppExtensionUtil.h" +#import "ADWebAuthController+Internal.h" +#import "ADAuthenticationViewController.h" +#import "ADALFrameworkUtils.h" @implementation ADNTLMUIPrompt + (void)presentPrompt:(void (^)(NSString * username, NSString * password))block { - [UIAlertView presentCredentialAlert:^(NSUInteger index) { - if (index == 1) - { - UITextField* tfUsername = [[UIAlertView getAlertInstance] textFieldAtIndex:0]; - NSString* username = tfUsername.text; - UITextField* tfPassword = [[UIAlertView getAlertInstance] textFieldAtIndex:1]; - NSString* password = tfPassword.text; - - block(username, password); - } else { - block(nil, nil); - } + UIViewController* viewController = [[ADWebAuthController sharedInstance] viewController]; + if ([ADAppExtensionUtil isExecutingInAppExtension] || !viewController) + { + block(nil, nil); + return; + } + + NSBundle* bundle = [ADALFrameworkUtils frameworkBundle]; + + NSString* title = NSLocalizedStringFromTableInBundle(@"Enter your credentials", nil, bundle, nil); + UIAlertController* alert = [UIAlertController alertControllerWithTitle:title + message:nil + preferredStyle:UIAlertControllerStyleAlert]; + + UIAlertAction* cancelAction = + [UIAlertAction actionWithTitle:NSLocalizedStringFromTableInBundle(@"Cancel", nil, bundle, nil) + style:UIAlertActionStyleCancel + handler:^(UIAlertAction * _Nonnull action) + { + (void)action; + block(nil, nil); + }]; + + UIAlertAction* loginAction = + [UIAlertAction actionWithTitle:NSLocalizedStringFromTableInBundle(@"Login", nil, bundle, nil) + style:UIAlertActionStyleDefault + handler:^(UIAlertAction * _Nonnull action) + { + (void)action; + UITextField* username = alert.textFields.firstObject; + UITextField* password = alert.textFields.lastObject; + + block(username.text, password.text); }]; + + [alert addAction:cancelAction]; + [alert addAction:loginAction]; + + [alert addTextFieldWithConfigurationHandler:^(UITextField * _Nonnull textField) { (void)textField; }]; + [alert addTextFieldWithConfigurationHandler:^(UITextField * _Nonnull textField) { + textField.secureTextEntry = YES; + }]; + + [viewController presentViewController:alert animated:YES completion:^{}]; } @end diff --git a/ADAL/src/ui/ios/UIAlertView+Additions.h b/ADAL/src/ui/ios/UIAlertView+Additions.h deleted file mode 100644 index 83cee31d5..000000000 --- a/ADAL/src/ui/ios/UIAlertView+Additions.h +++ /dev/null @@ -1,8 +0,0 @@ -#import - -@interface UIAlertView (Additions) - -+ (void)presentCredentialAlert:(void(^)(NSUInteger index))handler; - -+ (id) getAlertInstance; -@end \ No newline at end of file diff --git a/ADAL/src/ui/ios/UIAlertView+Additions.m b/ADAL/src/ui/ios/UIAlertView+Additions.m deleted file mode 100755 index fa1157694..000000000 --- a/ADAL/src/ui/ios/UIAlertView+Additions.m +++ /dev/null @@ -1,58 +0,0 @@ -#import -#import "ADWebAuthController.h" -#import "ADALFrameworkUtils.h" -#import "ADAppExtensionUtil.h" - -@implementation UIAlertView (Additions) - -static const char* HANDLER_KEY = "com.microsoft.adal.alertviewHandler"; - -static UIAlertView* alert; - -+ (void)presentCredentialAlert:(void (^)(NSUInteger))handler -{ - if ([ADAppExtensionUtil isExecutingInAppExtension]) - { - handler(0); - return; - } - - - dispatch_async(dispatch_get_main_queue(), ^{ - NSBundle* bundle = [ADALFrameworkUtils frameworkBundle]; - - if (!bundle) - { - bundle = [NSBundle mainBundle]; - } - - alert = [[UIAlertView alloc] initWithFrame:CGRectZero]; - alert.title = NSLocalizedStringFromTableInBundle(@"Enter your credentials", nil, bundle, nil); - alert.alertViewStyle = UIAlertViewStyleLoginAndPasswordInput; - - [alert addButtonWithTitle:NSLocalizedStringFromTableInBundle(@"Cancel", nil, bundle, nil)]; - [alert addButtonWithTitle:NSLocalizedStringFromTableInBundle(@"Login", nil, bundle, nil)]; - [alert setCancelButtonIndex:0]; - - [alert setDelegate:alert]; - [alert show]; - }); -} - -- (void)alertView:(UIAlertView*)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex -{ - id handler = objc_getAssociatedObject(alertView, HANDLER_KEY); - - if (handler) - { - // Execute associated handler - ((void(^)())handler)(buttonIndex); - } -} - -+ (id)getAlertInstance -{ - return alert; -} - -@end From 123559f85459f45a3027acbec746f65d8358e96e Mon Sep 17 00:00:00 2001 From: Ryan Pangrle Date: Mon, 5 Dec 2016 18:38:05 -0800 Subject: [PATCH 75/92] New NTLMUIPrompt needs to be able to get at the authentication view controller --- ADAL/src/ui/ADWebAuthController+Internal.h | 2 ++ ADAL/src/ui/ADWebAuthController.m | 5 +++++ 2 files changed, 7 insertions(+) diff --git a/ADAL/src/ui/ADWebAuthController+Internal.h b/ADAL/src/ui/ADWebAuthController+Internal.h index f2d956108..b438a6b75 100644 --- a/ADAL/src/ui/ADWebAuthController+Internal.h +++ b/ADAL/src/ui/ADWebAuthController+Internal.h @@ -53,4 +53,6 @@ typedef void (^ADBrokerCallback)(ADAuthenticationError* error, NSURL*); + (void)setInterruptedBrokerResult:(ADAuthenticationResult*)result; #endif // TARGET_OS_IPHONE +- (ADAuthenticationViewController*)viewController; + @end diff --git a/ADAL/src/ui/ADWebAuthController.m b/ADAL/src/ui/ADWebAuthController.m index 476a7152c..375c11725 100755 --- a/ADAL/src/ui/ADWebAuthController.m +++ b/ADAL/src/ui/ADWebAuthController.m @@ -651,4 +651,9 @@ + (void)setInterruptedBrokerResult:(ADAuthenticationResult*)result } #endif // TARGET_OS_IPHONE +- (ADAuthenticationViewController*)viewController +{ + return _authenticationViewController; +} + @end From bbb0c97fe832c03bef5ebe34132a6850474e0b30 Mon Sep 17 00:00:00 2001 From: Ryan Pangrle Date: Tue, 6 Dec 2016 13:16:04 -0800 Subject: [PATCH 76/92] Remove unused addition to NSURL --- ADAL/src/utils/NSURL+ADExtensions.h | 1 - ADAL/src/utils/NSURL+ADExtensions.m | 19 ------------------- 2 files changed, 20 deletions(-) diff --git a/ADAL/src/utils/NSURL+ADExtensions.h b/ADAL/src/utils/NSURL+ADExtensions.h index 0cbb24f90..953715973 100644 --- a/ADAL/src/utils/NSURL+ADExtensions.h +++ b/ADAL/src/utils/NSURL+ADExtensions.h @@ -25,7 +25,6 @@ @interface NSURL ( ADAL ) -@property (readonly, nonatomic) NSString *adAuthority; @property (readonly, nonatomic) NSDictionary *adFragmentParameters; @property (readonly, nonatomic) NSDictionary *adQueryParameters; diff --git a/ADAL/src/utils/NSURL+ADExtensions.m b/ADAL/src/utils/NSURL+ADExtensions.m index f2fe8c3ef..a48a58785 100644 --- a/ADAL/src/utils/NSURL+ADExtensions.m +++ b/ADAL/src/utils/NSURL+ADExtensions.m @@ -30,25 +30,6 @@ @implementation NSURL ( ADAL ) -- (NSString *) adAuthority -{ - NSInteger port = self.port.integerValue; - - if ( port == 0 ) - { - if ( [self.scheme isEqualToString:@"http"] ) - { - port = 80; - } - else if ( [self.scheme isEqualToString:@"https"] ) - { - port = 443; - } - } - - return [NSString stringWithFormat:@"%@:%ld", self.host, (long)port]; -} - //Used for getting the parameters from either the fragment or the query //string. This internal helper method attempts to extract the parameters //for the substring of the URL succeeding the separator. Also, if the From 6b76e610b11ed5af2c6e265094c0dcd60ea69555 Mon Sep 17 00:00:00 2001 From: Ryan Pangrle Date: Tue, 6 Dec 2016 13:16:39 -0800 Subject: [PATCH 77/92] Remove unused method in ADWebRequest --- ADAL/src/request/ADWebRequest.m | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/ADAL/src/request/ADWebRequest.m b/ADAL/src/request/ADWebRequest.m index 8b5d4fe6b..3e526523d 100644 --- a/ADAL/src/request/ADWebRequest.m +++ b/ADAL/src/request/ADWebRequest.m @@ -40,7 +40,6 @@ @interface ADWebRequest () - (void)completeWithError:(NSError *)error andResponse:(ADWebResponse *)response; - (void)send; -- (BOOL)verifyRequestURL:(NSURL *)requestURL; @end @@ -216,17 +215,6 @@ - (void)send [_connection start]; } -- (BOOL)verifyRequestURL:(NSURL *)requestURL -{ - if ( requestURL == nil ) - return NO; - - if ( ![requestURL.scheme isEqualToString:@"http"] && ![requestURL.scheme isEqualToString:@"https"] ) - return NO; - - return YES; -} - #pragma mark - NSURLConnectionDelegate // Connection Authentication From 40a5ec5c1becd73077a6d1a72c3ce1b632818467 Mon Sep 17 00:00:00 2001 From: Ryan Pangrle Date: Tue, 6 Dec 2016 13:17:52 -0800 Subject: [PATCH 78/92] Do UI on the main thread --- ADAL/src/ui/ios/ADNTLMUIPrompt.m | 85 ++++++++++++++++++-------------- 1 file changed, 47 insertions(+), 38 deletions(-) diff --git a/ADAL/src/ui/ios/ADNTLMUIPrompt.m b/ADAL/src/ui/ios/ADNTLMUIPrompt.m index 4ef1d2bb8..c8cbbb8e3 100644 --- a/ADAL/src/ui/ios/ADNTLMUIPrompt.m +++ b/ADAL/src/ui/ios/ADNTLMUIPrompt.m @@ -31,50 +31,59 @@ @implementation ADNTLMUIPrompt + (void)presentPrompt:(void (^)(NSString * username, NSString * password))block { - UIViewController* viewController = [[ADWebAuthController sharedInstance] viewController]; - if ([ADAppExtensionUtil isExecutingInAppExtension] || !viewController) + + if ([ADAppExtensionUtil isExecutingInAppExtension]) { block(nil, nil); return; } - NSBundle* bundle = [ADALFrameworkUtils frameworkBundle]; - - NSString* title = NSLocalizedStringFromTableInBundle(@"Enter your credentials", nil, bundle, nil); - UIAlertController* alert = [UIAlertController alertControllerWithTitle:title - message:nil - preferredStyle:UIAlertControllerStyleAlert]; - - UIAlertAction* cancelAction = - [UIAlertAction actionWithTitle:NSLocalizedStringFromTableInBundle(@"Cancel", nil, bundle, nil) - style:UIAlertActionStyleCancel - handler:^(UIAlertAction * _Nonnull action) - { - (void)action; - block(nil, nil); - }]; - - UIAlertAction* loginAction = - [UIAlertAction actionWithTitle:NSLocalizedStringFromTableInBundle(@"Login", nil, bundle, nil) - style:UIAlertActionStyleDefault - handler:^(UIAlertAction * _Nonnull action) - { - (void)action; - UITextField* username = alert.textFields.firstObject; - UITextField* password = alert.textFields.lastObject; + dispatch_async(dispatch_get_main_queue(), ^{ + UIViewController* viewController = [[ADWebAuthController sharedInstance] viewController]; + if (!viewController) + { + block(nil, nil); + return; + } - block(username.text, password.text); - }]; - - [alert addAction:cancelAction]; - [alert addAction:loginAction]; - - [alert addTextFieldWithConfigurationHandler:^(UITextField * _Nonnull textField) { (void)textField; }]; - [alert addTextFieldWithConfigurationHandler:^(UITextField * _Nonnull textField) { - textField.secureTextEntry = YES; - }]; - - [viewController presentViewController:alert animated:YES completion:^{}]; + NSBundle* bundle = [ADALFrameworkUtils frameworkBundle]; + + NSString* title = NSLocalizedStringFromTableInBundle(@"Enter your credentials", nil, bundle, nil); + UIAlertController* alert = [UIAlertController alertControllerWithTitle:title + message:nil + preferredStyle:UIAlertControllerStyleAlert]; + + UIAlertAction* cancelAction = + [UIAlertAction actionWithTitle:NSLocalizedStringFromTableInBundle(@"Cancel", nil, bundle, nil) + style:UIAlertActionStyleCancel + handler:^(UIAlertAction * _Nonnull action) + { + (void)action; + block(nil, nil); + }]; + + UIAlertAction* loginAction = + [UIAlertAction actionWithTitle:NSLocalizedStringFromTableInBundle(@"Login", nil, bundle, nil) + style:UIAlertActionStyleDefault + handler:^(UIAlertAction * _Nonnull action) + { + (void)action; + UITextField* username = alert.textFields.firstObject; + UITextField* password = alert.textFields.lastObject; + + block(username.text, password.text); + }]; + + [alert addAction:cancelAction]; + [alert addAction:loginAction]; + + [alert addTextFieldWithConfigurationHandler:^(UITextField * _Nonnull textField) { (void)textField; }]; + [alert addTextFieldWithConfigurationHandler:^(UITextField * _Nonnull textField) { + textField.secureTextEntry = YES; + }]; + + [viewController presentViewController:alert animated:YES completion:^{}]; + }); } @end From 59153cd35ea4b2edc12ab4d4535789f39246cd99 Mon Sep 17 00:00:00 2001 From: jasoncoolmax Date: Tue, 6 Dec 2016 23:56:01 -0800 Subject: [PATCH 79/92] make ADTelemetry.h public, add unit test to verify telemetry output --- ADAL/ADAL.xcodeproj/project.pbxproj | 10 +- ADAL/src/public/ADAL.h | 1 + ADAL/src/{telemetry => public}/ADTelemetry.h | 0 .../ADAuthenticationRequest+AcquireToken.m | 1 + ADAL/src/telemetry/ADTelemetryHttpEvent.m | 7 +- ADAL/tests/ADTelemetryTests.m | 202 +++++++++++++----- 6 files changed, 158 insertions(+), 63 deletions(-) rename ADAL/src/{telemetry => public}/ADTelemetry.h (100%) diff --git a/ADAL/ADAL.xcodeproj/project.pbxproj b/ADAL/ADAL.xcodeproj/project.pbxproj index 874d1ff38..d3f2c987e 100755 --- a/ADAL/ADAL.xcodeproj/project.pbxproj +++ b/ADAL/ADAL.xcodeproj/project.pbxproj @@ -64,6 +64,9 @@ 605C16821D8FD0AC0097DBA0 /* ADTelemetryEventStrings.m in Sources */ = {isa = PBXBuildFile; fileRef = 605C16801D8FD0AC0097DBA0 /* ADTelemetryEventStrings.m */; }; 605C16831D8FD1AC0097DBA0 /* ADTelemetryEventStrings.m in Sources */ = {isa = PBXBuildFile; fileRef = 605C16801D8FD0AC0097DBA0 /* ADTelemetryEventStrings.m */; }; 6071B5E41C14C0B0006F6CC2 /* ADTestURLConnection.m in Sources */ = {isa = PBXBuildFile; fileRef = 6071B5E31C14C0B0006F6CC2 /* ADTestURLConnection.m */; }; + 6085CBF01DF764EB004BBF2A /* ADTelemetry.h in Copy Files */ = {isa = PBXBuildFile; fileRef = 6004019F1D340B760020EAAB /* ADTelemetry.h */; }; + 6085CBF31DF76982004BBF2A /* ADTelemetry.h in Headers */ = {isa = PBXBuildFile; fileRef = 6004019F1D340B760020EAAB /* ADTelemetry.h */; settings = {ATTRIBUTES = (Public, ); }; }; + 6085CBF41DF76C3C004BBF2A /* ADTelemetry.h in Headers */ = {isa = PBXBuildFile; fileRef = 6004019F1D340B760020EAAB /* ADTelemetry.h */; settings = {ATTRIBUTES = (Public, ); }; }; 60C351BA1DA0D588006C8435 /* ADAL.m in Sources */ = {isa = PBXBuildFile; fileRef = 60C351B91DA0D588006C8435 /* ADAL.m */; }; 60D2F3FF1D524F7A008725D9 /* ADRequestParameters.h in Headers */ = {isa = PBXBuildFile; fileRef = 60D2F3FE1D524F7A008725D9 /* ADRequestParameters.h */; }; 60D2F4021D531F16008725D9 /* ADRequestParameters.m in Sources */ = {isa = PBXBuildFile; fileRef = 60D2F4001D531F16008725D9 /* ADRequestParameters.m */; }; @@ -366,6 +369,7 @@ dstPath = include/ADAL; dstSubfolderSpec = 16; files = ( + 6085CBF01DF764EB004BBF2A /* ADTelemetry.h in Copy Files */, D69A720C1D4FF65200E91DB3 /* ADAL.h in Copy Files */, D69A720D1D4FF65200E91DB3 /* ADAuthenticationContext.h in Copy Files */, D69A720E1D4FF65200E91DB3 /* ADAuthenticationError.h in Copy Files */, @@ -726,7 +730,6 @@ 600401A21D3420C10020EAAB /* telemetry */ = { isa = PBXGroup; children = ( - 6004019F1D340B760020EAAB /* ADTelemetry.h */, 600401A61D3426250020EAAB /* ADTelemetry+Internal.h */, 600401A31D3421480020EAAB /* ADTelemetry.m */, 600401C11D39A18E0020EAAB /* ADDefaultDispatcher.h */, @@ -1096,6 +1099,7 @@ 9453C3BD1C583AE6006B9E79 /* ADErrorCodes.h */, 9453C3BE1C583AE6006B9E79 /* ADLogger.h */, 9453C3BF1C583AE6006B9E79 /* ADTokenCacheItem.h */, + 6004019F1D340B760020EAAB /* ADTelemetry.h */, 9453C3C01C583AE6006B9E79 /* ADUserIdentifier.h */, 9453C3C11C583AE6006B9E79 /* ADUserInformation.h */, 9453C3C21C583AE6006B9E79 /* ADWebAuthController.h */, @@ -1253,6 +1257,7 @@ 9453C3DA1C583E8B006B9E79 /* ADAuthenticationSettings.h in Headers */, 9453C3D81C583E8B006B9E79 /* ADAuthenticationParameters.h in Headers */, 9453C3DD1C583E8B006B9E79 /* ADTokenCacheItem.h in Headers */, + 6085CBF31DF76982004BBF2A /* ADTelemetry.h in Headers */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -1263,6 +1268,7 @@ 9453C4461C58647E006B9E79 /* NSURL+ADExtensions.h in Headers */, 9453C40B1C586456006B9E79 /* ADAuthenticationParameters+Internal.h in Headers */, 94DD18D31C5AC8DE00F80C62 /* ADAuthenticationResult.h in Headers */, + 6085CBF41DF76C3C004BBF2A /* ADTelemetry.h in Headers */, D6F0951A1CDC2BC300D28FC2 /* ADWebAuthRequest.h in Headers */, 9453C40E1C586456006B9E79 /* ADAuthenticationResult+Internal.h in Headers */, 9453C4481C58647E006B9E79 /* NSUUID+ADExtensions.h in Headers */, @@ -1814,6 +1820,7 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( + D69A72191D4FF68300E91DB3 /* ADTelemetry.m in Sources */, 605C16831D8FD1AC0097DBA0 /* ADTelemetryEventStrings.m in Sources */, 603389291D595AD50024A9BF /* ADTelemetryUIEvent.m in Sources */, 6033892A1D595AD50024A9BF /* ADTelemetryHttpEvent.m in Sources */, @@ -1831,7 +1838,6 @@ D664F1811D302B9C0017B799 /* ADWebAuthResponse.m in Sources */, D664F1821D302B9C0017B799 /* ADWorkPlaceJoinUtil.m in Sources */, D664F1831D302B9C0017B799 /* ADJwtHelper.m in Sources */, - D69A72191D4FF68300E91DB3 /* ADTelemetry.m in Sources */, D664F1841D302B9C0017B799 /* ADNTLMHandler.m in Sources */, D664F1851D302B9C0017B799 /* ADAuthenticationRequest+Broker.m in Sources */, D664F1861D302B9C0017B799 /* ADTokenCacheItem+Internal.m in Sources */, diff --git a/ADAL/src/public/ADAL.h b/ADAL/src/public/ADAL.h index 0d736826a..d8ffc3825 100644 --- a/ADAL/src/public/ADAL.h +++ b/ADAL/src/public/ADAL.h @@ -58,6 +58,7 @@ typedef void(^ADAuthenticationCallback)(ADAuthenticationResult* result); #import #import #import +#import #if TARGET_OS_IPHONE #import diff --git a/ADAL/src/telemetry/ADTelemetry.h b/ADAL/src/public/ADTelemetry.h similarity index 100% rename from ADAL/src/telemetry/ADTelemetry.h rename to ADAL/src/public/ADTelemetry.h diff --git a/ADAL/src/request/ADAuthenticationRequest+AcquireToken.m b/ADAL/src/request/ADAuthenticationRequest+AcquireToken.m index 2accc4917..1b8c4b8b8 100644 --- a/ADAL/src/request/ADAuthenticationRequest+AcquireToken.m +++ b/ADAL/src/request/ADAuthenticationRequest+AcquireToken.m @@ -80,6 +80,7 @@ - (void)acquireToken:(NSString *)eventName [event setCorrelationId:self.correlationId]; [event setClientId:_requestParams.clientId]; + [event setAuthority:_context.authority]; [event setExtendedExpiresOnSetting:[_requestParams extendedLifetime]? AD_TELEMETRY_YES:AD_TELEMETRY_NO]; [event setPromptBehavior:_promptBehavior]; [event setUserInformation:[[result tokenCacheItem] userInformation]]; diff --git a/ADAL/src/telemetry/ADTelemetryHttpEvent.m b/ADAL/src/telemetry/ADTelemetryHttpEvent.m index 3798f9c7e..f8528d3c0 100644 --- a/ADAL/src/telemetry/ADTelemetryHttpEvent.m +++ b/ADAL/src/telemetry/ADTelemetryHttpEvent.m @@ -88,11 +88,8 @@ - (void)addAggregatedPropertiesToDictionary:(NSMutableDictionary*)eventToBeDispa NSArray* properties = [self getProperties]; for (ADTelemetryProperty* property in properties) { - if ([property.name isEqualToString:AD_TELEMETRY_HTTP_RESPONSE_CODE] - ||[property.name isEqualToString:AD_TELEMETRY_OAUTH_ERROR_CODE] - ||[property.name isEqualToString:AD_TELEMETRY_HTTP_ERROR_DOMAIN] - ||[property.name isEqualToString:AD_TELEMETRY_HTTP_PATH] - ||[property.name isEqualToString:AD_TELEMETRY_HTTP_REQUEST_ID_HEADER]) + if ([property.name isEqualToString:AD_TELEMETRY_OAUTH_ERROR_CODE] + ||[property.name isEqualToString:AD_TELEMETRY_HTTP_ERROR_DOMAIN]) { [eventToBeDispatched setObject:property.value forKey:property.name]; } diff --git a/ADAL/tests/ADTelemetryTests.m b/ADAL/tests/ADTelemetryTests.m index c1101e765..254d5c192 100644 --- a/ADAL/tests/ADTelemetryTests.m +++ b/ADAL/tests/ADTelemetryTests.m @@ -26,6 +26,11 @@ #import "ADTelemetry+Internal.h" #import "ADTelemetryDefaultEvent.h" #import "ADTelemetryAPIEvent.h" +#import "ADAuthenticationContext+Internal.h" +#import "ADTestURLConnection.h" +#import "XCTestCase+TestHelperMethods.h" +#import "ADTokenCache+Internal.h" +#import "ADTokenCacheItem.h" typedef void(^TestCallback)(NSArray* event); @@ -57,19 +62,35 @@ - (void)dispatchEvent:(NSArray*)event @end @interface ADTelemetryTests : XCTestCase - +{ +@private + dispatch_semaphore_t _dsem; +} @end @implementation ADTelemetryTests -- (void)setUp { +- (void)setUp +{ [super setUp]; + [self adTestBegin:ADAL_LOG_LEVEL_INFO]; + _dsem = dispatch_semaphore_create(0); } -- (void)tearDown { +- (void)tearDown +{ +#if !__has_feature(objc_arc) + dispatch_release(_dsem); +#endif + _dsem = nil; + + XCTAssertTrue([ADTestURLConnection noResponsesLeft]); + [ADTestURLConnection clearResponses]; + [self adTestEnd]; [super tearDown]; } + - (void)testDefaultEventProperties { // new a dispatcher TestDispatcher* dispatcher = [TestDispatcher new]; @@ -99,34 +120,26 @@ - (void)testDefaultEventProperties { // make sure the default properties are recorded in the telemetry event, // i.e. sdk_id, sdk_version, device_id, device_name - XCTAssertNotNil([self getPropertyFromEvent:[receivedEvents firstObject] - propertyName:@"x-client-SKU"]); XCTAssertEqual([self getPropertyCount:[receivedEvents firstObject] propertyName:@"x-client-SKU"], 1); - XCTAssertNotNil([self getPropertyFromEvent:[receivedEvents firstObject] - propertyName:@"x-client-Ver"]); XCTAssertEqual([self getPropertyCount:[receivedEvents firstObject] propertyName:@"x-client-Ver"], 1); - - XCTAssertNotNil([self getPropertyFromEvent:[receivedEvents firstObject] - propertyName:@"device_id"]); + XCTAssertEqual([self getPropertyCount:[receivedEvents firstObject] propertyName:@"device_id"], 1); - XCTAssertNotNil([self getPropertyFromEvent:[receivedEvents firstObject] - propertyName:@"request_id"]); XCTAssertEqual([self getPropertyCount:[receivedEvents firstObject] propertyName:@"request_id"], 1); - XCTAssertNotNil([self getPropertyFromEvent:[receivedEvents firstObject] - propertyName:@"correlation_id"]); XCTAssertEqual([self getPropertyCount:[receivedEvents firstObject] propertyName:@"correlation_id"], 1); - // application_name, application_version are also default properties, - // but they are not available in unit test framework, so we omit them here + XCTAssertEqual([self getPropertyCount:[receivedEvents firstObject] + propertyName:@"application_version"], 1); + XCTAssertEqual([self getPropertyCount:[receivedEvents firstObject] + propertyName:@"application_name"], 1); } - (void)testSequentialEvents { @@ -166,38 +179,25 @@ - (void)testSequentialEvents { XCTAssertEqual([receivedEvents count], 2); // make sure the 1st event has an event_name, start_time and stop_time - XCTAssertNotNil([self getPropertyFromEvent:[receivedEvents firstObject] - propertyName:@"event_name"]); XCTAssertEqual([self getPropertyCount:[receivedEvents firstObject] propertyName:@"event_name"], 1); - XCTAssertNotNil([self getPropertyFromEvent:[receivedEvents firstObject] - propertyName:@"start_time"]); XCTAssertEqual([self getPropertyCount:[receivedEvents firstObject] propertyName:@"start_time"], 1); - XCTAssertNotNil([self getPropertyFromEvent:[receivedEvents firstObject] - propertyName:@"stop_time"]); XCTAssertEqual([self getPropertyCount:[receivedEvents firstObject] propertyName:@"stop_time"], 1); // make sure the 2nd event has customized_property, event_name, start_time and stop_time - XCTAssertNotNil([self getPropertyFromEvent:[receivedEvents objectAtIndex:1] - propertyName:@"customized_property"]); XCTAssertEqual([self getPropertyCount:[receivedEvents objectAtIndex:1] propertyName:@"customized_property"], 1); - XCTAssertNotNil([self getPropertyFromEvent:[receivedEvents firstObject] - propertyName:@"event_name"]); + XCTAssertEqual([self getPropertyCount:[receivedEvents firstObject] propertyName:@"event_name"], 1); - XCTAssertNotNil([self getPropertyFromEvent:[receivedEvents firstObject] - propertyName:@"start_time"]); XCTAssertEqual([self getPropertyCount:[receivedEvents firstObject] propertyName:@"start_time"], 1); - XCTAssertNotNil([self getPropertyFromEvent:[receivedEvents firstObject] - propertyName:@"stop_time"]); XCTAssertEqual([self getPropertyCount:[receivedEvents firstObject] propertyName:@"stop_time"], 1); @@ -307,18 +307,12 @@ - (void)testNestedEvents { XCTAssertEqual([self getPropertyCount:[receivedEvents firstObject] propertyName:@"event_name"], 1); - XCTAssertNotNil([self getPropertyFromEvent:[receivedEvents firstObject] - propertyName:@"customized_property"]); XCTAssertEqual([self getPropertyCount:[receivedEvents firstObject] propertyName:@"customized_property"], 1); - XCTAssertNotNil([self getPropertyFromEvent:[receivedEvents firstObject] - propertyName:@"start_time"]); XCTAssertEqual([self getPropertyCount:[receivedEvents firstObject] propertyName:@"start_time"], 1); - XCTAssertNotNil([self getPropertyFromEvent:[receivedEvents firstObject] - propertyName:@"stop_time"]); XCTAssertEqual([self getPropertyCount:[receivedEvents firstObject] propertyName:@"stop_time"], 1); @@ -329,13 +323,9 @@ - (void)testNestedEvents { XCTAssertEqual([self getPropertyCount:[receivedEvents objectAtIndex:1] propertyName:@"event_name"], 1); - XCTAssertNotNil([self getPropertyFromEvent:[receivedEvents objectAtIndex:1] - propertyName:@"start_time"]); XCTAssertEqual([self getPropertyCount:[receivedEvents objectAtIndex:1] propertyName:@"start_time"], 1); - XCTAssertNotNil([self getPropertyFromEvent:[receivedEvents objectAtIndex:1] - propertyName:@"stop_time"]); XCTAssertEqual([self getPropertyCount:[receivedEvents objectAtIndex:1] propertyName:@"stop_time"], 1); @@ -454,13 +444,9 @@ - (void)testComplexEvents { XCTAssertEqual([self getPropertyCount:[receivedEvents firstObject] propertyName:@"event_name"], 1); - XCTAssertNotNil([self getPropertyFromEvent:[receivedEvents firstObject] - propertyName:@"start_time"]); XCTAssertEqual([self getPropertyCount:[receivedEvents firstObject] propertyName:@"start_time"], 1); - XCTAssertNotNil([self getPropertyFromEvent:[receivedEvents firstObject] - propertyName:@"stop_time"]); XCTAssertEqual([self getPropertyCount:[receivedEvents firstObject] propertyName:@"stop_time"], 1); @@ -470,13 +456,9 @@ - (void)testComplexEvents { XCTAssertEqual([self getPropertyCount:[receivedEvents objectAtIndex:1] propertyName:@"event_name"], 1); - XCTAssertNotNil([self getPropertyFromEvent:[receivedEvents objectAtIndex:1] - propertyName:@"start_time"]); XCTAssertEqual([self getPropertyCount:[receivedEvents objectAtIndex:1] propertyName:@"start_time"], 1); - XCTAssertNotNil([self getPropertyFromEvent:[receivedEvents objectAtIndex:1] - propertyName:@"stop_time"]); XCTAssertEqual([self getPropertyCount:[receivedEvents objectAtIndex:1] propertyName:@"stop_time"], 1); @@ -486,13 +468,9 @@ - (void)testComplexEvents { XCTAssertEqual([self getPropertyCount:[receivedEvents objectAtIndex:2] propertyName:@"event_name"], 1); - XCTAssertNotNil([self getPropertyFromEvent:[receivedEvents objectAtIndex:2] - propertyName:@"start_time"]); XCTAssertEqual([self getPropertyCount:[receivedEvents objectAtIndex:2] propertyName:@"start_time"], 1); - XCTAssertNotNil([self getPropertyFromEvent:[receivedEvents objectAtIndex:2] - propertyName:@"stop_time"]); XCTAssertEqual([self getPropertyCount:[receivedEvents objectAtIndex:2] propertyName:@"stop_time"], 1); @@ -502,13 +480,9 @@ - (void)testComplexEvents { XCTAssertEqual([self getPropertyCount:[receivedEvents objectAtIndex:3] propertyName:@"event_name"], 1); - XCTAssertNotNil([self getPropertyFromEvent:[receivedEvents objectAtIndex:3] - propertyName:@"start_time"]); XCTAssertEqual([self getPropertyCount:[receivedEvents objectAtIndex:3] propertyName:@"start_time"], 1); - XCTAssertNotNil([self getPropertyFromEvent:[receivedEvents objectAtIndex:3] - propertyName:@"stop_time"]); XCTAssertEqual([self getPropertyCount:[receivedEvents objectAtIndex:3] propertyName:@"stop_time"], 1); } @@ -584,6 +558,104 @@ - (void)testComplexEventsWithAggregation { propertyName:@"customized_property"], 0); } +- (void)testAcquireTokenOutputAggregation +{ + // prepare the dispatcher + TestDispatcher* dispatcher = [TestDispatcher new]; + NSMutableArray* receivedEvents = [NSMutableArray new]; + [dispatcher setTestCallback:^(NSArray* event) + { + [receivedEvents addObject:event]; + }]; + + // register the dispatcher + [[ADTelemetry sharedInstance] registerDispatcher:dispatcher aggregationRequired:YES]; + + // Simplest FRT case, the only RT available is the FRT so that would should be the one used + ADAuthenticationError* error = nil; + ADAuthenticationContext* context = [self getTestAuthenticationContext]; + + id cache = [context tokenCacheStore].dataSource; + XCTAssertNotNil(cache); + + XCTAssertTrue([cache addOrUpdateItem:[self adCreateFRTCacheItem] correlationId:nil error:&error]); + XCTAssertNil(error); + + ADTestURLResponse* response = [self adResponseRefreshToken:@"family refresh token" + authority:TEST_AUTHORITY + resource:TEST_RESOURCE + clientId:TEST_CLIENT_ID + correlationId:TEST_CORRELATION_ID + newRefreshToken:@"new family refresh token" + newAccessToken:TEST_ACCESS_TOKEN + additionalFields:@{ ADAL_CLIENT_FAMILY_ID : @"1"}]; + + [ADTestURLConnection addResponse:response]; + + [context acquireTokenSilentWithResource:TEST_RESOURCE + clientId:TEST_CLIENT_ID + redirectUri:TEST_REDIRECT_URL + userId:TEST_USER_ID + completionBlock:^(ADAuthenticationResult *result) + { + XCTAssertNotNil(result); + XCTAssertEqual(result.status, AD_SUCCEEDED); + + // there should be 1 telemetry events recorded as aggregation flag is ON + XCTAssertEqual([receivedEvents count], 1); + + // the following properties are expected in an aggregrated event + XCTAssertEqual([self getPropertyCount:[receivedEvents firstObject] + propertyName:@"api_id"], 1); + XCTAssertEqual([self getPropertyCount:[receivedEvents firstObject] + propertyName:@"request_id"], 1); + XCTAssertEqual([self getPropertyCount:[receivedEvents firstObject] + propertyName:@"correlation_id"], 1); + XCTAssertEqual([self getPropertyCount:[receivedEvents firstObject] + propertyName:@"application_version"], 1); + XCTAssertEqual([self getPropertyCount:[receivedEvents firstObject] + propertyName:@"application_name"], 1); + XCTAssertEqual([self getPropertyCount:[receivedEvents firstObject] + propertyName:@"x-client-Ver"], 1); + XCTAssertEqual([self getPropertyCount:[receivedEvents firstObject] + propertyName:@"x-client-SKU"], 1); + XCTAssertEqual([self getPropertyCount:[receivedEvents firstObject] + propertyName:@"client_id"], 1); + XCTAssertEqual([self getPropertyCount:[receivedEvents firstObject] + propertyName:@"device_id"], 1); + XCTAssertEqual([self getPropertyCount:[receivedEvents firstObject] + propertyName:@"authority_type"], 1); + XCTAssertEqual([self getPropertyCount:[receivedEvents firstObject] + propertyName:@"extended_expires_on_setting"], 1); + XCTAssertEqual([self getPropertyCount:[receivedEvents firstObject] + propertyName:@"prompt_behavior"], 1); + XCTAssertEqual([self getPropertyCount:[receivedEvents firstObject] + propertyName:@"status"], 1); + XCTAssertEqual([self getPropertyCount:[receivedEvents firstObject] + propertyName:@"tenant_id"], 1); + XCTAssertEqual([self getPropertyCount:[receivedEvents firstObject] + propertyName:@"user_id"], 1); + XCTAssertEqual([self getPropertyCount:[receivedEvents firstObject] + propertyName:@"response_time"], 1); + XCTAssertEqual([self getPropertyCount:[receivedEvents firstObject] + propertyName:@"cache_event_count"], 1); + XCTAssertEqual([self getPropertyCount:[receivedEvents firstObject] + propertyName:@"token_rt_status"], 1); + XCTAssertEqual([self getPropertyCount:[receivedEvents firstObject] + propertyName:@"token_mrrt_status"], 1); + XCTAssertEqual([self getPropertyCount:[receivedEvents firstObject] + propertyName:@"token_frt_status"], 1); + XCTAssertEqual([self getPropertyCount:[receivedEvents firstObject] + propertyName:@"http_event_count"], 1); + XCTAssertEqual([self getPropertyCount:[receivedEvents firstObject] + propertyName:@"http_event_count"], 1); + XCTAssertEqual([self getPropertyCount:[receivedEvents firstObject] + propertyName:@"error_code"], 1); + TEST_SIGNAL; + }]; + TEST_WAIT; +} + - (NSString*)getPropertyFromEvent:(NSArray*)event propertyName:(NSString*)propertyName { @@ -611,4 +683,22 @@ - (NSInteger)getPropertyCount:(NSArray*)event return count; } +- (ADAuthenticationContext *)getTestAuthenticationContext +{ + ADAuthenticationContext* context = + [[ADAuthenticationContext alloc] initWithAuthority:TEST_AUTHORITY + validateAuthority:NO + error:nil]; + + NSAssert(context, @"If this is failing for whatever reason you should probably fix it before trying to run tests."); + ADTokenCache *tokenCache = [ADTokenCache new]; + SAFE_ARC_AUTORELEASE(tokenCache); + [context setTokenCacheStore:tokenCache]; + [context setCorrelationId:TEST_CORRELATION_ID]; + + SAFE_ARC_AUTORELEASE(context); + + return context; +} + @end From a16c94081d8f530bf2632eb4a7588d055d7499d3 Mon Sep 17 00:00:00 2001 From: jasoncoolmax Date: Wed, 7 Dec 2016 10:03:51 -0800 Subject: [PATCH 80/92] fix unit tests for mac --- ADAL/tests/ADTelemetryTests.m | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/ADAL/tests/ADTelemetryTests.m b/ADAL/tests/ADTelemetryTests.m index 254d5c192..62b480c81 100644 --- a/ADAL/tests/ADTelemetryTests.m +++ b/ADAL/tests/ADTelemetryTests.m @@ -134,9 +134,11 @@ - (void)testDefaultEventProperties { XCTAssertEqual([self getPropertyCount:[receivedEvents firstObject] propertyName:@"correlation_id"], 1); - +#if TARGET_OS_IPHONE + // application_version is only available in unit test framework with host app XCTAssertEqual([self getPropertyCount:[receivedEvents firstObject] propertyName:@"application_version"], 1); +#endif XCTAssertEqual([self getPropertyCount:[receivedEvents firstObject] propertyName:@"application_name"], 1); @@ -611,8 +613,11 @@ - (void)testAcquireTokenOutputAggregation propertyName:@"request_id"], 1); XCTAssertEqual([self getPropertyCount:[receivedEvents firstObject] propertyName:@"correlation_id"], 1); +#if TARGET_OS_IPHONE + // application_version is only available in unit test framework with host app XCTAssertEqual([self getPropertyCount:[receivedEvents firstObject] propertyName:@"application_version"], 1); +#endif XCTAssertEqual([self getPropertyCount:[receivedEvents firstObject] propertyName:@"application_name"], 1); XCTAssertEqual([self getPropertyCount:[receivedEvents firstObject] From e5590b7c8259617eb3cfbf222493bb48df65b500 Mon Sep 17 00:00:00 2001 From: Ryan Pangrle Date: Wed, 7 Dec 2016 13:28:41 -0800 Subject: [PATCH 81/92] Make keyloop a little better on NTLM dialog --- ADAL/src/ui/mac/ADNTLMUIPrompt.m | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/ADAL/src/ui/mac/ADNTLMUIPrompt.m b/ADAL/src/ui/mac/ADNTLMUIPrompt.m index 0868f3fc0..542cbf7ea 100644 --- a/ADAL/src/ui/mac/ADNTLMUIPrompt.m +++ b/ADAL/src/ui/mac/ADNTLMUIPrompt.m @@ -39,8 +39,8 @@ + (void)presentPrompt:(void (^)(NSString * username, NSString * password))comple NSAlert* alert = [NSAlert new]; [alert setMessageText:NSLocalizedString(@"Enter your credentials", nil)]; - [alert addButtonWithTitle:NSLocalizedString(@"Login", nil)]; - [alert addButtonWithTitle:NSLocalizedString(@"Cancel", nil)]; + NSButton* loginButton = [alert addButtonWithTitle:NSLocalizedString(@"Login", nil)]; + NSButton* cancelButton = [alert addButtonWithTitle:NSLocalizedString(@"Cancel", nil)]; ADCredentialCollectionController* view = [ADCredentialCollectionController new]; SAFE_ARC_AUTORELEASE(view); @@ -48,6 +48,16 @@ + (void)presentPrompt:(void (^)(NSString * username, NSString * password))comple [view.passwordLabel setStringValue:NSLocalizedString(@"Password", nil)]; [alert setAccessoryView:view.customView]; + [view.usernameField setNextKeyView:view.passwordField]; + [view.passwordField setNextKeyView:cancelButton]; + [cancelButton setNextKeyView:loginButton]; + [loginButton setNextKeyView:view.usernameField]; + + // TODO: NSAlert some time after this overides the keyview loop so that + // it gets stuck between loginButton and cancel button.To fix this bug + // we'll have to ditch NSAlert entirely. (#851) + [[alert window] setInitialFirstResponder:view.usernameField]; + [alert beginSheetModalForWindow:[NSApp keyWindow] completionHandler:^(NSModalResponse returnCode) { if (returnCode == 1000) From 3d0c32d66c1fc0a54d65907e0bec84d9e7f6847c Mon Sep 17 00:00:00 2001 From: jasoncoolmax Date: Thu, 8 Dec 2016 10:49:52 -0800 Subject: [PATCH 82/92] verify telemetry output for more acquireToken calls --- ADAL/ADAL.xcodeproj/project.pbxproj | 8 + .../ADAuthenticationRequest+AcquireToken.m | 8 +- ADAL/src/telemetry/ADTelemetry.m | 6 + ADAL/src/telemetry/ADTelemetryAPIEvent.h | 1 + ADAL/src/telemetry/ADTelemetryAPIEvent.m | 5 + ADAL/tests/ADAcquireTokenTests.m | 237 +++++++++++++ ADAL/tests/ADTelemetryTestDispatcher.h | 36 ++ ADAL/tests/ADTelemetryTestDispatcher.m | 43 +++ ADAL/tests/ADTelemetryTests.m | 334 ++++-------------- ADAL/tests/XCTestCase+TestHelperMethods.h | 9 + ADAL/tests/XCTestCase+TestHelperMethods.m | 27 ++ 11 files changed, 452 insertions(+), 262 deletions(-) create mode 100644 ADAL/tests/ADTelemetryTestDispatcher.h create mode 100644 ADAL/tests/ADTelemetryTestDispatcher.m diff --git a/ADAL/ADAL.xcodeproj/project.pbxproj b/ADAL/ADAL.xcodeproj/project.pbxproj index d3f2c987e..8475404ba 100755 --- a/ADAL/ADAL.xcodeproj/project.pbxproj +++ b/ADAL/ADAL.xcodeproj/project.pbxproj @@ -60,6 +60,8 @@ 6033892A1D595AD50024A9BF /* ADTelemetryHttpEvent.m in Sources */ = {isa = PBXBuildFile; fileRef = 6010EDEF1D47B2A600B62072 /* ADTelemetryHttpEvent.m */; }; 6033892B1D595AD50024A9BF /* ADTelemetryCacheEvent.m in Sources */ = {isa = PBXBuildFile; fileRef = 6010EDF41D47B2CE00B62072 /* ADTelemetryCacheEvent.m */; }; 6033892C1D595AD50024A9BF /* ADTelemetryBrokerEvent.m in Sources */ = {isa = PBXBuildFile; fileRef = 6010EDF91D47B2F300B62072 /* ADTelemetryBrokerEvent.m */; }; + 603841A01DF9248F00D30F3D /* ADTelemetryTestDispatcher.m in Sources */ = {isa = PBXBuildFile; fileRef = 6038419F1DF9248F00D30F3D /* ADTelemetryTestDispatcher.m */; }; + 603841A11DF9248F00D30F3D /* ADTelemetryTestDispatcher.m in Sources */ = {isa = PBXBuildFile; fileRef = 6038419F1DF9248F00D30F3D /* ADTelemetryTestDispatcher.m */; }; 605C167C1D8FBA5A0097DBA0 /* ADTelemetryEventStrings.h in Headers */ = {isa = PBXBuildFile; fileRef = 605C167B1D8FBA590097DBA0 /* ADTelemetryEventStrings.h */; }; 605C16821D8FD0AC0097DBA0 /* ADTelemetryEventStrings.m in Sources */ = {isa = PBXBuildFile; fileRef = 605C16801D8FD0AC0097DBA0 /* ADTelemetryEventStrings.m */; }; 605C16831D8FD1AC0097DBA0 /* ADTelemetryEventStrings.m in Sources */ = {isa = PBXBuildFile; fileRef = 605C16801D8FD0AC0097DBA0 /* ADTelemetryEventStrings.m */; }; @@ -425,6 +427,8 @@ 601BEE2F1C6D9CCE004AA8C1 /* ADTestAuthenticationViewController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ADTestAuthenticationViewController.h; sourceTree = ""; }; 601BEE301C6DAA86004AA8C1 /* ADTestAuthenticationViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ADTestAuthenticationViewController.m; sourceTree = ""; }; 601BEE331C6DCB0B004AA8C1 /* ADWebAuthControllerTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ADWebAuthControllerTests.m; sourceTree = ""; }; + 6038419E1DF9246D00D30F3D /* ADTelemetryTestDispatcher.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ADTelemetryTestDispatcher.h; sourceTree = ""; }; + 6038419F1DF9248F00D30F3D /* ADTelemetryTestDispatcher.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ADTelemetryTestDispatcher.m; sourceTree = ""; }; 605C167B1D8FBA590097DBA0 /* ADTelemetryEventStrings.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ADTelemetryEventStrings.h; sourceTree = ""; }; 605C16801D8FD0AC0097DBA0 /* ADTelemetryEventStrings.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ADTelemetryEventStrings.m; sourceTree = ""; }; 6071B5E21C14C0B0006F6CC2 /* ADTestURLConnection.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ADTestURLConnection.h; sourceTree = ""; }; @@ -874,6 +878,8 @@ 601BEE301C6DAA86004AA8C1 /* ADTestAuthenticationViewController.m */, 601BEE331C6DCB0B004AA8C1 /* ADWebAuthControllerTests.m */, 600401B01D3578C30020EAAB /* ADTelemetryTests.m */, + 6038419E1DF9246D00D30F3D /* ADTelemetryTestDispatcher.h */, + 6038419F1DF9248F00D30F3D /* ADTelemetryTestDispatcher.m */, ); path = tests; sourceTree = ""; @@ -1677,6 +1683,7 @@ buildActionMask = 2147483647; files = ( D6F999801D235ACF004E682C /* ADAcquireTokenPkeyAuthTests.m in Sources */, + 603841A01DF9248F00D30F3D /* ADTelemetryTestDispatcher.m in Sources */, D60D8FE81D25C8D400F3E6C9 /* ADHelpersTests.m in Sources */, 601BEE341C6DCB0B004AA8C1 /* ADWebAuthControllerTests.m in Sources */, 940CC8881D8A34610087E9EA /* ADBrokerMessageTests.m in Sources */, @@ -1790,6 +1797,7 @@ 94DD18F91C5ACFF900F80C62 /* ADUserInformationTests.m in Sources */, 94DD18F71C5ACFF900F80C62 /* ADLoggerTests.m in Sources */, 94DD18F11C5ACFF000F80C62 /* ADAuthenticationParametersTests.m in Sources */, + 603841A11DF9248F00D30F3D /* ADTelemetryTestDispatcher.m in Sources */, 94DD18FB1C5ACFF900F80C62 /* ADTokenCacheKeyTests.m in Sources */, 94DD18F41C5ACFF900F80C62 /* ADAuthenticationErrorTests.m in Sources */, 94DD18EF1C5ACFF000F80C62 /* ADAuthorityValidationTests.m in Sources */, diff --git a/ADAL/src/request/ADAuthenticationRequest+AcquireToken.m b/ADAL/src/request/ADAuthenticationRequest+AcquireToken.m index 1b8c4b8b8..072a42a6e 100644 --- a/ADAL/src/request/ADAuthenticationRequest+AcquireToken.m +++ b/ADAL/src/request/ADAuthenticationRequest+AcquireToken.m @@ -83,7 +83,13 @@ - (void)acquireToken:(NSString *)eventName [event setAuthority:_context.authority]; [event setExtendedExpiresOnSetting:[_requestParams extendedLifetime]? AD_TELEMETRY_YES:AD_TELEMETRY_NO]; [event setPromptBehavior:_promptBehavior]; - [event setUserInformation:[[result tokenCacheItem] userInformation]]; + if ([result tokenCacheItem]) + { + [event setUserInformation:[[result tokenCacheItem] userInformation]]; + } + else{ + [event setUserId:_requestParams.identifier.userId]; + } [event setResultStatus:result.status]; [event setIsExtendedLifeTimeToken:[result extendedLifeTimeToken]? AD_TELEMETRY_YES:AD_TELEMETRY_NO]; [event setErrorCode:[NSString stringWithFormat:@"%ld",(long)[result.error code]]]; diff --git a/ADAL/src/telemetry/ADTelemetry.m b/ADAL/src/telemetry/ADTelemetry.m index 7339cf595..1e5086815 100644 --- a/ADAL/src/telemetry/ADTelemetry.m +++ b/ADAL/src/telemetry/ADTelemetry.m @@ -67,6 +67,12 @@ - (void)registerDispatcher:(id)dispatcher @synchronized(self) { SAFE_ARC_RELEASE(_dispatcher); + if (!dispatcher) + { + _dispatcher = nil; + return; + } + if (aggregationRequired) { _dispatcher = [[ADAggregatedDispatcher alloc] initWithDispatcher:dispatcher]; diff --git a/ADAL/src/telemetry/ADTelemetryAPIEvent.h b/ADAL/src/telemetry/ADTelemetryAPIEvent.h index 273660572..53d5c041a 100644 --- a/ADAL/src/telemetry/ADTelemetryAPIEvent.h +++ b/ADAL/src/telemetry/ADTelemetryAPIEvent.h @@ -30,6 +30,7 @@ - (void)setExtendedExpiresOnSetting:(NSString*)extendedExpiresOnSetting; - (void)setPromptBehavior:(ADPromptBehavior)promptBehavior; - (void)setUserInformation:(ADUserInformation*)userInfo; +- (void)setUserId:(NSString*)userId; - (void)setClientId:(NSString*)clientId; - (void)setIsExtendedLifeTimeToken:(NSString*)isExtendedLifeToken; - (void)setErrorCode:(NSString*)errorCode; diff --git a/ADAL/src/telemetry/ADTelemetryAPIEvent.m b/ADAL/src/telemetry/ADTelemetryAPIEvent.m index 6de57dc4c..3aff14ca4 100644 --- a/ADAL/src/telemetry/ADTelemetryAPIEvent.m +++ b/ADAL/src/telemetry/ADTelemetryAPIEvent.m @@ -67,6 +67,11 @@ - (void)setUserInformation:(ADUserInformation*)userInfo [self setProperty:AD_TELEMETRY_IDP value:[userInfo identityProvider]]; } +- (void)setUserId:(NSString*)userId +{ + [self setProperty:AD_TELEMETRY_USER_ID value:[userId adComputeSHA256]]; +} + - (void)setClientId:(NSString*)clientId { [self setProperty:AD_TELEMETRY_CLIENT_ID value:clientId]; diff --git a/ADAL/tests/ADAcquireTokenTests.m b/ADAL/tests/ADAcquireTokenTests.m index 0cbd51f28..41e899ca0 100644 --- a/ADAL/tests/ADAcquireTokenTests.m +++ b/ADAL/tests/ADAcquireTokenTests.m @@ -36,6 +36,7 @@ #import "ADTokenCacheItem+Internal.h" #import "ADTokenCacheKey.h" #import "ADTokenCacheDataSource.h" +#import "ADTelemetryTestDispatcher.h" const int sAsyncContextTimeout = 10; @@ -344,6 +345,15 @@ - (void)testCachedWithNilUserId - (void)testFailsWithNilUserIdAndMultipleCachedUsers { + // prepare and register telemetry dispatcher + ADTelemetryTestDispatcher* dispatcher = [ADTelemetryTestDispatcher new]; + NSMutableArray* receivedEvents = [NSMutableArray new]; + [dispatcher setTestCallback:^(NSArray* event) + { + [receivedEvents addObject:event]; + }]; + [[ADTelemetry sharedInstance] registerDispatcher:dispatcher aggregationRequired:YES]; + ADAuthenticationError* error = nil; ADAuthenticationContext* context = [self getTestAuthenticationContext]; @@ -369,6 +379,54 @@ - (void)testFailsWithNilUserIdAndMultipleCachedUsers }]; TEST_WAIT; + + // verify telemetry output + // there should be 1 telemetry events recorded as aggregation flag is ON + XCTAssertEqual([receivedEvents count], 1); + + // the following properties are expected in an aggregrated event + XCTAssertEqual([self adGetPropertyCount:[receivedEvents firstObject] + propertyName:@"api_id"], 1); + XCTAssertEqual([self adGetPropertyCount:[receivedEvents firstObject] + propertyName:@"request_id"], 1); + XCTAssertEqual([self adGetPropertyCount:[receivedEvents firstObject] + propertyName:@"correlation_id"], 1); +#if TARGET_OS_IPHONE + // application_version is only available in unit test framework with host app + XCTAssertEqual([self adGetPropertyCount:[receivedEvents firstObject] + propertyName:@"application_version"], 1); +#endif + XCTAssertEqual([self adGetPropertyCount:[receivedEvents firstObject] + propertyName:@"application_name"], 1); + XCTAssertEqual([self adGetPropertyCount:[receivedEvents firstObject] + propertyName:@"x-client-Ver"], 1); + XCTAssertEqual([self adGetPropertyCount:[receivedEvents firstObject] + propertyName:@"x-client-SKU"], 1); + XCTAssertEqual([self adGetPropertyCount:[receivedEvents firstObject] + propertyName:@"client_id"], 1); + XCTAssertEqual([self adGetPropertyCount:[receivedEvents firstObject] + propertyName:@"device_id"], 1); + XCTAssertEqual([self adGetPropertyCount:[receivedEvents firstObject] + propertyName:@"authority_type"], 1); + XCTAssertEqual([self adGetPropertyCount:[receivedEvents firstObject] + propertyName:@"extended_expires_on_setting"], 1); + XCTAssertEqual([self adGetPropertyCount:[receivedEvents firstObject] + propertyName:@"prompt_behavior"], 1); + XCTAssertEqual([self adGetPropertyCount:[receivedEvents firstObject] + propertyName:@"status"], 1); + XCTAssertEqual([self adGetPropertyCount:[receivedEvents firstObject] + propertyName:@"response_time"], 1); + XCTAssertEqual([self adGetPropertyCount:[receivedEvents firstObject] + propertyName:@"cache_event_count"], 1); + XCTAssertEqual([self adGetPropertyCount:[receivedEvents firstObject] + propertyName:@"error_code"], 1); + XCTAssertEqual([self adGetPropertyCount:[receivedEvents firstObject] + propertyName:@"error_domain"], 1); + XCTAssertEqual([self adGetPropertyCount:[receivedEvents firstObject] + propertyName:@"error_description"], 1); + + //unregister the dispatcher + [[ADTelemetry sharedInstance] registerDispatcher:nil aggregationRequired:YES]; } - (void)testCachedWithNoIdtoken @@ -526,6 +584,15 @@ - (void)testSilentBadRefreshToken - (void)testSilentExpiredATBadMRRT { + // prepare and register telemetry dispatcher + ADTelemetryTestDispatcher* dispatcher = [ADTelemetryTestDispatcher new]; + NSMutableArray* receivedEvents = [NSMutableArray new]; + [dispatcher setTestCallback:^(NSArray* event) + { + [receivedEvents addObject:event]; + }]; + [[ADTelemetry sharedInstance] registerDispatcher:dispatcher aggregationRequired:YES]; + ADAuthenticationError* error = nil; ADAuthenticationContext* context = [self getTestAuthenticationContext]; @@ -586,6 +653,111 @@ - (void)testSilentExpiredATBadMRRT }]; TEST_WAIT; + + // verify telemetry output + // there should be 2 telemetry events recorded as there are 2 acquire token calls + XCTAssertEqual([receivedEvents count], 2); + + // the following properties are expected for the 1st acquire token call + XCTAssertEqual([self adGetPropertyCount:[receivedEvents firstObject] + propertyName:@"api_id"], 1); + XCTAssertEqual([self adGetPropertyCount:[receivedEvents firstObject] + propertyName:@"request_id"], 1); + XCTAssertEqual([self adGetPropertyCount:[receivedEvents firstObject] + propertyName:@"correlation_id"], 1); +#if TARGET_OS_IPHONE + // application_version is only available in unit test framework with host app + XCTAssertEqual([self adGetPropertyCount:[receivedEvents firstObject] + propertyName:@"application_version"], 1); +#endif + XCTAssertEqual([self adGetPropertyCount:[receivedEvents firstObject] + propertyName:@"application_name"], 1); + XCTAssertEqual([self adGetPropertyCount:[receivedEvents firstObject] + propertyName:@"x-client-Ver"], 1); + XCTAssertEqual([self adGetPropertyCount:[receivedEvents firstObject] + propertyName:@"x-client-SKU"], 1); + XCTAssertEqual([self adGetPropertyCount:[receivedEvents firstObject] + propertyName:@"client_id"], 1); + XCTAssertEqual([self adGetPropertyCount:[receivedEvents firstObject] + propertyName:@"device_id"], 1); + XCTAssertEqual([self adGetPropertyCount:[receivedEvents firstObject] + propertyName:@"authority_type"], 1); + XCTAssertEqual([self adGetPropertyCount:[receivedEvents firstObject] + propertyName:@"extended_expires_on_setting"], 1); + XCTAssertEqual([self adGetPropertyCount:[receivedEvents firstObject] + propertyName:@"prompt_behavior"], 1); + XCTAssertEqual([self adGetPropertyCount:[receivedEvents firstObject] + propertyName:@"status"], 1); + XCTAssertEqual([self adGetPropertyCount:[receivedEvents firstObject] + propertyName:@"user_id"], 1); + XCTAssertEqual([self adGetPropertyCount:[receivedEvents firstObject] + propertyName:@"response_time"], 1); + XCTAssertEqual([self adGetPropertyCount:[receivedEvents firstObject] + propertyName:@"cache_event_count"], 1); + XCTAssertEqual([self adGetPropertyCount:[receivedEvents firstObject] + propertyName:@"token_mrrt_status"], 1); + XCTAssertEqual([self adGetPropertyCount:[receivedEvents firstObject] + propertyName:@"token_frt_status"], 1); + XCTAssertEqual([self adGetPropertyCount:[receivedEvents firstObject] + propertyName:@"http_event_count"], 1); + XCTAssertEqual([self adGetPropertyCount:[receivedEvents firstObject] + propertyName:@"error_code"], 1); + XCTAssertEqual([self adGetPropertyCount:[receivedEvents firstObject] + propertyName:@"error_domain"], 1); + XCTAssertEqual([self adGetPropertyCount:[receivedEvents firstObject] + propertyName:@"error_description"], 1); + + // the following properties are expected for 2nd acquire token call + XCTAssertEqual([self adGetPropertyCount:[receivedEvents firstObject] + propertyName:@"api_id"], 1); + XCTAssertEqual([self adGetPropertyCount:[receivedEvents firstObject] + propertyName:@"request_id"], 1); + XCTAssertEqual([self adGetPropertyCount:[receivedEvents firstObject] + propertyName:@"correlation_id"], 1); +#if TARGET_OS_IPHONE + // application_version is only available in unit test framework with host app + XCTAssertEqual([self adGetPropertyCount:[receivedEvents firstObject] + propertyName:@"application_version"], 1); +#endif + XCTAssertEqual([self adGetPropertyCount:[receivedEvents objectAtIndex:1] + propertyName:@"application_name"], 1); + XCTAssertEqual([self adGetPropertyCount:[receivedEvents objectAtIndex:1] + propertyName:@"x-client-Ver"], 1); + XCTAssertEqual([self adGetPropertyCount:[receivedEvents objectAtIndex:1] + propertyName:@"x-client-SKU"], 1); + XCTAssertEqual([self adGetPropertyCount:[receivedEvents objectAtIndex:1] + propertyName:@"client_id"], 1); + XCTAssertEqual([self adGetPropertyCount:[receivedEvents objectAtIndex:1] + propertyName:@"device_id"], 1); + XCTAssertEqual([self adGetPropertyCount:[receivedEvents objectAtIndex:1] + propertyName:@"authority_type"], 1); + XCTAssertEqual([self adGetPropertyCount:[receivedEvents objectAtIndex:1] + propertyName:@"extended_expires_on_setting"], 1); + XCTAssertEqual([self adGetPropertyCount:[receivedEvents objectAtIndex:1] + propertyName:@"prompt_behavior"], 1); + XCTAssertEqual([self adGetPropertyCount:[receivedEvents objectAtIndex:1] + propertyName:@"status"], 1); + XCTAssertEqual([self adGetPropertyCount:[receivedEvents objectAtIndex:1] + propertyName:@"user_id"], 1); + XCTAssertEqual([self adGetPropertyCount:[receivedEvents objectAtIndex:1] + propertyName:@"response_time"], 1); + XCTAssertEqual([self adGetPropertyCount:[receivedEvents objectAtIndex:1] + propertyName:@"cache_event_count"], 1); + XCTAssertEqual([self adGetPropertyCount:[receivedEvents objectAtIndex:1] + propertyName:@"token_rt_status"], 1); + XCTAssertEqual([self adGetPropertyCount:[receivedEvents objectAtIndex:1] + propertyName:@"token_mrrt_status"], 1); + XCTAssertEqual([self adGetPropertyCount:[receivedEvents objectAtIndex:1] + propertyName:@"token_frt_status"], 1); + XCTAssertEqual([self adGetPropertyCount:[receivedEvents objectAtIndex:1] + propertyName:@"error_code"], 1); + XCTAssertEqual([self adGetPropertyCount:[receivedEvents objectAtIndex:1] + propertyName:@"error_domain"], 1); + XCTAssertEqual([self adGetPropertyCount:[receivedEvents objectAtIndex:1] + propertyName:@"error_description"], 1); + + //unregister the dispatcher + [[ADTelemetry sharedInstance] registerDispatcher:nil aggregationRequired:YES]; } - (void)testSilentExpiredATRefreshMRRTNetwork @@ -949,6 +1121,15 @@ - (void)testAcquireRefreshFamilyTokenNetwork - (void)testAcquireTokenUsingFRT { + // prepare and register telemetry dispatcher + ADTelemetryTestDispatcher* dispatcher = [ADTelemetryTestDispatcher new]; + NSMutableArray* receivedEvents = [NSMutableArray new]; + [dispatcher setTestCallback:^(NSArray* event) + { + [receivedEvents addObject:event]; + }]; + [[ADTelemetry sharedInstance] registerDispatcher:dispatcher aggregationRequired:YES]; + // Simplest FRT case, the only RT available is the FRT so that would should be the one used ADAuthenticationError* error = nil; ADAuthenticationContext* context = [self getTestAuthenticationContext]; @@ -986,6 +1167,62 @@ - (void)testAcquireTokenUsingFRT }]; TEST_WAIT; + + // verify telemetry output + // there should be 1 telemetry events recorded as aggregation flag is ON + XCTAssertEqual([receivedEvents count], 1); + + // the following properties are expected in an aggregrated event + XCTAssertEqual([self adGetPropertyCount:[receivedEvents firstObject] + propertyName:@"api_id"], 1); + XCTAssertEqual([self adGetPropertyCount:[receivedEvents firstObject] + propertyName:@"request_id"], 1); + XCTAssertEqual([self adGetPropertyCount:[receivedEvents firstObject] + propertyName:@"correlation_id"], 1); +#if TARGET_OS_IPHONE + // application_version is only available in unit test framework with host app + XCTAssertEqual([self adGetPropertyCount:[receivedEvents firstObject] + propertyName:@"application_version"], 1); +#endif + XCTAssertEqual([self adGetPropertyCount:[receivedEvents firstObject] + propertyName:@"application_name"], 1); + XCTAssertEqual([self adGetPropertyCount:[receivedEvents firstObject] + propertyName:@"x-client-Ver"], 1); + XCTAssertEqual([self adGetPropertyCount:[receivedEvents firstObject] + propertyName:@"x-client-SKU"], 1); + XCTAssertEqual([self adGetPropertyCount:[receivedEvents firstObject] + propertyName:@"client_id"], 1); + XCTAssertEqual([self adGetPropertyCount:[receivedEvents firstObject] + propertyName:@"device_id"], 1); + XCTAssertEqual([self adGetPropertyCount:[receivedEvents firstObject] + propertyName:@"authority_type"], 1); + XCTAssertEqual([self adGetPropertyCount:[receivedEvents firstObject] + propertyName:@"extended_expires_on_setting"], 1); + XCTAssertEqual([self adGetPropertyCount:[receivedEvents firstObject] + propertyName:@"prompt_behavior"], 1); + XCTAssertEqual([self adGetPropertyCount:[receivedEvents firstObject] + propertyName:@"status"], 1); + XCTAssertEqual([self adGetPropertyCount:[receivedEvents firstObject] + propertyName:@"tenant_id"], 1); + XCTAssertEqual([self adGetPropertyCount:[receivedEvents firstObject] + propertyName:@"user_id"], 1); + XCTAssertEqual([self adGetPropertyCount:[receivedEvents firstObject] + propertyName:@"response_time"], 1); + XCTAssertEqual([self adGetPropertyCount:[receivedEvents firstObject] + propertyName:@"cache_event_count"], 1); + XCTAssertEqual([self adGetPropertyCount:[receivedEvents firstObject] + propertyName:@"token_rt_status"], 1); + XCTAssertEqual([self adGetPropertyCount:[receivedEvents firstObject] + propertyName:@"token_mrrt_status"], 1); + XCTAssertEqual([self adGetPropertyCount:[receivedEvents firstObject] + propertyName:@"token_frt_status"], 1); + XCTAssertEqual([self adGetPropertyCount:[receivedEvents firstObject] + propertyName:@"http_event_count"], 1); + XCTAssertEqual([self adGetPropertyCount:[receivedEvents firstObject] + propertyName:@"error_code"], 1); + + //unregister the dispatcher + [[ADTelemetry sharedInstance] registerDispatcher:nil aggregationRequired:YES]; } - (void)testAcquireTokenMRRTFailFRTFallback diff --git a/ADAL/tests/ADTelemetryTestDispatcher.h b/ADAL/tests/ADTelemetryTestDispatcher.h new file mode 100644 index 000000000..b5e0a6bc1 --- /dev/null +++ b/ADAL/tests/ADTelemetryTestDispatcher.h @@ -0,0 +1,36 @@ +// Copyright (c) Microsoft Corporation. +// All rights reserved. +// +// This code is licensed under the MIT License. +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files(the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and / or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions : +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE. + +#import "ADTelemetry.h" + +typedef void(^TestCallback)(NSArray* event); + +//A simple telemetry dispatcher implementation for test purpose +//There is a callback function added to dispatcher only because of unit test +@interface ADTelemetryTestDispatcher : NSObject +{ + TestCallback _testCallback; +} + +- (void)setTestCallback:(TestCallback)callback; +@end \ No newline at end of file diff --git a/ADAL/tests/ADTelemetryTestDispatcher.m b/ADAL/tests/ADTelemetryTestDispatcher.m new file mode 100644 index 000000000..e4e163a43 --- /dev/null +++ b/ADAL/tests/ADTelemetryTestDispatcher.m @@ -0,0 +1,43 @@ +// Copyright (c) Microsoft Corporation. +// All rights reserved. +// +// This code is licensed under the MIT License. +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files(the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and / or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions : +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE. + +#import "ADTelemetryTestDispatcher.h" + +@implementation ADTelemetryTestDispatcher + +- (void)setTestCallback:(TestCallback)callback +{ + _testCallback = callback; +} + +- (void)dispatchEvent:(NSArray*)event +{ + // call _testCallback when it receives telemetry event + // this is for the purpose of unit test + if (_testCallback) + { + _testCallback(event); + } +} + +@end \ No newline at end of file diff --git a/ADAL/tests/ADTelemetryTests.m b/ADAL/tests/ADTelemetryTests.m index 62b480c81..47a801e27 100644 --- a/ADAL/tests/ADTelemetryTests.m +++ b/ADAL/tests/ADTelemetryTests.m @@ -31,69 +31,27 @@ #import "XCTestCase+TestHelperMethods.h" #import "ADTokenCache+Internal.h" #import "ADTokenCacheItem.h" - -typedef void(^TestCallback)(NSArray* event); - -@interface TestDispatcher : NSObject -{ - TestCallback _testCallback; -} - -- (void)setTestCallback:(TestCallback)callback; -@end - -@implementation TestDispatcher - -- (void)setTestCallback:(TestCallback)callback -{ - _testCallback = callback; -} - -- (void)dispatchEvent:(NSArray*)event -{ - // call _testCallback when it receives telemetry event - // this is for the purpose of unit test - if (_testCallback) - { - _testCallback(event); - } -} - -@end +#import "ADTelemetryTestDispatcher.h" @interface ADTelemetryTests : XCTestCase -{ -@private - dispatch_semaphore_t _dsem; -} + @end @implementation ADTelemetryTests -- (void)setUp -{ +- (void)setUp { [super setUp]; - [self adTestBegin:ADAL_LOG_LEVEL_INFO]; - _dsem = dispatch_semaphore_create(0); + // Put setup code here. This method is called before the invocation of each test method in the class. } -- (void)tearDown -{ -#if !__has_feature(objc_arc) - dispatch_release(_dsem); -#endif - _dsem = nil; - - XCTAssertTrue([ADTestURLConnection noResponsesLeft]); - [ADTestURLConnection clearResponses]; - [self adTestEnd]; +- (void)tearDown { + // Put teardown code here. This method is called after the invocation of each test method in the class. [super tearDown]; } - - (void)testDefaultEventProperties { // new a dispatcher - TestDispatcher* dispatcher = [TestDispatcher new]; + ADTelemetryTestDispatcher* dispatcher = [ADTelemetryTestDispatcher new]; NSMutableArray* receivedEvents = [NSMutableArray new]; // the dispatcher will store the telemetry events it receives @@ -120,33 +78,33 @@ - (void)testDefaultEventProperties { // make sure the default properties are recorded in the telemetry event, // i.e. sdk_id, sdk_version, device_id, device_name - XCTAssertEqual([self getPropertyCount:[receivedEvents firstObject] + XCTAssertEqual([self adGetPropertyCount:[receivedEvents firstObject] propertyName:@"x-client-SKU"], 1); - XCTAssertEqual([self getPropertyCount:[receivedEvents firstObject] + XCTAssertEqual([self adGetPropertyCount:[receivedEvents firstObject] propertyName:@"x-client-Ver"], 1); - XCTAssertEqual([self getPropertyCount:[receivedEvents firstObject] + XCTAssertEqual([self adGetPropertyCount:[receivedEvents firstObject] propertyName:@"device_id"], 1); - XCTAssertEqual([self getPropertyCount:[receivedEvents firstObject] + XCTAssertEqual([self adGetPropertyCount:[receivedEvents firstObject] propertyName:@"request_id"], 1); - XCTAssertEqual([self getPropertyCount:[receivedEvents firstObject] + XCTAssertEqual([self adGetPropertyCount:[receivedEvents firstObject] propertyName:@"correlation_id"], 1); #if TARGET_OS_IPHONE // application_version is only available in unit test framework with host app - XCTAssertEqual([self getPropertyCount:[receivedEvents firstObject] + XCTAssertEqual([self adGetPropertyCount:[receivedEvents firstObject] propertyName:@"application_version"], 1); #endif - XCTAssertEqual([self getPropertyCount:[receivedEvents firstObject] + XCTAssertEqual([self adGetPropertyCount:[receivedEvents firstObject] propertyName:@"application_name"], 1); } - (void)testSequentialEvents { // new a dispatcher - TestDispatcher* dispatcher = [TestDispatcher new]; + ADTelemetryTestDispatcher* dispatcher = [ADTelemetryTestDispatcher new]; NSMutableArray* receivedEvents = [NSMutableArray new]; // the dispatcher will store the telemetry events it receives @@ -181,33 +139,33 @@ - (void)testSequentialEvents { XCTAssertEqual([receivedEvents count], 2); // make sure the 1st event has an event_name, start_time and stop_time - XCTAssertEqual([self getPropertyCount:[receivedEvents firstObject] + XCTAssertEqual([self adGetPropertyCount:[receivedEvents firstObject] propertyName:@"event_name"], 1); - XCTAssertEqual([self getPropertyCount:[receivedEvents firstObject] + XCTAssertEqual([self adGetPropertyCount:[receivedEvents firstObject] propertyName:@"start_time"], 1); - XCTAssertEqual([self getPropertyCount:[receivedEvents firstObject] + XCTAssertEqual([self adGetPropertyCount:[receivedEvents firstObject] propertyName:@"stop_time"], 1); // make sure the 2nd event has customized_property, event_name, start_time and stop_time - XCTAssertEqual([self getPropertyCount:[receivedEvents objectAtIndex:1] + XCTAssertEqual([self adGetPropertyCount:[receivedEvents objectAtIndex:1] propertyName:@"customized_property"], 1); - XCTAssertEqual([self getPropertyCount:[receivedEvents firstObject] + XCTAssertEqual([self adGetPropertyCount:[receivedEvents firstObject] propertyName:@"event_name"], 1); - XCTAssertEqual([self getPropertyCount:[receivedEvents firstObject] + XCTAssertEqual([self adGetPropertyCount:[receivedEvents firstObject] propertyName:@"start_time"], 1); - XCTAssertEqual([self getPropertyCount:[receivedEvents firstObject] + XCTAssertEqual([self adGetPropertyCount:[receivedEvents firstObject] propertyName:@"stop_time"], 1); } - (void)testSequentialEventsWithAggregation { // new a dispatcher - TestDispatcher* dispatcher = [TestDispatcher new]; + ADTelemetryTestDispatcher* dispatcher = [ADTelemetryTestDispatcher new]; NSMutableArray* receivedEvents = [NSMutableArray new]; NSUUID* correlationId = [NSUUID UUID]; @@ -243,32 +201,32 @@ - (void)testSequentialEventsWithAggregation { XCTAssertEqual([receivedEvents count], 1); // the aggregated event outputs the default properties like correlation_id, request_id, etc. - XCTAssertEqual([self getPropertyCount:[receivedEvents firstObject] + XCTAssertEqual([self adGetPropertyCount:[receivedEvents firstObject] propertyName:@"correlation_id"], 1); - XCTAssertEqual([self getPropertyCount:[receivedEvents firstObject] + XCTAssertEqual([self adGetPropertyCount:[receivedEvents firstObject] propertyName:@"request_id"], 1); // it will also outputs some designated properties like response_time, but not for event_name, etc. - XCTAssertEqual([self getPropertyCount:[receivedEvents firstObject] + XCTAssertEqual([self adGetPropertyCount:[receivedEvents firstObject] propertyName:@"response_time"], 1); - XCTAssertEqual([self getPropertyCount:[receivedEvents firstObject] + XCTAssertEqual([self adGetPropertyCount:[receivedEvents firstObject] propertyName:@"event_name"], 0); - XCTAssertEqual([self getPropertyCount:[receivedEvents firstObject] + XCTAssertEqual([self adGetPropertyCount:[receivedEvents firstObject] propertyName:@"start_time"], 0); - XCTAssertEqual([self getPropertyCount:[receivedEvents firstObject] + XCTAssertEqual([self adGetPropertyCount:[receivedEvents firstObject] propertyName:@"stop_time"], 0); - XCTAssertEqual([self getPropertyCount:[receivedEvents firstObject] + XCTAssertEqual([self adGetPropertyCount:[receivedEvents firstObject] propertyName:@"customized_property"], 0); } - (void)testNestedEvents { // new a dispatcher - TestDispatcher* dispatcher = [TestDispatcher new]; + ADTelemetryTestDispatcher* dispatcher = [ADTelemetryTestDispatcher new]; NSMutableArray* receivedEvents = [NSMutableArray new]; // the dispatcher will store the telemetry events it receives @@ -304,38 +262,38 @@ - (void)testNestedEvents { // the first event recorded is event2 // make sure it has customized_property, event_name, start_time and stop_time - XCTAssertTrue([[self getPropertyFromEvent:[receivedEvents firstObject] + XCTAssertTrue([[self adGetPropertyFromEvent:[receivedEvents firstObject] propertyName:@"event_name"] isEqualToString:@"testEvent2"]); - XCTAssertEqual([self getPropertyCount:[receivedEvents firstObject] + XCTAssertEqual([self adGetPropertyCount:[receivedEvents firstObject] propertyName:@"event_name"], 1); - XCTAssertEqual([self getPropertyCount:[receivedEvents firstObject] + XCTAssertEqual([self adGetPropertyCount:[receivedEvents firstObject] propertyName:@"customized_property"], 1); - XCTAssertEqual([self getPropertyCount:[receivedEvents firstObject] + XCTAssertEqual([self adGetPropertyCount:[receivedEvents firstObject] propertyName:@"start_time"], 1); - XCTAssertEqual([self getPropertyCount:[receivedEvents firstObject] + XCTAssertEqual([self adGetPropertyCount:[receivedEvents firstObject] propertyName:@"stop_time"], 1); // the second event recorded is event1 // make sure it has event_name, start_time and stop_time - XCTAssertTrue([[self getPropertyFromEvent:[receivedEvents objectAtIndex:1] + XCTAssertTrue([[self adGetPropertyFromEvent:[receivedEvents objectAtIndex:1] propertyName:@"event_name"] isEqualToString:@"testEvent1"]); - XCTAssertEqual([self getPropertyCount:[receivedEvents objectAtIndex:1] + XCTAssertEqual([self adGetPropertyCount:[receivedEvents objectAtIndex:1] propertyName:@"event_name"], 1); - XCTAssertEqual([self getPropertyCount:[receivedEvents objectAtIndex:1] + XCTAssertEqual([self adGetPropertyCount:[receivedEvents objectAtIndex:1] propertyName:@"start_time"], 1); - XCTAssertEqual([self getPropertyCount:[receivedEvents objectAtIndex:1] + XCTAssertEqual([self adGetPropertyCount:[receivedEvents objectAtIndex:1] propertyName:@"stop_time"], 1); } - (void)testNestedEventsWithAggregation { // new a dispatcher - TestDispatcher* dispatcher = [TestDispatcher new]; + ADTelemetryTestDispatcher* dispatcher = [ADTelemetryTestDispatcher new]; NSMutableArray* receivedEvents = [NSMutableArray new]; NSUUID* correlationId = [NSUUID UUID]; @@ -371,31 +329,31 @@ - (void)testNestedEventsWithAggregation { XCTAssertEqual([receivedEvents count], 1); // the aggregated event outputs the default properties like correlation_id, request_id, etc. - XCTAssertEqual([self getPropertyCount:[receivedEvents firstObject] + XCTAssertEqual([self adGetPropertyCount:[receivedEvents firstObject] propertyName:@"correlation_id"], 1); - XCTAssertEqual([self getPropertyCount:[receivedEvents firstObject] + XCTAssertEqual([self adGetPropertyCount:[receivedEvents firstObject] propertyName:@"request_id"], 1); // it will also outputs some designated properties like response_time, but not for event_name, etc. - XCTAssertEqual([self getPropertyCount:[receivedEvents firstObject] + XCTAssertEqual([self adGetPropertyCount:[receivedEvents firstObject] propertyName:@"response_time"], 1); - XCTAssertEqual([self getPropertyCount:[receivedEvents firstObject] + XCTAssertEqual([self adGetPropertyCount:[receivedEvents firstObject] propertyName:@"event_name"], 0); - XCTAssertEqual([self getPropertyCount:[receivedEvents firstObject] + XCTAssertEqual([self adGetPropertyCount:[receivedEvents firstObject] propertyName:@"start_time"], 0); - XCTAssertEqual([self getPropertyCount:[receivedEvents firstObject] + XCTAssertEqual([self adGetPropertyCount:[receivedEvents firstObject] propertyName:@"stop_time"], 0); - XCTAssertEqual([self getPropertyCount:[receivedEvents firstObject] + XCTAssertEqual([self adGetPropertyCount:[receivedEvents firstObject] propertyName:@"customized_property"], 0); } - (void)testComplexEvents { // new a dispatcher - TestDispatcher* dispatcher = [TestDispatcher new]; + ADTelemetryTestDispatcher* dispatcher = [ADTelemetryTestDispatcher new]; NSMutableArray* receivedEvents = [NSMutableArray new]; // the dispatcher will store the telemetry events it receives @@ -441,57 +399,57 @@ - (void)testComplexEvents { XCTAssertEqual([receivedEvents count], 4); // the first event recorded is event3 - XCTAssertTrue([[self getPropertyFromEvent:[receivedEvents firstObject] + XCTAssertTrue([[self adGetPropertyFromEvent:[receivedEvents firstObject] propertyName:@"event_name"] isEqualToString:@"testEvent3"]); - XCTAssertEqual([self getPropertyCount:[receivedEvents firstObject] + XCTAssertEqual([self adGetPropertyCount:[receivedEvents firstObject] propertyName:@"event_name"], 1); - XCTAssertEqual([self getPropertyCount:[receivedEvents firstObject] + XCTAssertEqual([self adGetPropertyCount:[receivedEvents firstObject] propertyName:@"start_time"], 1); - XCTAssertEqual([self getPropertyCount:[receivedEvents firstObject] + XCTAssertEqual([self adGetPropertyCount:[receivedEvents firstObject] propertyName:@"stop_time"], 1); // the second event recorded is event2 - XCTAssertTrue([[self getPropertyFromEvent:[receivedEvents objectAtIndex:1] + XCTAssertTrue([[self adGetPropertyFromEvent:[receivedEvents objectAtIndex:1] propertyName:@"event_name"] isEqualToString:@"testEvent2"]); - XCTAssertEqual([self getPropertyCount:[receivedEvents objectAtIndex:1] + XCTAssertEqual([self adGetPropertyCount:[receivedEvents objectAtIndex:1] propertyName:@"event_name"], 1); - XCTAssertEqual([self getPropertyCount:[receivedEvents objectAtIndex:1] + XCTAssertEqual([self adGetPropertyCount:[receivedEvents objectAtIndex:1] propertyName:@"start_time"], 1); - XCTAssertEqual([self getPropertyCount:[receivedEvents objectAtIndex:1] + XCTAssertEqual([self adGetPropertyCount:[receivedEvents objectAtIndex:1] propertyName:@"stop_time"], 1); // the third event recorded is event1 - XCTAssertTrue([[self getPropertyFromEvent:[receivedEvents objectAtIndex:2] + XCTAssertTrue([[self adGetPropertyFromEvent:[receivedEvents objectAtIndex:2] propertyName:@"event_name"] isEqualToString:@"testEvent1"]); - XCTAssertEqual([self getPropertyCount:[receivedEvents objectAtIndex:2] + XCTAssertEqual([self adGetPropertyCount:[receivedEvents objectAtIndex:2] propertyName:@"event_name"], 1); - XCTAssertEqual([self getPropertyCount:[receivedEvents objectAtIndex:2] + XCTAssertEqual([self adGetPropertyCount:[receivedEvents objectAtIndex:2] propertyName:@"start_time"], 1); - XCTAssertEqual([self getPropertyCount:[receivedEvents objectAtIndex:2] + XCTAssertEqual([self adGetPropertyCount:[receivedEvents objectAtIndex:2] propertyName:@"stop_time"], 1); // the fourth event recorded is event4 - XCTAssertTrue([[self getPropertyFromEvent:[receivedEvents objectAtIndex:3] + XCTAssertTrue([[self adGetPropertyFromEvent:[receivedEvents objectAtIndex:3] propertyName:@"event_name"] isEqualToString:@"testEvent4"]); - XCTAssertEqual([self getPropertyCount:[receivedEvents objectAtIndex:3] + XCTAssertEqual([self adGetPropertyCount:[receivedEvents objectAtIndex:3] propertyName:@"event_name"], 1); - XCTAssertEqual([self getPropertyCount:[receivedEvents objectAtIndex:3] + XCTAssertEqual([self adGetPropertyCount:[receivedEvents objectAtIndex:3] propertyName:@"start_time"], 1); - XCTAssertEqual([self getPropertyCount:[receivedEvents objectAtIndex:3] + XCTAssertEqual([self adGetPropertyCount:[receivedEvents objectAtIndex:3] propertyName:@"stop_time"], 1); } - (void)testComplexEventsWithAggregation { // new a dispatcher - TestDispatcher* dispatcher = [TestDispatcher new]; + ADTelemetryTestDispatcher* dispatcher = [ADTelemetryTestDispatcher new]; NSMutableArray* receivedEvents = [NSMutableArray new]; NSUUID* correlationId = [NSUUID UUID]; @@ -538,172 +496,26 @@ - (void)testComplexEventsWithAggregation { XCTAssertEqual([receivedEvents count], 1); // the aggregated event outputs the default properties like correlation_id, request_id, etc. - XCTAssertEqual([self getPropertyCount:[receivedEvents firstObject] + XCTAssertEqual([self adGetPropertyCount:[receivedEvents firstObject] propertyName:@"correlation_id"], 1); - XCTAssertEqual([self getPropertyCount:[receivedEvents firstObject] + XCTAssertEqual([self adGetPropertyCount:[receivedEvents firstObject] propertyName:@"request_id"], 1); // it will also outputs some designated properties like response_time, but not for event_name, etc. - XCTAssertEqual([self getPropertyCount:[receivedEvents firstObject] + XCTAssertEqual([self adGetPropertyCount:[receivedEvents firstObject] propertyName:@"response_time"], 1); - XCTAssertEqual([self getPropertyCount:[receivedEvents firstObject] + XCTAssertEqual([self adGetPropertyCount:[receivedEvents firstObject] propertyName:@"event_name"], 0); - XCTAssertEqual([self getPropertyCount:[receivedEvents firstObject] + XCTAssertEqual([self adGetPropertyCount:[receivedEvents firstObject] propertyName:@"start_time"], 0); - XCTAssertEqual([self getPropertyCount:[receivedEvents firstObject] + XCTAssertEqual([self adGetPropertyCount:[receivedEvents firstObject] propertyName:@"stop_time"], 0); - XCTAssertEqual([self getPropertyCount:[receivedEvents firstObject] + XCTAssertEqual([self adGetPropertyCount:[receivedEvents firstObject] propertyName:@"customized_property"], 0); } -- (void)testAcquireTokenOutputAggregation -{ - // prepare the dispatcher - TestDispatcher* dispatcher = [TestDispatcher new]; - NSMutableArray* receivedEvents = [NSMutableArray new]; - [dispatcher setTestCallback:^(NSArray* event) - { - [receivedEvents addObject:event]; - }]; - - // register the dispatcher - [[ADTelemetry sharedInstance] registerDispatcher:dispatcher aggregationRequired:YES]; - - // Simplest FRT case, the only RT available is the FRT so that would should be the one used - ADAuthenticationError* error = nil; - ADAuthenticationContext* context = [self getTestAuthenticationContext]; - - id cache = [context tokenCacheStore].dataSource; - XCTAssertNotNil(cache); - - XCTAssertTrue([cache addOrUpdateItem:[self adCreateFRTCacheItem] correlationId:nil error:&error]); - XCTAssertNil(error); - - ADTestURLResponse* response = [self adResponseRefreshToken:@"family refresh token" - authority:TEST_AUTHORITY - resource:TEST_RESOURCE - clientId:TEST_CLIENT_ID - correlationId:TEST_CORRELATION_ID - newRefreshToken:@"new family refresh token" - newAccessToken:TEST_ACCESS_TOKEN - additionalFields:@{ ADAL_CLIENT_FAMILY_ID : @"1"}]; - - [ADTestURLConnection addResponse:response]; - - [context acquireTokenSilentWithResource:TEST_RESOURCE - clientId:TEST_CLIENT_ID - redirectUri:TEST_REDIRECT_URL - userId:TEST_USER_ID - completionBlock:^(ADAuthenticationResult *result) - { - XCTAssertNotNil(result); - XCTAssertEqual(result.status, AD_SUCCEEDED); - - // there should be 1 telemetry events recorded as aggregation flag is ON - XCTAssertEqual([receivedEvents count], 1); - - // the following properties are expected in an aggregrated event - XCTAssertEqual([self getPropertyCount:[receivedEvents firstObject] - propertyName:@"api_id"], 1); - XCTAssertEqual([self getPropertyCount:[receivedEvents firstObject] - propertyName:@"request_id"], 1); - XCTAssertEqual([self getPropertyCount:[receivedEvents firstObject] - propertyName:@"correlation_id"], 1); -#if TARGET_OS_IPHONE - // application_version is only available in unit test framework with host app - XCTAssertEqual([self getPropertyCount:[receivedEvents firstObject] - propertyName:@"application_version"], 1); -#endif - XCTAssertEqual([self getPropertyCount:[receivedEvents firstObject] - propertyName:@"application_name"], 1); - XCTAssertEqual([self getPropertyCount:[receivedEvents firstObject] - propertyName:@"x-client-Ver"], 1); - XCTAssertEqual([self getPropertyCount:[receivedEvents firstObject] - propertyName:@"x-client-SKU"], 1); - XCTAssertEqual([self getPropertyCount:[receivedEvents firstObject] - propertyName:@"client_id"], 1); - XCTAssertEqual([self getPropertyCount:[receivedEvents firstObject] - propertyName:@"device_id"], 1); - XCTAssertEqual([self getPropertyCount:[receivedEvents firstObject] - propertyName:@"authority_type"], 1); - XCTAssertEqual([self getPropertyCount:[receivedEvents firstObject] - propertyName:@"extended_expires_on_setting"], 1); - XCTAssertEqual([self getPropertyCount:[receivedEvents firstObject] - propertyName:@"prompt_behavior"], 1); - XCTAssertEqual([self getPropertyCount:[receivedEvents firstObject] - propertyName:@"status"], 1); - XCTAssertEqual([self getPropertyCount:[receivedEvents firstObject] - propertyName:@"tenant_id"], 1); - XCTAssertEqual([self getPropertyCount:[receivedEvents firstObject] - propertyName:@"user_id"], 1); - XCTAssertEqual([self getPropertyCount:[receivedEvents firstObject] - propertyName:@"response_time"], 1); - XCTAssertEqual([self getPropertyCount:[receivedEvents firstObject] - propertyName:@"cache_event_count"], 1); - XCTAssertEqual([self getPropertyCount:[receivedEvents firstObject] - propertyName:@"token_rt_status"], 1); - XCTAssertEqual([self getPropertyCount:[receivedEvents firstObject] - propertyName:@"token_mrrt_status"], 1); - XCTAssertEqual([self getPropertyCount:[receivedEvents firstObject] - propertyName:@"token_frt_status"], 1); - XCTAssertEqual([self getPropertyCount:[receivedEvents firstObject] - propertyName:@"http_event_count"], 1); - XCTAssertEqual([self getPropertyCount:[receivedEvents firstObject] - propertyName:@"http_event_count"], 1); - XCTAssertEqual([self getPropertyCount:[receivedEvents firstObject] - propertyName:@"error_code"], 1); - TEST_SIGNAL; - }]; - TEST_WAIT; -} - -- (NSString*)getPropertyFromEvent:(NSArray*)event - propertyName:(NSString*)propertyName -{ - for (ADTelemetryProperty* property in event) - { - if ([property.name isEqualToString:propertyName]) - { - return property.value; - } - } - return nil; -} - -- (NSInteger)getPropertyCount:(NSArray*)event - propertyName:(NSString*)propertyName -{ - NSInteger count = 0; - for (ADTelemetryProperty* property in event) - { - if ([property.name isEqualToString:propertyName]) - { - count++; - } - } - return count; -} - -- (ADAuthenticationContext *)getTestAuthenticationContext -{ - ADAuthenticationContext* context = - [[ADAuthenticationContext alloc] initWithAuthority:TEST_AUTHORITY - validateAuthority:NO - error:nil]; - - NSAssert(context, @"If this is failing for whatever reason you should probably fix it before trying to run tests."); - ADTokenCache *tokenCache = [ADTokenCache new]; - SAFE_ARC_AUTORELEASE(tokenCache); - [context setTokenCacheStore:tokenCache]; - [context setCorrelationId:TEST_CORRELATION_ID]; - - SAFE_ARC_AUTORELEASE(context); - - return context; -} - @end diff --git a/ADAL/tests/XCTestCase+TestHelperMethods.h b/ADAL/tests/XCTestCase+TestHelperMethods.h index 17205af56..e0529c943 100644 --- a/ADAL/tests/XCTestCase+TestHelperMethods.h +++ b/ADAL/tests/XCTestCase+TestHelperMethods.h @@ -24,6 +24,7 @@ #import #import "ADAuthenticationError.h" #import "ADAL_Internal.h" +#import "ADTelemetry.h" #define ADTAssertContains(_str, _contains) XCTAssertTrue([_str containsString:_contains], "%@ does not contain \"%@\"", _str, _contains) @@ -210,6 +211,14 @@ typedef enum line:(int)line semaphore:(dispatch_semaphore_t)signal block:(void (^)(void)) block; + +//The method retrieves property value from a telemetry event by property name +- (NSString*)adGetPropertyFromEvent:(NSArray*)event + propertyName:(NSString*)propertyName; + +//The method counts the properties in a telemetry event matching propertyName +- (NSInteger)adGetPropertyCount:(NSArray*)event + propertyName:(NSString*)propertyName; @end //Fixes the issue with XCTAssertEqual not comparing int and long values diff --git a/ADAL/tests/XCTestCase+TestHelperMethods.m b/ADAL/tests/XCTestCase+TestHelperMethods.m index cd25a74f2..b77437c65 100644 --- a/ADAL/tests/XCTestCase+TestHelperMethods.m +++ b/ADAL/tests/XCTestCase+TestHelperMethods.m @@ -508,4 +508,31 @@ - (ADTestURLResponse *)adResponseRefreshToken:(NSString *)oldRefreshToken } +- (NSString*)adGetPropertyFromEvent:(NSArray*)event + propertyName:(NSString*)propertyName +{ + for (ADTelemetryProperty* property in event) + { + if ([property.name isEqualToString:propertyName]) + { + return property.value; + } + } + return nil; +} + +- (NSInteger)adGetPropertyCount:(NSArray*)event + propertyName:(NSString*)propertyName +{ + NSInteger count = 0; + for (ADTelemetryProperty* property in event) + { + if ([property.name isEqualToString:propertyName]) + { + count++; + } + } + return count; +} + @end From 897b6e27c5cf68d043e9bbc363ca6b85dde7aa72 Mon Sep 17 00:00:00 2001 From: Jason Kim Date: Thu, 8 Dec 2016 11:35:57 -0800 Subject: [PATCH 83/92] adding keyboard disappear on return to userid textfield. --- .../MyTestiOSApp/ADTestAppAcquireTokenViewController.m | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/Samples/MyTestiOSApp/MyTestiOSApp/ADTestAppAcquireTokenViewController.m b/Samples/MyTestiOSApp/MyTestiOSApp/ADTestAppAcquireTokenViewController.m index a8f55cbc4..d10945c20 100644 --- a/Samples/MyTestiOSApp/MyTestiOSApp/ADTestAppAcquireTokenViewController.m +++ b/Samples/MyTestiOSApp/MyTestiOSApp/ADTestAppAcquireTokenViewController.m @@ -26,7 +26,7 @@ #import "ADKeychainTokenCache+Internal.h" #import "ADTestAppAcquireLayoutBuilder.h" -@interface ADTestAppAcquireTokenViewController () +@interface ADTestAppAcquireTokenViewController () @end @@ -105,6 +105,7 @@ - (UIView*)createSettingsAndResultView _userIdField = [[UITextField alloc] initWithFrame:CGRectMake(0, 0, 400, 20)]; _userIdField.borderStyle = UITextBorderStyleRoundedRect; + _userIdField.delegate = self; [layout addControl:_userIdField title:@"userId"]; _userIdType = [[UISegmentedControl alloc] initWithItems:@[@"Optional", @"Required", @"Unique"]]; @@ -273,6 +274,12 @@ - (void)loadView [mainView addConstraint:_bottomConstraint]; } +- (BOOL)textFieldShouldReturn:(UITextField *)textField +{ + [textField resignFirstResponder]; + return YES; +} + - (void)viewDidLoad { [super viewDidLoad]; From bf17e54090219290b82caed28dfcab1195ea08f6 Mon Sep 17 00:00:00 2001 From: jasoncoolmax Date: Thu, 8 Dec 2016 13:47:01 -0800 Subject: [PATCH 84/92] fix format issue --- .../ADAuthenticationRequest+AcquireToken.m | 5 +- ADAL/src/telemetry/ADTelemetryAPIEvent.h | 30 +-- ADAL/src/telemetry/ADTelemetryAPIEvent.m | 32 ++-- ADAL/src/telemetry/ADTelemetryHttpEvent.m | 10 +- ADAL/tests/ADAcquireTokenTests.m | 172 +++++++++--------- ADAL/tests/ADTelemetryTests.m | 100 +++++----- ADAL/tests/XCTestCase+TestHelperMethods.h | 8 +- ADAL/tests/XCTestCase+TestHelperMethods.m | 8 +- 8 files changed, 187 insertions(+), 178 deletions(-) diff --git a/ADAL/src/request/ADAuthenticationRequest+AcquireToken.m b/ADAL/src/request/ADAuthenticationRequest+AcquireToken.m index 072a42a6e..37aeb3e3b 100644 --- a/ADAL/src/request/ADAuthenticationRequest+AcquireToken.m +++ b/ADAL/src/request/ADAuthenticationRequest+AcquireToken.m @@ -85,9 +85,10 @@ - (void)acquireToken:(NSString *)eventName [event setPromptBehavior:_promptBehavior]; if ([result tokenCacheItem]) { - [event setUserInformation:[[result tokenCacheItem] userInformation]]; + [event setUserInformation:result.tokenCacheItem.userInformation]; } - else{ + else + { [event setUserId:_requestParams.identifier.userId]; } [event setResultStatus:result.status]; diff --git a/ADAL/src/telemetry/ADTelemetryAPIEvent.h b/ADAL/src/telemetry/ADTelemetryAPIEvent.h index 53d5c041a..fc88bdc4a 100644 --- a/ADAL/src/telemetry/ADTelemetryAPIEvent.h +++ b/ADAL/src/telemetry/ADTelemetryAPIEvent.h @@ -26,24 +26,24 @@ @interface ADTelemetryAPIEvent : ADTelemetryDefaultEvent - (void)setResultStatus:(ADAuthenticationResultStatus)status; -- (void)setCorrelationId:(NSUUID*)correlationId; -- (void)setExtendedExpiresOnSetting:(NSString*)extendedExpiresOnSetting; +- (void)setCorrelationId:(NSUUID *)correlationId; +- (void)setExtendedExpiresOnSetting:(NSString *)extendedExpiresOnSetting; - (void)setPromptBehavior:(ADPromptBehavior)promptBehavior; -- (void)setUserInformation:(ADUserInformation*)userInfo; -- (void)setUserId:(NSString*)userId; -- (void)setClientId:(NSString*)clientId; -- (void)setIsExtendedLifeTimeToken:(NSString*)isExtendedLifeToken; -- (void)setErrorCode:(NSString*)errorCode; -- (void)setProtocolCode:(NSString*)protocolCode; -- (void)setErrorDescription:(NSString*)errorDescription; -- (void)setErrorDomain:(NSString*)errorDomain; +- (void)setUserInformation:(ADUserInformation *)userInfo; +- (void)setUserId:(NSString *)userId; +- (void)setClientId:(NSString *)clientId; +- (void)setIsExtendedLifeTimeToken:(NSString *)isExtendedLifeToken; +- (void)setErrorCode:(NSString *)errorCode; +- (void)setProtocolCode:(NSString *)protocolCode; +- (void)setErrorDescription:(NSString *)errorDescription; +- (void)setErrorDomain:(NSString *)errorDomain; -- (void)setAuthorityValidationStatus:(NSString*)status; -- (void)setAuthority:(NSString*)authority; +- (void)setAuthorityValidationStatus:(NSString *)status; +- (void)setAuthority:(NSString *)authority; -- (void)setGrantType:(NSString*)grantType; -- (void)setAPIStatus:(NSString*)status; +- (void)setGrantType:(NSString *)grantType; +- (void)setAPIStatus:(NSString *)status; -- (void)setApiId:(NSString*)apiId; +- (void)setApiId:(NSString *)apiId; @end \ No newline at end of file diff --git a/ADAL/src/telemetry/ADTelemetryAPIEvent.m b/ADAL/src/telemetry/ADTelemetryAPIEvent.m index 3aff14ca4..4b19e5eeb 100644 --- a/ADAL/src/telemetry/ADTelemetryAPIEvent.m +++ b/ADAL/src/telemetry/ADTelemetryAPIEvent.m @@ -50,64 +50,64 @@ - (void)setResultStatus:(ADAuthenticationResultStatus)status [self setProperty:AD_TELEMETRY_RESULT_STATUS value:statusStr]; } -- (void)setCorrelationId:(NSUUID*)correlationId +- (void)setCorrelationId:(NSUUID *)correlationId { [self setProperty:AD_TELEMETRY_CORRELATION_ID value:[correlationId UUIDString]]; } -- (void)setExtendedExpiresOnSetting:(NSString*)extendedExpiresOnSetting +- (void)setExtendedExpiresOnSetting:(NSString *)extendedExpiresOnSetting { [self setProperty:AD_TELEMETRY_EXTENDED_EXPIRES_ON_SETTING value:extendedExpiresOnSetting]; } -- (void)setUserInformation:(ADUserInformation*)userInfo +- (void)setUserInformation:(ADUserInformation *)userInfo { [self setProperty:AD_TELEMETRY_USER_ID value:[[userInfo userId] adComputeSHA256]]; [self setProperty:AD_TELEMETRY_TENANT_ID value:[[userInfo tenantId] adComputeSHA256]]; [self setProperty:AD_TELEMETRY_IDP value:[userInfo identityProvider]]; } -- (void)setUserId:(NSString*)userId +- (void)setUserId:(NSString *)userId { [self setProperty:AD_TELEMETRY_USER_ID value:[userId adComputeSHA256]]; } -- (void)setClientId:(NSString*)clientId +- (void)setClientId:(NSString *)clientId { [self setProperty:AD_TELEMETRY_CLIENT_ID value:clientId]; } -- (void)setIsExtendedLifeTimeToken:(NSString*)isExtendedLifeToken +- (void)setIsExtendedLifeTimeToken:(NSString *)isExtendedLifeToken { [self setProperty:AD_TELEMETRY_IS_EXTENED_LIFE_TIME_TOKEN value:isExtendedLifeToken]; } -- (void)setErrorCode:(NSString*)errorCode +- (void)setErrorCode:(NSString *)errorCode { [self setProperty:AD_TELEMETRY_ERROR_CODE value:errorCode]; } -- (void)setProtocolCode:(NSString*)protocolCode +- (void)setProtocolCode:(NSString *)protocolCode { [self setProperty:AD_TELEMETRY_PROTOCOL_CODE value:protocolCode]; } -- (void)setErrorDescription:(NSString*)errorDescription +- (void)setErrorDescription:(NSString *)errorDescription { [self setProperty:AD_TELEMETRY_ERROR_DESCRIPTION value:errorDescription]; } -- (void)setErrorDomain:(NSString*)errorDomain +- (void)setErrorDomain:(NSString *)errorDomain { [self setProperty:AD_TELEMETRY_ERROR_DOMAIN value:errorDomain]; } -- (void)setAuthorityValidationStatus:(NSString*)status +- (void)setAuthorityValidationStatus:(NSString *)status { [self setProperty:AD_TELEMETRY_AUTHORITY_VALIDATION_STATUS value:status]; } -- (void)setAuthority:(NSString*)authority +- (void)setAuthority:(NSString *)authority { [self setProperty:AD_TELEMETRY_AUTHORITY value:authority]; @@ -120,17 +120,17 @@ - (void)setAuthority:(NSString*)authority [self setProperty:AD_TELEMETRY_AUTHORITY_TYPE value:authorityType]; } -- (void)setGrantType:(NSString*)grantType +- (void)setGrantType:(NSString *)grantType { [self setProperty:AD_TELEMETRY_GRANT_TYPE value:grantType]; } -- (void)setAPIStatus:(NSString*)status +- (void)setAPIStatus:(NSString *)status { [self setProperty:AD_TELEMETRY_API_STATUS value:status]; } -- (void)setApiId:(NSString*)apiId +- (void)setApiId:(NSString *)apiId { [self setProperty:AD_TELEMETRY_API_ID value:apiId]; } @@ -158,7 +158,7 @@ - (void)setPromptBehavior:(ADPromptBehavior)promptBehavior [self setProperty:AD_TELEMETRY_PROMPT_BEHAVIOR value:promptBehaviorString]; } -- (void)addAggregatedPropertiesToDictionary:(NSMutableDictionary*)eventToBeDispatched +- (void)addAggregatedPropertiesToDictionary:(NSMutableDictionary *)eventToBeDispatched { [super addAggregatedPropertiesToDictionary:eventToBeDispatched]; diff --git a/ADAL/src/telemetry/ADTelemetryHttpEvent.m b/ADAL/src/telemetry/ADTelemetryHttpEvent.m index f8528d3c0..03931fc7f 100644 --- a/ADAL/src/telemetry/ADTelemetryHttpEvent.m +++ b/ADAL/src/telemetry/ADTelemetryHttpEvent.m @@ -85,15 +85,7 @@ - (void)addAggregatedPropertiesToDictionary:(NSMutableDictionary*)eventToBeDispa } [eventToBeDispatched setObject:[NSString stringWithFormat:@"%d", httpEventCount] forKey:AD_TELEMETRY_HTTP_EVENT_COUNT]; - NSArray* properties = [self getProperties]; - for (ADTelemetryProperty* property in properties) - { - if ([property.name isEqualToString:AD_TELEMETRY_OAUTH_ERROR_CODE] - ||[property.name isEqualToString:AD_TELEMETRY_HTTP_ERROR_DOMAIN]) - { - [eventToBeDispatched setObject:property.value forKey:property.name]; - } - } + //TODO: output http event properties to aggregated event } - (NSString*)scrubTenantFromUrl:(NSString*)url diff --git a/ADAL/tests/ADAcquireTokenTests.m b/ADAL/tests/ADAcquireTokenTests.m index 41e899ca0..5de1133be 100644 --- a/ADAL/tests/ADAcquireTokenTests.m +++ b/ADAL/tests/ADAcquireTokenTests.m @@ -385,44 +385,45 @@ - (void)testFailsWithNilUserIdAndMultipleCachedUsers XCTAssertEqual([receivedEvents count], 1); // the following properties are expected in an aggregrated event - XCTAssertEqual([self adGetPropertyCount:[receivedEvents firstObject] + NSArray* event = [receivedEvents firstObject]; + XCTAssertEqual([self adGetPropertyCount:event propertyName:@"api_id"], 1); - XCTAssertEqual([self adGetPropertyCount:[receivedEvents firstObject] + XCTAssertEqual([self adGetPropertyCount:event propertyName:@"request_id"], 1); - XCTAssertEqual([self adGetPropertyCount:[receivedEvents firstObject] + XCTAssertEqual([self adGetPropertyCount:event propertyName:@"correlation_id"], 1); #if TARGET_OS_IPHONE // application_version is only available in unit test framework with host app - XCTAssertEqual([self adGetPropertyCount:[receivedEvents firstObject] + XCTAssertEqual([self adGetPropertyCount:event propertyName:@"application_version"], 1); #endif - XCTAssertEqual([self adGetPropertyCount:[receivedEvents firstObject] + XCTAssertEqual([self adGetPropertyCount:event propertyName:@"application_name"], 1); - XCTAssertEqual([self adGetPropertyCount:[receivedEvents firstObject] + XCTAssertEqual([self adGetPropertyCount:event propertyName:@"x-client-Ver"], 1); - XCTAssertEqual([self adGetPropertyCount:[receivedEvents firstObject] + XCTAssertEqual([self adGetPropertyCount:event propertyName:@"x-client-SKU"], 1); - XCTAssertEqual([self adGetPropertyCount:[receivedEvents firstObject] + XCTAssertEqual([self adGetPropertyCount:event propertyName:@"client_id"], 1); - XCTAssertEqual([self adGetPropertyCount:[receivedEvents firstObject] + XCTAssertEqual([self adGetPropertyCount:event propertyName:@"device_id"], 1); - XCTAssertEqual([self adGetPropertyCount:[receivedEvents firstObject] + XCTAssertEqual([self adGetPropertyCount:event propertyName:@"authority_type"], 1); - XCTAssertEqual([self adGetPropertyCount:[receivedEvents firstObject] + XCTAssertEqual([self adGetPropertyCount:event propertyName:@"extended_expires_on_setting"], 1); - XCTAssertEqual([self adGetPropertyCount:[receivedEvents firstObject] + XCTAssertEqual([self adGetPropertyCount:event propertyName:@"prompt_behavior"], 1); - XCTAssertEqual([self adGetPropertyCount:[receivedEvents firstObject] + XCTAssertEqual([self adGetPropertyCount:event propertyName:@"status"], 1); - XCTAssertEqual([self adGetPropertyCount:[receivedEvents firstObject] + XCTAssertEqual([self adGetPropertyCount:event propertyName:@"response_time"], 1); - XCTAssertEqual([self adGetPropertyCount:[receivedEvents firstObject] + XCTAssertEqual([self adGetPropertyCount:event propertyName:@"cache_event_count"], 1); - XCTAssertEqual([self adGetPropertyCount:[receivedEvents firstObject] + XCTAssertEqual([self adGetPropertyCount:event propertyName:@"error_code"], 1); - XCTAssertEqual([self adGetPropertyCount:[receivedEvents firstObject] + XCTAssertEqual([self adGetPropertyCount:event propertyName:@"error_domain"], 1); - XCTAssertEqual([self adGetPropertyCount:[receivedEvents firstObject] + XCTAssertEqual([self adGetPropertyCount:event propertyName:@"error_description"], 1); //unregister the dispatcher @@ -659,101 +660,103 @@ - (void)testSilentExpiredATBadMRRT XCTAssertEqual([receivedEvents count], 2); // the following properties are expected for the 1st acquire token call - XCTAssertEqual([self adGetPropertyCount:[receivedEvents firstObject] + NSArray* firstEvent = [receivedEvents firstObject]; + XCTAssertEqual([self adGetPropertyCount:firstEvent propertyName:@"api_id"], 1); - XCTAssertEqual([self adGetPropertyCount:[receivedEvents firstObject] + XCTAssertEqual([self adGetPropertyCount:firstEvent propertyName:@"request_id"], 1); - XCTAssertEqual([self adGetPropertyCount:[receivedEvents firstObject] + XCTAssertEqual([self adGetPropertyCount:firstEvent propertyName:@"correlation_id"], 1); #if TARGET_OS_IPHONE // application_version is only available in unit test framework with host app - XCTAssertEqual([self adGetPropertyCount:[receivedEvents firstObject] + XCTAssertEqual([self adGetPropertyCount:firstEvent propertyName:@"application_version"], 1); #endif - XCTAssertEqual([self adGetPropertyCount:[receivedEvents firstObject] + XCTAssertEqual([self adGetPropertyCount:firstEvent propertyName:@"application_name"], 1); - XCTAssertEqual([self adGetPropertyCount:[receivedEvents firstObject] + XCTAssertEqual([self adGetPropertyCount:firstEvent propertyName:@"x-client-Ver"], 1); - XCTAssertEqual([self adGetPropertyCount:[receivedEvents firstObject] + XCTAssertEqual([self adGetPropertyCount:firstEvent propertyName:@"x-client-SKU"], 1); - XCTAssertEqual([self adGetPropertyCount:[receivedEvents firstObject] + XCTAssertEqual([self adGetPropertyCount:firstEvent propertyName:@"client_id"], 1); - XCTAssertEqual([self adGetPropertyCount:[receivedEvents firstObject] + XCTAssertEqual([self adGetPropertyCount:firstEvent propertyName:@"device_id"], 1); - XCTAssertEqual([self adGetPropertyCount:[receivedEvents firstObject] + XCTAssertEqual([self adGetPropertyCount:firstEvent propertyName:@"authority_type"], 1); - XCTAssertEqual([self adGetPropertyCount:[receivedEvents firstObject] + XCTAssertEqual([self adGetPropertyCount:firstEvent propertyName:@"extended_expires_on_setting"], 1); - XCTAssertEqual([self adGetPropertyCount:[receivedEvents firstObject] + XCTAssertEqual([self adGetPropertyCount:firstEvent propertyName:@"prompt_behavior"], 1); - XCTAssertEqual([self adGetPropertyCount:[receivedEvents firstObject] + XCTAssertEqual([self adGetPropertyCount:firstEvent propertyName:@"status"], 1); - XCTAssertEqual([self adGetPropertyCount:[receivedEvents firstObject] + XCTAssertEqual([self adGetPropertyCount:firstEvent propertyName:@"user_id"], 1); - XCTAssertEqual([self adGetPropertyCount:[receivedEvents firstObject] + XCTAssertEqual([self adGetPropertyCount:firstEvent propertyName:@"response_time"], 1); - XCTAssertEqual([self adGetPropertyCount:[receivedEvents firstObject] + XCTAssertEqual([self adGetPropertyCount:firstEvent propertyName:@"cache_event_count"], 1); - XCTAssertEqual([self adGetPropertyCount:[receivedEvents firstObject] + XCTAssertEqual([self adGetPropertyCount:firstEvent propertyName:@"token_mrrt_status"], 1); - XCTAssertEqual([self adGetPropertyCount:[receivedEvents firstObject] + XCTAssertEqual([self adGetPropertyCount:firstEvent propertyName:@"token_frt_status"], 1); - XCTAssertEqual([self adGetPropertyCount:[receivedEvents firstObject] + XCTAssertEqual([self adGetPropertyCount:firstEvent propertyName:@"http_event_count"], 1); - XCTAssertEqual([self adGetPropertyCount:[receivedEvents firstObject] + XCTAssertEqual([self adGetPropertyCount:firstEvent propertyName:@"error_code"], 1); - XCTAssertEqual([self adGetPropertyCount:[receivedEvents firstObject] + XCTAssertEqual([self adGetPropertyCount:firstEvent propertyName:@"error_domain"], 1); - XCTAssertEqual([self adGetPropertyCount:[receivedEvents firstObject] + XCTAssertEqual([self adGetPropertyCount:firstEvent propertyName:@"error_description"], 1); // the following properties are expected for 2nd acquire token call - XCTAssertEqual([self adGetPropertyCount:[receivedEvents firstObject] + NSArray* secondEvent = [receivedEvents objectAtIndex:1]; + XCTAssertEqual([self adGetPropertyCount:secondEvent propertyName:@"api_id"], 1); - XCTAssertEqual([self adGetPropertyCount:[receivedEvents firstObject] + XCTAssertEqual([self adGetPropertyCount:secondEvent propertyName:@"request_id"], 1); - XCTAssertEqual([self adGetPropertyCount:[receivedEvents firstObject] + XCTAssertEqual([self adGetPropertyCount:secondEvent propertyName:@"correlation_id"], 1); #if TARGET_OS_IPHONE // application_version is only available in unit test framework with host app - XCTAssertEqual([self adGetPropertyCount:[receivedEvents firstObject] + XCTAssertEqual([self adGetPropertyCount:secondEvent propertyName:@"application_version"], 1); #endif - XCTAssertEqual([self adGetPropertyCount:[receivedEvents objectAtIndex:1] + XCTAssertEqual([self adGetPropertyCount:secondEvent propertyName:@"application_name"], 1); - XCTAssertEqual([self adGetPropertyCount:[receivedEvents objectAtIndex:1] + XCTAssertEqual([self adGetPropertyCount:secondEvent propertyName:@"x-client-Ver"], 1); - XCTAssertEqual([self adGetPropertyCount:[receivedEvents objectAtIndex:1] + XCTAssertEqual([self adGetPropertyCount:secondEvent propertyName:@"x-client-SKU"], 1); - XCTAssertEqual([self adGetPropertyCount:[receivedEvents objectAtIndex:1] + XCTAssertEqual([self adGetPropertyCount:secondEvent propertyName:@"client_id"], 1); - XCTAssertEqual([self adGetPropertyCount:[receivedEvents objectAtIndex:1] + XCTAssertEqual([self adGetPropertyCount:secondEvent propertyName:@"device_id"], 1); - XCTAssertEqual([self adGetPropertyCount:[receivedEvents objectAtIndex:1] + XCTAssertEqual([self adGetPropertyCount:secondEvent propertyName:@"authority_type"], 1); - XCTAssertEqual([self adGetPropertyCount:[receivedEvents objectAtIndex:1] + XCTAssertEqual([self adGetPropertyCount:secondEvent propertyName:@"extended_expires_on_setting"], 1); - XCTAssertEqual([self adGetPropertyCount:[receivedEvents objectAtIndex:1] + XCTAssertEqual([self adGetPropertyCount:secondEvent propertyName:@"prompt_behavior"], 1); - XCTAssertEqual([self adGetPropertyCount:[receivedEvents objectAtIndex:1] + XCTAssertEqual([self adGetPropertyCount:secondEvent propertyName:@"status"], 1); - XCTAssertEqual([self adGetPropertyCount:[receivedEvents objectAtIndex:1] + XCTAssertEqual([self adGetPropertyCount:secondEvent propertyName:@"user_id"], 1); - XCTAssertEqual([self adGetPropertyCount:[receivedEvents objectAtIndex:1] + XCTAssertEqual([self adGetPropertyCount:secondEvent propertyName:@"response_time"], 1); - XCTAssertEqual([self adGetPropertyCount:[receivedEvents objectAtIndex:1] + XCTAssertEqual([self adGetPropertyCount:secondEvent propertyName:@"cache_event_count"], 1); - XCTAssertEqual([self adGetPropertyCount:[receivedEvents objectAtIndex:1] + XCTAssertEqual([self adGetPropertyCount:secondEvent propertyName:@"token_rt_status"], 1); - XCTAssertEqual([self adGetPropertyCount:[receivedEvents objectAtIndex:1] + XCTAssertEqual([self adGetPropertyCount:secondEvent propertyName:@"token_mrrt_status"], 1); - XCTAssertEqual([self adGetPropertyCount:[receivedEvents objectAtIndex:1] + XCTAssertEqual([self adGetPropertyCount:secondEvent propertyName:@"token_frt_status"], 1); - XCTAssertEqual([self adGetPropertyCount:[receivedEvents objectAtIndex:1] + XCTAssertEqual([self adGetPropertyCount:secondEvent propertyName:@"error_code"], 1); - XCTAssertEqual([self adGetPropertyCount:[receivedEvents objectAtIndex:1] + XCTAssertEqual([self adGetPropertyCount:secondEvent propertyName:@"error_domain"], 1); - XCTAssertEqual([self adGetPropertyCount:[receivedEvents objectAtIndex:1] + XCTAssertEqual([self adGetPropertyCount:secondEvent propertyName:@"error_description"], 1); //unregister the dispatcher @@ -1173,52 +1176,53 @@ - (void)testAcquireTokenUsingFRT XCTAssertEqual([receivedEvents count], 1); // the following properties are expected in an aggregrated event - XCTAssertEqual([self adGetPropertyCount:[receivedEvents firstObject] + NSArray* event = [receivedEvents firstObject]; + XCTAssertEqual([self adGetPropertyCount:event propertyName:@"api_id"], 1); - XCTAssertEqual([self adGetPropertyCount:[receivedEvents firstObject] + XCTAssertEqual([self adGetPropertyCount:event propertyName:@"request_id"], 1); - XCTAssertEqual([self adGetPropertyCount:[receivedEvents firstObject] + XCTAssertEqual([self adGetPropertyCount:event propertyName:@"correlation_id"], 1); #if TARGET_OS_IPHONE // application_version is only available in unit test framework with host app - XCTAssertEqual([self adGetPropertyCount:[receivedEvents firstObject] + XCTAssertEqual([self adGetPropertyCount:event propertyName:@"application_version"], 1); #endif - XCTAssertEqual([self adGetPropertyCount:[receivedEvents firstObject] + XCTAssertEqual([self adGetPropertyCount:event propertyName:@"application_name"], 1); - XCTAssertEqual([self adGetPropertyCount:[receivedEvents firstObject] + XCTAssertEqual([self adGetPropertyCount:event propertyName:@"x-client-Ver"], 1); - XCTAssertEqual([self adGetPropertyCount:[receivedEvents firstObject] + XCTAssertEqual([self adGetPropertyCount:event propertyName:@"x-client-SKU"], 1); - XCTAssertEqual([self adGetPropertyCount:[receivedEvents firstObject] + XCTAssertEqual([self adGetPropertyCount:event propertyName:@"client_id"], 1); - XCTAssertEqual([self adGetPropertyCount:[receivedEvents firstObject] + XCTAssertEqual([self adGetPropertyCount:event propertyName:@"device_id"], 1); - XCTAssertEqual([self adGetPropertyCount:[receivedEvents firstObject] + XCTAssertEqual([self adGetPropertyCount:event propertyName:@"authority_type"], 1); - XCTAssertEqual([self adGetPropertyCount:[receivedEvents firstObject] + XCTAssertEqual([self adGetPropertyCount:event propertyName:@"extended_expires_on_setting"], 1); - XCTAssertEqual([self adGetPropertyCount:[receivedEvents firstObject] + XCTAssertEqual([self adGetPropertyCount:event propertyName:@"prompt_behavior"], 1); - XCTAssertEqual([self adGetPropertyCount:[receivedEvents firstObject] + XCTAssertEqual([self adGetPropertyCount:event propertyName:@"status"], 1); - XCTAssertEqual([self adGetPropertyCount:[receivedEvents firstObject] + XCTAssertEqual([self adGetPropertyCount:event propertyName:@"tenant_id"], 1); - XCTAssertEqual([self adGetPropertyCount:[receivedEvents firstObject] + XCTAssertEqual([self adGetPropertyCount:event propertyName:@"user_id"], 1); - XCTAssertEqual([self adGetPropertyCount:[receivedEvents firstObject] + XCTAssertEqual([self adGetPropertyCount:event propertyName:@"response_time"], 1); - XCTAssertEqual([self adGetPropertyCount:[receivedEvents firstObject] + XCTAssertEqual([self adGetPropertyCount:event propertyName:@"cache_event_count"], 1); - XCTAssertEqual([self adGetPropertyCount:[receivedEvents firstObject] + XCTAssertEqual([self adGetPropertyCount:event propertyName:@"token_rt_status"], 1); - XCTAssertEqual([self adGetPropertyCount:[receivedEvents firstObject] + XCTAssertEqual([self adGetPropertyCount:event propertyName:@"token_mrrt_status"], 1); - XCTAssertEqual([self adGetPropertyCount:[receivedEvents firstObject] + XCTAssertEqual([self adGetPropertyCount:event propertyName:@"token_frt_status"], 1); - XCTAssertEqual([self adGetPropertyCount:[receivedEvents firstObject] + XCTAssertEqual([self adGetPropertyCount:event propertyName:@"http_event_count"], 1); - XCTAssertEqual([self adGetPropertyCount:[receivedEvents firstObject] + XCTAssertEqual([self adGetPropertyCount:event propertyName:@"error_code"], 1); //unregister the dispatcher diff --git a/ADAL/tests/ADTelemetryTests.m b/ADAL/tests/ADTelemetryTests.m index 47a801e27..3b518448e 100644 --- a/ADAL/tests/ADTelemetryTests.m +++ b/ADAL/tests/ADTelemetryTests.m @@ -78,27 +78,29 @@ - (void)testDefaultEventProperties { // make sure the default properties are recorded in the telemetry event, // i.e. sdk_id, sdk_version, device_id, device_name - XCTAssertEqual([self adGetPropertyCount:[receivedEvents firstObject] + NSArray* event = [receivedEvents firstObject]; + + XCTAssertEqual([self adGetPropertyCount:event propertyName:@"x-client-SKU"], 1); - XCTAssertEqual([self adGetPropertyCount:[receivedEvents firstObject] + XCTAssertEqual([self adGetPropertyCount:event propertyName:@"x-client-Ver"], 1); - XCTAssertEqual([self adGetPropertyCount:[receivedEvents firstObject] + XCTAssertEqual([self adGetPropertyCount:event propertyName:@"device_id"], 1); - XCTAssertEqual([self adGetPropertyCount:[receivedEvents firstObject] + XCTAssertEqual([self adGetPropertyCount:event propertyName:@"request_id"], 1); - XCTAssertEqual([self adGetPropertyCount:[receivedEvents firstObject] + XCTAssertEqual([self adGetPropertyCount:event propertyName:@"correlation_id"], 1); #if TARGET_OS_IPHONE // application_version is only available in unit test framework with host app - XCTAssertEqual([self adGetPropertyCount:[receivedEvents firstObject] + XCTAssertEqual([self adGetPropertyCount:event propertyName:@"application_version"], 1); #endif - XCTAssertEqual([self adGetPropertyCount:[receivedEvents firstObject] + XCTAssertEqual([self adGetPropertyCount:event propertyName:@"application_name"], 1); } @@ -139,26 +141,30 @@ - (void)testSequentialEvents { XCTAssertEqual([receivedEvents count], 2); // make sure the 1st event has an event_name, start_time and stop_time - XCTAssertEqual([self adGetPropertyCount:[receivedEvents firstObject] + NSArray* firstEvent = [receivedEvents firstObject]; + + XCTAssertEqual([self adGetPropertyCount:firstEvent propertyName:@"event_name"], 1); - XCTAssertEqual([self adGetPropertyCount:[receivedEvents firstObject] + XCTAssertEqual([self adGetPropertyCount:firstEvent propertyName:@"start_time"], 1); - XCTAssertEqual([self adGetPropertyCount:[receivedEvents firstObject] + XCTAssertEqual([self adGetPropertyCount:firstEvent propertyName:@"stop_time"], 1); // make sure the 2nd event has customized_property, event_name, start_time and stop_time - XCTAssertEqual([self adGetPropertyCount:[receivedEvents objectAtIndex:1] + NSArray* secondEvent = [receivedEvents objectAtIndex:1]; + + XCTAssertEqual([self adGetPropertyCount:secondEvent propertyName:@"customized_property"], 1); - XCTAssertEqual([self adGetPropertyCount:[receivedEvents firstObject] + XCTAssertEqual([self adGetPropertyCount:secondEvent propertyName:@"event_name"], 1); - XCTAssertEqual([self adGetPropertyCount:[receivedEvents firstObject] + XCTAssertEqual([self adGetPropertyCount:secondEvent propertyName:@"start_time"], 1); - XCTAssertEqual([self adGetPropertyCount:[receivedEvents firstObject] + XCTAssertEqual([self adGetPropertyCount:secondEvent propertyName:@"stop_time"], 1); } @@ -201,25 +207,26 @@ - (void)testSequentialEventsWithAggregation { XCTAssertEqual([receivedEvents count], 1); // the aggregated event outputs the default properties like correlation_id, request_id, etc. - XCTAssertEqual([self adGetPropertyCount:[receivedEvents firstObject] + NSArray* event = [receivedEvents firstObject]; + XCTAssertEqual([self adGetPropertyCount:event propertyName:@"correlation_id"], 1); - XCTAssertEqual([self adGetPropertyCount:[receivedEvents firstObject] + XCTAssertEqual([self adGetPropertyCount:event propertyName:@"request_id"], 1); // it will also outputs some designated properties like response_time, but not for event_name, etc. - XCTAssertEqual([self adGetPropertyCount:[receivedEvents firstObject] + XCTAssertEqual([self adGetPropertyCount:event propertyName:@"response_time"], 1); - XCTAssertEqual([self adGetPropertyCount:[receivedEvents firstObject] + XCTAssertEqual([self adGetPropertyCount:event propertyName:@"event_name"], 0); - XCTAssertEqual([self adGetPropertyCount:[receivedEvents firstObject] + XCTAssertEqual([self adGetPropertyCount:event propertyName:@"start_time"], 0); - XCTAssertEqual([self adGetPropertyCount:[receivedEvents firstObject] + XCTAssertEqual([self adGetPropertyCount:event propertyName:@"stop_time"], 0); - XCTAssertEqual([self adGetPropertyCount:[receivedEvents firstObject] + XCTAssertEqual([self adGetPropertyCount:event propertyName:@"customized_property"], 0); } @@ -262,31 +269,33 @@ - (void)testNestedEvents { // the first event recorded is event2 // make sure it has customized_property, event_name, start_time and stop_time - XCTAssertTrue([[self adGetPropertyFromEvent:[receivedEvents firstObject] + NSArray* firstEvent = [receivedEvents firstObject]; + XCTAssertTrue([[self adGetPropertyFromEvent:firstEvent propertyName:@"event_name"] isEqualToString:@"testEvent2"]); - XCTAssertEqual([self adGetPropertyCount:[receivedEvents firstObject] + XCTAssertEqual([self adGetPropertyCount:firstEvent propertyName:@"event_name"], 1); - XCTAssertEqual([self adGetPropertyCount:[receivedEvents firstObject] + XCTAssertEqual([self adGetPropertyCount:firstEvent propertyName:@"customized_property"], 1); - XCTAssertEqual([self adGetPropertyCount:[receivedEvents firstObject] + XCTAssertEqual([self adGetPropertyCount:firstEvent propertyName:@"start_time"], 1); - XCTAssertEqual([self adGetPropertyCount:[receivedEvents firstObject] + XCTAssertEqual([self adGetPropertyCount:firstEvent propertyName:@"stop_time"], 1); // the second event recorded is event1 // make sure it has event_name, start_time and stop_time - XCTAssertTrue([[self adGetPropertyFromEvent:[receivedEvents objectAtIndex:1] + NSArray* secondEvent = [receivedEvents objectAtIndex:1]; + XCTAssertTrue([[self adGetPropertyFromEvent:secondEvent propertyName:@"event_name"] isEqualToString:@"testEvent1"]); - XCTAssertEqual([self adGetPropertyCount:[receivedEvents objectAtIndex:1] + XCTAssertEqual([self adGetPropertyCount:secondEvent propertyName:@"event_name"], 1); - XCTAssertEqual([self adGetPropertyCount:[receivedEvents objectAtIndex:1] + XCTAssertEqual([self adGetPropertyCount:secondEvent propertyName:@"start_time"], 1); - XCTAssertEqual([self adGetPropertyCount:[receivedEvents objectAtIndex:1] + XCTAssertEqual([self adGetPropertyCount:secondEvent propertyName:@"stop_time"], 1); } @@ -329,25 +338,26 @@ - (void)testNestedEventsWithAggregation { XCTAssertEqual([receivedEvents count], 1); // the aggregated event outputs the default properties like correlation_id, request_id, etc. - XCTAssertEqual([self adGetPropertyCount:[receivedEvents firstObject] + NSArray* event = [receivedEvents firstObject]; + XCTAssertEqual([self adGetPropertyCount:event propertyName:@"correlation_id"], 1); - XCTAssertEqual([self adGetPropertyCount:[receivedEvents firstObject] + XCTAssertEqual([self adGetPropertyCount:event propertyName:@"request_id"], 1); // it will also outputs some designated properties like response_time, but not for event_name, etc. - XCTAssertEqual([self adGetPropertyCount:[receivedEvents firstObject] + XCTAssertEqual([self adGetPropertyCount:event propertyName:@"response_time"], 1); - XCTAssertEqual([self adGetPropertyCount:[receivedEvents firstObject] + XCTAssertEqual([self adGetPropertyCount:event propertyName:@"event_name"], 0); - XCTAssertEqual([self adGetPropertyCount:[receivedEvents firstObject] + XCTAssertEqual([self adGetPropertyCount:event propertyName:@"start_time"], 0); - XCTAssertEqual([self adGetPropertyCount:[receivedEvents firstObject] + XCTAssertEqual([self adGetPropertyCount:event propertyName:@"stop_time"], 0); - XCTAssertEqual([self adGetPropertyCount:[receivedEvents firstObject] + XCTAssertEqual([self adGetPropertyCount:event propertyName:@"customized_property"], 0); } @@ -496,25 +506,27 @@ - (void)testComplexEventsWithAggregation { XCTAssertEqual([receivedEvents count], 1); // the aggregated event outputs the default properties like correlation_id, request_id, etc. - XCTAssertEqual([self adGetPropertyCount:[receivedEvents firstObject] + NSArray* event = [receivedEvents firstObject]; + + XCTAssertEqual([self adGetPropertyCount:event propertyName:@"correlation_id"], 1); - XCTAssertEqual([self adGetPropertyCount:[receivedEvents firstObject] + XCTAssertEqual([self adGetPropertyCount:event propertyName:@"request_id"], 1); // it will also outputs some designated properties like response_time, but not for event_name, etc. - XCTAssertEqual([self adGetPropertyCount:[receivedEvents firstObject] + XCTAssertEqual([self adGetPropertyCount:event propertyName:@"response_time"], 1); - XCTAssertEqual([self adGetPropertyCount:[receivedEvents firstObject] + XCTAssertEqual([self adGetPropertyCount:event propertyName:@"event_name"], 0); - XCTAssertEqual([self adGetPropertyCount:[receivedEvents firstObject] + XCTAssertEqual([self adGetPropertyCount:event propertyName:@"start_time"], 0); - XCTAssertEqual([self adGetPropertyCount:[receivedEvents firstObject] + XCTAssertEqual([self adGetPropertyCount:event propertyName:@"stop_time"], 0); - XCTAssertEqual([self adGetPropertyCount:[receivedEvents firstObject] + XCTAssertEqual([self adGetPropertyCount:event propertyName:@"customized_property"], 0); } diff --git a/ADAL/tests/XCTestCase+TestHelperMethods.h b/ADAL/tests/XCTestCase+TestHelperMethods.h index e0529c943..f9ecc9d49 100644 --- a/ADAL/tests/XCTestCase+TestHelperMethods.h +++ b/ADAL/tests/XCTestCase+TestHelperMethods.h @@ -213,12 +213,12 @@ typedef enum block:(void (^)(void)) block; //The method retrieves property value from a telemetry event by property name -- (NSString*)adGetPropertyFromEvent:(NSArray*)event - propertyName:(NSString*)propertyName; +- (NSString *)adGetPropertyFromEvent:(NSArray *)event + propertyName:(NSString *)propertyName; //The method counts the properties in a telemetry event matching propertyName -- (NSInteger)adGetPropertyCount:(NSArray*)event - propertyName:(NSString*)propertyName; +- (NSInteger)adGetPropertyCount:(NSArray *)event + propertyName:(NSString *)propertyName; @end //Fixes the issue with XCTAssertEqual not comparing int and long values diff --git a/ADAL/tests/XCTestCase+TestHelperMethods.m b/ADAL/tests/XCTestCase+TestHelperMethods.m index b77437c65..db388b849 100644 --- a/ADAL/tests/XCTestCase+TestHelperMethods.m +++ b/ADAL/tests/XCTestCase+TestHelperMethods.m @@ -508,8 +508,8 @@ - (ADTestURLResponse *)adResponseRefreshToken:(NSString *)oldRefreshToken } -- (NSString*)adGetPropertyFromEvent:(NSArray*)event - propertyName:(NSString*)propertyName +- (NSString *)adGetPropertyFromEvent:(NSArray *)event + propertyName:(NSString *)propertyName { for (ADTelemetryProperty* property in event) { @@ -521,8 +521,8 @@ - (NSString*)adGetPropertyFromEvent:(NSArray*)event return nil; } -- (NSInteger)adGetPropertyCount:(NSArray*)event - propertyName:(NSString*)propertyName +- (NSInteger)adGetPropertyCount:(NSArray *)event + propertyName:(NSString *)propertyName { NSInteger count = 0; for (ADTelemetryProperty* property in event) From b66ef31fe8f0dc7cb6c3b67115eb8d61c42dfb7e Mon Sep 17 00:00:00 2001 From: jasoncoolmax Date: Thu, 8 Dec 2016 14:54:09 -0800 Subject: [PATCH 85/92] revert a change for outputting http event properties --- ADAL/src/telemetry/ADTelemetryHttpEvent.m | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/ADAL/src/telemetry/ADTelemetryHttpEvent.m b/ADAL/src/telemetry/ADTelemetryHttpEvent.m index 03931fc7f..f8528d3c0 100644 --- a/ADAL/src/telemetry/ADTelemetryHttpEvent.m +++ b/ADAL/src/telemetry/ADTelemetryHttpEvent.m @@ -85,7 +85,15 @@ - (void)addAggregatedPropertiesToDictionary:(NSMutableDictionary*)eventToBeDispa } [eventToBeDispatched setObject:[NSString stringWithFormat:@"%d", httpEventCount] forKey:AD_TELEMETRY_HTTP_EVENT_COUNT]; - //TODO: output http event properties to aggregated event + NSArray* properties = [self getProperties]; + for (ADTelemetryProperty* property in properties) + { + if ([property.name isEqualToString:AD_TELEMETRY_OAUTH_ERROR_CODE] + ||[property.name isEqualToString:AD_TELEMETRY_HTTP_ERROR_DOMAIN]) + { + [eventToBeDispatched setObject:property.value forKey:property.name]; + } + } } - (NSString*)scrubTenantFromUrl:(NSString*)url From 9beadffeedeed7c03a99b9370d14d4276757f03e Mon Sep 17 00:00:00 2001 From: Ryan Pangrle Date: Mon, 12 Dec 2016 11:27:41 -0800 Subject: [PATCH 86/92] Mac and iOS Test App Consistency Changes - Name buttons "acquireToken" and "acquireTokenSilent" on both platforms - Added a profile chooser button on the acquire page of the iOS test app - Consistent result strings for clearing the cache on iOS and Mac - Removed IBOutlets from code no longer using XIBs - Fixed a minor bug in scrollview caused by not using autolayout through the entire view heirarchy. --- .../ADTestAppAcquireTokenWindowController.m | 9 ++- .../ADTestAppAcquireLayoutBuilder.m | 5 +- .../ADTestAppAcquireTokenViewController.m | 66 +++++++++++++------ .../MyTestiOSApp/ADTestAppDelegate.m | 8 ++- .../ADTestAppProfileViewController.m | 9 ++- .../ADTestAppSettingsViewController.m | 4 +- 6 files changed, 72 insertions(+), 29 deletions(-) diff --git a/Samples/MyTestMacOSApp/MyTestMacOSApp/ADTestAppAcquireTokenWindowController.m b/Samples/MyTestMacOSApp/MyTestMacOSApp/ADTestAppAcquireTokenWindowController.m index 58233d295..855321b5d 100644 --- a/Samples/MyTestMacOSApp/MyTestMacOSApp/ADTestAppAcquireTokenWindowController.m +++ b/Samples/MyTestMacOSApp/MyTestMacOSApp/ADTestAppAcquireTokenWindowController.m @@ -305,7 +305,14 @@ - (IBAction)clearCache:(id)sender { OSStatus status = [[ADTestAppCache sharedCache] deleteFromKeychain]; - [_resultView setString:[NSString stringWithFormat:@"Cache cleared (%d)", (int)status]]; + if (status == errSecSuccess || status == errSecItemNotFound) + { + _resultView.string = @"Successfully cleared cache."; + } + else + { + _resultView.string = [NSString stringWithFormat:@"Failed to clear cache, error = %d", (int)status]; + } } - (IBAction)clearCookies:(id)sender diff --git a/Samples/MyTestiOSApp/MyTestiOSApp/ADTestAppAcquireLayoutBuilder.m b/Samples/MyTestiOSApp/MyTestiOSApp/ADTestAppAcquireLayoutBuilder.m index 2cd6526d0..dfe58f0de 100644 --- a/Samples/MyTestiOSApp/MyTestiOSApp/ADTestAppAcquireLayoutBuilder.m +++ b/Samples/MyTestiOSApp/MyTestiOSApp/ADTestAppAcquireLayoutBuilder.m @@ -32,7 +32,7 @@ - (id)init _screenRect = UIScreen.mainScreen.bounds; _contentView = [[UIView alloc] initWithFrame:_screenRect]; - _contentView.autoresizingMask = UIViewAutoresizingFlexibleWidth; + _contentView.translatesAutoresizingMaskIntoConstraints = NO; _views = [NSMutableDictionary new]; _keys = [NSMutableArray new]; @@ -108,7 +108,7 @@ - (UIView*)contentView } NSMutableString* verticalConstraint = [NSMutableString new]; - [verticalConstraint appendString:@"V:|-24-"]; + [verticalConstraint appendString:@"V:|"]; for (int i = 0; i < _keys.count - 1; i++) { @@ -119,7 +119,6 @@ - (UIView*)contentView NSString* lastKey = _keys.lastObject; [verticalConstraint appendFormat:@"[%@(>=200)]-36-|", lastKey]; - //[verticalConstraint appendString:@"-|"]; NSArray* verticalConstraints = [NSLayoutConstraint constraintsWithVisualFormat:verticalConstraint options:0 metrics:NULL views:_views]; [_contentView addConstraints:verticalConstraints]; diff --git a/Samples/MyTestiOSApp/MyTestiOSApp/ADTestAppAcquireTokenViewController.m b/Samples/MyTestiOSApp/MyTestiOSApp/ADTestAppAcquireTokenViewController.m index a8f55cbc4..e5d397f01 100644 --- a/Samples/MyTestiOSApp/MyTestiOSApp/ADTestAppAcquireTokenViewController.m +++ b/Samples/MyTestiOSApp/MyTestiOSApp/ADTestAppAcquireTokenViewController.m @@ -25,6 +25,7 @@ #import "ADTestAppSettings.h" #import "ADKeychainTokenCache+Internal.h" #import "ADTestAppAcquireLayoutBuilder.h" +#import "ADTestAppProfileViewController.h" @interface ADTestAppAcquireTokenViewController () @@ -32,21 +33,23 @@ @interface ADTestAppAcquireTokenViewController () @implementation ADTestAppAcquireTokenViewController { - IBOutlet UIView* _acquireSettingsView; - IBOutlet UITextField* _userIdField; - IBOutlet UISegmentedControl* _userIdType; + UIView* _acquireSettingsView; + UITextField* _userIdField; + UISegmentedControl* _userIdType; UISegmentedControl* _promptBehavior; + + UIButton* _profileButton; - IBOutlet UISegmentedControl* _brokerEnabled; - IBOutlet UISegmentedControl* _webViewType; - IBOutlet UISegmentedControl* _fullScreen; - IBOutlet UISegmentedControl* _validateAuthority; + UISegmentedControl* _brokerEnabled; + UISegmentedControl* _webViewType; + UISegmentedControl* _fullScreen; + UISegmentedControl* _validateAuthority; - IBOutlet UITextView* _resultView; + UITextView* _resultView; - IBOutlet UIView* _authView; - IBOutlet UIWebView* _webView; + UIView* _authView; + UIWebView* _webView; NSLayoutConstraint* _bottomConstraint; NSLayoutConstraint* _bottomConstraint2; @@ -60,7 +63,6 @@ - (id)init { return nil; } - UITabBarItem* tabBarItem = [[UITabBarItem alloc] initWithTitle:@"Acquire" image:nil tag:0]; [self setTabBarItem:tabBarItem]; @@ -115,6 +117,12 @@ - (UIView*)createSettingsAndResultView _promptBehavior.selectedSegmentIndex = 0; [layout addControl:_promptBehavior title:@"prompt"]; + _profileButton = [UIButton buttonWithType:UIButtonTypeSystem]; + [_profileButton setTitle:ADTestAppSettings.currentProfileTitle forState:UIControlStateNormal]; + [_profileButton addTarget:self action:@selector(changeProfile:) forControlEvents:UIControlEventTouchUpInside]; + _profileButton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft; + [layout addControl:_profileButton title:@"profile"]; + _webViewType = [[UISegmentedControl alloc] initWithItems:@[@"Passed In", @"ADAL"]]; _webViewType.selectedSegmentIndex = 1; [layout addControl:_webViewType title:@"webView"]; @@ -151,7 +159,11 @@ - (UIView*)createSettingsAndResultView UIView* contentView = [layout contentView]; [scrollView addSubview:contentView]; - scrollView.contentSize = contentView.bounds.size; + + NSDictionary* views = @{ @"contentView" : contentView, @"scrollView" : scrollView }; + [scrollView addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:|[contentView]|" options:0 metrics:nil views:views]]; + [scrollView addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:|[contentView]|" options:0 metrics:nil views:views]]; + [scrollView addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"[contentView(==scrollView)]" options:0 metrics:nil views:views]]; return scrollView; } @@ -159,11 +171,11 @@ - (UIView*)createSettingsAndResultView - (UIView *)createAcquireButtonsView { UIButton* acquireButton = [UIButton buttonWithType:UIButtonTypeSystem]; - [acquireButton setTitle:@"acquire" forState:UIControlStateNormal]; + [acquireButton setTitle:@"acquireToken" forState:UIControlStateNormal]; [acquireButton addTarget:self action:@selector(acquireTokenInteractive:) forControlEvents:UIControlEventTouchUpInside]; UIButton* acquireSilentButton = [UIButton buttonWithType:UIButtonTypeSystem]; - [acquireSilentButton setTitle:@"acquireSilent" forState:UIControlStateNormal]; + [acquireSilentButton setTitle:@"acquireTokenSilent" forState:UIControlStateNormal]; [acquireSilentButton addTarget:self action:@selector(acquireTokenSilent:) forControlEvents:UIControlEventTouchUpInside]; UIView* acquireButtonsView = [self createTwoItemLayoutView:acquireButton item2:acquireSilentButton]; @@ -324,13 +336,17 @@ - (void)keyboardWillHide:(NSNotification *)note { - (void)viewWillAppear:(BOOL)animated { ADTestAppSettings* settings = [ADTestAppSettings settings]; - if (!_userIdEdited) + NSString* defaultUser = settings.defaultUser; + if (![NSString adIsStringNilOrBlank:defaultUser]) { - [_userIdField setText:settings.defaultUser]; + _userIdField.text = defaultUser; } - [_validateAuthority setSelectedSegmentIndex:settings.validateAuthority ? 0 : 1]; - [_brokerEnabled setSelectedSegmentIndex:settings.enableBroker ? 1 : 0]; + self.navigationController.navigationBarHidden = YES; + _validateAuthority.selectedSegmentIndex = settings.validateAuthority ? 0 : 1; + _brokerEnabled.selectedSegmentIndex = settings.enableBroker ? 1 : 0; + [_profileButton setTitle:[ADTestAppSettings currentProfileTitle] forState:UIControlStateNormal]; + } - (void)didReceiveMemoryWarning { @@ -570,7 +586,14 @@ - (IBAction)clearCache:(id)sender NSDictionary* query = [[ADKeychainTokenCache defaultKeychainCache] defaultKeychainQuery]; OSStatus status = SecItemDelete((CFDictionaryRef)query); - _resultView.text = [NSString stringWithFormat:@"Deleted keychain items (%d)", (int)status]; + if (status == errSecSuccess || status == errSecItemNotFound) + { + _resultView.text = @"Successfully cleared cache."; + } + else + { + _resultView.text = [NSString stringWithFormat:@"Failed to clear cache, error = %d", (int)status]; + } } - (IBAction)clearCookies:(id)sender @@ -585,4 +608,9 @@ - (IBAction)clearCookies:(id)sender _resultView.text = [NSString stringWithFormat:@"Cleared %lu cookies.", (unsigned long)cookies.count]; } +- (IBAction)changeProfile:(id)sender +{ + [self.navigationController pushViewController:[ADTestAppProfileViewController sharedProfileViewController] animated:YES]; +} + @end diff --git a/Samples/MyTestiOSApp/MyTestiOSApp/ADTestAppDelegate.m b/Samples/MyTestiOSApp/MyTestiOSApp/ADTestAppDelegate.m index 3b48572e8..b8845dabf 100644 --- a/Samples/MyTestiOSApp/MyTestiOSApp/ADTestAppDelegate.m +++ b/Samples/MyTestiOSApp/MyTestiOSApp/ADTestAppDelegate.m @@ -53,14 +53,18 @@ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:( _tabBar = [UITabBarController new]; + ADTestAppAcquireTokenViewController* tokenController = [ADTestAppAcquireTokenViewController new]; - [_tabBar addChildViewController:tokenController]; + UINavigationController* tokenNavController = [[UINavigationController alloc] initWithRootViewController:tokenController]; + tokenNavController.tabBarItem = tokenController.tabBarItem; + tokenNavController.navigationBar.hidden = YES; + [_tabBar addChildViewController:tokenNavController]; // Settings controller is contained in a navigation controller ADTestAppSettingsViewController* settingsController = [ADTestAppSettingsViewController new]; UINavigationController* navController = [[UINavigationController alloc] initWithRootViewController:settingsController]; - navController.navigationBar.hidden = NO; + navController.navigationBar.hidden = YES; navController.tabBarItem = [[UITabBarItem alloc] initWithTitle:@"Settings" image:[UIImage imageNamed:@"Settings"] tag:0]; diff --git a/Samples/MyTestiOSApp/MyTestiOSApp/ADTestAppProfileViewController.m b/Samples/MyTestiOSApp/MyTestiOSApp/ADTestAppProfileViewController.m index fe14100bc..9799bcffa 100644 --- a/Samples/MyTestiOSApp/MyTestiOSApp/ADTestAppProfileViewController.m +++ b/Samples/MyTestiOSApp/MyTestiOSApp/ADTestAppProfileViewController.m @@ -49,8 +49,6 @@ - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view. - - self.navigationController.navigationBarHidden = NO; self.navigationItem.hidesBackButton = NO; self.navigationItem.title = @"Select Application Profile"; @@ -71,6 +69,13 @@ - (void)viewDidLoad self.view = rootView; } +- (void)viewWillAppear:(BOOL)animated +{ + (void)animated; + + self.navigationController.navigationBarHidden = NO; +} + - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. diff --git a/Samples/MyTestiOSApp/MyTestiOSApp/ADTestAppSettingsViewController.m b/Samples/MyTestiOSApp/MyTestiOSApp/ADTestAppSettingsViewController.m index 2f8e342a3..017cd293a 100644 --- a/Samples/MyTestiOSApp/MyTestiOSApp/ADTestAppSettingsViewController.m +++ b/Samples/MyTestiOSApp/MyTestiOSApp/ADTestAppSettingsViewController.m @@ -88,8 +88,6 @@ - (id)init { return nil; } - - self.navigationController.navigationBarHidden = YES; self.tabBarItem = [[UITabBarItem alloc] initWithTitle:@"Settings" image:[UIImage imageNamed:@"Settings"] tag:0]; @@ -153,6 +151,8 @@ - (void)viewWillAppear:(BOOL)animated _wpjState = wpjLabel; + self.navigationController.navigationBarHidden = YES; + [_tableView reloadData]; } From aad873cf9b771ed602e005127780c84b21ea4ea9 Mon Sep 17 00:00:00 2001 From: Ryan Pangrle Date: Mon, 12 Dec 2016 13:59:12 -0800 Subject: [PATCH 87/92] Create 2.3.0 release branch, mark version as "2.3.0-rc1" --- ADAL/src/ADAL_Internal.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ADAL/src/ADAL_Internal.h b/ADAL/src/ADAL_Internal.h index c5dc4bfd6..b6d0294de 100644 --- a/ADAL/src/ADAL_Internal.h +++ b/ADAL/src/ADAL_Internal.h @@ -37,8 +37,8 @@ // Framework versions only support high and low for the double value, sadly. #define ADAL_VERSION_NUMBER INT_CONCAT(ADAL_VER_HIGH, ADAL_VER_LOW) -#define ADAL_VERSION_STRING STR(ADAL_VER_HIGH) "." STR(ADAL_VER_LOW) "." STR(ADAL_VER_PATCH) "-dev1" -#define ADAL_VERSION_NSSTRING @"" STR(ADAL_VER_HIGH) "." STR(ADAL_VER_LOW) "." STR(ADAL_VER_PATCH) "-dev1" +#define ADAL_VERSION_STRING STR(ADAL_VER_HIGH) "." STR(ADAL_VER_LOW) "." STR(ADAL_VER_PATCH) "-rc1" +#define ADAL_VERSION_NSSTRING @"" STR(ADAL_VER_HIGH) "." STR(ADAL_VER_LOW) "." STR(ADAL_VER_PATCH) "-rc1" #define ADAL_VERSION_HELPER(high, low, patch) adalVersion_ ## high ## _ ## low ## _ ## patch #define ADAL_VERSION_(high, low, patch) ADAL_VERSION_HELPER(high, low, patch) From 59387399b8422b07f885bc9b4ef4609a983d6c05 Mon Sep 17 00:00:00 2001 From: Ryan Pangrle Date: Tue, 13 Dec 2016 17:18:28 -0800 Subject: [PATCH 88/92] Add missing nullable markers in ADTokenCacheItem --- ADAL/src/public/ADTokenCacheItem.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ADAL/src/public/ADTokenCacheItem.h b/ADAL/src/public/ADTokenCacheItem.h index 633474ac0..e4f7204e1 100644 --- a/ADAL/src/public/ADTokenCacheItem.h +++ b/ADAL/src/public/ADTokenCacheItem.h @@ -88,12 +88,12 @@ NS_ASSUME_NONNULL_BEGIN @"protocolCode":error code returned by the server for the rejected RT @"errorDetails":error details of the rejected RT */ -- (NSDictionary*)tombstone; +- (nullable NSDictionary*)tombstone; /*! Obtains a key to be used for the internal cache from the full cache item. @param error: if a key cannot be extracted, the method will return nil and if this parameter is not nil, it will be filled with the appropriate error information.*/ -- (ADTokenCacheKey*) extractKey:(ADAuthenticationError * _Nullable __autoreleasing * _Nullable)error; +- (nullable ADTokenCacheKey*)extractKey:(ADAuthenticationError * _Nullable __autoreleasing * _Nullable)error; /*! Compares expiresOn with the current time. If expiresOn is not nil, the function returns the comparison of expires on and the current time. If expiresOn is nil, the function returns NO, From 57e99a4d97d2b004c96b343a879ccb7216e81e98 Mon Sep 17 00:00:00 2001 From: Ryan Pangrle Date: Thu, 5 Jan 2017 14:38:29 -0800 Subject: [PATCH 89/92] Make ADTelemetry.h private again There's enough design talk on this feature still that we need to spend more time staging it, and can't hold up the larger 2.3.0 release for it. --- ADAL/ADAL.xcodeproj/project.pbxproj | 10 ++-------- ADAL/src/public/ADAL.h | 1 - ADAL/src/{public => telemetry}/ADTelemetry.h | 0 3 files changed, 2 insertions(+), 9 deletions(-) rename ADAL/src/{public => telemetry}/ADTelemetry.h (100%) diff --git a/ADAL/ADAL.xcodeproj/project.pbxproj b/ADAL/ADAL.xcodeproj/project.pbxproj index 7ab64df9f..2224ab590 100755 --- a/ADAL/ADAL.xcodeproj/project.pbxproj +++ b/ADAL/ADAL.xcodeproj/project.pbxproj @@ -66,9 +66,6 @@ 605C16821D8FD0AC0097DBA0 /* ADTelemetryEventStrings.m in Sources */ = {isa = PBXBuildFile; fileRef = 605C16801D8FD0AC0097DBA0 /* ADTelemetryEventStrings.m */; }; 605C16831D8FD1AC0097DBA0 /* ADTelemetryEventStrings.m in Sources */ = {isa = PBXBuildFile; fileRef = 605C16801D8FD0AC0097DBA0 /* ADTelemetryEventStrings.m */; }; 6071B5E41C14C0B0006F6CC2 /* ADTestURLConnection.m in Sources */ = {isa = PBXBuildFile; fileRef = 6071B5E31C14C0B0006F6CC2 /* ADTestURLConnection.m */; }; - 6085CBF01DF764EB004BBF2A /* ADTelemetry.h in Copy Files */ = {isa = PBXBuildFile; fileRef = 6004019F1D340B760020EAAB /* ADTelemetry.h */; }; - 6085CBF31DF76982004BBF2A /* ADTelemetry.h in Headers */ = {isa = PBXBuildFile; fileRef = 6004019F1D340B760020EAAB /* ADTelemetry.h */; settings = {ATTRIBUTES = (Public, ); }; }; - 6085CBF41DF76C3C004BBF2A /* ADTelemetry.h in Headers */ = {isa = PBXBuildFile; fileRef = 6004019F1D340B760020EAAB /* ADTelemetry.h */; settings = {ATTRIBUTES = (Public, ); }; }; 60C351BA1DA0D588006C8435 /* ADAL.m in Sources */ = {isa = PBXBuildFile; fileRef = 60C351B91DA0D588006C8435 /* ADAL.m */; }; 60D2F3FF1D524F7A008725D9 /* ADRequestParameters.h in Headers */ = {isa = PBXBuildFile; fileRef = 60D2F3FE1D524F7A008725D9 /* ADRequestParameters.h */; }; 60D2F4021D531F16008725D9 /* ADRequestParameters.m in Sources */ = {isa = PBXBuildFile; fileRef = 60D2F4001D531F16008725D9 /* ADRequestParameters.m */; }; @@ -370,7 +367,6 @@ dstPath = include/ADAL; dstSubfolderSpec = 16; files = ( - 6085CBF01DF764EB004BBF2A /* ADTelemetry.h in Copy Files */, D69A720C1D4FF65200E91DB3 /* ADAL.h in Copy Files */, D69A720D1D4FF65200E91DB3 /* ADAuthenticationContext.h in Copy Files */, D69A720E1D4FF65200E91DB3 /* ADAuthenticationError.h in Copy Files */, @@ -402,7 +398,6 @@ 04AB6D531D9D619B007E9A83 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = ""; }; 04AB6D551D9D619B007E9A83 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 04AB6D5A1D9D61CA007E9A83 /* UnitTestHostApp.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = UnitTestHostApp.entitlements; sourceTree = ""; }; - 6004019F1D340B760020EAAB /* ADTelemetry.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ADTelemetry.h; sourceTree = ""; }; 600401A31D3421480020EAAB /* ADTelemetry.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ADTelemetry.m; sourceTree = ""; }; 600401A61D3426250020EAAB /* ADTelemetry+Internal.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "ADTelemetry+Internal.h"; sourceTree = ""; }; 600401A81D3428770020EAAB /* ADTelemetryDefaultEvent.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ADTelemetryDefaultEvent.h; sourceTree = ""; }; @@ -618,6 +613,7 @@ D680402F1D21C4EB007A61AC /* ADWorkPlaceJoinUtil.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ADWorkPlaceJoinUtil.m; sourceTree = ""; }; D68040311D22F686007A61AC /* ADWebAuthResponse.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ADWebAuthResponse.h; sourceTree = ""; }; D68040321D22F686007A61AC /* ADWebAuthResponse.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ADWebAuthResponse.m; sourceTree = ""; }; + D6B1ADF11E1F012900835CBD /* ADTelemetry.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ADTelemetry.h; sourceTree = ""; }; D6D8A83E1D4FD14100D20DE6 /* ADKeychainUtil.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ADKeychainUtil.h; sourceTree = ""; }; D6D8A83F1D4FD14E00D20DE6 /* ADKeychainUtil.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ADKeychainUtil.m; sourceTree = ""; }; D6E43A681B04026D000F5BE2 /* ADAuthenticationContext+Internal.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "ADAuthenticationContext+Internal.h"; sourceTree = ""; }; @@ -731,6 +727,7 @@ 600401A21D3420C10020EAAB /* telemetry */ = { isa = PBXGroup; children = ( + D6B1ADF11E1F012900835CBD /* ADTelemetry.h */, 600401A61D3426250020EAAB /* ADTelemetry+Internal.h */, 600401A31D3421480020EAAB /* ADTelemetry.m */, 600401C11D39A18E0020EAAB /* ADDefaultDispatcher.h */, @@ -1100,7 +1097,6 @@ 9453C3BD1C583AE6006B9E79 /* ADErrorCodes.h */, 9453C3BE1C583AE6006B9E79 /* ADLogger.h */, 9453C3BF1C583AE6006B9E79 /* ADTokenCacheItem.h */, - 6004019F1D340B760020EAAB /* ADTelemetry.h */, 9453C3C01C583AE6006B9E79 /* ADUserIdentifier.h */, 9453C3C11C583AE6006B9E79 /* ADUserInformation.h */, 9453C3C21C583AE6006B9E79 /* ADWebAuthController.h */, @@ -1258,7 +1254,6 @@ 9453C3DA1C583E8B006B9E79 /* ADAuthenticationSettings.h in Headers */, 9453C3D81C583E8B006B9E79 /* ADAuthenticationParameters.h in Headers */, 9453C3DD1C583E8B006B9E79 /* ADTokenCacheItem.h in Headers */, - 6085CBF31DF76982004BBF2A /* ADTelemetry.h in Headers */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -1269,7 +1264,6 @@ 9453C4461C58647E006B9E79 /* NSURL+ADExtensions.h in Headers */, 9453C40B1C586456006B9E79 /* ADAuthenticationParameters+Internal.h in Headers */, 94DD18D31C5AC8DE00F80C62 /* ADAuthenticationResult.h in Headers */, - 6085CBF41DF76C3C004BBF2A /* ADTelemetry.h in Headers */, D6F0951A1CDC2BC300D28FC2 /* ADWebAuthRequest.h in Headers */, 9453C40E1C586456006B9E79 /* ADAuthenticationResult+Internal.h in Headers */, 9453C4481C58647E006B9E79 /* NSUUID+ADExtensions.h in Headers */, diff --git a/ADAL/src/public/ADAL.h b/ADAL/src/public/ADAL.h index d8ffc3825..0d736826a 100644 --- a/ADAL/src/public/ADAL.h +++ b/ADAL/src/public/ADAL.h @@ -58,7 +58,6 @@ typedef void(^ADAuthenticationCallback)(ADAuthenticationResult* result); #import #import #import -#import #if TARGET_OS_IPHONE #import diff --git a/ADAL/src/public/ADTelemetry.h b/ADAL/src/telemetry/ADTelemetry.h similarity index 100% rename from ADAL/src/public/ADTelemetry.h rename to ADAL/src/telemetry/ADTelemetry.h From d18c0701006f88c26118cbcfba7929601b292864 Mon Sep 17 00:00:00 2001 From: Ryan Pangrle Date: Mon, 9 Jan 2017 13:37:03 -0800 Subject: [PATCH 90/92] Add back if check on RedirectUri error In the broker refactor this if check was removed, however we didn't error out, so the code path still worked, we just got an extraneous (and erroneous) error message. This condition is checked very early on in the request so we fail reliably early, instead of late, which is why this wasn't caught, nor caused any run time issues. The erroneous log message though is obnooxious enough that it's worth fixing now. --- ADAL/src/request/ADAuthenticationRequest+Broker.m | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/ADAL/src/request/ADAuthenticationRequest+Broker.m b/ADAL/src/request/ADAuthenticationRequest+Broker.m index 03ae43a4e..52190943d 100644 --- a/ADAL/src/request/ADAuthenticationRequest+Broker.m +++ b/ADAL/src/request/ADAuthenticationRequest+Broker.m @@ -267,7 +267,11 @@ - (NSURL *)composeBrokerRequest:(ADAuthenticationError* __autoreleasing *)error ARG_RETURN_IF_NIL(_requestParams.clientId, _requestParams.correlationId); ARG_RETURN_IF_NIL(_requestParams.correlationId, _requestParams.correlationId); - AUTH_ERROR(AD_ERROR_TOKENBROKER_INVALID_REDIRECT_URI, ADRedirectUriInvalidError, _requestParams.correlationId); + if(![ADAuthenticationRequest validBrokerRedirectUri:_redirectUri]) + { + AUTH_ERROR(AD_ERROR_TOKENBROKER_INVALID_REDIRECT_URI, ADRedirectUriInvalidError, _requestParams.correlationId); + return nil; + } AD_LOG_INFO(@"Invoking broker for authentication", _requestParams.correlationId, nil); #if TARGET_OS_IPHONE // Broker Message Encryption From 706a775e75722f5cf9f1fb85011fcb62af4a7352 Mon Sep 17 00:00:00 2001 From: Ryan Pangrle Date: Mon, 9 Jan 2017 15:03:39 -0800 Subject: [PATCH 91/92] Fix copy & paste error --- ADAL/src/request/ADAuthenticationRequest+Broker.m | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ADAL/src/request/ADAuthenticationRequest+Broker.m b/ADAL/src/request/ADAuthenticationRequest+Broker.m index 52190943d..ecbcfd7c3 100644 --- a/ADAL/src/request/ADAuthenticationRequest+Broker.m +++ b/ADAL/src/request/ADAuthenticationRequest+Broker.m @@ -267,7 +267,7 @@ - (NSURL *)composeBrokerRequest:(ADAuthenticationError* __autoreleasing *)error ARG_RETURN_IF_NIL(_requestParams.clientId, _requestParams.correlationId); ARG_RETURN_IF_NIL(_requestParams.correlationId, _requestParams.correlationId); - if(![ADAuthenticationRequest validBrokerRedirectUri:_redirectUri]) + if(![ADAuthenticationRequest validBrokerRedirectUri:_requestParams.redirectUri]) { AUTH_ERROR(AD_ERROR_TOKENBROKER_INVALID_REDIRECT_URI, ADRedirectUriInvalidError, _requestParams.correlationId); return nil; From f214ef90993fe8b3abb3da131425224f2147241c Mon Sep 17 00:00:00 2001 From: Ryan Pangrle Date: Tue, 17 Jan 2017 18:17:39 -0800 Subject: [PATCH 92/92] Changelog and remove "-rc1" for 2.3.0 --- ADAL.podspec | 4 ++-- ADAL/src/ADAL_Internal.h | 4 ++-- changelog.txt | 10 ++++++++++ 3 files changed, 14 insertions(+), 4 deletions(-) diff --git a/ADAL.podspec b/ADAL.podspec index 23646bf64..03e0aa679 100644 --- a/ADAL.podspec +++ b/ADAL.podspec @@ -1,11 +1,11 @@ Pod::Spec.new do |s| s.name = "ADAL" s.module_name = "ADAL" - s.version = "2.2.7" + s.version = "2.3.0" s.summary = "The ADAL SDK for iOS gives you the ability to add Azure Identity authentication to your application" s.description = <<-DESC - The Azure Identity Library for Objective C. This library gives you the ability to add support for Work Accounts to your iOS and OS X applications with just a few lines of additional code. This SDK gives your application the full functionality of Microsoft Azure AD, including industry standard protocol support for OAuth2, Web API integration with user level consent, and two factor authentication support. + The Azure Identity Library for Objective C. This library gives you the ability to add support for Work Accounts to your iOS and macOS applications with just a few lines of additional code. This SDK gives your application the full functionality of Microsoft Azure AD, including industry standard protocol support for OAuth2, Web API integration with user level consent, and two factor authentication support. DESC s.homepage = "https://github.com/AzureAD/azure-activedirectory-library-for-objc" s.license = { diff --git a/ADAL/src/ADAL_Internal.h b/ADAL/src/ADAL_Internal.h index b6d0294de..986f41ab7 100644 --- a/ADAL/src/ADAL_Internal.h +++ b/ADAL/src/ADAL_Internal.h @@ -37,8 +37,8 @@ // Framework versions only support high and low for the double value, sadly. #define ADAL_VERSION_NUMBER INT_CONCAT(ADAL_VER_HIGH, ADAL_VER_LOW) -#define ADAL_VERSION_STRING STR(ADAL_VER_HIGH) "." STR(ADAL_VER_LOW) "." STR(ADAL_VER_PATCH) "-rc1" -#define ADAL_VERSION_NSSTRING @"" STR(ADAL_VER_HIGH) "." STR(ADAL_VER_LOW) "." STR(ADAL_VER_PATCH) "-rc1" +#define ADAL_VERSION_STRING STR(ADAL_VER_HIGH) "." STR(ADAL_VER_LOW) "." STR(ADAL_VER_PATCH) +#define ADAL_VERSION_NSSTRING @"" STR(ADAL_VER_HIGH) "." STR(ADAL_VER_LOW) "." STR(ADAL_VER_PATCH) #define ADAL_VERSION_HELPER(high, low, patch) adalVersion_ ## high ## _ ## low ## _ ## patch #define ADAL_VERSION_(high, low, patch) ADAL_VERSION_HELPER(high, low, patch) diff --git a/changelog.txt b/changelog.txt index 88140bca2..6f18743af 100644 --- a/changelog.txt +++ b/changelog.txt @@ -1,3 +1,13 @@ +Version 2.3.0 (01.17.2016) +------------- +* Added the extendedLifetimeEnabled property on ADAuthenticationContext to allow ADAL to return tokens in the extended expiration window during an AAD service outage. (#643) +* Fixed crashes caused by the NTLM dialog being launched on a background thread on iOS (#849) and Mac (#801) +* (iOS) Replaced deprecated UIAlertView usage with UIAlertController (#849) +* (Mac) Added the +[ADTokenCache defaultTokenCache] convenience method for accessing the default ADAL cache. (#808) +* (Mac) ADAL on macOS no longer errors out immediately when receiving a conditional access request. Erroring out immediately was preventing ADAL from being able to continue further with authentication methods that might still work. (#804) +* Added error checking on passed in extraQueryParameters to prevent crashes when invalid query parameters are passed in. (#819, #822) + + Version 2.2.7 (10.19.2016) ------------- * Improved the robustness of the broker message parser (#779)