From 9ab073022aaab0e8916ddc40046da749be650e7c Mon Sep 17 00:00:00 2001 From: Syed Yusuf Date: Tue, 3 Sep 2019 14:47:31 +0530 Subject: [PATCH 01/16] iOS13 Changes for ASN.1 decoding null pointer bit string issue --- .../services/security/ASN1CertificateParse/MASASN1Decoder.m | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/MASFoundation/Classes/_private_/services/security/ASN1CertificateParse/MASASN1Decoder.m b/MASFoundation/Classes/_private_/services/security/ASN1CertificateParse/MASASN1Decoder.m index 6cf1c60d..9a5c3134 100644 --- a/MASFoundation/Classes/_private_/services/security/ASN1CertificateParse/MASASN1Decoder.m +++ b/MASFoundation/Classes/_private_/services/security/ASN1CertificateParse/MASASN1Decoder.m @@ -194,7 +194,11 @@ - (NSMutableArray *)parseWithRange:(NSRange)range } case MASASN1TagBitStr: { - NSData *dataWithoutUnusedBit = [subContentData subdataWithRange:NSMakeRange(1, [subContentData length]-1)]; + NSData *dataWithoutUnusedBit = [NSData data]; + if (subContentData && [subContentData length]) { + + dataWithoutUnusedBit = [subContentData subdataWithRange:NSMakeRange(1, [subContentData length]-1)]; + } thisObject.value = dataWithoutUnusedBit; break; } From e43509bab6713ae35fb8ade69abf3ccaa6525849 Mon Sep 17 00:00:00 2001 From: Robert Weber Date: Fri, 13 Sep 2019 11:37:22 -0700 Subject: [PATCH 02/16] Removing Mac Catalyst Support for Final build --- MASFoundation.xcodeproj/project.pbxproj | 3 +++ 1 file changed, 3 insertions(+) diff --git a/MASFoundation.xcodeproj/project.pbxproj b/MASFoundation.xcodeproj/project.pbxproj index 29f7e848..4a12ed50 100644 --- a/MASFoundation.xcodeproj/project.pbxproj +++ b/MASFoundation.xcodeproj/project.pbxproj @@ -1842,6 +1842,7 @@ developmentRegion = English; hasScannedForEncodings = 0; knownRegions = ( + English, en, ); mainGroup = 1059D3661B61AA3700223267; @@ -2228,6 +2229,7 @@ PRODUCT_BUNDLE_IDENTIFIER = "com.ca.$(PRODUCT_NAME:rfc1034identifier)"; PRODUCT_NAME = "$(TARGET_NAME)"; SKIP_INSTALL = YES; + SUPPORTS_MACCATALYST = NO; SWIFT_OBJC_BRIDGING_HEADER = ""; }; name = Debug; @@ -2273,6 +2275,7 @@ PRODUCT_BUNDLE_IDENTIFIER = "com.ca.$(PRODUCT_NAME:rfc1034identifier)"; PRODUCT_NAME = "$(TARGET_NAME)"; SKIP_INSTALL = YES; + SUPPORTS_MACCATALYST = NO; SWIFT_OBJC_BRIDGING_HEADER = ""; }; name = Release; From f93934b5705d77504c4c8f8cc1ecd18d246b28cd Mon Sep 17 00:00:00 2001 From: Robert Weber Date: Fri, 13 Sep 2019 11:59:24 -0700 Subject: [PATCH 03/16] Removing Mac Catalyst Support for Final Build --- MASFoundation.xcodeproj/project.pbxproj | 2 ++ 1 file changed, 2 insertions(+) diff --git a/MASFoundation.xcodeproj/project.pbxproj b/MASFoundation.xcodeproj/project.pbxproj index 4a12ed50..ab36eaa7 100644 --- a/MASFoundation.xcodeproj/project.pbxproj +++ b/MASFoundation.xcodeproj/project.pbxproj @@ -2328,6 +2328,7 @@ ENABLE_BITCODE = YES; MACH_O_TYPE = staticlib; PRODUCT_NAME = "$(TARGET_NAME)"; + SUPPORTS_MACCATALYST = NO; }; name = Debug; }; @@ -2339,6 +2340,7 @@ ENABLE_BITCODE = YES; MACH_O_TYPE = staticlib; PRODUCT_NAME = "$(TARGET_NAME)"; + SUPPORTS_MACCATALYST = NO; }; name = Release; }; From 31c4231be4b808670d89307f97faeaf5ca592779 Mon Sep 17 00:00:00 2001 From: Robert Weber Date: Tue, 17 Sep 2019 10:32:09 -0700 Subject: [PATCH 04/16] Fixing test targets for iOS 13 --- MASFoundation.xcodeproj/project.pbxproj | 2 ++ 1 file changed, 2 insertions(+) diff --git a/MASFoundation.xcodeproj/project.pbxproj b/MASFoundation.xcodeproj/project.pbxproj index ab36eaa7..112beb2e 100644 --- a/MASFoundation.xcodeproj/project.pbxproj +++ b/MASFoundation.xcodeproj/project.pbxproj @@ -2299,6 +2299,7 @@ LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = "com.ca.$(PRODUCT_NAME:rfc1034identifier)"; PRODUCT_NAME = "$(TARGET_NAME)"; + SUPPORTS_MACCATALYST = NO; }; name = Debug; }; @@ -2317,6 +2318,7 @@ LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = "com.ca.$(PRODUCT_NAME:rfc1034identifier)"; PRODUCT_NAME = "$(TARGET_NAME)"; + SUPPORTS_MACCATALYST = NO; }; name = Release; }; From 8682e502a0cae5af682385ec441a27b5e4c0abcf Mon Sep 17 00:00:00 2001 From: Syed Yusuf Date: Wed, 18 Sep 2019 13:13:19 +0530 Subject: [PATCH 05/16] Updated changelog for 1.9.20 --- CHANGELOG.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index e0b51af1..0db62391 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,8 @@ +# Version 1.9.20 + +### Bug fixes +- ASN.1 Bit String Null Range Handled. [US604961] + # Version 1.9.10 ### Bug fixes From 1e6d30917912c1ea1c81f3e412805347bafc75e3 Mon Sep 17 00:00:00 2001 From: Sander Saelmans Date: Tue, 8 Dec 2020 12:43:34 +0100 Subject: [PATCH 06/16] Added the option for a user to configure what browser they want to use for browser based authentication --- MASFoundation.xcodeproj/project.pbxproj | 42 +++++++++- .../xcshareddata/IDEWorkspaceChecks.plist | 8 ++ MASFoundation/Classes/MAS.h | 8 ++ MASFoundation/Classes/MAS.m | 6 ++ MASFoundation/Classes/MASConstants.h | 16 +++- .../MASSafariBrowserBasedAuthentication.h | 20 +++++ .../MASSafariBrowserBasedAuthentication.m | 70 +++++++++++++++++ ...ASTypedBrowserBasedAuthenticationFactory.h | 29 +++++++ ...ASTypedBrowserBasedAuthenticationFactory.m | 29 +++++++ ...TypedBrowserBasedAuthenticationInterface.h | 31 ++++++++ .../MASWebSessionBrowserBasedAuthentication.h | 21 +++++ .../MASWebSessionBrowserBasedAuthentication.m | 77 +++++++++++++++++++ .../services/model/MASModelService.h | 16 ++++ .../services/model/MASModelService.m | 14 ++++ .../Classes/models/MASAuthorizationResponse.h | 16 +++- .../Classes/models/MASAuthorizationResponse.m | 6 ++ .../models/MASBrowserBasedAuthentication.m | 66 +++++----------- 17 files changed, 423 insertions(+), 52 deletions(-) create mode 100644 MASFoundation.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist create mode 100644 MASFoundation/Classes/_private_/models/MASSafariBrowserBasedAuthentication.h create mode 100644 MASFoundation/Classes/_private_/models/MASSafariBrowserBasedAuthentication.m create mode 100644 MASFoundation/Classes/_private_/models/MASTypedBrowserBasedAuthenticationFactory.h create mode 100644 MASFoundation/Classes/_private_/models/MASTypedBrowserBasedAuthenticationFactory.m create mode 100644 MASFoundation/Classes/_private_/models/MASTypedBrowserBasedAuthenticationInterface.h create mode 100644 MASFoundation/Classes/_private_/models/MASWebSessionBrowserBasedAuthentication.h create mode 100644 MASFoundation/Classes/_private_/models/MASWebSessionBrowserBasedAuthentication.m diff --git a/MASFoundation.xcodeproj/project.pbxproj b/MASFoundation.xcodeproj/project.pbxproj index c4357fe1..3d80863c 100644 --- a/MASFoundation.xcodeproj/project.pbxproj +++ b/MASFoundation.xcodeproj/project.pbxproj @@ -147,7 +147,6 @@ A898EF6B2182D3DF00CF291B /* NSURLSession+MASPrivate.h in Headers */ = {isa = PBXBuildFile; fileRef = A898EF692182D3DF00CF291B /* NSURLSession+MASPrivate.h */; }; A898EF6C2182D3DF00CF291B /* NSURLSession+MASPrivate.m in Sources */ = {isa = PBXBuildFile; fileRef = A898EF6A2182D3DF00CF291B /* NSURLSession+MASPrivate.m */; }; C81CC3CC1FC2EA190058718E /* MASBrowserBasedAuthentication.h in Headers */ = {isa = PBXBuildFile; fileRef = C81CC3CA1FC2EA190058718E /* MASBrowserBasedAuthentication.h */; }; - C81CC3CD1FC2EA190058718E /* MASBrowserBasedAuthentication.m in Sources */ = {isa = PBXBuildFile; fileRef = C81CC3CB1FC2EA190058718E /* MASBrowserBasedAuthentication.m */; }; C81CC3D01FC2EFBB0058718E /* UIAlertController+MAS.h in Headers */ = {isa = PBXBuildFile; fileRef = C81CC3CE1FC2EFBB0058718E /* UIAlertController+MAS.h */; }; C81CC3D11FC2EFBB0058718E /* UIAlertController+MAS.m in Sources */ = {isa = PBXBuildFile; fileRef = C81CC3CF1FC2EFBB0058718E /* UIAlertController+MAS.m */; }; C858D6B52398FC5400963763 /* MASDataTask+MASPrivate.h in Headers */ = {isa = PBXBuildFile; fileRef = C858D6B32398FC5400963763 /* MASDataTask+MASPrivate.h */; }; @@ -327,6 +326,14 @@ CBD25B151E7A0A9200DFB47F /* MF_Base64Additions.m in Sources */ = {isa = PBXBuildFile; fileRef = CBD25B131E7A0A9200DFB47F /* MF_Base64Additions.m */; }; CBFA70F41F1ED5D6006D025D /* MASSecurityPolicy.h in Headers */ = {isa = PBXBuildFile; fileRef = CBFA70F21F1ED5D6006D025D /* MASSecurityPolicy.h */; }; CBFA70F51F1ED5D6006D025D /* MASSecurityPolicy.m in Sources */ = {isa = PBXBuildFile; fileRef = CBFA70F31F1ED5D6006D025D /* MASSecurityPolicy.m */; }; + E0BA784D257E7FEF0003A9B8 /* MASSafariBrowserBasedAuthentication.m in Sources */ = {isa = PBXBuildFile; fileRef = E0BA784B257E7FEF0003A9B8 /* MASSafariBrowserBasedAuthentication.m */; }; + E0BA7861257EB8C00003A9B8 /* MASWebSessionBrowserBasedAuthentication.m in Sources */ = {isa = PBXBuildFile; fileRef = E0BA785F257EB8C00003A9B8 /* MASWebSessionBrowserBasedAuthentication.m */; }; + E0BA7867257F62570003A9B8 /* MASSafariBrowserBasedAuthentication.h in Headers */ = {isa = PBXBuildFile; fileRef = E0BA784A257E7FEF0003A9B8 /* MASSafariBrowserBasedAuthentication.h */; }; + E0BA7869257F62590003A9B8 /* MASWebSessionBrowserBasedAuthentication.h in Headers */ = {isa = PBXBuildFile; fileRef = E0BA785E257EB8C00003A9B8 /* MASWebSessionBrowserBasedAuthentication.h */; }; + E0BA786D257F62820003A9B8 /* MASTypedBrowserBasedAuthenticationInterface.h in Headers */ = {isa = PBXBuildFile; fileRef = E0BA7849257E7FA60003A9B8 /* MASTypedBrowserBasedAuthenticationInterface.h */; }; + E0BA7877257F708A0003A9B8 /* MASBrowserBasedAuthentication.m in Sources */ = {isa = PBXBuildFile; fileRef = C81CC3CB1FC2EA190058718E /* MASBrowserBasedAuthentication.m */; }; + E0BA788A257F78820003A9B8 /* MASTypedBrowserBasedAuthenticationFactory.h in Headers */ = {isa = PBXBuildFile; fileRef = E0BA7888257F78820003A9B8 /* MASTypedBrowserBasedAuthenticationFactory.h */; }; + E0BA788B257F78820003A9B8 /* MASTypedBrowserBasedAuthenticationFactory.m in Sources */ = {isa = PBXBuildFile; fileRef = E0BA7889257F78820003A9B8 /* MASTypedBrowserBasedAuthenticationFactory.m */; }; E3662A3723DEE503007A76A1 /* MASIHTTPRequestOperation.h in Headers */ = {isa = PBXBuildFile; fileRef = E3662A3523DEE502007A76A1 /* MASIHTTPRequestOperation.h */; }; E3662A3823DEE503007A76A1 /* MASIHTTPRequestOperation.m in Sources */ = {isa = PBXBuildFile; fileRef = E3662A3623DEE502007A76A1 /* MASIHTTPRequestOperation.m */; }; E3662A3B23DEE52C007A76A1 /* MASIURLResponseSerialization.m in Sources */ = {isa = PBXBuildFile; fileRef = E3662A3923DEE52B007A76A1 /* MASIURLResponseSerialization.m */; }; @@ -687,6 +694,13 @@ CBD25B131E7A0A9200DFB47F /* MF_Base64Additions.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MF_Base64Additions.m; sourceTree = ""; }; CBFA70F21F1ED5D6006D025D /* MASSecurityPolicy.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MASSecurityPolicy.h; sourceTree = ""; }; CBFA70F31F1ED5D6006D025D /* MASSecurityPolicy.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MASSecurityPolicy.m; sourceTree = ""; }; + E0BA7849257E7FA60003A9B8 /* MASTypedBrowserBasedAuthenticationInterface.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MASTypedBrowserBasedAuthenticationInterface.h; sourceTree = ""; }; + E0BA784A257E7FEF0003A9B8 /* MASSafariBrowserBasedAuthentication.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MASSafariBrowserBasedAuthentication.h; sourceTree = ""; }; + E0BA784B257E7FEF0003A9B8 /* MASSafariBrowserBasedAuthentication.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = MASSafariBrowserBasedAuthentication.m; sourceTree = ""; }; + E0BA785E257EB8C00003A9B8 /* MASWebSessionBrowserBasedAuthentication.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MASWebSessionBrowserBasedAuthentication.h; sourceTree = ""; }; + E0BA785F257EB8C00003A9B8 /* MASWebSessionBrowserBasedAuthentication.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = MASWebSessionBrowserBasedAuthentication.m; sourceTree = ""; }; + E0BA7888257F78820003A9B8 /* MASTypedBrowserBasedAuthenticationFactory.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MASTypedBrowserBasedAuthenticationFactory.h; sourceTree = ""; }; + E0BA7889257F78820003A9B8 /* MASTypedBrowserBasedAuthenticationFactory.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = MASTypedBrowserBasedAuthenticationFactory.m; sourceTree = ""; }; E3662A3523DEE502007A76A1 /* MASIHTTPRequestOperation.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MASIHTTPRequestOperation.h; sourceTree = ""; }; E3662A3623DEE502007A76A1 /* MASIHTTPRequestOperation.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MASIHTTPRequestOperation.m; sourceTree = ""; }; E3662A3923DEE52B007A76A1 /* MASIURLResponseSerialization.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MASIURLResponseSerialization.m; sourceTree = ""; }; @@ -1122,6 +1136,13 @@ A898EF662182D35700CF291B /* MASJWKSet.m */, CBA3EB301E94634C00E64D9D /* MASClaims+MASPrivate.h */, CBA3EB311E94634C00E64D9D /* MASClaims+MASPrivate.m */, + E0BA7849257E7FA60003A9B8 /* MASTypedBrowserBasedAuthenticationInterface.h */, + E0BA784A257E7FEF0003A9B8 /* MASSafariBrowserBasedAuthentication.h */, + E0BA784B257E7FEF0003A9B8 /* MASSafariBrowserBasedAuthentication.m */, + E0BA785E257EB8C00003A9B8 /* MASWebSessionBrowserBasedAuthentication.h */, + E0BA785F257EB8C00003A9B8 /* MASWebSessionBrowserBasedAuthentication.m */, + E0BA7888257F78820003A9B8 /* MASTypedBrowserBasedAuthenticationFactory.h */, + E0BA7889257F78820003A9B8 /* MASTypedBrowserBasedAuthenticationFactory.m */, ); path = models; sourceTree = ""; @@ -1493,15 +1514,18 @@ CB9B1207210949D5008A2075 /* NSMutableData+MASASN1Helper.h in Headers */, CBA3EB2E1E945F2400E64D9D /* MASClaims.h in Headers */, CB0B58591E258C2A00BC0163 /* MASAuthorizationResponse.h in Headers */, + E0BA786D257F62820003A9B8 /* MASTypedBrowserBasedAuthenticationInterface.h in Headers */, CBA3EB321E94634C00E64D9D /* MASClaims+MASPrivate.h in Headers */, CBD25AFF1E78C47C00DFB47F /* JWTClaimsSetVerifier.h in Headers */, CBD25AF21E78C47C00DFB47F /* JWTRSAlgorithm.h in Headers */, CB6491F01FE9DAF300281288 /* MQTTPersistence.h in Headers */, 10E027A11F72B10100EAB103 /* RNCryptor+Private.h in Headers */, CBD25B0C1E78C47C00DFB47F /* JWTBase64Coder.h in Headers */, + E0BA788A257F78820003A9B8 /* MASTypedBrowserBasedAuthenticationFactory.h in Headers */, A419B3A11C176259008DC88C /* NSData+MAS.h in Headers */, A488CE751C0B97FD00B8B961 /* MASService.h in Headers */, CB6491FB1FE9DAF300281288 /* MQTTSSLSecurityPolicy.h in Headers */, + E0BA7867257F62570003A9B8 /* MASSafariBrowserBasedAuthentication.h in Headers */, CBD25B0B1E78C47C00DFB47F /* JWT.h in Headers */, CBD25B091E78C47C00DFB47F /* JWTCoding.h in Headers */, CB6491F71FE9DAF300281288 /* MQTTSessionManager.h in Headers */, @@ -1523,6 +1547,7 @@ A4E340F91B9E9F2000883AD3 /* MAS.h in Headers */, E3662A4223DEE5A4007A76A1 /* MASINetworking.h in Headers */, CBD25AF31E78C47C00DFB47F /* JWTCryptoKey.h in Headers */, + E0BA7869257F62590003A9B8 /* MASWebSessionBrowserBasedAuthentication.h in Headers */, CB6492031FE9DAF300281288 /* MQTTStrict.h in Headers */, A4831AFD1BD1A917007B4AE6 /* MASUser+MASPrivate.h in Headers */, CBD25AEC1E78C47C00DFB47F /* JWTAlgorithmDataHolderChain.h in Headers */, @@ -1698,6 +1723,7 @@ TargetAttributes = { 1059D36F1B61AA3700223267 = { CreatedOnToolsVersion = 6.4; + LastSwiftMigration = 1210; ProvisioningStyle = Manual; }; 1059D37A1B61AA3800223267 = { @@ -1782,12 +1808,14 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( + E0BA788B257F78820003A9B8 /* MASTypedBrowserBasedAuthenticationFactory.m in Sources */, CB5E4C711C1D250D001B3B8A /* MASPutURLRequest.m in Sources */, CB2A4056209B9DA600F988AA /* MASMultiFactorHandler+MASPrivate.m in Sources */, A858C6661D0978A6001FB9AD /* MASOTPService.m in Sources */, CBD25AE71E78C47C00DFB47F /* JWTAlgorithmNone.m in Sources */, CB1C151F1E450109002B31A5 /* NSURL+MASPrivate.m in Sources */, 10D2D49F1C1686ED00DF8AC4 /* MASGroup+MASPrivate.m in Sources */, + E0BA7877257F708A0003A9B8 /* MASBrowserBasedAuthentication.m in Sources */, CB99754F1EDF5837006CEBB1 /* MASAuthCredentialsAuthorizationCode.m in Sources */, A488CE761C0B97FD00B8B961 /* MASService.m in Sources */, A42A86A11BBDA27F00AE98AC /* NSError+MASPrivate.m in Sources */, @@ -1799,6 +1827,7 @@ CB2357971F0EFDEA00D4C420 /* MASSessionTaskOperation.m in Sources */, CB6491E91FE9DAF300281288 /* MQTTDecoder.m in Sources */, CB64920A1FE9DAF300281288 /* ReconnectTimer.m in Sources */, + E0BA784D257E7FEF0003A9B8 /* MASSafariBrowserBasedAuthentication.m in Sources */, 10E027A01F72B10100EAB103 /* RNCryptor.m in Sources */, CBAFD24D1F2BD46C0034DF02 /* MASSecurityConfiguration.m in Sources */, CB6491E11FE9DAF300281288 /* MQTTCFSocketEncoder.m in Sources */, @@ -1826,6 +1855,7 @@ 10E027A71F72B10100EAB103 /* RNEncryptor.m in Sources */, 699570E72062FF1300017244 /* MASError.m in Sources */, CB9975571EDF5986006CEBB1 /* MASAuthCredentialsClientCredentials.m in Sources */, + E0BA7861257EB8C00003A9B8 /* MASWebSessionBrowserBasedAuthentication.m in Sources */, 5BD3E7E420630FC900A151C7 /* MASConstants.m in Sources */, A47332D01BBC61F50002A492 /* NSData+MASPrivate.m in Sources */, CBAFD2511F2BD48B0034DF02 /* MASSecurityConfiguration+MASPrivate.m in Sources */, @@ -1877,7 +1907,6 @@ CBD25AF61E78C47C00DFB47F /* JWTCryptoKeyExtractor.m in Sources */, A4150E701BF1643900037E27 /* MASIJSONResponseSerializer+MASPrivate.m in Sources */, A417BA521BF033C300EC9BCB /* CLLocation+MASPrivate.m in Sources */, - C81CC3CD1FC2EA190058718E /* MASBrowserBasedAuthentication.m in Sources */, 69B7DF6D1F96756B0056DD3A /* MASRequest+MASPrivate.m in Sources */, A4831AB21BD1A551007B4AE6 /* MASFile.m in Sources */, CB0B585A1E258C2A00BC0163 /* MASAuthorizationResponse.m in Sources */, @@ -1992,7 +2021,7 @@ GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; GCC_WARN_UNUSED_FUNCTION = YES; GCC_WARN_UNUSED_VARIABLE = YES; - IPHONEOS_DEPLOYMENT_TARGET = 8.4; + IPHONEOS_DEPLOYMENT_TARGET = 9.0; MTL_ENABLE_DEBUG_INFO = YES; ONLY_ACTIVE_ARCH = YES; SDKROOT = iphoneos; @@ -2034,7 +2063,7 @@ GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; GCC_WARN_UNUSED_FUNCTION = YES; GCC_WARN_UNUSED_VARIABLE = YES; - IPHONEOS_DEPLOYMENT_TARGET = 8.4; + IPHONEOS_DEPLOYMENT_TARGET = 9.0; MTL_ENABLE_DEBUG_INFO = NO; SDKROOT = iphoneos; TARGETED_DEVICE_FAMILY = "1,2"; @@ -2047,6 +2076,7 @@ 1059D3871B61AA3800223267 /* Debug */ = { isa = XCBuildConfiguration; buildSettings = { + CLANG_ENABLE_MODULES = YES; CODE_SIGN_IDENTITY = "iPhone Developer"; "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; CODE_SIGN_STYLE = Manual; @@ -2090,12 +2120,15 @@ SKIP_INSTALL = YES; SUPPORTS_MACCATALYST = NO; SWIFT_OBJC_BRIDGING_HEADER = ""; + SWIFT_OPTIMIZATION_LEVEL = "-Onone"; + SWIFT_VERSION = 5.0; }; name = Debug; }; 1059D3881B61AA3800223267 /* Release */ = { isa = XCBuildConfiguration; buildSettings = { + CLANG_ENABLE_MODULES = YES; CODE_SIGN_IDENTITY = "iPhone Developer"; "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; CODE_SIGN_STYLE = Manual; @@ -2139,6 +2172,7 @@ SKIP_INSTALL = YES; SUPPORTS_MACCATALYST = NO; SWIFT_OBJC_BRIDGING_HEADER = ""; + SWIFT_VERSION = 5.0; }; name = Release; }; diff --git a/MASFoundation.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist b/MASFoundation.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist new file mode 100644 index 00000000..18d98100 --- /dev/null +++ b/MASFoundation.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist @@ -0,0 +1,8 @@ + + + + + IDEDidComputeMac32BitWarning + + + diff --git a/MASFoundation/Classes/MAS.h b/MASFoundation/Classes/MAS.h index 410e6302..08d69cee 100644 --- a/MASFoundation/Classes/MAS.h +++ b/MASFoundation/Classes/MAS.h @@ -195,6 +195,14 @@ + (void)enableBrowserBasedAuthentication:(BOOL)enable; +/** + * Sets preferred type of browser used for Browser Based Authentication (templatized login). + * By default this is `MASBrowserBasedAuthenticationTypeSafari`. + + @param browserBasedAuthenticationType MASBrowserBasedAuthenticationType value indicating which type of browser should be used for Browser Based Authentication. + */ ++ (void)preferredBrowserBasedAuthenticationType:(MASBrowserBasedAuthenticationType)browserBasedAuthenticationType; + /** * Returns current MASState enumeration value. The value can be used to determine which state SDK is currently at. diff --git a/MASFoundation/Classes/MAS.m b/MASFoundation/Classes/MAS.m index 98d97c26..f4a692a4 100644 --- a/MASFoundation/Classes/MAS.m +++ b/MASFoundation/Classes/MAS.m @@ -123,6 +123,12 @@ + (void)enableBrowserBasedAuthentication:(BOOL)enable } ++ (void)preferredBrowserBasedAuthenticationType:(MASBrowserBasedAuthenticationType)browserBasedAuthenticationType +{ + [MASModelService setBrowserBasedAuthenticationType:browserBasedAuthenticationType]; +} + + + (void)setKeychainSynchronizable:(BOOL)enabled { [MASAccessService setKeychainSynchronizable:enabled]; diff --git a/MASFoundation/Classes/MASConstants.h b/MASFoundation/Classes/MASConstants.h index 4e1db729..b557c6d8 100644 --- a/MASFoundation/Classes/MASConstants.h +++ b/MASFoundation/Classes/MASConstants.h @@ -273,7 +273,7 @@ typedef NS_ENUM(NSInteger, MASRequestResponseType) * The enumerated MASState that can indicate what state of SDK currently is at. */ typedef NS_ENUM(NSInteger, MASState) { - + /** * State that SDK has not been initialized and does not have configuration file * either in local file system based on the default configuration file name, nor in the keychain storage. @@ -309,6 +309,20 @@ typedef NS_ENUM(NSInteger, MASState) { MASStateIsBeingStopped }; +/** + * The enumerated MASBrowserBasedAuthenticationTypes that can be used to initiate a browser based login + */ +typedef NS_CLOSED_ENUM(NSUInteger, MASBrowserBasedAuthenticationType) { + + /** + * Type which tells the SDK an SFSafariViewController should be used when the user invokes browser based authentication. + */ + MASBrowserBasedAuthenticationTypeSafari, + /** + * Type which tells the SDK an ASWebAuthenticationSession should be used when the user invokes browser based authentication. + */ + MASBrowserBasedAuthenticationTypeWebSession API_AVAILABLE(ios(12.0), macCatalyst(13.0), macos(10.15), watchos(6.2)) API_UNAVAILABLE(tvos) +}; /** * Enumerated MASFileDirectoryType that indicates which directory to store MASFile into. diff --git a/MASFoundation/Classes/_private_/models/MASSafariBrowserBasedAuthentication.h b/MASFoundation/Classes/_private_/models/MASSafariBrowserBasedAuthentication.h new file mode 100644 index 00000000..7bd71248 --- /dev/null +++ b/MASFoundation/Classes/_private_/models/MASSafariBrowserBasedAuthentication.h @@ -0,0 +1,20 @@ +// +// MASSafariBrowserBasedAuthentication.h +// MASFoundation +// +// Copyright (c) 2020 CA. All rights reserved. +// +// This software may be modified and distributed under the terms +// of the MIT license. See the LICENSE file for details. +// + +#import + +@protocol MASTypedBrowserBasedAuthenticationInterface; + +/** + * A Browser Based Authentication type utilising an SFSafarViewController + */ +@interface MASSafariBrowserBasedAuthentication : NSObject + +@end diff --git a/MASFoundation/Classes/_private_/models/MASSafariBrowserBasedAuthentication.m b/MASFoundation/Classes/_private_/models/MASSafariBrowserBasedAuthentication.m new file mode 100644 index 00000000..b9c57922 --- /dev/null +++ b/MASFoundation/Classes/_private_/models/MASSafariBrowserBasedAuthentication.m @@ -0,0 +1,70 @@ +// +// MASSafariBrowserBasedAuthentication.m +// MASFoundation +// +// Copyright (c) 2020 CA. All rights reserved. +// +// This software may be modified and distributed under the terms +// of the MIT license. See the LICENSE file for details. +// + +#import +#import "MASSafariBrowserBasedAuthentication.h" +#import "MASTypedBrowserBasedAuthenticationInterface.h" +#import "UIAlertController+MAS.h" + +@interface MASSafariBrowserBasedAuthentication() + +@property (nonatomic, strong) SFSafariViewController *safariViewController; +@property (nonatomic, assign) MASAuthCredentialsBlock webLoginBlock; + +@end + +@implementation MASSafariBrowserBasedAuthentication + + +- (void)startWithURL:(NSURL *)url completion:(MASAuthCredentialsBlock)webLoginBlock +{ + self.safariViewController = [[SFSafariViewController alloc] initWithURL:url]; + self.safariViewController.delegate = self; + self.webLoginBlock = webLoginBlock; + + __block MASSafariBrowserBasedAuthentication *blockSelf = self; + dispatch_async(dispatch_get_main_queue(), ^{ + [UIAlertController rootViewController].modalTransitionStyle = UIModalTransitionStyleCoverVertical; + + [[UIAlertController rootViewController] presentViewController:blockSelf.safariViewController + animated:YES + completion:^{ + DLog(@"Successfully displayed login template"); + }]; + + return; + }); +} + + +- (void)dismiss +{ + __block MASSafariBrowserBasedAuthentication *blockSelf = self; + dispatch_async(dispatch_get_main_queue(), ^{ + [blockSelf.safariViewController dismissViewControllerAnimated:true completion: nil]; + }); + +} + + + +#pragma mark - SFSafariViewControllerDelegate + +- (void)safariViewControllerDidFinish:(SFSafariViewController *)controller { + self.webLoginBlock(nil, YES, ^(BOOL completed, NSError* error){ + if(error) + { + DLog(@"Browser cancel clicked"); + } + }); +} + +@end + diff --git a/MASFoundation/Classes/_private_/models/MASTypedBrowserBasedAuthenticationFactory.h b/MASFoundation/Classes/_private_/models/MASTypedBrowserBasedAuthenticationFactory.h new file mode 100644 index 00000000..e2c3eb9b --- /dev/null +++ b/MASFoundation/Classes/_private_/models/MASTypedBrowserBasedAuthenticationFactory.h @@ -0,0 +1,29 @@ +// +// MASTypedBrowserBasedAuthenticationFactory.h +// MASFoundation +// +// Copyright (c) 2020 CA. All rights reserved. +// +// This software may be modified and distributed under the terms +// of the MIT license. See the LICENSE file for details. +// + +#import +#import "MASConstants.h" + +@protocol MASTypedBrowserBasedAuthenticationInterface; + +/** + * Utility factory class to build the correct browser type to use + */ +@interface MASTypedBrowserBasedAuthenticationFactory : NSObject + +/** + * Build a new browser used for Browser Based Authentication + * + * @param browserBasedAuthenticationType A MASBrowserBasedAuthenticationType object telling the factory what to build information. + * @return id object which can be used to start Browser Based Authentication. + */ ++ (id)buildBrowserForType:(MASBrowserBasedAuthenticationType)browserBasedAuthenticationType; + +@end diff --git a/MASFoundation/Classes/_private_/models/MASTypedBrowserBasedAuthenticationFactory.m b/MASFoundation/Classes/_private_/models/MASTypedBrowserBasedAuthenticationFactory.m new file mode 100644 index 00000000..21bffb35 --- /dev/null +++ b/MASFoundation/Classes/_private_/models/MASTypedBrowserBasedAuthenticationFactory.m @@ -0,0 +1,29 @@ +// +// MASTypedBrowserBasedAuthenticationFactory.m +// MASFoundation +// +// Copyright (c) 2020 CA. All rights reserved. +// +// This software may be modified and distributed under the terms +// of the MIT license. See the LICENSE file for details. +// + +#import "MASTypedBrowserBasedAuthenticationFactory.h" +#import "MASSafariBrowserBasedAuthentication.h" +#import "MASWebSessionBrowserBasedAuthentication.h" + +@implementation MASTypedBrowserBasedAuthenticationFactory + ++ (id)buildBrowserForType:(MASBrowserBasedAuthenticationType)browserBasedAuthenticationType { + if (@available(iOS 12.0, macOS 10.15, *)) { + switch (browserBasedAuthenticationType) { + case MASBrowserBasedAuthenticationTypeSafari: + return [[MASSafariBrowserBasedAuthentication alloc] init]; + case MASBrowserBasedAuthenticationTypeWebSession: + return [[MASWebSessionBrowserBasedAuthentication alloc] init]; + } + } else { + return [[MASSafariBrowserBasedAuthentication alloc] init]; + } +} +@end diff --git a/MASFoundation/Classes/_private_/models/MASTypedBrowserBasedAuthenticationInterface.h b/MASFoundation/Classes/_private_/models/MASTypedBrowserBasedAuthenticationInterface.h new file mode 100644 index 00000000..bb4b4937 --- /dev/null +++ b/MASFoundation/Classes/_private_/models/MASTypedBrowserBasedAuthenticationInterface.h @@ -0,0 +1,31 @@ +// +// MASTypedBrowserBasedAuthenticationInterface.h +// MASFoundation +// +// Copyright (c) 2020 CA. All rights reserved. +// +// This software may be modified and distributed under the terms +// of the MIT license. See the LICENSE file for details. +// +#import "MASConstants.h" + +/** + * Interface used to abstract different type of browsers used for Browser Based Authentication + */ +@protocol MASTypedBrowserBasedAuthenticationInterface + +/** + Starts the Browser based authentication with the given url and completion block. + + @param templatizedURL NSURL sent to the browser + @param completion MASAuthCredentialsBlock object. + */ +- (void)startWithURL:(NSURL *)templatizedURL completion:(MASAuthCredentialsBlock)webLoginBlock; + + +/** + Dismisses the currently presented browser. + */ +- (void)dismiss; + +@end diff --git a/MASFoundation/Classes/_private_/models/MASWebSessionBrowserBasedAuthentication.h b/MASFoundation/Classes/_private_/models/MASWebSessionBrowserBasedAuthentication.h new file mode 100644 index 00000000..c23d662f --- /dev/null +++ b/MASFoundation/Classes/_private_/models/MASWebSessionBrowserBasedAuthentication.h @@ -0,0 +1,21 @@ +// +// MASWebSessionBrowserBasedAuthentication.h +// MASFoundation +// +// Copyright (c) 2020 CA. All rights reserved. +// +// This software may be modified and distributed under the terms +// of the MIT license. See the LICENSE file for details. +// + +#import + +@protocol MASTypedBrowserBasedAuthenticationInterface; + +/** + * A Browser Based Authentication type utilising an ASWebAuthenticationSession + */ +API_AVAILABLE(ios(12.0), macCatalyst(13.0), macos(10.15), watchos(6.2)) +@interface MASWebSessionBrowserBasedAuthentication : NSObject + +@end diff --git a/MASFoundation/Classes/_private_/models/MASWebSessionBrowserBasedAuthentication.m b/MASFoundation/Classes/_private_/models/MASWebSessionBrowserBasedAuthentication.m new file mode 100644 index 00000000..2d965322 --- /dev/null +++ b/MASFoundation/Classes/_private_/models/MASWebSessionBrowserBasedAuthentication.m @@ -0,0 +1,77 @@ +// +// MASWebSessionBrowserBasedAuthentication.m +// MASFoundation +// +// Copyright (c) 2020 CA. All rights reserved. +// +// This software may be modified and distributed under the terms +// of the MIT license. See the LICENSE file for details. +// + +#import "MASWebSessionBrowserBasedAuthentication.h" +#import +#import "MASTypedBrowserBasedAuthenticationInterface.h" +#import "MASAuthorizationResponse.h" + +API_AVAILABLE(ios(12.0), macCatalyst(13.0), macos(10.15), watchos(6.2)) +@interface MASWebSessionBrowserBasedAuthentication() + +@property (nonatomic, strong) ASWebAuthenticationSession *session; +@property (nonatomic, assign) MASAuthCredentialsBlock webLoginBlock; +@property (nonatomic, weak) id window; + +@end + +API_AVAILABLE(ios(13.0), macos(10.15)) +@interface MASWebSessionBrowserBasedAuthentication() +@end + +@implementation MASWebSessionBrowserBasedAuthentication + +- (void)startWithURL:(NSURL *)url completion:(MASAuthCredentialsBlock)webLoginBlock +{ + self.session = [[ASWebAuthenticationSession alloc] initWithURL:url callbackURLScheme:nil completionHandler:^(NSURL * _Nullable callbackURL, NSError * _Nullable error) { + if (callbackURL != nil) { + [MASAuthorizationResponse.sharedInstance handleAuthorizationResponseURL:callbackURL]; + } else { + webLoginBlock(nil, YES, ^(BOOL completed, NSError* error) { + if(error) + { + DLog("An error occured or the user pressed cancel") + } + }); + } + }]; + if (@available(iOS 13.0, macOS 10.15, *)) { + self.session.presentationContextProvider = self; + } + + __block MASWebSessionBrowserBasedAuthentication* blockSelf = self; + dispatch_async(dispatch_get_main_queue(), ^{ +#if TARGET_OS_IOS + blockSelf.window = [[UIApplication sharedApplication] keyWindow]; +#else + blockSelf.window = [[NSApplication sharedApplication] keyWindow]; +#endif + [blockSelf.session start]; + }); + +} + + +- (void)dismiss +{ + [self.session cancel]; +} + + + +#pragma mark - ASWebAuthenticationPresentationContextProviding + +- (ASPresentationAnchor)presentationAnchorForWebAuthenticationSession:(ASWebAuthenticationSession *)session { + return self.window; +} + +@end + + diff --git a/MASFoundation/Classes/_private_/services/model/MASModelService.h b/MASFoundation/Classes/_private_/services/model/MASModelService.h index 4e0c5abe..978d770f 100644 --- a/MASFoundation/Classes/_private_/services/model/MASModelService.h +++ b/MASFoundation/Classes/_private_/services/model/MASModelService.h @@ -101,6 +101,22 @@ + (BOOL)browserBasedAuthentication; +/** + * Sets the browser based authentication type property. Default is MASSafariBrowserBasedAuthenticationType. + * + * @param browserBasedAuthenticationType The type of browser used when invoking a browser based login. + */ ++ (void)setBrowserBasedAuthenticationType:(MASBrowserBasedAuthenticationType)browserBasedAuthenticationType; + + +/** + * The current browser based authentication type. + * + * @return MASBrowserBasedAuthenticationType value is returned. + */ ++ (MASBrowserBasedAuthenticationType)browserBasedAuthenticationType; + + ///-------------------------------------- /// @name Application ///-------------------------------------- diff --git a/MASFoundation/Classes/_private_/services/model/MASModelService.m b/MASFoundation/Classes/_private_/services/model/MASModelService.m index ebad3efa..67a99908 100644 --- a/MASFoundation/Classes/_private_/services/model/MASModelService.m +++ b/MASFoundation/Classes/_private_/services/model/MASModelService.m @@ -11,6 +11,7 @@ #import "MASModelService.h" #import "MASAccessService.h" #import "MASConfigurationService.h" +#import "MASConstants.h" #import "MASFileService.h" #import "MASSecurityService.h" #import "MASServiceRegistry.h" @@ -40,6 +41,7 @@ @implementation MASModelService static MASGrantFlow _grantFlow_ = MASGrantFlowClientCredentials; static MASUserAuthCredentialsBlock _userAuthCredentialsBlock_ = nil; static BOOL _isBrowserBasedAuthentication_ = NO; +static MASBrowserBasedAuthenticationType _browserBasedAuthenticationType_ = MASBrowserBasedAuthenticationTypeSafari; # pragma mark - Properties @@ -85,6 +87,18 @@ + (BOOL)browserBasedAuthentication } ++ (void)setBrowserBasedAuthenticationType:(MASBrowserBasedAuthenticationType)browserBasedAuthenticationType +{ + _browserBasedAuthenticationType_ = browserBasedAuthenticationType; +} + + ++ (MASBrowserBasedAuthenticationType)browserBasedAuthenticationType +{ + return _browserBasedAuthenticationType_; +} + + # pragma mark - Shared Service + (instancetype)sharedService diff --git a/MASFoundation/Classes/models/MASAuthorizationResponse.h b/MASFoundation/Classes/models/MASAuthorizationResponse.h index 1aeb77f7..9dbc4bb8 100644 --- a/MASFoundation/Classes/models/MASAuthorizationResponse.h +++ b/MASFoundation/Classes/models/MASAuthorizationResponse.h @@ -87,7 +87,7 @@ NS_ASSUME_NONNULL_BEGIN #if __IPHONE_OS_VERSION_MAX_ALLOWED > __IPHONE_9_3 /** - * Prase returned URL from SFSafariViewController with authorization code and OAuth state. + * Prase returned URL from Browser Based Authentication with authorization code and OAuth state. * Call this method inside [UIApplicationDelegate application:openURL:options:] of the AppDelegate for the application. * This method should be invoked in order to properly perform social login in MASFoundation SDK. * @@ -103,7 +103,7 @@ NS_ASSUME_NONNULL_BEGIN /** - * Prase returned URL from SFSafariViewController with authorization code and OAuth state. + * Prase returned URL from Browser Based Authentication with authorization code and OAuth state. * Call this method inside [UIApplicationDelegate application:openURL:sourceApplication:annotation:] of the AppDelegate for the application. * This method should be invoked in order to properly perform social login in MASFoundation SDK. * @@ -116,6 +116,18 @@ NS_ASSUME_NONNULL_BEGIN */ - (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation; + +/** + * Prase returned URL from Browser Based Authentication with authorization code and OAuth state. + * Call this method inside [UIApplicationDelegate application:openURL:sourceApplication:annotation:] of the AppDelegate for the application. + * This method should be invoked in order to properly perform social login in MASFoundation SDK. + * + * @param url NSURL object as passed in [UIApplicationDelegate application:openURL:sourceApplication:annotation:]. + * + * @return BOOL value whether the URL is specific for social login in MASFoundation or not. + */ +- (BOOL)handleAuthorizationResponseURL:(NSURL *)url; + NS_ASSUME_NONNULL_END @end diff --git a/MASFoundation/Classes/models/MASAuthorizationResponse.m b/MASFoundation/Classes/models/MASAuthorizationResponse.m index abe3cebb..d547ecea 100644 --- a/MASFoundation/Classes/models/MASAuthorizationResponse.m +++ b/MASFoundation/Classes/models/MASAuthorizationResponse.m @@ -70,6 +70,12 @@ - (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceAppl } +- (BOOL)handleAuthorizationResponseURL:(NSURL *)url +{ + return [self validateURLForAuthorizationURL:url]; +} + + # pragma mark - Private - (BOOL)validateURLForAuthorizationURL:(NSURL *)url diff --git a/MASFoundation/Classes/models/MASBrowserBasedAuthentication.m b/MASFoundation/Classes/models/MASBrowserBasedAuthentication.m index a10e97f2..ba72b647 100644 --- a/MASFoundation/Classes/models/MASBrowserBasedAuthentication.m +++ b/MASFoundation/Classes/models/MASBrowserBasedAuthentication.m @@ -14,6 +14,8 @@ #import "MASConfigurationService.h" #import "MASGetURLRequest.h" #import "MASModelService.h" +#import "MASTypedBrowserBasedAuthenticationFactory.h" +#import "MASTypedBrowserBasedAuthenticationInterface.h" #import "UIAlertController+MAS.h" #import @@ -22,7 +24,7 @@ @interface MASBrowserBasedAuthentication () browser; @property (nonatomic) MASAuthCredentialsBlock webLoginCallBack; @end @@ -181,22 +183,22 @@ - (MASSessionDataTaskHTTPRedirectBlock)getRedirectionBlock { __block MASBrowserBasedAuthentication *blockSelf = self; MASSessionDataTaskHTTPRedirectBlock redirectionBlock = ^(NSURLSession *session, NSURLSessionTask *task, NSURLResponse * response, NSURLRequest *request){ - NSHTTPURLResponse *httpResponse = (NSHTTPURLResponse *)response; - if(httpResponse.statusCode == 302 && [self isBBARedirection:task.originalRequest]) + NSHTTPURLResponse *httpResponse = (NSHTTPURLResponse *)response; + if(httpResponse.statusCode == 302 && [self isBBARedirection:task.originalRequest]) + { + DLog(@"all headers %@",httpResponse.allHeaderFields); + NSString* locationURL = [httpResponse.allHeaderFields objectForKey:@"Location"]; + NSURL* redirectURL = [NSURL URLWithString:locationURL]; + [task cancel]; + + if(![blockSelf redirectURLHasErrors:redirectURL]) { - DLog(@"all headers %@",httpResponse.allHeaderFields); - NSString* locationURL = [httpResponse.allHeaderFields objectForKey:@"Location"]; - NSURL* redirectURL = [NSURL URLWithString:locationURL]; - [task cancel]; - - if(![blockSelf redirectURLHasErrors:redirectURL]) - { - [blockSelf launchBrowserWithURL:redirectURL]; - } - else{ - blockSelf.webLoginCallBack(nil, YES, nil); - } + [blockSelf launchBrowserWithURL:redirectURL]; + } + else{ + blockSelf.webLoginCallBack(nil, YES, nil); } + } //return a nil request as we would have already cancelled the request //return a nil as compiler expects a NSURLRequest object NSURLRequest* nilRequest = nil; @@ -230,35 +232,9 @@ - (BOOL)redirectURLHasErrors :(NSURL*)redirectURL - (void)launchBrowserWithURL:(NSURL*)templatizedURL { - __block MASBrowserBasedAuthentication *blockSelf = self; - __weak __typeof__(self) weakSelf = self; - blockSelf.safariViewController = [[SFSafariViewController alloc] initWithURL:templatizedURL]; - blockSelf.safariViewController.delegate = weakSelf; - - dispatch_async(dispatch_get_main_queue(), ^{ - [UIAlertController rootViewController].modalTransitionStyle = UIModalTransitionStyleCoverVertical; - - [[UIAlertController rootViewController] presentViewController:blockSelf.safariViewController animated:YES - completion:^{ - - DLog(@"Successfully displayed login template"); - }]; - - return; - }); -} - - -#pragma mark - SafariViewController Delegates - -- (void)safariViewControllerDidFinish:(SFSafariViewController *)controller -{ - self.webLoginCallBack(nil, YES, ^(BOOL completed, NSError* error){ - if(error) - { - DLog(@"Browser cancel clicked"); - } - }); + MASBrowserBasedAuthenticationType type = [MASModelService browserBasedAuthenticationType]; + self.browser = [MASTypedBrowserBasedAuthenticationFactory buildBrowserForType:type]; + [self.browser startWithURL:templatizedURL completion: self.webLoginCallBack]; } @@ -298,7 +274,7 @@ - (void)didReceiveError:(NSError *)error - (void)dismissBrowser { dispatch_async(dispatch_get_main_queue(), ^{ - [[UIAlertController rootViewController] dismissViewControllerAnimated:YES completion:nil]; + [self.browser dismiss]; }); } From 6423696142d3e77ddf0e062c7b93cc355f946a7a Mon Sep 17 00:00:00 2001 From: Sander Saelmans Date: Tue, 8 Dec 2020 12:45:20 +0100 Subject: [PATCH 07/16] Fixed indentation --- .../models/MASBrowserBasedAuthentication.m | 24 +++++++++---------- 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/MASFoundation/Classes/models/MASBrowserBasedAuthentication.m b/MASFoundation/Classes/models/MASBrowserBasedAuthentication.m index ba72b647..d097cddc 100644 --- a/MASFoundation/Classes/models/MASBrowserBasedAuthentication.m +++ b/MASFoundation/Classes/models/MASBrowserBasedAuthentication.m @@ -164,18 +164,18 @@ - (void)getURLForWebLogin // This get request would result in a redirection which contains the actual URL to be loaded into browser and hence this would be canceled after the redirection // [[MASNetworkingService sharedService] getFrom:endPoint withParameters:parameterInfo andHeaders:headerInfo requestType:MASRequestResponseTypeWwwFormUrlEncoded responseType:MASRequestResponseTypeWwwFormUrlEncoded completion:^(NSDictionary* response, NSError* error){ - - // - // We expect this API to be cancelled in the redirection and hence the only acceptable error here is cancel.Any other error could mean an error for authenticaion itself. Hence cancel authorization. - // - if(error.code != NSURLErrorCancelled) - { - DLog(@"error occured in BBA error info: %@",error); - blockSelf.webLoginCallBack(nil, YES, nil); - return; - } - - [[MASNetworkingService sharedService] setHttpRedirectionBlock:previousRedirectionBlock]; + + // + // We expect this API to be cancelled in the redirection and hence the only acceptable error here is cancel.Any other error could mean an error for authenticaion itself. Hence cancel authorization. + // + if(error.code != NSURLErrorCancelled) + { + DLog(@"error occured in BBA error info: %@",error); + blockSelf.webLoginCallBack(nil, YES, nil); + return; + } + + [[MASNetworkingService sharedService] setHttpRedirectionBlock:previousRedirectionBlock]; }]; } From 9428327562ed6bdc0cdbd66a87de077d258058c7 Mon Sep 17 00:00:00 2001 From: Sander Saelmans Date: Tue, 8 Dec 2020 12:59:46 +0100 Subject: [PATCH 08/16] Remove unneeded edits to the project file --- MASFoundation.xcodeproj/project.pbxproj | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/MASFoundation.xcodeproj/project.pbxproj b/MASFoundation.xcodeproj/project.pbxproj index 3d80863c..b873f88b 100644 --- a/MASFoundation.xcodeproj/project.pbxproj +++ b/MASFoundation.xcodeproj/project.pbxproj @@ -1723,7 +1723,6 @@ TargetAttributes = { 1059D36F1B61AA3700223267 = { CreatedOnToolsVersion = 6.4; - LastSwiftMigration = 1210; ProvisioningStyle = Manual; }; 1059D37A1B61AA3800223267 = { @@ -2021,7 +2020,7 @@ GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; GCC_WARN_UNUSED_FUNCTION = YES; GCC_WARN_UNUSED_VARIABLE = YES; - IPHONEOS_DEPLOYMENT_TARGET = 9.0; + IPHONEOS_DEPLOYMENT_TARGET = 8.4; MTL_ENABLE_DEBUG_INFO = YES; ONLY_ACTIVE_ARCH = YES; SDKROOT = iphoneos; @@ -2063,7 +2062,7 @@ GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; GCC_WARN_UNUSED_FUNCTION = YES; GCC_WARN_UNUSED_VARIABLE = YES; - IPHONEOS_DEPLOYMENT_TARGET = 9.0; + IPHONEOS_DEPLOYMENT_TARGET = 8.4; MTL_ENABLE_DEBUG_INFO = NO; SDKROOT = iphoneos; TARGETED_DEVICE_FAMILY = "1,2"; @@ -2076,7 +2075,6 @@ 1059D3871B61AA3800223267 /* Debug */ = { isa = XCBuildConfiguration; buildSettings = { - CLANG_ENABLE_MODULES = YES; CODE_SIGN_IDENTITY = "iPhone Developer"; "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; CODE_SIGN_STYLE = Manual; @@ -2104,7 +2102,7 @@ ); INFOPLIST_FILE = MASFoundation/Info.plist; INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; - IPHONEOS_DEPLOYMENT_TARGET = 9.0; + IPHONEOS_DEPLOYMENT_TARGET = 8.4; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; LIBRARY_SEARCH_PATHS = ( "$(inherited)", @@ -2120,15 +2118,12 @@ SKIP_INSTALL = YES; SUPPORTS_MACCATALYST = NO; SWIFT_OBJC_BRIDGING_HEADER = ""; - SWIFT_OPTIMIZATION_LEVEL = "-Onone"; - SWIFT_VERSION = 5.0; }; name = Debug; }; 1059D3881B61AA3800223267 /* Release */ = { isa = XCBuildConfiguration; buildSettings = { - CLANG_ENABLE_MODULES = YES; CODE_SIGN_IDENTITY = "iPhone Developer"; "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; CODE_SIGN_STYLE = Manual; @@ -2156,7 +2151,7 @@ ); INFOPLIST_FILE = MASFoundation/Info.plist; INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; - IPHONEOS_DEPLOYMENT_TARGET = 9.0; + IPHONEOS_DEPLOYMENT_TARGET = 8.4; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; LIBRARY_SEARCH_PATHS = ( "$(inherited)", @@ -2172,7 +2167,6 @@ SKIP_INSTALL = YES; SUPPORTS_MACCATALYST = NO; SWIFT_OBJC_BRIDGING_HEADER = ""; - SWIFT_VERSION = 5.0; }; name = Release; }; From ef20369f2f7ed8094235fbd464edfa04dfebfb49 Mon Sep 17 00:00:00 2001 From: Sander Saelmans Date: Tue, 8 Dec 2020 13:02:17 +0100 Subject: [PATCH 09/16] Remove workspace checks --- .../xcshareddata/IDEWorkspaceChecks.plist | 8 -------- 1 file changed, 8 deletions(-) delete mode 100644 MASFoundation.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist diff --git a/MASFoundation.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist b/MASFoundation.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist deleted file mode 100644 index 18d98100..00000000 --- a/MASFoundation.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist +++ /dev/null @@ -1,8 +0,0 @@ - - - - - IDEDidComputeMac32BitWarning - - - From a2374bc2e84dc18dccfaa72f3002d20327d63717 Mon Sep 17 00:00:00 2001 From: Sander Saelmans Date: Tue, 8 Dec 2020 13:04:57 +0100 Subject: [PATCH 10/16] Remove more unneeded edits --- MASFoundation.xcodeproj/project.pbxproj | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/MASFoundation.xcodeproj/project.pbxproj b/MASFoundation.xcodeproj/project.pbxproj index b873f88b..6c1d1d71 100644 --- a/MASFoundation.xcodeproj/project.pbxproj +++ b/MASFoundation.xcodeproj/project.pbxproj @@ -2102,7 +2102,7 @@ ); INFOPLIST_FILE = MASFoundation/Info.plist; INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; - IPHONEOS_DEPLOYMENT_TARGET = 8.4; + IPHONEOS_DEPLOYMENT_TARGET = 9.0; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; LIBRARY_SEARCH_PATHS = ( "$(inherited)", @@ -2151,7 +2151,7 @@ ); INFOPLIST_FILE = MASFoundation/Info.plist; INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; - IPHONEOS_DEPLOYMENT_TARGET = 8.4; + IPHONEOS_DEPLOYMENT_TARGET = 9.0; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; LIBRARY_SEARCH_PATHS = ( "$(inherited)", From 33158cfed256d40ea620e4905d32f038781366bf Mon Sep 17 00:00:00 2001 From: Sander Saelmans Date: Tue, 8 Dec 2020 13:06:25 +0100 Subject: [PATCH 11/16] Add some more whitespaces to adhere to coding guidelines --- MASFoundation/Classes/MASConstants.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/MASFoundation/Classes/MASConstants.h b/MASFoundation/Classes/MASConstants.h index b557c6d8..83311ab3 100644 --- a/MASFoundation/Classes/MASConstants.h +++ b/MASFoundation/Classes/MASConstants.h @@ -309,6 +309,7 @@ typedef NS_ENUM(NSInteger, MASState) { MASStateIsBeingStopped }; + /** * The enumerated MASBrowserBasedAuthenticationTypes that can be used to initiate a browser based login */ @@ -324,6 +325,7 @@ typedef NS_CLOSED_ENUM(NSUInteger, MASBrowserBasedAuthenticationType) { MASBrowserBasedAuthenticationTypeWebSession API_AVAILABLE(ios(12.0), macCatalyst(13.0), macos(10.15), watchos(6.2)) API_UNAVAILABLE(tvos) }; + /** * Enumerated MASFileDirectoryType that indicates which directory to store MASFile into. */ From 6a2da196436167846c789a292fac24cbe8de9880 Mon Sep 17 00:00:00 2001 From: Sander Saelmans Date: Tue, 8 Dec 2020 13:14:58 +0100 Subject: [PATCH 12/16] Added pragma marks, and utility log statements --- .../MASSafariBrowserBasedAuthentication.m | 21 +++++++++++++--- .../MASWebSessionBrowserBasedAuthentication.m | 24 ++++++++++++++++++- 2 files changed, 41 insertions(+), 4 deletions(-) diff --git a/MASFoundation/Classes/_private_/models/MASSafariBrowserBasedAuthentication.m b/MASFoundation/Classes/_private_/models/MASSafariBrowserBasedAuthentication.m index b9c57922..97494ed6 100644 --- a/MASFoundation/Classes/_private_/models/MASSafariBrowserBasedAuthentication.m +++ b/MASFoundation/Classes/_private_/models/MASSafariBrowserBasedAuthentication.m @@ -15,13 +15,27 @@ @interface MASSafariBrowserBasedAuthentication() +///-------------------------------------- +/// @name Properties +///------------------------------------- + +# pragma mark - Properties + @property (nonatomic, strong) SFSafariViewController *safariViewController; + @property (nonatomic, assign) MASAuthCredentialsBlock webLoginBlock; @end + @implementation MASSafariBrowserBasedAuthentication +///-------------------------------------- +/// @name Start & Stop +///-------------------------------------- + +# pragma mark - Start & Stop + - (void)startWithURL:(NSURL *)url completion:(MASAuthCredentialsBlock)webLoginBlock { @@ -33,9 +47,7 @@ - (void)startWithURL:(NSURL *)url completion:(MASAuthCredentialsBlock)webLoginBl dispatch_async(dispatch_get_main_queue(), ^{ [UIAlertController rootViewController].modalTransitionStyle = UIModalTransitionStyleCoverVertical; - [[UIAlertController rootViewController] presentViewController:blockSelf.safariViewController - animated:YES - completion:^{ + [[UIAlertController rootViewController] presentViewController:blockSelf.safariViewController animated:YES completion:^{ DLog(@"Successfully displayed login template"); }]; @@ -54,6 +66,9 @@ - (void)dismiss } +///-------------------------------------- +/// @name SFSafariViewControllerDelegate +///-------------------------------------- #pragma mark - SFSafariViewControllerDelegate diff --git a/MASFoundation/Classes/_private_/models/MASWebSessionBrowserBasedAuthentication.m b/MASFoundation/Classes/_private_/models/MASWebSessionBrowserBasedAuthentication.m index 2d965322..6f6b6d9b 100644 --- a/MASFoundation/Classes/_private_/models/MASWebSessionBrowserBasedAuthentication.m +++ b/MASFoundation/Classes/_private_/models/MASWebSessionBrowserBasedAuthentication.m @@ -16,8 +16,16 @@ API_AVAILABLE(ios(12.0), macCatalyst(13.0), macos(10.15), watchos(6.2)) @interface MASWebSessionBrowserBasedAuthentication() +///-------------------------------------- +/// @name Properties +///------------------------------------- + +# pragma mark - Properties + @property (nonatomic, strong) ASWebAuthenticationSession *session; + @property (nonatomic, assign) MASAuthCredentialsBlock webLoginBlock; + @property (nonatomic, weak) id window; @end @@ -26,8 +34,16 @@ @interface MASWebSessionBrowserBasedAuthentication() @interface MASWebSessionBrowserBasedAuthentication() @end + @implementation MASWebSessionBrowserBasedAuthentication +///-------------------------------------- +/// @name Start & Stop +///-------------------------------------- + +# pragma mark - Start & Stop + + - (void)startWithURL:(NSURL *)url completion:(MASAuthCredentialsBlock)webLoginBlock { self.session = [[ASWebAuthenticationSession alloc] initWithURL:url callbackURLScheme:nil completionHandler:^(NSURL * _Nullable callbackURL, NSError * _Nullable error) { @@ -53,7 +69,9 @@ - (void)startWithURL:(NSURL *)url completion:(MASAuthCredentialsBlock)webLoginBl #else blockSelf.window = [[NSApplication sharedApplication] keyWindow]; #endif - [blockSelf.session start]; + if ([blockSelf.session start]) { + DLog(@"Successfully displayed login template"); + } }); } @@ -66,6 +84,10 @@ - (void)dismiss +///-------------------------------------- +/// @name ASWebAuthenticationPresentationContextProviding +///-------------------------------------- + #pragma mark - ASWebAuthenticationPresentationContextProviding - (ASPresentationAnchor)presentationAnchorForWebAuthenticationSession:(ASWebAuthenticationSession *)session { From 7ee1716665e3ff73f36574b04548da17a52e51a9 Mon Sep 17 00:00:00 2001 From: Sander Saelmans Date: Tue, 8 Dec 2020 13:22:22 +0100 Subject: [PATCH 13/16] Change __block to __weak to prevent possible retain cycles --- .../models/MASSafariBrowserBasedAuthentication.m | 9 +++++---- .../models/MASWebSessionBrowserBasedAuthentication.m | 8 +++++--- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/MASFoundation/Classes/_private_/models/MASSafariBrowserBasedAuthentication.m b/MASFoundation/Classes/_private_/models/MASSafariBrowserBasedAuthentication.m index 97494ed6..f1767285 100644 --- a/MASFoundation/Classes/_private_/models/MASSafariBrowserBasedAuthentication.m +++ b/MASFoundation/Classes/_private_/models/MASSafariBrowserBasedAuthentication.m @@ -23,6 +23,7 @@ @interface MASSafariBrowserBasedAuthentication() Date: Tue, 8 Dec 2020 13:23:14 +0100 Subject: [PATCH 14/16] Missed 1 weakSelf --- .../_private_/models/MASWebSessionBrowserBasedAuthentication.m | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/MASFoundation/Classes/_private_/models/MASWebSessionBrowserBasedAuthentication.m b/MASFoundation/Classes/_private_/models/MASWebSessionBrowserBasedAuthentication.m index facdf520..aae83bd0 100644 --- a/MASFoundation/Classes/_private_/models/MASWebSessionBrowserBasedAuthentication.m +++ b/MASFoundation/Classes/_private_/models/MASWebSessionBrowserBasedAuthentication.m @@ -71,7 +71,7 @@ - (void)startWithURL:(NSURL *)url completion:(MASAuthCredentialsBlock)webLoginBl #else weakSelf.window = [[NSApplication sharedApplication] keyWindow]; #endif - if ([blockSelf.session start]) { + if ([weakSelf.session start]) { DLog(@"Successfully displayed login template"); } }); From 7c48c4391bc0e181953b180afb9949cec002dbac Mon Sep 17 00:00:00 2001 From: Sander Saelmans Date: Tue, 22 Dec 2020 09:36:18 +0100 Subject: [PATCH 15/16] Added option to provide the callack url scheme when choosing to use we session browser based login --- MASFoundation.xcodeproj/project.pbxproj | 10 +++- MASFoundation/Classes/MAS.h | 9 ++-- MASFoundation/Classes/MAS.m | 4 +- MASFoundation/Classes/MASConstants.h | 16 ------ ...ASTypedBrowserBasedAuthenticationFactory.h | 5 +- ...ASTypedBrowserBasedAuthenticationFactory.m | 26 +++++---- .../MASWebSessionBrowserBasedAuthentication.h | 25 +++++++++ .../MASWebSessionBrowserBasedAuthentication.m | 20 ++++++- .../services/model/MASModelService.h | 12 ++--- .../services/model/MASModelService.m | 14 +++-- .../models/MASBrowserBasedAuthentication.m | 4 +- ...SBrowserBasedAuthenticationConfiguration.h | 54 +++++++++++++++++++ ...SBrowserBasedAuthenticationConfiguration.m | 25 +++++++++ .../models/MFA/MASMultiFactorHandler.h | 4 +- 14 files changed, 177 insertions(+), 51 deletions(-) create mode 100644 MASFoundation/Classes/models/MASBrowserBasedAuthenticationConfiguration.h create mode 100644 MASFoundation/Classes/models/MASBrowserBasedAuthenticationConfiguration.m diff --git a/MASFoundation.xcodeproj/project.pbxproj b/MASFoundation.xcodeproj/project.pbxproj index 6c1d1d71..1e1de0a2 100644 --- a/MASFoundation.xcodeproj/project.pbxproj +++ b/MASFoundation.xcodeproj/project.pbxproj @@ -146,7 +146,7 @@ A898EF682182D35700CF291B /* MASJWKSet.m in Sources */ = {isa = PBXBuildFile; fileRef = A898EF662182D35700CF291B /* MASJWKSet.m */; }; A898EF6B2182D3DF00CF291B /* NSURLSession+MASPrivate.h in Headers */ = {isa = PBXBuildFile; fileRef = A898EF692182D3DF00CF291B /* NSURLSession+MASPrivate.h */; }; A898EF6C2182D3DF00CF291B /* NSURLSession+MASPrivate.m in Sources */ = {isa = PBXBuildFile; fileRef = A898EF6A2182D3DF00CF291B /* NSURLSession+MASPrivate.m */; }; - C81CC3CC1FC2EA190058718E /* MASBrowserBasedAuthentication.h in Headers */ = {isa = PBXBuildFile; fileRef = C81CC3CA1FC2EA190058718E /* MASBrowserBasedAuthentication.h */; }; + C81CC3CC1FC2EA190058718E /* MASBrowserBasedAuthentication.h in Headers */ = {isa = PBXBuildFile; fileRef = C81CC3CA1FC2EA190058718E /* MASBrowserBasedAuthentication.h */; settings = {ATTRIBUTES = (Public, ); }; }; C81CC3D01FC2EFBB0058718E /* UIAlertController+MAS.h in Headers */ = {isa = PBXBuildFile; fileRef = C81CC3CE1FC2EFBB0058718E /* UIAlertController+MAS.h */; }; C81CC3D11FC2EFBB0058718E /* UIAlertController+MAS.m in Sources */ = {isa = PBXBuildFile; fileRef = C81CC3CF1FC2EFBB0058718E /* UIAlertController+MAS.m */; }; C858D6B52398FC5400963763 /* MASDataTask+MASPrivate.h in Headers */ = {isa = PBXBuildFile; fileRef = C858D6B32398FC5400963763 /* MASDataTask+MASPrivate.h */; }; @@ -326,6 +326,8 @@ CBD25B151E7A0A9200DFB47F /* MF_Base64Additions.m in Sources */ = {isa = PBXBuildFile; fileRef = CBD25B131E7A0A9200DFB47F /* MF_Base64Additions.m */; }; CBFA70F41F1ED5D6006D025D /* MASSecurityPolicy.h in Headers */ = {isa = PBXBuildFile; fileRef = CBFA70F21F1ED5D6006D025D /* MASSecurityPolicy.h */; }; CBFA70F51F1ED5D6006D025D /* MASSecurityPolicy.m in Sources */ = {isa = PBXBuildFile; fileRef = CBFA70F31F1ED5D6006D025D /* MASSecurityPolicy.m */; }; + E0A461A72590972200C21439 /* MASBrowserBasedAuthenticationConfiguration.m in Sources */ = {isa = PBXBuildFile; fileRef = E0A461A62590972200C21439 /* MASBrowserBasedAuthenticationConfiguration.m */; }; + E0A461AA2590985900C21439 /* MASBrowserBasedAuthenticationConfiguration.h in Headers */ = {isa = PBXBuildFile; fileRef = E0A461A12590955B00C21439 /* MASBrowserBasedAuthenticationConfiguration.h */; settings = {ATTRIBUTES = (Public, ); }; }; E0BA784D257E7FEF0003A9B8 /* MASSafariBrowserBasedAuthentication.m in Sources */ = {isa = PBXBuildFile; fileRef = E0BA784B257E7FEF0003A9B8 /* MASSafariBrowserBasedAuthentication.m */; }; E0BA7861257EB8C00003A9B8 /* MASWebSessionBrowserBasedAuthentication.m in Sources */ = {isa = PBXBuildFile; fileRef = E0BA785F257EB8C00003A9B8 /* MASWebSessionBrowserBasedAuthentication.m */; }; E0BA7867257F62570003A9B8 /* MASSafariBrowserBasedAuthentication.h in Headers */ = {isa = PBXBuildFile; fileRef = E0BA784A257E7FEF0003A9B8 /* MASSafariBrowserBasedAuthentication.h */; }; @@ -694,6 +696,8 @@ CBD25B131E7A0A9200DFB47F /* MF_Base64Additions.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MF_Base64Additions.m; sourceTree = ""; }; CBFA70F21F1ED5D6006D025D /* MASSecurityPolicy.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MASSecurityPolicy.h; sourceTree = ""; }; CBFA70F31F1ED5D6006D025D /* MASSecurityPolicy.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MASSecurityPolicy.m; sourceTree = ""; }; + E0A461A12590955B00C21439 /* MASBrowserBasedAuthenticationConfiguration.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MASBrowserBasedAuthenticationConfiguration.h; sourceTree = ""; }; + E0A461A62590972200C21439 /* MASBrowserBasedAuthenticationConfiguration.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = MASBrowserBasedAuthenticationConfiguration.m; sourceTree = ""; }; E0BA7849257E7FA60003A9B8 /* MASTypedBrowserBasedAuthenticationInterface.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MASTypedBrowserBasedAuthenticationInterface.h; sourceTree = ""; }; E0BA784A257E7FEF0003A9B8 /* MASSafariBrowserBasedAuthentication.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MASSafariBrowserBasedAuthentication.h; sourceTree = ""; }; E0BA784B257E7FEF0003A9B8 /* MASSafariBrowserBasedAuthentication.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = MASSafariBrowserBasedAuthentication.m; sourceTree = ""; }; @@ -1015,6 +1019,8 @@ CB1FD14A1FB23701000AFA25 /* MASSharedStorage.m */, C81CC3CA1FC2EA190058718E /* MASBrowserBasedAuthentication.h */, C81CC3CB1FC2EA190058718E /* MASBrowserBasedAuthentication.m */, + E0A461A12590955B00C21439 /* MASBrowserBasedAuthenticationConfiguration.h */, + E0A461A62590972200C21439 /* MASBrowserBasedAuthenticationConfiguration.m */, ); path = models; sourceTree = ""; @@ -1588,6 +1594,7 @@ CBAFD2501F2BD48B0034DF02 /* MASSecurityConfiguration+MASPrivate.h in Headers */, CB23579A1F100EC400D4C420 /* MASSessionDataTaskOperation.h in Headers */, A4831AB31BD1A551007B4AE6 /* MASObject.h in Headers */, + E0A461AA2590985900C21439 /* MASBrowserBasedAuthenticationConfiguration.h in Headers */, E3662A3F23DEE557007A76A1 /* MASISecurityPolicy.h in Headers */, CBD25AF71E78C47C00DFB47F /* JWTCryptoSecurity.h in Headers */, CB58986B1F183E0A005C1E82 /* MASAuthValidationOperation.h in Headers */, @@ -1947,6 +1954,7 @@ E3662A3B23DEE52C007A76A1 /* MASIURLResponseSerialization.m in Sources */, 69B7DF6B1F9675600056DD3A /* MASRequestBuilder.m in Sources */, CBBA9A8120742BA800BB307F /* MASNetworkReachability.m in Sources */, + E0A461A72590972200C21439 /* MASBrowserBasedAuthenticationConfiguration.m in Sources */, A4150EFE1BF16EE200037E27 /* MASSecurityService.m in Sources */, A46F49C21C2F5FC500A4C370 /* MASIKeyChainStore.m in Sources */, CB1907F91C17950700A5EF16 /* MASAccessService.m in Sources */, diff --git a/MASFoundation/Classes/MAS.h b/MASFoundation/Classes/MAS.h index 08d69cee..265964a3 100644 --- a/MASFoundation/Classes/MAS.h +++ b/MASFoundation/Classes/MAS.h @@ -15,6 +15,7 @@ #import "MASRequest.h" #import "MASMultiFactorAuthenticator.h" #import "MASMultiPartFormData.h" +#import "MASBrowserBasedAuthenticationConfiguration.h" /** * The top level MAS object represents the Mobile App Services SDK in it's entirety. It @@ -196,12 +197,12 @@ /** - * Sets preferred type of browser used for Browser Based Authentication (templatized login). - * By default this is `MASBrowserBasedAuthenticationTypeSafari`. + * Sets a configuration to use for Browser Based Authentication (templatized login). + * By default this is `MASSafariBrowserBasedAuthenticationConfiguration`. - @param browserBasedAuthenticationType MASBrowserBasedAuthenticationType value indicating which type of browser should be used for Browser Based Authentication. + @param configuration MASBrowserBasedAuthenticationConfigurationInterface conforming object to configure the browser based authentication.. */ -+ (void)preferredBrowserBasedAuthenticationType:(MASBrowserBasedAuthenticationType)browserBasedAuthenticationType; ++ (void)preferredBrowserBasedAuthenticationConfiguration:(id _Nonnull)configuration; /** diff --git a/MASFoundation/Classes/MAS.m b/MASFoundation/Classes/MAS.m index f4a692a4..062513a1 100644 --- a/MASFoundation/Classes/MAS.m +++ b/MASFoundation/Classes/MAS.m @@ -123,9 +123,9 @@ + (void)enableBrowserBasedAuthentication:(BOOL)enable } -+ (void)preferredBrowserBasedAuthenticationType:(MASBrowserBasedAuthenticationType)browserBasedAuthenticationType ++ (void)preferredBrowserBasedAuthenticationConfiguration:(id _Nonnull)configuration { - [MASModelService setBrowserBasedAuthenticationType:browserBasedAuthenticationType]; + [MASModelService setBrowserBasedAuthenticationConfiguration:configuration]; } diff --git a/MASFoundation/Classes/MASConstants.h b/MASFoundation/Classes/MASConstants.h index 83311ab3..99cb13c6 100644 --- a/MASFoundation/Classes/MASConstants.h +++ b/MASFoundation/Classes/MASConstants.h @@ -310,22 +310,6 @@ typedef NS_ENUM(NSInteger, MASState) { }; -/** - * The enumerated MASBrowserBasedAuthenticationTypes that can be used to initiate a browser based login - */ -typedef NS_CLOSED_ENUM(NSUInteger, MASBrowserBasedAuthenticationType) { - - /** - * Type which tells the SDK an SFSafariViewController should be used when the user invokes browser based authentication. - */ - MASBrowserBasedAuthenticationTypeSafari, - /** - * Type which tells the SDK an ASWebAuthenticationSession should be used when the user invokes browser based authentication. - */ - MASBrowserBasedAuthenticationTypeWebSession API_AVAILABLE(ios(12.0), macCatalyst(13.0), macos(10.15), watchos(6.2)) API_UNAVAILABLE(tvos) -}; - - /** * Enumerated MASFileDirectoryType that indicates which directory to store MASFile into. */ diff --git a/MASFoundation/Classes/_private_/models/MASTypedBrowserBasedAuthenticationFactory.h b/MASFoundation/Classes/_private_/models/MASTypedBrowserBasedAuthenticationFactory.h index e2c3eb9b..300e8a8e 100644 --- a/MASFoundation/Classes/_private_/models/MASTypedBrowserBasedAuthenticationFactory.h +++ b/MASFoundation/Classes/_private_/models/MASTypedBrowserBasedAuthenticationFactory.h @@ -12,6 +12,7 @@ #import "MASConstants.h" @protocol MASTypedBrowserBasedAuthenticationInterface; +@protocol MASBrowserBasedAuthenticationConfigurationInterface; /** * Utility factory class to build the correct browser type to use @@ -21,9 +22,9 @@ /** * Build a new browser used for Browser Based Authentication * - * @param browserBasedAuthenticationType A MASBrowserBasedAuthenticationType object telling the factory what to build information. + * @param configuration MASBrowserBasedAuthenticationConfigurationInterface conforming object telling the factory what and how to build its product. * @return id object which can be used to start Browser Based Authentication. */ -+ (id)buildBrowserForType:(MASBrowserBasedAuthenticationType)browserBasedAuthenticationType; ++ (id)buildBrowserWithConfiguration:(id)configuration; @end diff --git a/MASFoundation/Classes/_private_/models/MASTypedBrowserBasedAuthenticationFactory.m b/MASFoundation/Classes/_private_/models/MASTypedBrowserBasedAuthenticationFactory.m index 21bffb35..f2280304 100644 --- a/MASFoundation/Classes/_private_/models/MASTypedBrowserBasedAuthenticationFactory.m +++ b/MASFoundation/Classes/_private_/models/MASTypedBrowserBasedAuthenticationFactory.m @@ -9,21 +9,29 @@ // #import "MASTypedBrowserBasedAuthenticationFactory.h" +#import "MASBrowserBasedAuthenticationConfiguration.h" #import "MASSafariBrowserBasedAuthentication.h" #import "MASWebSessionBrowserBasedAuthentication.h" @implementation MASTypedBrowserBasedAuthenticationFactory -+ (id)buildBrowserForType:(MASBrowserBasedAuthenticationType)browserBasedAuthenticationType { - if (@available(iOS 12.0, macOS 10.15, *)) { - switch (browserBasedAuthenticationType) { - case MASBrowserBasedAuthenticationTypeSafari: - return [[MASSafariBrowserBasedAuthentication alloc] init]; - case MASBrowserBasedAuthenticationTypeWebSession: - return [[MASWebSessionBrowserBasedAuthentication alloc] init]; - } - } else { ++ (id)buildBrowserWithConfiguration:(id)configuration { + + if ([configuration isKindOfClass: [MASSafariBrowserBasedAuthenticationConfiguration class]]) + { return [[MASSafariBrowserBasedAuthentication alloc] init]; } + if (@available(iOS 12.0, macOS 10.15, *)) + { + if ([configuration isKindOfClass: [MASWebSessionBrowserBasedAuthenticationConfiguration class]]) + { + MASWebSessionBrowserBasedAuthenticationConfiguration *castedConfiguration = configuration; + + return [[MASWebSessionBrowserBasedAuthentication alloc] initWithCallbackURLScheme:castedConfiguration.callbackURLScheme]; + } + } + + @throw [NSException exceptionWithName:NSInternalInconsistencyException reason:@"Cannot produce result with the provided configuration." userInfo:nil]; + return nil; } @end diff --git a/MASFoundation/Classes/_private_/models/MASWebSessionBrowserBasedAuthentication.h b/MASFoundation/Classes/_private_/models/MASWebSessionBrowserBasedAuthentication.h index c23d662f..41848bdf 100644 --- a/MASFoundation/Classes/_private_/models/MASWebSessionBrowserBasedAuthentication.h +++ b/MASFoundation/Classes/_private_/models/MASWebSessionBrowserBasedAuthentication.h @@ -10,6 +10,12 @@ #import + + +NS_ASSUME_NONNULL_BEGIN + + + @protocol MASTypedBrowserBasedAuthenticationInterface; /** @@ -18,4 +24,23 @@ API_AVAILABLE(ios(12.0), macCatalyst(13.0), macos(10.15), watchos(6.2)) @interface MASWebSessionBrowserBasedAuthentication : NSObject + +///-------------------------------------- +/// @name Lifecycle +///-------------------------------------- + +# pragma mark - Lifecycle + +/** + * Initializer to perform default initialization. + * + * @param callbackURLScheme NSString containing the callback url scheme to use. + * @return Returns the newly initialized MASWebSessionBrowserBasedAuthentication. + */ +- (instancetype)initWithCallbackURLScheme:(NSString *)callbackURLScheme; + @end + + + +NS_ASSUME_NONNULL_END diff --git a/MASFoundation/Classes/_private_/models/MASWebSessionBrowserBasedAuthentication.m b/MASFoundation/Classes/_private_/models/MASWebSessionBrowserBasedAuthentication.m index aae83bd0..179d9e5f 100644 --- a/MASFoundation/Classes/_private_/models/MASWebSessionBrowserBasedAuthentication.m +++ b/MASFoundation/Classes/_private_/models/MASWebSessionBrowserBasedAuthentication.m @@ -30,6 +30,9 @@ @interface MASWebSessionBrowserBasedAuthentication() @property (nonatomic, weak) id window; + +@property (nonatomic, strong) NSString *callbackURLScheme; + @end API_AVAILABLE(ios(13.0), macos(10.15)) @@ -39,16 +42,29 @@ @interface MASWebSessionBrowserBasedAuthentication() )configuration; /** - * The current browser based authentication type. + * The current browser based authentication configuration. * - * @return MASBrowserBasedAuthenticationType value is returned. + * @return MASBrowserBasedAuthenticationConfigurationInterface conforming object is returned. */ -+ (MASBrowserBasedAuthenticationType)browserBasedAuthenticationType; ++ (id)browserBasedAuthenticationConfiguration; ///-------------------------------------- diff --git a/MASFoundation/Classes/_private_/services/model/MASModelService.m b/MASFoundation/Classes/_private_/services/model/MASModelService.m index 67a99908..40a69ec5 100644 --- a/MASFoundation/Classes/_private_/services/model/MASModelService.m +++ b/MASFoundation/Classes/_private_/services/model/MASModelService.m @@ -41,7 +41,7 @@ @implementation MASModelService static MASGrantFlow _grantFlow_ = MASGrantFlowClientCredentials; static MASUserAuthCredentialsBlock _userAuthCredentialsBlock_ = nil; static BOOL _isBrowserBasedAuthentication_ = NO; -static MASBrowserBasedAuthenticationType _browserBasedAuthenticationType_ = MASBrowserBasedAuthenticationTypeSafari; +static id _browserBasedAuthenticationConfiguration_; # pragma mark - Properties @@ -87,15 +87,19 @@ + (BOOL)browserBasedAuthentication } -+ (void)setBrowserBasedAuthenticationType:(MASBrowserBasedAuthenticationType)browserBasedAuthenticationType ++ (void)setBrowserBasedAuthenticationConfiguration:(id)configuration { - _browserBasedAuthenticationType_ = browserBasedAuthenticationType; + _browserBasedAuthenticationConfiguration_ = configuration; } -+ (MASBrowserBasedAuthenticationType)browserBasedAuthenticationType ++ (id)browserBasedAuthenticationConfiguration { - return _browserBasedAuthenticationType_; + if (_browserBasedAuthenticationConfiguration_ == nil) + { + _browserBasedAuthenticationConfiguration_ = [[MASSafariBrowserBasedAuthenticationConfiguration alloc] init]; + } + return _browserBasedAuthenticationConfiguration_; } diff --git a/MASFoundation/Classes/models/MASBrowserBasedAuthentication.m b/MASFoundation/Classes/models/MASBrowserBasedAuthentication.m index d097cddc..a4e4f40a 100644 --- a/MASFoundation/Classes/models/MASBrowserBasedAuthentication.m +++ b/MASFoundation/Classes/models/MASBrowserBasedAuthentication.m @@ -232,8 +232,8 @@ - (BOOL)redirectURLHasErrors :(NSURL*)redirectURL - (void)launchBrowserWithURL:(NSURL*)templatizedURL { - MASBrowserBasedAuthenticationType type = [MASModelService browserBasedAuthenticationType]; - self.browser = [MASTypedBrowserBasedAuthenticationFactory buildBrowserForType:type]; + id configuration = [MASModelService browserBasedAuthenticationConfiguration]; + self.browser = [MASTypedBrowserBasedAuthenticationFactory buildBrowserWithConfiguration:configuration]; [self.browser startWithURL:templatizedURL completion: self.webLoginCallBack]; } diff --git a/MASFoundation/Classes/models/MASBrowserBasedAuthenticationConfiguration.h b/MASFoundation/Classes/models/MASBrowserBasedAuthenticationConfiguration.h new file mode 100644 index 00000000..88859f74 --- /dev/null +++ b/MASFoundation/Classes/models/MASBrowserBasedAuthenticationConfiguration.h @@ -0,0 +1,54 @@ +// +// MASBrowserBasedAuthenticationConfigurationInterface.h +// MASFoundation +// +// Created by sander saelmans on 21/12/2020. +// Copyright © 2020 CA Technologies. All rights reserved. +// + +#import + +/** + MASBrowserBasedAuthenticationConfigurationInterface protocol is used to define a set of object which can be used to configure the preferred browser based authentication behaviour + */ +@protocol MASBrowserBasedAuthenticationConfigurationInterface +@end + + + +/** + MASSafariBrowserBasedAuthenticationConfiguration class is used to present a SFSafariViewController browser based login + */ +@interface MASSafariBrowserBasedAuthenticationConfiguration : NSObject + +@end + + + + +API_AVAILABLE(ios(12.0), macCatalyst(13.0), macos(10.15), watchos(6.2)) API_UNAVAILABLE(tvos) +/** + MASSafariBrowserBasedAuthenticationConfiguration class is used to present a ASWebAuthenticationSession browser based login + @note You have to provide a valid callback url scheme in order for this configuration to work properly. + */ +@interface MASWebSessionBrowserBasedAuthenticationConfiguration : NSObject + + +@property (nonatomic, strong, nonnull) NSString *callbackURLScheme; + + +/** + * Initialises a MASWebSessionBrowserBasedAuthenticationConfiguration with the provided callback url scheme + * + * @param callbackURLScheme Nonnull NSString object represeting the callback url scheme used to notify the login session has concluded. + * @return Returns an initialized MASWebSessionBrowserBasedAuthenticationConfiguration + */ +- (instancetype _Nonnull)initWithCallbackURLScheme:(NSString * _Nonnull)callbackURLScheme; + + +- (instancetype _Null_unspecified)init NS_UNAVAILABLE; + + ++ (instancetype _Null_unspecified)new NS_UNAVAILABLE; + +@end diff --git a/MASFoundation/Classes/models/MASBrowserBasedAuthenticationConfiguration.m b/MASFoundation/Classes/models/MASBrowserBasedAuthenticationConfiguration.m new file mode 100644 index 00000000..bfc8787a --- /dev/null +++ b/MASFoundation/Classes/models/MASBrowserBasedAuthenticationConfiguration.m @@ -0,0 +1,25 @@ +// +// MASBrowserBasedAuthenticationConfiguration.m +// MASFoundation +// +// Created by sander saelmans on 21/12/2020. +// Copyright © 2020 CA Technologies. All rights reserved. +// + +#import +#import "MASBrowserBasedAuthenticationConfiguration.h" + +@implementation MASSafariBrowserBasedAuthenticationConfiguration +@end + +@implementation MASWebSessionBrowserBasedAuthenticationConfiguration + +- (instancetype)initWithCallbackURLScheme:(NSString *)callbackURLScheme +{ + self = [super init]; + self.callbackURLScheme = callbackURLScheme; + + return self; +} +@end + diff --git a/MASFoundation/Classes/models/MFA/MASMultiFactorHandler.h b/MASFoundation/Classes/models/MFA/MASMultiFactorHandler.h index 5e9ace76..46a2a146 100644 --- a/MASFoundation/Classes/models/MFA/MASMultiFactorHandler.h +++ b/MASFoundation/Classes/models/MFA/MASMultiFactorHandler.h @@ -49,7 +49,7 @@ @return nil will always be returned with this initialization method. */ -- (instancetype _Nullable)init NS_UNAVAILABLE; +- (instancetype _Null_unspecified)init NS_UNAVAILABLE; @@ -58,7 +58,7 @@ @return nil will always be returned with this initialization method. */ -+ (instancetype _Nullable)new NS_UNAVAILABLE; ++ (instancetype _Null_unspecified)new NS_UNAVAILABLE; From 4e6029db08ca79cec6fc787f4a5fe866aa5fba14 Mon Sep 17 00:00:00 2001 From: Sander Saelmans Date: Mon, 1 Feb 2021 10:32:42 +0100 Subject: [PATCH 16/16] Removed the need to provide a url scheme when using the Web session browser type. Also improved interface when setting the type of browser used for swift. --- MASFoundation.xcodeproj/project.pbxproj | 32 +++++------ MASFoundation/Classes/MAS.h | 9 ++-- MASFoundation/Classes/MAS.m | 4 +- MASFoundation/Classes/MASConstants.h | 17 ++++++ ...=> MASBrowserBasedAuthenticationFactory.h} | 9 ++-- .../MASBrowserBasedAuthenticationFactory.m | 26 +++++++++ ... MASBrowserBasedAuthenticationInterface.h} | 4 +- .../MASSafariBrowserBasedAuthentication.h | 4 +- .../MASSafariBrowserBasedAuthentication.m | 2 +- ...ASTypedBrowserBasedAuthenticationFactory.m | 37 ------------- .../MASWebSessionBrowserBasedAuthentication.h | 19 +------ .../MASWebSessionBrowserBasedAuthentication.m | 22 ++------ .../services/model/MASModelService.h | 13 +++-- .../services/model/MASModelService.m | 14 ++--- .../models/MASBrowserBasedAuthentication.m | 10 ++-- ...SBrowserBasedAuthenticationConfiguration.h | 54 ------------------- ...SBrowserBasedAuthenticationConfiguration.m | 25 --------- 17 files changed, 93 insertions(+), 208 deletions(-) rename MASFoundation/Classes/_private_/models/{MASTypedBrowserBasedAuthenticationFactory.h => MASBrowserBasedAuthenticationFactory.h} (54%) create mode 100644 MASFoundation/Classes/_private_/models/MASBrowserBasedAuthenticationFactory.m rename MASFoundation/Classes/_private_/models/{MASTypedBrowserBasedAuthenticationInterface.h => MASBrowserBasedAuthenticationInterface.h} (85%) delete mode 100644 MASFoundation/Classes/_private_/models/MASTypedBrowserBasedAuthenticationFactory.m delete mode 100644 MASFoundation/Classes/models/MASBrowserBasedAuthenticationConfiguration.h delete mode 100644 MASFoundation/Classes/models/MASBrowserBasedAuthenticationConfiguration.m diff --git a/MASFoundation.xcodeproj/project.pbxproj b/MASFoundation.xcodeproj/project.pbxproj index 1e1de0a2..1d0d2b70 100644 --- a/MASFoundation.xcodeproj/project.pbxproj +++ b/MASFoundation.xcodeproj/project.pbxproj @@ -326,16 +326,14 @@ CBD25B151E7A0A9200DFB47F /* MF_Base64Additions.m in Sources */ = {isa = PBXBuildFile; fileRef = CBD25B131E7A0A9200DFB47F /* MF_Base64Additions.m */; }; CBFA70F41F1ED5D6006D025D /* MASSecurityPolicy.h in Headers */ = {isa = PBXBuildFile; fileRef = CBFA70F21F1ED5D6006D025D /* MASSecurityPolicy.h */; }; CBFA70F51F1ED5D6006D025D /* MASSecurityPolicy.m in Sources */ = {isa = PBXBuildFile; fileRef = CBFA70F31F1ED5D6006D025D /* MASSecurityPolicy.m */; }; - E0A461A72590972200C21439 /* MASBrowserBasedAuthenticationConfiguration.m in Sources */ = {isa = PBXBuildFile; fileRef = E0A461A62590972200C21439 /* MASBrowserBasedAuthenticationConfiguration.m */; }; - E0A461AA2590985900C21439 /* MASBrowserBasedAuthenticationConfiguration.h in Headers */ = {isa = PBXBuildFile; fileRef = E0A461A12590955B00C21439 /* MASBrowserBasedAuthenticationConfiguration.h */; settings = {ATTRIBUTES = (Public, ); }; }; E0BA784D257E7FEF0003A9B8 /* MASSafariBrowserBasedAuthentication.m in Sources */ = {isa = PBXBuildFile; fileRef = E0BA784B257E7FEF0003A9B8 /* MASSafariBrowserBasedAuthentication.m */; }; E0BA7861257EB8C00003A9B8 /* MASWebSessionBrowserBasedAuthentication.m in Sources */ = {isa = PBXBuildFile; fileRef = E0BA785F257EB8C00003A9B8 /* MASWebSessionBrowserBasedAuthentication.m */; }; E0BA7867257F62570003A9B8 /* MASSafariBrowserBasedAuthentication.h in Headers */ = {isa = PBXBuildFile; fileRef = E0BA784A257E7FEF0003A9B8 /* MASSafariBrowserBasedAuthentication.h */; }; E0BA7869257F62590003A9B8 /* MASWebSessionBrowserBasedAuthentication.h in Headers */ = {isa = PBXBuildFile; fileRef = E0BA785E257EB8C00003A9B8 /* MASWebSessionBrowserBasedAuthentication.h */; }; - E0BA786D257F62820003A9B8 /* MASTypedBrowserBasedAuthenticationInterface.h in Headers */ = {isa = PBXBuildFile; fileRef = E0BA7849257E7FA60003A9B8 /* MASTypedBrowserBasedAuthenticationInterface.h */; }; + E0BA786D257F62820003A9B8 /* MASBrowserBasedAuthenticationInterface.h in Headers */ = {isa = PBXBuildFile; fileRef = E0BA7849257E7FA60003A9B8 /* MASBrowserBasedAuthenticationInterface.h */; }; E0BA7877257F708A0003A9B8 /* MASBrowserBasedAuthentication.m in Sources */ = {isa = PBXBuildFile; fileRef = C81CC3CB1FC2EA190058718E /* MASBrowserBasedAuthentication.m */; }; - E0BA788A257F78820003A9B8 /* MASTypedBrowserBasedAuthenticationFactory.h in Headers */ = {isa = PBXBuildFile; fileRef = E0BA7888257F78820003A9B8 /* MASTypedBrowserBasedAuthenticationFactory.h */; }; - E0BA788B257F78820003A9B8 /* MASTypedBrowserBasedAuthenticationFactory.m in Sources */ = {isa = PBXBuildFile; fileRef = E0BA7889257F78820003A9B8 /* MASTypedBrowserBasedAuthenticationFactory.m */; }; + E0BA788A257F78820003A9B8 /* MASBrowserBasedAuthenticationFactory.h in Headers */ = {isa = PBXBuildFile; fileRef = E0BA7888257F78820003A9B8 /* MASBrowserBasedAuthenticationFactory.h */; }; + E0BA788B257F78820003A9B8 /* MASBrowserBasedAuthenticationFactory.m in Sources */ = {isa = PBXBuildFile; fileRef = E0BA7889257F78820003A9B8 /* MASBrowserBasedAuthenticationFactory.m */; }; E3662A3723DEE503007A76A1 /* MASIHTTPRequestOperation.h in Headers */ = {isa = PBXBuildFile; fileRef = E3662A3523DEE502007A76A1 /* MASIHTTPRequestOperation.h */; }; E3662A3823DEE503007A76A1 /* MASIHTTPRequestOperation.m in Sources */ = {isa = PBXBuildFile; fileRef = E3662A3623DEE502007A76A1 /* MASIHTTPRequestOperation.m */; }; E3662A3B23DEE52C007A76A1 /* MASIURLResponseSerialization.m in Sources */ = {isa = PBXBuildFile; fileRef = E3662A3923DEE52B007A76A1 /* MASIURLResponseSerialization.m */; }; @@ -696,15 +694,13 @@ CBD25B131E7A0A9200DFB47F /* MF_Base64Additions.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MF_Base64Additions.m; sourceTree = ""; }; CBFA70F21F1ED5D6006D025D /* MASSecurityPolicy.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MASSecurityPolicy.h; sourceTree = ""; }; CBFA70F31F1ED5D6006D025D /* MASSecurityPolicy.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MASSecurityPolicy.m; sourceTree = ""; }; - E0A461A12590955B00C21439 /* MASBrowserBasedAuthenticationConfiguration.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MASBrowserBasedAuthenticationConfiguration.h; sourceTree = ""; }; - E0A461A62590972200C21439 /* MASBrowserBasedAuthenticationConfiguration.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = MASBrowserBasedAuthenticationConfiguration.m; sourceTree = ""; }; - E0BA7849257E7FA60003A9B8 /* MASTypedBrowserBasedAuthenticationInterface.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MASTypedBrowserBasedAuthenticationInterface.h; sourceTree = ""; }; + E0BA7849257E7FA60003A9B8 /* MASBrowserBasedAuthenticationInterface.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MASBrowserBasedAuthenticationInterface.h; sourceTree = ""; }; E0BA784A257E7FEF0003A9B8 /* MASSafariBrowserBasedAuthentication.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MASSafariBrowserBasedAuthentication.h; sourceTree = ""; }; E0BA784B257E7FEF0003A9B8 /* MASSafariBrowserBasedAuthentication.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = MASSafariBrowserBasedAuthentication.m; sourceTree = ""; }; E0BA785E257EB8C00003A9B8 /* MASWebSessionBrowserBasedAuthentication.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MASWebSessionBrowserBasedAuthentication.h; sourceTree = ""; }; E0BA785F257EB8C00003A9B8 /* MASWebSessionBrowserBasedAuthentication.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = MASWebSessionBrowserBasedAuthentication.m; sourceTree = ""; }; - E0BA7888257F78820003A9B8 /* MASTypedBrowserBasedAuthenticationFactory.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MASTypedBrowserBasedAuthenticationFactory.h; sourceTree = ""; }; - E0BA7889257F78820003A9B8 /* MASTypedBrowserBasedAuthenticationFactory.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = MASTypedBrowserBasedAuthenticationFactory.m; sourceTree = ""; }; + E0BA7888257F78820003A9B8 /* MASBrowserBasedAuthenticationFactory.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MASBrowserBasedAuthenticationFactory.h; sourceTree = ""; }; + E0BA7889257F78820003A9B8 /* MASBrowserBasedAuthenticationFactory.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = MASBrowserBasedAuthenticationFactory.m; sourceTree = ""; }; E3662A3523DEE502007A76A1 /* MASIHTTPRequestOperation.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MASIHTTPRequestOperation.h; sourceTree = ""; }; E3662A3623DEE502007A76A1 /* MASIHTTPRequestOperation.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MASIHTTPRequestOperation.m; sourceTree = ""; }; E3662A3923DEE52B007A76A1 /* MASIURLResponseSerialization.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MASIURLResponseSerialization.m; sourceTree = ""; }; @@ -1019,8 +1015,6 @@ CB1FD14A1FB23701000AFA25 /* MASSharedStorage.m */, C81CC3CA1FC2EA190058718E /* MASBrowserBasedAuthentication.h */, C81CC3CB1FC2EA190058718E /* MASBrowserBasedAuthentication.m */, - E0A461A12590955B00C21439 /* MASBrowserBasedAuthenticationConfiguration.h */, - E0A461A62590972200C21439 /* MASBrowserBasedAuthenticationConfiguration.m */, ); path = models; sourceTree = ""; @@ -1142,13 +1136,13 @@ A898EF662182D35700CF291B /* MASJWKSet.m */, CBA3EB301E94634C00E64D9D /* MASClaims+MASPrivate.h */, CBA3EB311E94634C00E64D9D /* MASClaims+MASPrivate.m */, - E0BA7849257E7FA60003A9B8 /* MASTypedBrowserBasedAuthenticationInterface.h */, + E0BA7849257E7FA60003A9B8 /* MASBrowserBasedAuthenticationInterface.h */, E0BA784A257E7FEF0003A9B8 /* MASSafariBrowserBasedAuthentication.h */, E0BA784B257E7FEF0003A9B8 /* MASSafariBrowserBasedAuthentication.m */, E0BA785E257EB8C00003A9B8 /* MASWebSessionBrowserBasedAuthentication.h */, E0BA785F257EB8C00003A9B8 /* MASWebSessionBrowserBasedAuthentication.m */, - E0BA7888257F78820003A9B8 /* MASTypedBrowserBasedAuthenticationFactory.h */, - E0BA7889257F78820003A9B8 /* MASTypedBrowserBasedAuthenticationFactory.m */, + E0BA7888257F78820003A9B8 /* MASBrowserBasedAuthenticationFactory.h */, + E0BA7889257F78820003A9B8 /* MASBrowserBasedAuthenticationFactory.m */, ); path = models; sourceTree = ""; @@ -1520,14 +1514,14 @@ CB9B1207210949D5008A2075 /* NSMutableData+MASASN1Helper.h in Headers */, CBA3EB2E1E945F2400E64D9D /* MASClaims.h in Headers */, CB0B58591E258C2A00BC0163 /* MASAuthorizationResponse.h in Headers */, - E0BA786D257F62820003A9B8 /* MASTypedBrowserBasedAuthenticationInterface.h in Headers */, + E0BA786D257F62820003A9B8 /* MASBrowserBasedAuthenticationInterface.h in Headers */, CBA3EB321E94634C00E64D9D /* MASClaims+MASPrivate.h in Headers */, CBD25AFF1E78C47C00DFB47F /* JWTClaimsSetVerifier.h in Headers */, CBD25AF21E78C47C00DFB47F /* JWTRSAlgorithm.h in Headers */, CB6491F01FE9DAF300281288 /* MQTTPersistence.h in Headers */, 10E027A11F72B10100EAB103 /* RNCryptor+Private.h in Headers */, CBD25B0C1E78C47C00DFB47F /* JWTBase64Coder.h in Headers */, - E0BA788A257F78820003A9B8 /* MASTypedBrowserBasedAuthenticationFactory.h in Headers */, + E0BA788A257F78820003A9B8 /* MASBrowserBasedAuthenticationFactory.h in Headers */, A419B3A11C176259008DC88C /* NSData+MAS.h in Headers */, A488CE751C0B97FD00B8B961 /* MASService.h in Headers */, CB6491FB1FE9DAF300281288 /* MQTTSSLSecurityPolicy.h in Headers */, @@ -1594,7 +1588,6 @@ CBAFD2501F2BD48B0034DF02 /* MASSecurityConfiguration+MASPrivate.h in Headers */, CB23579A1F100EC400D4C420 /* MASSessionDataTaskOperation.h in Headers */, A4831AB31BD1A551007B4AE6 /* MASObject.h in Headers */, - E0A461AA2590985900C21439 /* MASBrowserBasedAuthenticationConfiguration.h in Headers */, E3662A3F23DEE557007A76A1 /* MASISecurityPolicy.h in Headers */, CBD25AF71E78C47C00DFB47F /* JWTCryptoSecurity.h in Headers */, CB58986B1F183E0A005C1E82 /* MASAuthValidationOperation.h in Headers */, @@ -1814,7 +1807,7 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( - E0BA788B257F78820003A9B8 /* MASTypedBrowserBasedAuthenticationFactory.m in Sources */, + E0BA788B257F78820003A9B8 /* MASBrowserBasedAuthenticationFactory.m in Sources */, CB5E4C711C1D250D001B3B8A /* MASPutURLRequest.m in Sources */, CB2A4056209B9DA600F988AA /* MASMultiFactorHandler+MASPrivate.m in Sources */, A858C6661D0978A6001FB9AD /* MASOTPService.m in Sources */, @@ -1954,7 +1947,6 @@ E3662A3B23DEE52C007A76A1 /* MASIURLResponseSerialization.m in Sources */, 69B7DF6B1F9675600056DD3A /* MASRequestBuilder.m in Sources */, CBBA9A8120742BA800BB307F /* MASNetworkReachability.m in Sources */, - E0A461A72590972200C21439 /* MASBrowserBasedAuthenticationConfiguration.m in Sources */, A4150EFE1BF16EE200037E27 /* MASSecurityService.m in Sources */, A46F49C21C2F5FC500A4C370 /* MASIKeyChainStore.m in Sources */, CB1907F91C17950700A5EF16 /* MASAccessService.m in Sources */, diff --git a/MASFoundation/Classes/MAS.h b/MASFoundation/Classes/MAS.h index 265964a3..75490163 100644 --- a/MASFoundation/Classes/MAS.h +++ b/MASFoundation/Classes/MAS.h @@ -15,7 +15,6 @@ #import "MASRequest.h" #import "MASMultiFactorAuthenticator.h" #import "MASMultiPartFormData.h" -#import "MASBrowserBasedAuthenticationConfiguration.h" /** * The top level MAS object represents the Mobile App Services SDK in it's entirety. It @@ -197,12 +196,12 @@ /** - * Sets a configuration to use for Browser Based Authentication (templatized login). - * By default this is `MASSafariBrowserBasedAuthenticationConfiguration`. + * Sets the type of browser to use for Browser Based Authentication (templatized login). + * By default this is `MASBrowserBasedAuthenticationBrowserTypeSafari`. - @param configuration MASBrowserBasedAuthenticationConfigurationInterface conforming object to configure the browser based authentication.. + @param browserType MASBrowserBasedAuthenticationBrowserType object indicating the browser type used for browser based authentication. */ -+ (void)preferredBrowserBasedAuthenticationConfiguration:(id _Nonnull)configuration; ++ (void)setBrowserBasedAuthenticationBrowserType:(MASBrowserBasedAuthenticationBrowserType)browserType; /** diff --git a/MASFoundation/Classes/MAS.m b/MASFoundation/Classes/MAS.m index 062513a1..22e5a43f 100644 --- a/MASFoundation/Classes/MAS.m +++ b/MASFoundation/Classes/MAS.m @@ -123,9 +123,9 @@ + (void)enableBrowserBasedAuthentication:(BOOL)enable } -+ (void)preferredBrowserBasedAuthenticationConfiguration:(id _Nonnull)configuration ++ (void)setBrowserBasedAuthenticationBrowserType:(MASBrowserBasedAuthenticationBrowserType)browserType { - [MASModelService setBrowserBasedAuthenticationConfiguration:configuration]; + [MASModelService setBrowserBasedAuthenticationBrowserType:browserType]; } diff --git a/MASFoundation/Classes/MASConstants.h b/MASFoundation/Classes/MASConstants.h index 99cb13c6..97a995e5 100644 --- a/MASFoundation/Classes/MASConstants.h +++ b/MASFoundation/Classes/MASConstants.h @@ -221,6 +221,23 @@ typedef NS_ENUM(NSInteger, MASGrantFlow) }; +/** + * The enumerated MASBrowserBasedAuthenticationBrowserType. + */ +typedef NS_ENUM(NSInteger, MASBrowserBasedAuthenticationBrowserType) +{ + /** + * Type used to launch browser based authentication in a `SafariViewController` + */ + MASBrowserBasedAuthenticationBrowserTypeSafari, + + /** + * Type used to launch browser based authentication in a `ASWebAuthenticationSession` + */ + MASBrowserBasedAuthenticationBrowserTypeWebSession API_AVAILABLE(ios(12.0), macCatalyst(13.0), macos(10.15), watchos(6.2)), +}; + + /** * The enumerated MASRequestResponseTypes that can indicate what data format is expected * in a request or a response. diff --git a/MASFoundation/Classes/_private_/models/MASTypedBrowserBasedAuthenticationFactory.h b/MASFoundation/Classes/_private_/models/MASBrowserBasedAuthenticationFactory.h similarity index 54% rename from MASFoundation/Classes/_private_/models/MASTypedBrowserBasedAuthenticationFactory.h rename to MASFoundation/Classes/_private_/models/MASBrowserBasedAuthenticationFactory.h index 300e8a8e..70a6b219 100644 --- a/MASFoundation/Classes/_private_/models/MASTypedBrowserBasedAuthenticationFactory.h +++ b/MASFoundation/Classes/_private_/models/MASBrowserBasedAuthenticationFactory.h @@ -11,20 +11,19 @@ #import #import "MASConstants.h" -@protocol MASTypedBrowserBasedAuthenticationInterface; -@protocol MASBrowserBasedAuthenticationConfigurationInterface; +@protocol MASBrowserBasedAuthenticationInterface; /** * Utility factory class to build the correct browser type to use */ -@interface MASTypedBrowserBasedAuthenticationFactory : NSObject +@interface MASBrowserBasedAuthenticationFactory : NSObject /** * Build a new browser used for Browser Based Authentication * - * @param configuration MASBrowserBasedAuthenticationConfigurationInterface conforming object telling the factory what and how to build its product. + * @param browserType MASBrowserBasedAuthenticationBrowserType object used to indicate type of browser built * @return id object which can be used to start Browser Based Authentication. */ -+ (id)buildBrowserWithConfiguration:(id)configuration; ++ (id)buildBrowserOfBrowserType:(MASBrowserBasedAuthenticationBrowserType)browserType; @end diff --git a/MASFoundation/Classes/_private_/models/MASBrowserBasedAuthenticationFactory.m b/MASFoundation/Classes/_private_/models/MASBrowserBasedAuthenticationFactory.m new file mode 100644 index 00000000..8695d451 --- /dev/null +++ b/MASFoundation/Classes/_private_/models/MASBrowserBasedAuthenticationFactory.m @@ -0,0 +1,26 @@ +// +// MASBrowserBasedAuthenticationFactory.m +// MASFoundation +// +// Copyright (c) 2020 CA. All rights reserved. +// +// This software may be modified and distributed under the terms +// of the MIT license. See the LICENSE file for details. +// + +#import "MASBrowserBasedAuthenticationFactory.h" +#import "MASSafariBrowserBasedAuthentication.h" +#import "MASWebSessionBrowserBasedAuthentication.h" + +@implementation MASBrowserBasedAuthenticationFactory + ++ (id)buildBrowserOfBrowserType:(MASBrowserBasedAuthenticationBrowserType)browserType { + + switch (browserType) { + case MASBrowserBasedAuthenticationBrowserTypeSafari: + return [[MASSafariBrowserBasedAuthentication alloc] init]; + case MASBrowserBasedAuthenticationBrowserTypeWebSession: + return [[MASWebSessionBrowserBasedAuthentication alloc] init]; + } +} +@end diff --git a/MASFoundation/Classes/_private_/models/MASTypedBrowserBasedAuthenticationInterface.h b/MASFoundation/Classes/_private_/models/MASBrowserBasedAuthenticationInterface.h similarity index 85% rename from MASFoundation/Classes/_private_/models/MASTypedBrowserBasedAuthenticationInterface.h rename to MASFoundation/Classes/_private_/models/MASBrowserBasedAuthenticationInterface.h index bb4b4937..ec821617 100644 --- a/MASFoundation/Classes/_private_/models/MASTypedBrowserBasedAuthenticationInterface.h +++ b/MASFoundation/Classes/_private_/models/MASBrowserBasedAuthenticationInterface.h @@ -1,5 +1,5 @@ // -// MASTypedBrowserBasedAuthenticationInterface.h +// MASBrowserBasedAuthenticationInterface.h // MASFoundation // // Copyright (c) 2020 CA. All rights reserved. @@ -12,7 +12,7 @@ /** * Interface used to abstract different type of browsers used for Browser Based Authentication */ -@protocol MASTypedBrowserBasedAuthenticationInterface +@protocol MASBrowserBasedAuthenticationInterface /** Starts the Browser based authentication with the given url and completion block. diff --git a/MASFoundation/Classes/_private_/models/MASSafariBrowserBasedAuthentication.h b/MASFoundation/Classes/_private_/models/MASSafariBrowserBasedAuthentication.h index 7bd71248..bcdb7f2c 100644 --- a/MASFoundation/Classes/_private_/models/MASSafariBrowserBasedAuthentication.h +++ b/MASFoundation/Classes/_private_/models/MASSafariBrowserBasedAuthentication.h @@ -10,11 +10,11 @@ #import -@protocol MASTypedBrowserBasedAuthenticationInterface; +@protocol MASBrowserBasedAuthenticationInterface; /** * A Browser Based Authentication type utilising an SFSafarViewController */ -@interface MASSafariBrowserBasedAuthentication : NSObject +@interface MASSafariBrowserBasedAuthentication : NSObject @end diff --git a/MASFoundation/Classes/_private_/models/MASSafariBrowserBasedAuthentication.m b/MASFoundation/Classes/_private_/models/MASSafariBrowserBasedAuthentication.m index f1767285..eaf693dd 100644 --- a/MASFoundation/Classes/_private_/models/MASSafariBrowserBasedAuthentication.m +++ b/MASFoundation/Classes/_private_/models/MASSafariBrowserBasedAuthentication.m @@ -10,7 +10,7 @@ #import #import "MASSafariBrowserBasedAuthentication.h" -#import "MASTypedBrowserBasedAuthenticationInterface.h" +#import "MASBrowserBasedAuthenticationInterface.h" #import "UIAlertController+MAS.h" @interface MASSafariBrowserBasedAuthentication() diff --git a/MASFoundation/Classes/_private_/models/MASTypedBrowserBasedAuthenticationFactory.m b/MASFoundation/Classes/_private_/models/MASTypedBrowserBasedAuthenticationFactory.m deleted file mode 100644 index f2280304..00000000 --- a/MASFoundation/Classes/_private_/models/MASTypedBrowserBasedAuthenticationFactory.m +++ /dev/null @@ -1,37 +0,0 @@ -// -// MASTypedBrowserBasedAuthenticationFactory.m -// MASFoundation -// -// Copyright (c) 2020 CA. All rights reserved. -// -// This software may be modified and distributed under the terms -// of the MIT license. See the LICENSE file for details. -// - -#import "MASTypedBrowserBasedAuthenticationFactory.h" -#import "MASBrowserBasedAuthenticationConfiguration.h" -#import "MASSafariBrowserBasedAuthentication.h" -#import "MASWebSessionBrowserBasedAuthentication.h" - -@implementation MASTypedBrowserBasedAuthenticationFactory - -+ (id)buildBrowserWithConfiguration:(id)configuration { - - if ([configuration isKindOfClass: [MASSafariBrowserBasedAuthenticationConfiguration class]]) - { - return [[MASSafariBrowserBasedAuthentication alloc] init]; - } - if (@available(iOS 12.0, macOS 10.15, *)) - { - if ([configuration isKindOfClass: [MASWebSessionBrowserBasedAuthenticationConfiguration class]]) - { - MASWebSessionBrowserBasedAuthenticationConfiguration *castedConfiguration = configuration; - - return [[MASWebSessionBrowserBasedAuthentication alloc] initWithCallbackURLScheme:castedConfiguration.callbackURLScheme]; - } - } - - @throw [NSException exceptionWithName:NSInternalInconsistencyException reason:@"Cannot produce result with the provided configuration." userInfo:nil]; - return nil; -} -@end diff --git a/MASFoundation/Classes/_private_/models/MASWebSessionBrowserBasedAuthentication.h b/MASFoundation/Classes/_private_/models/MASWebSessionBrowserBasedAuthentication.h index 41848bdf..cc09d194 100644 --- a/MASFoundation/Classes/_private_/models/MASWebSessionBrowserBasedAuthentication.h +++ b/MASFoundation/Classes/_private_/models/MASWebSessionBrowserBasedAuthentication.h @@ -16,28 +16,13 @@ NS_ASSUME_NONNULL_BEGIN -@protocol MASTypedBrowserBasedAuthenticationInterface; +@protocol MASBrowserBasedAuthenticationInterface; /** * A Browser Based Authentication type utilising an ASWebAuthenticationSession */ API_AVAILABLE(ios(12.0), macCatalyst(13.0), macos(10.15), watchos(6.2)) -@interface MASWebSessionBrowserBasedAuthentication : NSObject - - -///-------------------------------------- -/// @name Lifecycle -///-------------------------------------- - -# pragma mark - Lifecycle - -/** - * Initializer to perform default initialization. - * - * @param callbackURLScheme NSString containing the callback url scheme to use. - * @return Returns the newly initialized MASWebSessionBrowserBasedAuthentication. - */ -- (instancetype)initWithCallbackURLScheme:(NSString *)callbackURLScheme; +@interface MASWebSessionBrowserBasedAuthentication : NSObject @end diff --git a/MASFoundation/Classes/_private_/models/MASWebSessionBrowserBasedAuthentication.m b/MASFoundation/Classes/_private_/models/MASWebSessionBrowserBasedAuthentication.m index 179d9e5f..112c5c2f 100644 --- a/MASFoundation/Classes/_private_/models/MASWebSessionBrowserBasedAuthentication.m +++ b/MASFoundation/Classes/_private_/models/MASWebSessionBrowserBasedAuthentication.m @@ -10,8 +10,9 @@ #import "MASWebSessionBrowserBasedAuthentication.h" #import -#import "MASTypedBrowserBasedAuthenticationInterface.h" +#import "MASBrowserBasedAuthenticationInterface.h" #import "MASAuthorizationResponse.h" +#import "MASApplication+MASPrivate.h" API_AVAILABLE(ios(12.0), macCatalyst(13.0), macos(10.15), watchos(6.2)) @interface MASWebSessionBrowserBasedAuthentication() @@ -31,8 +32,6 @@ @interface MASWebSessionBrowserBasedAuthentication() @property (nonatomic, weak) id window; -@property (nonatomic, strong) NSString *callbackURLScheme; - @end API_AVAILABLE(ios(13.0), macos(10.15)) @@ -42,19 +41,6 @@ @interface MASWebSessionBrowserBasedAuthentication() )configuration; ++ (void)setBrowserBasedAuthenticationBrowserType:(MASBrowserBasedAuthenticationBrowserType)browserType; /** - * The current browser based authentication configuration. + * The current browser based authentication browser type. * - * @return MASBrowserBasedAuthenticationConfigurationInterface conforming object is returned. + * @return MASBrowserBasedAuthenticationBrowserType object is returned. */ -+ (id)browserBasedAuthenticationConfiguration; ++ (MASBrowserBasedAuthenticationBrowserType)browserBasedAuthenticationBrowserType; ///-------------------------------------- diff --git a/MASFoundation/Classes/_private_/services/model/MASModelService.m b/MASFoundation/Classes/_private_/services/model/MASModelService.m index 40a69ec5..6562bef5 100644 --- a/MASFoundation/Classes/_private_/services/model/MASModelService.m +++ b/MASFoundation/Classes/_private_/services/model/MASModelService.m @@ -41,7 +41,7 @@ @implementation MASModelService static MASGrantFlow _grantFlow_ = MASGrantFlowClientCredentials; static MASUserAuthCredentialsBlock _userAuthCredentialsBlock_ = nil; static BOOL _isBrowserBasedAuthentication_ = NO; -static id _browserBasedAuthenticationConfiguration_; +static MASBrowserBasedAuthenticationBrowserType _browserBasedAuthenticationBrowserType_ = MASBrowserBasedAuthenticationBrowserTypeSafari; # pragma mark - Properties @@ -87,19 +87,15 @@ + (BOOL)browserBasedAuthentication } -+ (void)setBrowserBasedAuthenticationConfiguration:(id)configuration ++ (void)setBrowserBasedAuthenticationBrowserType:(MASBrowserBasedAuthenticationBrowserType)browserType { - _browserBasedAuthenticationConfiguration_ = configuration; + _browserBasedAuthenticationBrowserType_ = browserType; } -+ (id)browserBasedAuthenticationConfiguration ++ (MASBrowserBasedAuthenticationBrowserType)browserBasedAuthenticationBrowserType { - if (_browserBasedAuthenticationConfiguration_ == nil) - { - _browserBasedAuthenticationConfiguration_ = [[MASSafariBrowserBasedAuthenticationConfiguration alloc] init]; - } - return _browserBasedAuthenticationConfiguration_; + return _browserBasedAuthenticationBrowserType_; } diff --git a/MASFoundation/Classes/models/MASBrowserBasedAuthentication.m b/MASFoundation/Classes/models/MASBrowserBasedAuthentication.m index a4e4f40a..8f1510eb 100644 --- a/MASFoundation/Classes/models/MASBrowserBasedAuthentication.m +++ b/MASFoundation/Classes/models/MASBrowserBasedAuthentication.m @@ -14,8 +14,8 @@ #import "MASConfigurationService.h" #import "MASGetURLRequest.h" #import "MASModelService.h" -#import "MASTypedBrowserBasedAuthenticationFactory.h" -#import "MASTypedBrowserBasedAuthenticationInterface.h" +#import "MASBrowserBasedAuthenticationFactory.h" +#import "MASBrowserBasedAuthenticationInterface.h" #import "UIAlertController+MAS.h" #import @@ -24,7 +24,7 @@ @interface MASBrowserBasedAuthentication () browser; +@property (nonatomic, strong) id browser; @property (nonatomic) MASAuthCredentialsBlock webLoginCallBack; @end @@ -232,8 +232,8 @@ - (BOOL)redirectURLHasErrors :(NSURL*)redirectURL - (void)launchBrowserWithURL:(NSURL*)templatizedURL { - id configuration = [MASModelService browserBasedAuthenticationConfiguration]; - self.browser = [MASTypedBrowserBasedAuthenticationFactory buildBrowserWithConfiguration:configuration]; + MASBrowserBasedAuthenticationBrowserType browserType = [MASModelService browserBasedAuthenticationBrowserType]; + self.browser = [MASBrowserBasedAuthenticationFactory buildBrowserOfBrowserType:browserType]; [self.browser startWithURL:templatizedURL completion: self.webLoginCallBack]; } diff --git a/MASFoundation/Classes/models/MASBrowserBasedAuthenticationConfiguration.h b/MASFoundation/Classes/models/MASBrowserBasedAuthenticationConfiguration.h deleted file mode 100644 index 88859f74..00000000 --- a/MASFoundation/Classes/models/MASBrowserBasedAuthenticationConfiguration.h +++ /dev/null @@ -1,54 +0,0 @@ -// -// MASBrowserBasedAuthenticationConfigurationInterface.h -// MASFoundation -// -// Created by sander saelmans on 21/12/2020. -// Copyright © 2020 CA Technologies. All rights reserved. -// - -#import - -/** - MASBrowserBasedAuthenticationConfigurationInterface protocol is used to define a set of object which can be used to configure the preferred browser based authentication behaviour - */ -@protocol MASBrowserBasedAuthenticationConfigurationInterface -@end - - - -/** - MASSafariBrowserBasedAuthenticationConfiguration class is used to present a SFSafariViewController browser based login - */ -@interface MASSafariBrowserBasedAuthenticationConfiguration : NSObject - -@end - - - - -API_AVAILABLE(ios(12.0), macCatalyst(13.0), macos(10.15), watchos(6.2)) API_UNAVAILABLE(tvos) -/** - MASSafariBrowserBasedAuthenticationConfiguration class is used to present a ASWebAuthenticationSession browser based login - @note You have to provide a valid callback url scheme in order for this configuration to work properly. - */ -@interface MASWebSessionBrowserBasedAuthenticationConfiguration : NSObject - - -@property (nonatomic, strong, nonnull) NSString *callbackURLScheme; - - -/** - * Initialises a MASWebSessionBrowserBasedAuthenticationConfiguration with the provided callback url scheme - * - * @param callbackURLScheme Nonnull NSString object represeting the callback url scheme used to notify the login session has concluded. - * @return Returns an initialized MASWebSessionBrowserBasedAuthenticationConfiguration - */ -- (instancetype _Nonnull)initWithCallbackURLScheme:(NSString * _Nonnull)callbackURLScheme; - - -- (instancetype _Null_unspecified)init NS_UNAVAILABLE; - - -+ (instancetype _Null_unspecified)new NS_UNAVAILABLE; - -@end diff --git a/MASFoundation/Classes/models/MASBrowserBasedAuthenticationConfiguration.m b/MASFoundation/Classes/models/MASBrowserBasedAuthenticationConfiguration.m deleted file mode 100644 index bfc8787a..00000000 --- a/MASFoundation/Classes/models/MASBrowserBasedAuthenticationConfiguration.m +++ /dev/null @@ -1,25 +0,0 @@ -// -// MASBrowserBasedAuthenticationConfiguration.m -// MASFoundation -// -// Created by sander saelmans on 21/12/2020. -// Copyright © 2020 CA Technologies. All rights reserved. -// - -#import -#import "MASBrowserBasedAuthenticationConfiguration.h" - -@implementation MASSafariBrowserBasedAuthenticationConfiguration -@end - -@implementation MASWebSessionBrowserBasedAuthenticationConfiguration - -- (instancetype)initWithCallbackURLScheme:(NSString *)callbackURLScheme -{ - self = [super init]; - self.callbackURLScheme = callbackURLScheme; - - return self; -} -@end -