diff --git a/DemoApp/DemoApp.xcodeproj/project.pbxproj b/DemoApp/DemoApp.xcodeproj/project.pbxproj index f29f8ceb..be295fef 100644 --- a/DemoApp/DemoApp.xcodeproj/project.pbxproj +++ b/DemoApp/DemoApp.xcodeproj/project.pbxproj @@ -10,6 +10,7 @@ 191FF0FFCC8156460546E43A /* Pods_DemoApp.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 0E13E2EBAF8AC955FF850B86 /* Pods_DemoApp.framework */; }; 2001BA381FA0EF0F0074EA67 /* Config.xcconfig in Resources */ = {isa = PBXBuildFile; fileRef = 2001BA371FA0EF0F0074EA67 /* Config.xcconfig */; }; 20ABD1D71F0188DD00DCA2E0 /* TweetCollectionViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 20ABD1D61F0188DC00DCA2E0 /* TweetCollectionViewController.swift */; }; + 2BB65BAD234654280090B40E /* WebKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 2BB65BA8234654280090B40E /* WebKit.framework */; }; 377340651ECA3D080065FFE0 /* DeletedTweet.json in Resources */ = {isa = PBXBuildFile; fileRef = 377340641ECA3D080065FFE0 /* DeletedTweet.json */; }; 377783891E96AF1700BC4830 /* TwitterKitResources.bundle in Resources */ = {isa = PBXBuildFile; fileRef = 377783881E96AF1700BC4830 /* TwitterKitResources.bundle */; }; 3777838B1E96AFD500BC4830 /* Images.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 3777838A1E96AFD500BC4830 /* Images.xcassets */; }; @@ -168,6 +169,7 @@ 0E13E2EBAF8AC955FF850B86 /* Pods_DemoApp.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_DemoApp.framework; sourceTree = BUILT_PRODUCTS_DIR; }; 2001BA371FA0EF0F0074EA67 /* Config.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; name = Config.xcconfig; path = ../Config.xcconfig; sourceTree = ""; }; 20ABD1D61F0188DC00DCA2E0 /* TweetCollectionViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TweetCollectionViewController.swift; sourceTree = ""; }; + 2BB65BA8234654280090B40E /* WebKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = WebKit.framework; path = System/Library/Frameworks/WebKit.framework; sourceTree = SDKROOT; }; 3733E29D1EA8276800E95681 /* TwitterShareExtensionUIResources.bundle */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.plug-in"; path = TwitterShareExtensionUIResources.bundle; sourceTree = BUILT_PRODUCTS_DIR; }; 377340641ECA3D080065FFE0 /* DeletedTweet.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = DeletedTweet.json; sourceTree = ""; }; 377783881E96AF1700BC4830 /* TwitterKitResources.bundle */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.plug-in"; name = TwitterKitResources.bundle; path = ../TwitterKit/TwitterKitResources.bundle; sourceTree = ""; }; @@ -249,6 +251,7 @@ 191FF0FFCC8156460546E43A /* Pods_DemoApp.framework in Frameworks */, 377941671E96DBCF0049A022 /* FLEX.framework in Frameworks */, 377941681E96DBCF0049A022 /* MoPub.framework in Frameworks */, + 2BB65BAD234654280090B40E /* WebKit.framework in Frameworks */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -361,6 +364,7 @@ A7BC0A74110949C5A64504DE /* Frameworks */ = { isa = PBXGroup; children = ( + 2BB65BA8234654280090B40E /* WebKit.framework */, AA3E099520119D3F00792255 /* MapKit.framework */, AAEE1AF81FACCC8300F11160 /* SafariServices.framework */, 377941601E96DBCF0049A022 /* DCIntrospect_ARC.framework */, diff --git a/TwitterKit/TwitterKit/Social/Identity/TWTRMobileSSO.h b/TwitterKit/TwitterKit/Social/Identity/TWTRMobileSSO.h index df1124db..56c4b5ee 100644 --- a/TwitterKit/TwitterKit/Social/Identity/TWTRMobileSSO.h +++ b/TwitterKit/TwitterKit/Social/Identity/TWTRMobileSSO.h @@ -62,6 +62,16 @@ typedef void (^TWTRMobileSSOCompletion)(BOOL twitterAppInstalled); */ - (BOOL)isWebWithSourceApplication:(NSString *)sourceApplication; +/** + * Determines if the url sent from the calling applciation is valid. + */ +- (BOOL)isSSOWithURL:(NSURL *)url; + +/** + * Determines if the url sent from web is valid. + */ +- (BOOL)isWebWithURL:(NSURL *)url; + /** * Triggers an error completion when invalid source is detected */ diff --git a/TwitterKit/TwitterKit/Social/Identity/TWTRMobileSSO.m b/TwitterKit/TwitterKit/Social/Identity/TWTRMobileSSO.m index c2430113..6fcfc076 100644 --- a/TwitterKit/TwitterKit/Social/Identity/TWTRMobileSSO.m +++ b/TwitterKit/TwitterKit/Social/Identity/TWTRMobileSSO.m @@ -74,6 +74,20 @@ - (BOOL)isWebWithSourceApplication:(NSString *)sourceApplication return [sourceApplication hasPrefix:@"com.apple"] || [sourceApplication isEqualToString:bundleID]; } +- (BOOL)isSSOWithURL:(NSURL *)url +{ + if (url == nil) return NO; + return [url.host containsString:@"secret="] && + [url.host containsString:@"secret="] && + [url.host containsString:@"username="] ; +} + +- (BOOL)isWebWithURL:(NSURL *)url +{ + if (url == nil) return NO; + return [url.host isEqualToString:@"callback"]; +} + - (void)triggerInvalidSourceError { dispatch_async(dispatch_get_main_queue(), ^{ diff --git a/TwitterKit/TwitterKit/TWTRTwitter.m b/TwitterKit/TwitterKit/TWTRTwitter.m index d96cd0cc..68cdad59 100644 --- a/TwitterKit/TwitterKit/TWTRTwitter.m +++ b/TwitterKit/TwitterKit/TWTRTwitter.m @@ -379,9 +379,11 @@ - (BOOL)shouldShowWebBasedLogin:(NSError *)error - (BOOL)application:(UIApplication *)application openURL:(NSURL *)url options:(NSDictionary *)options { + // Bug fixed: https://github.com/twitter-archive/twitter-kit-ios/issues/122 + // Use the code from HackingGate(github.com), https://github.com/touren/twitter-kit-ios/pull/2 NSString *sourceApplication = options[UIApplicationOpenURLOptionsSourceApplicationKey]; - BOOL isSSOBundle = [self.mobileSSO isSSOWithSourceApplication:sourceApplication]; - BOOL isWeb = [self.mobileSSO isWebWithSourceApplication:sourceApplication]; + BOOL isSSOBundle = sourceApplication == nil ? [self.mobileSSO isSSOWithURL:url] : [self.mobileSSO isSSOWithSourceApplication:sourceApplication]; + BOOL isWeb = sourceApplication == nil ? [self.mobileSSO isWebWithURL:url] : [self.mobileSSO isWebWithSourceApplication:sourceApplication]; if (isSSOBundle) { [self.mobileSSO processRedirectURL:url];