Skip to content
This repository has been archived by the owner on Jul 13, 2023. It is now read-only.

Commit

Permalink
Merge pull request #39 from danielschibsted/danlazar/IDMOB-10/2
Browse files Browse the repository at this point in the history
IDMOB-10 Functionality for Apple account consolidation
  • Loading branch information
mikaoj authored Mar 13, 2017
2 parents ce3d194 + 7b64549 commit a5f90b1
Show file tree
Hide file tree
Showing 17 changed files with 737 additions and 36 deletions.
3 changes: 2 additions & 1 deletion SPiDExampleApp/SPiDExampleAppDelegate.m
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(
[SPiDClient setClientID:ClientID
clientSecret:ClientSecret
appURLScheme:AppURLScheme
serverURL:[NSURL URLWithString:ServerURL]];
serverURL:[NSURL URLWithString:ServerURL]
tokenStorageMode:SPiDTokenStorageModeDefault];
[[SPiDClient sharedInstance] setWebViewInitialHTML:@"<html><body>Loading SPiD login page</body></html>"];

[self setUseWebView:YES]; // As default, logout as logged in through webview
Expand Down
3 changes: 2 additions & 1 deletion SPiDFacebookApp/SPiDFacebookAppDelegate.m
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(
[SPiDClient setClientID:ClientID
clientSecret:ClientSecret
appURLScheme:AppURLScheme
serverURL:[NSURL URLWithString:ServerURL]];
serverURL:[NSURL URLWithString:ServerURL]
tokenStorageMode:SPiDTokenStorageModeDefault];
[[SPiDClient sharedInstance] setSignSecret:SignSecret];

MainViewController *mainViewController = [[MainViewController alloc] init];
Expand Down
3 changes: 2 additions & 1 deletion SPiDHybridApp/SPiDHybridAppDelegate.m
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(
[SPiDClient setClientID:ClientID
clientSecret:ClientSecret
appURLScheme:AppURLScheme
serverURL:[NSURL URLWithString:ServerURL]];
serverURL:[NSURL URLWithString:ServerURL]
tokenStorageMode:SPiDTokenStorageModeDefault];
[[SPiDClient sharedInstance] setServerClientID:ServerClientID];
[[SPiDClient sharedInstance] setServerRedirectUri:[NSURL URLWithString:ServerRedirectURI]];

Expand Down
3 changes: 2 additions & 1 deletion SPiDNativeApp/SPiDNativeAppDelegate.m
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(
[SPiDClient setClientID:ClientID
clientSecret:ClientSecret
appURLScheme:AppURLScheme
serverURL:[NSURL URLWithString:ServerURL]];
serverURL:[NSURL URLWithString:ServerURL]
tokenStorageMode:SPiDTokenStorageModeDefault];

MainViewController *mainViewController = [[MainViewController alloc] init];
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
Expand Down
64 changes: 46 additions & 18 deletions SPiDSDK.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,19 @@
/* End PBXAggregateTarget section */

/* Begin PBXBuildFile section */
089318561E6EFAD6002CD789 /* SPiDTokenStorage.h in Headers */ = {isa = PBXBuildFile; fileRef = 089318541E6EFAD6002CD789 /* SPiDTokenStorage.h */; };
089318571E6EFAD6002CD789 /* SPiDTokenStorage.m in Sources */ = {isa = PBXBuildFile; fileRef = 089318551E6EFAD6002CD789 /* SPiDTokenStorage.m */; };
0893185A1E6EFD52002CD789 /* SPiDTokenStorageUserDefaultsBackend.h in Headers */ = {isa = PBXBuildFile; fileRef = 089318581E6EFD52002CD789 /* SPiDTokenStorageUserDefaultsBackend.h */; };
0893185B1E6EFD52002CD789 /* SPiDTokenStorageUserDefaultsBackend.m in Sources */ = {isa = PBXBuildFile; fileRef = 089318591E6EFD52002CD789 /* SPiDTokenStorageUserDefaultsBackend.m */; };
0893185E1E6EFEA9002CD789 /* SPiDTokenStorageKeychainBackend.h in Headers */ = {isa = PBXBuildFile; fileRef = 0893185C1E6EFEA9002CD789 /* SPiDTokenStorageKeychainBackend.h */; };
0893185F1E6EFEA9002CD789 /* SPiDTokenStorageKeychainBackend.m in Sources */ = {isa = PBXBuildFile; fileRef = 0893185D1E6EFEA9002CD789 /* SPiDTokenStorageKeychainBackend.m */; };
089318611E716AE6002CD789 /* SPiDTokenStorageTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 089318601E716AE6002CD789 /* SPiDTokenStorageTests.m */; };
089318621E717174002CD789 /* SPiDTokenStorageUserDefaultsBackend.m in Sources */ = {isa = PBXBuildFile; fileRef = 089318591E6EFD52002CD789 /* SPiDTokenStorageUserDefaultsBackend.m */; };
089318641E7176DD002CD789 /* SPiDTokenStorageUserDefaultsBackendTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 089318631E7176DD002CD789 /* SPiDTokenStorageUserDefaultsBackendTests.m */; };
089318651E717AB9002CD789 /* SPiDTokenStorage.m in Sources */ = {isa = PBXBuildFile; fileRef = 089318551E6EFAD6002CD789 /* SPiDTokenStorage.m */; };
089318661E717AE6002CD789 /* SPiDTokenStorageKeychainBackend.m in Sources */ = {isa = PBXBuildFile; fileRef = 0893185D1E6EFEA9002CD789 /* SPiDTokenStorageKeychainBackend.m */; };
089318671E717AF4002CD789 /* SPiDKeychainWrapper.m in Sources */ = {isa = PBXBuildFile; fileRef = E304E86B163571BA2FDCE5BD /* SPiDKeychainWrapper.m */; };
089318681E717B44002CD789 /* Security.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = E304ECEC953C2E9C143FD9E2 /* Security.framework */; };
5306208B16C12440001B2A08 /* Security.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = E304ECEC953C2E9C143FD9E2 /* Security.framework */; };
5306209716C1375D001B2A08 /* Social.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 5306209616C1375D001B2A08 /* Social.framework */; settings = {ATTRIBUTES = (Weak, ); }; };
5306209B16C1376F001B2A08 /* Accounts.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 5306209A16C1376F001B2A08 /* Accounts.framework */; settings = {ATTRIBUTES = (Weak, ); }; };
Expand Down Expand Up @@ -153,6 +166,14 @@
/* End PBXBuildFile section */

/* Begin PBXFileReference section */
089318541E6EFAD6002CD789 /* SPiDTokenStorage.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SPiDTokenStorage.h; sourceTree = "<group>"; };
089318551E6EFAD6002CD789 /* SPiDTokenStorage.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SPiDTokenStorage.m; sourceTree = "<group>"; };
089318581E6EFD52002CD789 /* SPiDTokenStorageUserDefaultsBackend.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SPiDTokenStorageUserDefaultsBackend.h; sourceTree = "<group>"; };
089318591E6EFD52002CD789 /* SPiDTokenStorageUserDefaultsBackend.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SPiDTokenStorageUserDefaultsBackend.m; sourceTree = "<group>"; };
0893185C1E6EFEA9002CD789 /* SPiDTokenStorageKeychainBackend.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SPiDTokenStorageKeychainBackend.h; sourceTree = "<group>"; };
0893185D1E6EFEA9002CD789 /* SPiDTokenStorageKeychainBackend.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SPiDTokenStorageKeychainBackend.m; sourceTree = "<group>"; };
089318601E716AE6002CD789 /* SPiDTokenStorageTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SPiDTokenStorageTests.m; sourceTree = "<group>"; };
089318631E7176DD002CD789 /* SPiDTokenStorageUserDefaultsBackendTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SPiDTokenStorageUserDefaultsBackendTests.m; sourceTree = "<group>"; };
5306208716C082B8001B2A08 /* MainViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MainViewController.h; sourceTree = "<group>"; };
5306209616C1375D001B2A08 /* Social.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Social.framework; path = System/Library/Frameworks/Social.framework; sourceTree = SDKROOT; };
5306209816C13764001B2A08 /* AdSupport.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = AdSupport.framework; path = System/Library/Frameworks/AdSupport.framework; sourceTree = SDKROOT; };
Expand Down Expand Up @@ -342,6 +363,7 @@
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
089318681E717B44002CD789 /* Security.framework in Frameworks */,
537D220515FF224C000ABCA6 /* Foundation.framework in Frameworks */,
);
runOnlyForDeploymentPostprocessing = 0;
Expand Down Expand Up @@ -534,6 +556,8 @@
9698149C1E54942600439631 /* SPiDAccessTokenTests.m */,
969814A11E54972700439631 /* NSDictionary+Test.h */,
969814A21E54972700439631 /* NSDictionary+Test.m */,
089318601E716AE6002CD789 /* SPiDTokenStorageTests.m */,
089318631E7176DD002CD789 /* SPiDTokenStorageUserDefaultsBackendTests.m */,
);
path = SPiDSDKTests;
sourceTree = "<group>";
Expand Down Expand Up @@ -637,6 +661,12 @@
DAFD374A1CD9F9B300BF0DE3 /* Info.plist */,
9665D1F31E0820C300759F60 /* SPiDAgreements.h */,
9665D1F41E0820C300759F60 /* SPiDAgreements.m */,
089318541E6EFAD6002CD789 /* SPiDTokenStorage.h */,
089318551E6EFAD6002CD789 /* SPiDTokenStorage.m */,
089318581E6EFD52002CD789 /* SPiDTokenStorageUserDefaultsBackend.h */,
089318591E6EFD52002CD789 /* SPiDTokenStorageUserDefaultsBackend.m */,
0893185C1E6EFEA9002CD789 /* SPiDTokenStorageKeychainBackend.h */,
0893185D1E6EFEA9002CD789 /* SPiDTokenStorageKeychainBackend.m */,
);
path = SPiDSDK;
sourceTree = "<group>";
Expand All @@ -648,13 +678,15 @@
isa = PBXHeadersBuildPhase;
buildActionMask = 2147483647;
files = (
0893185A1E6EFD52002CD789 /* SPiDTokenStorageUserDefaultsBackend.h in Headers */,
DAFD37551CD9F9D700BF0DE3 /* SPiDResponse.h in Headers */,
DAFD37611CD9F9D700BF0DE3 /* SPiDJwt.h in Headers */,
DAFD375A1CD9F9D700BF0DE3 /* SPiDClient.h in Headers */,
DAFD37691CD9F9D700BF0DE3 /* SPiDStatus.h in Headers */,
DAFD374E1CD9F9D700BF0DE3 /* NSError+SPiD.h in Headers */,
DAF1DE401CDC78B8007B15B3 /* SPiDWebView.h in Headers */,
DAFD37561CD9F9D700BF0DE3 /* SPiDRequest.h in Headers */,
0893185E1E6EFEA9002CD789 /* SPiDTokenStorageKeychainBackend.h in Headers */,
DAFD37491CD9F9B300BF0DE3 /* SPiDSDK.h in Headers */,
DAFD37521CD9F9D700BF0DE3 /* SPiDAccessToken.h in Headers */,
DAFD37651CD9F9D700BF0DE3 /* SPiDUser.h in Headers */,
Expand All @@ -665,6 +697,7 @@
DAFD376A1CD9F9D700BF0DE3 /* NSURLRequest+SPiD.h in Headers */,
DAFD37631CD9F9D700BF0DE3 /* NSString+Crypto.h in Headers */,
DAC183B71CDA161600D08ABD /* NSCharacterSet+SPiD.h in Headers */,
089318561E6EFAD6002CD789 /* SPiDTokenStorage.h in Headers */,
DAFD375D1CD9F9D700BF0DE3 /* NSData+Base64.h in Headers */,
);
runOnlyForDeploymentPostprocessing = 0;
Expand Down Expand Up @@ -952,13 +985,19 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
089318661E717AE6002CD789 /* SPiDTokenStorageKeychainBackend.m in Sources */,
DAF1DE3D1CDC706D007B15B3 /* NSCharacterSet+SPiD.m in Sources */,
537D221115FF224C000ABCA6 /* SPiDSDKTests.m in Sources */,
9665D1F91E092DCE00759F60 /* SPiDAgreements.m in Sources */,
089318651E717AB9002CD789 /* SPiDTokenStorage.m in Sources */,
089318671E717AF4002CD789 /* SPiDKeychainWrapper.m in Sources */,
969814A31E54972700439631 /* NSDictionary+Test.m in Sources */,
9665D1F81E092C0000759F60 /* SPiDAgreementsTests.m in Sources */,
089318621E717174002CD789 /* SPiDTokenStorageUserDefaultsBackend.m in Sources */,
089318641E7176DD002CD789 /* SPiDTokenStorageUserDefaultsBackendTests.m in Sources */,
DAF1DE3C1CDC6F35007B15B3 /* SPiDUtils.m in Sources */,
9698149D1E54942600439631 /* SPiDAccessTokenTests.m in Sources */,
089318611E716AE6002CD789 /* SPiDTokenStorageTests.m in Sources */,
969814A41E549AEE00439631 /* SPiDAccessToken.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
Expand All @@ -980,12 +1019,15 @@
files = (
DAFD376B1CD9F9D700BF0DE3 /* NSURLRequest+SPiD.m in Sources */,
DAFD375B1CD9F9D700BF0DE3 /* SPiDClient.m in Sources */,
0893185F1E6EFEA9002CD789 /* SPiDTokenStorageKeychainBackend.m in Sources */,
DAFD37571CD9F9D700BF0DE3 /* SPiDRequest.m in Sources */,
DAFD37541CD9F9D700BF0DE3 /* SPiDResponse.m in Sources */,
DAFD37601CD9F9D700BF0DE3 /* SPiDJwt.m in Sources */,
0893185B1E6EFD52002CD789 /* SPiDTokenStorageUserDefaultsBackend.m in Sources */,
DAC183B91CDA161600D08ABD /* NSCharacterSet+SPiD.m in Sources */,
DAFD375E1CD9F9D700BF0DE3 /* SPiDTokenRequest.m in Sources */,
DAFD37621CD9F9D700BF0DE3 /* NSString+Crypto.m in Sources */,
089318571E6EFAD6002CD789 /* SPiDTokenStorage.m in Sources */,
9665D1F61E0820C300759F60 /* SPiDAgreements.m in Sources */,
DAFD374F1CD9F9D700BF0DE3 /* NSError+SPiD.m in Sources */,
DAFD37531CD9F9D700BF0DE3 /* SPiDAccessToken.m in Sources */,
Expand Down Expand Up @@ -1262,11 +1304,7 @@
537D221815FF224C000ABCA6 /* Debug */ = {
isa = XCBuildConfiguration;
buildSettings = {
FRAMEWORK_SEARCH_PATHS = (
"\"$(SDKROOT)/Developer/Library/Frameworks\"",
"\"$(DEVELOPER_LIBRARY_DIR)/Frameworks\"",
"$(inherited)",
);
FRAMEWORK_SEARCH_PATHS = "$(inherited)";
GCC_PRECOMPILE_PREFIX_HEADER = NO;
GCC_PREFIX_HEADER = "";
INFOPLIST_FILE = "SPiDSDKTests/SPiDSDKTests-Info.plist";
Expand All @@ -1278,11 +1316,7 @@
537D221915FF224C000ABCA6 /* Release */ = {
isa = XCBuildConfiguration;
buildSettings = {
FRAMEWORK_SEARCH_PATHS = (
"\"$(SDKROOT)/Developer/Library/Frameworks\"",
"\"$(DEVELOPER_LIBRARY_DIR)/Frameworks\"",
"$(inherited)",
);
FRAMEWORK_SEARCH_PATHS = "$(inherited)";
GCC_PRECOMPILE_PREFIX_HEADER = NO;
GCC_PREFIX_HEADER = "";
INFOPLIST_FILE = "SPiDSDKTests/SPiDSDKTests-Info.plist";
Expand All @@ -1296,10 +1330,7 @@
buildSettings = {
CODE_SIGN_IDENTITY = "iPhone Developer";
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
FRAMEWORK_SEARCH_PATHS = (
"$(inherited)",
"\"$(SYSTEM_APPS_DIR)/Xcode.app/Contents/Developer/Library/Frameworks\"",
);
FRAMEWORK_SEARCH_PATHS = "$(inherited)";
GCC_PRECOMPILE_PREFIX_HEADER = YES;
GCC_PREFIX_HEADER = "SPiDExampleApp/SPiDExampleApp-Prefix.pch";
INFOPLIST_FILE = "SPiDExampleApp/SPiDExampleApp-Info.plist";
Expand All @@ -1319,10 +1350,7 @@
buildSettings = {
CODE_SIGN_IDENTITY = "iPhone Developer";
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
FRAMEWORK_SEARCH_PATHS = (
"$(inherited)",
"\"$(SYSTEM_APPS_DIR)/Xcode.app/Contents/Developer/Library/Frameworks\"",
);
FRAMEWORK_SEARCH_PATHS = "$(inherited)";
GCC_PRECOMPILE_PREFIX_HEADER = YES;
GCC_PREFIX_HEADER = "SPiDExampleApp/SPiDExampleApp-Prefix.pch";
INFOPLIST_FILE = "SPiDExampleApp/SPiDExampleApp-Info.plist";
Expand Down
30 changes: 29 additions & 1 deletion SPiDSDK/SPiDClient.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,32 @@ NS_ASSUME_NONNULL_BEGIN
static NSString *const defaultAPIVersionSPiD = @"2";
static NSString *const AccessTokenKeychainIdentification = @"AccessToken";

/**
Options for persisting user tokens.
Normally an app should only use the keychain to store the tokens.
During app iTunes account migration the options here let
exporting or importing the data from NSUserDefaults.
This is needed to keep a user logged in after migration.
The migration can be done in 2 steps (2 app updates):
1. The first update is published to the old account with SPiDTokenStorageModeMigratePreITunesAccountMove
(and starts writing tokens to NSUserDefaults)
2. The second update is published to the new account with SPiDTokenStorageModeMigratePostITunesAccountMove
(and starts reading tokens from NSUserDefaults)
Both versions should stay in the store for a while
until the most users are able to upgrade and run it.
Eventually a subsequent update can revert back to use SPiDTokenStorageModeDefault
*/
typedef NS_ENUM(NSUInteger, SPiDTokenStorageMode) {
/** Use only keychain to store and retrieve user tokens */
SPiDTokenStorageModeDefault,
/** Retrieve user tokens from keychain, store to both keychain and NSUserDefaults */
SPiDTokenStorageModeMigratePreITunesAccountMove,
/** Try retrieving user tokens from NSUserDefaults after keychain, store to keychain only */
SPiDTokenStorageModeMigratePostITunesAccountMove,
};

// debug print used by SPiDSDK
#ifdef DEBUG
# define SPiDDebugLog(fmt, ...) NSLog((@"%s [Line %d] " fmt), __PRETTY_FUNCTION__, __LINE__, ##__VA_ARGS__);
Expand Down Expand Up @@ -148,11 +174,13 @@ static NSString *const AccessTokenKeychainIdentification = @"AccessToken";
@param clientSecret The client secret provided by SPiD
@param appURLSchema The url schema for the app (eg spidtest://)
@param serverURL The url to SPiD
@param tokenStorageMode See SPiDTokenStorageMode
*/
+ (void)setClientID:(NSString *)clientID
clientSecret:(NSString *)clientSecret
appURLScheme:(NSString *)appURLSchema
serverURL:(NSURL *)serverURL;
serverURL:(NSURL *)serverURL
tokenStorageMode:(SPiDTokenStorageMode)tokenStorageMode;

/** Redirects to safari for authorization
Expand Down
Loading

0 comments on commit a5f90b1

Please sign in to comment.