Skip to content
Browse files

Merge pull request #64 from forcedotcom/invalid_refresh

Re-authenticate if bad refresh token
  • Loading branch information...
2 parents 16c4b5b + b18425c commit 16af0f844edaff5bd45019e6e4babef46975dfe4 @khawkins khawkins committed May 7, 2012
View
1 hybrid/SalesforceHybridSDK/SalesforceHybridSDK/Container/SFContainerAppDelegate.h
@@ -73,6 +73,7 @@ extern NSString * const kSFSmartStorePluginName;
NSString* invokeString;
SalesforceOAuthPlugin *_oauthPlugin;
BOOL _foundHomeUrl;
+ BOOL _isAppStartup;
}
View
33 hybrid/SalesforceHybridSDK/SalesforceHybridSDK/Container/SFContainerAppDelegate.m
@@ -29,7 +29,7 @@
#import "NSURL+SFStringUtils.h"
// Public constants
-NSString * const kSFMobileSDKVersion = @"1.1.6";
+NSString * const kSFMobileSDKVersion = @"1.1.7";
NSString * const kUserAgentPropKey = @"UserAgent";
NSString * const kAppHomeUrlPropKey = @"AppHomeUrl";
NSString * const kSFMobileSDKHybridDesignator = @"Hybrid";
@@ -78,6 +78,7 @@ - (id) init
[dictionary release];
_foundHomeUrl = NO;
+ _isAppStartup = YES;
}
return self;
}
@@ -118,21 +119,27 @@ - (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url
return [super application:application handleOpenURL:url];
}
-- (void)applicationDidBecomeActive:(UIApplication *)application {
- //Ensure that we have an OAuth plugin instance asap
- if (nil == _oauthPlugin)
- _oauthPlugin = (SalesforceOAuthPlugin *)[[self getCommandInstance:kSFOAuthPluginName] retain];
+- (void)applicationDidBecomeActive:(UIApplication *)application {
- // If the app is in a state where it should be reset, re-initialize the app.
- if ([_oauthPlugin resetAppState]) {
- [_oauthPlugin release]; _oauthPlugin = nil;
- [self loadStartPageIntoWebView];
+ // These actions only need to be taken when the app is coming back to the foreground, i.e. not when the app is first starting,
+ // which has a separate bootstrapping process.
+ if (!_isAppStartup) {
+ //Ensure that we have an OAuth plugin instance asap
+ if (nil == _oauthPlugin)
+ _oauthPlugin = (SalesforceOAuthPlugin *)[[self getCommandInstance:kSFOAuthPluginName] retain];
+
+ // If the app is in a state where it should be reset, re-initialize the app.
+ if ([_oauthPlugin resetAppState]) {
+ [_oauthPlugin release]; _oauthPlugin = nil;
+ [self loadStartPageIntoWebView];
+ }
+
+ //Touch this to ensure that we have a SmartStore plugin instance that
+ //can listen for file data protection notifications.
+ [self getCommandInstance:kSFSmartStorePluginName];
}
- //Touch this to ensure that we have a SmartStore plugin instance that
- //can listen for file data protection notifications.
- [self getCommandInstance:kSFSmartStorePluginName];
-
+ _isAppStartup = NO;
[super applicationDidBecomeActive:application];
}
View
2 hybrid/SalesforceHybridSDK/SalesforceHybridSDK/Plugins/SFOAuthPlugin/SalesforceOAuthPlugin.h
@@ -84,7 +84,7 @@
/**
- Forces a logout from the current account.
+ Forces a logout from the current account, redirecting the user to the login process.
This throws out the OAuth refresh token.
*/
- (void)logout;
View
28 hybrid/SalesforceHybridSDK/SalesforceHybridSDK/Plugins/SFOAuthPlugin/SalesforceOAuthPlugin.m
@@ -121,10 +121,25 @@ - (void)fireSessionRefreshEvent:(NSDictionary*)creds;
*/
- (void)cleanupCoordinator;
+/**
+ Dismisses the authentication retry alert box, if present.
+ */
- (void)cleanupRetryAlert;
+/**
+ Displays an alert in the event of an unknown failure for OAuth, allowing the user
+ to retry authentication.
+ */
- (void)showRetryAlertForAuthError:(NSError *)error;
+/**
+ Revokes the current user's credentials for the app, optionally redirecting her to the
+ login screen.
+ @param restartAuthentication Whether or not to immediately restart the authentication
+ process.
+ */
+- (void)logout:(BOOL)restartAuthentication;
+
@end
// ------------------------------------------
@@ -233,7 +248,6 @@ - (void)logoutCurrentUser:(NSMutableArray*)arguments withDict:(NSMutableDictiona
{
NSLog(@"logoutCurrentUser");
[self logout];
- [_appDelegate loadStartPageIntoWebView];
}
- (void)getAppHomeUrl:(NSMutableArray*)arguments withDict:(NSMutableDictionary*)options
@@ -291,7 +305,7 @@ - (BOOL)resetAppState
BOOL shouldLogout = [self checkForUserLogout] ;
if (shouldLogout) {
shouldReset = YES;
- [self logout];
+ [self logout:NO];
} else {
BOOL loginHostChanged = [[self class] updateLoginHost];
if (loginHostChanged) {
@@ -368,6 +382,11 @@ - (void)login
- (void)logout
{
+ [self logout:YES];
+}
+
+- (void)logout:(BOOL)restartAuthentication
+{
// Clear any cookies set by the app.
[self removeCookies];
@@ -380,6 +399,9 @@ - (void)logout
//clear this since we just called revokeAuthentication
[defs setBool:NO forKey:kAccountLogoutUserDefault];
[defs synchronize];
+
+ if (restartAuthentication)
+ [_appDelegate loadStartPageIntoWebView];
}
- (void)loggedIn
@@ -647,7 +669,7 @@ - (void)oauthCoordinator:(SFOAuthCoordinator *)coordinator didFailWithError:(NSE
}
else {
// show alert and allow retry
- [self performSelector:@selector(showOAuthStatusAlert:) withObject:error afterDelay:0];
+ [self performSelector:@selector(showRetryAlertForAuthError:) withObject:error afterDelay:0];
}
}
View
2 native/SalesforceSDK/SalesforceSDK/Classes/SFRestAPI.m
@@ -31,7 +31,7 @@
#import "SFRestRequest.h"
#import "SFSessionRefresher.h"
-static NSString * const kSFMobileSDKVersion = @"1.1.6";
+static NSString * const kSFMobileSDKVersion = @"1.1.7";
NSString* const kSFRestDefaultAPIVersion = @"v23.0";
NSString* const kSFRestErrorDomain = @"com.salesforce.RestAPI.ErrorDomain";
NSInteger const kSFRestErrorCode = 999;

0 comments on commit 16af0f8

Please sign in to comment.
Something went wrong with that request. Please try again.