Skip to content
Browse files

Updating loggedIn to only update sid cookies

  • Loading branch information...
1 parent 6f740fb commit 911cc9448c9843785808973b1ec7ee8553799dc7 @khawkins khawkins committed Apr 29, 2012
2 external/shared
@@ -1 +1 @@
-Subproject commit 300265316228a943293f6cb50003c94ae42c3996
+Subproject commit 83439d8b0078ba28c0046dab4b7969cd79d31419
View
31 hybrid/SalesforceHybridSDK/SalesforceHybridSDK/Plugins/SFOAuthPlugin/SalesforceOAuthPlugin.m
@@ -93,6 +93,11 @@ - (void)addSidCookieForDomain:(NSString*)domain;
- (void)removeCookies;
/**
+ Remove any cookies with the given names from the given domains.
+ */
+- (void)removeCookies:(NSArray *)cookieNames fromDomains:(NSArray *)domainNames;
+
+/**
Convert the post-authentication credentials into a Dictionary, to return to
the calling client code.
@return Dictionary representation of oauth credentials.
@@ -379,9 +384,10 @@ - (void)logout
- (void)loggedIn
{
- // First, remove any cookies associated with the app.
+ // First, remove any session cookies associated with the app.
// All cookies should be reset with any new authentication (user agent, refresh, etc.).
- [self removeCookies];
+ [self removeCookies:[NSArray arrayWithObjects:@"sid", nil]
+ fromDomains:[NSArray arrayWithObjects:@".salesforce.com", @".force.com", nil]];
[self addSidCookieForDomain:@".salesforce.com"];
self.lastRefreshCompleted = [NSDate date];
@@ -408,13 +414,32 @@ - (void)removeCookies
}
}
+- (void)removeCookies:(NSArray *)cookieNames fromDomains:(NSArray *)domainNames
+{
+ NSAssert(cookieNames != nil && [cookieNames count] > 0, @"No cookie names given to delete.");
+ NSAssert(domainNames != nil && [domainNames count] > 0, @"No domain names given for deleting cookies.");
+
+ NSHTTPCookieStorage *cookieStorage = [NSHTTPCookieStorage sharedHTTPCookieStorage];
+ NSArray *fullCookieList = [NSArray arrayWithArray:[cookieStorage cookies]];
+ for (NSHTTPCookie *cookie in fullCookieList) {
+ for (NSString *cookieToRemoveName in cookieNames) {
+ for (NSString *domainToRemoveName in domainNames) {
+ if ([[[cookie name] lowercaseString] isEqualToString:[cookieToRemoveName lowercaseString]]
@wmathurin
wmathurin added a note Apr 30, 2012

[Splitting hairs] the if on the cookie name should move outside the domain for loop.

@khawkins
khawkins added a note Apr 30, 2012

Yeah, that's a fair point. I'll fix it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
+ && [[[cookie domain] lowercaseString] hasSuffix:[domainToRemoveName lowercaseString]])
+ {
+ [cookieStorage deleteCookie:cookie];
+ }
+ }
+ }
+ }
+}
+
- (void)addSidCookieForDomain:(NSString*)domain
{
NSAssert(domain != nil && [domain length] > 0, @"addSidCookieForDomain: domain cannot be empty");
NSLog(@"addSidCookieForDomain: %@", domain);
// Set the session ID cookie to be used by the web view.
- NSURL *hostURL = self.coordinator.credentials.instanceUrl;
NSHTTPCookieStorage *cookieStorage = [NSHTTPCookieStorage sharedHTTPCookieStorage];
[cookieStorage setCookieAcceptPolicy:NSHTTPCookieAcceptPolicyAlways];

0 comments on commit 911cc94

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