Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Here's a fix for the issue we've been talking about. #16

Merged
merged 4 commits into from

2 participants

@infiniteNIL

Fixed https issue that caused Facebook authentication window to never go away and things would just basically be in limbo. It also properly handles the expiration seconds for the token. Getting a 0 for the expiry means there is no expiration. Before the case was not honoring this and the expiration seconds would become negative.

@philippec
Owner

Nice! Thank you so much!

The magic numbers 7 and 8, do they correspond to the string length of "http://" and "https://"? If so, that should be documented, perhaps in a local constant.

@philippec

Suggest "> 0" to be sure that we're in the future

@philippec

Is this really necessary? If date is nil, won't [date timeIntervalSinceNow] be 0?

@philippec
Owner

Awesome! Just a couple of minor nits.

@infiniteNIL

Ok, I made those changes you suggested.

@philippec philippec merged commit 6e680fe into philippec:master
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
View
3  classes/PhAuthenticationToken.m
@@ -20,7 +20,8 @@ - (id) initWithToken: (NSString*) token secondsToExpiry: (NSTimeInterval) second
if ((self == [super init]))
{
self.authenticationToken = token;
- self.expiry = [NSDate dateWithTimeIntervalSinceNow: seconds];
+ if (seconds > 0)
+ self.expiry = [NSDate dateWithTimeIntervalSinceNow: seconds];
self.permissions = perms;
}
View
12 classes/PhFacebook.m
@@ -52,7 +52,10 @@ - (void) notifyDelegateForToken: (PhAuthenticationToken*) token withError: (NSSt
// Save it to user defaults
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
[defaults setObject: token.authenticationToken forKey: kFBStoreAccessToken];
- [defaults setObject: token.expiry forKey: kFBStoreTokenExpiry];
+ if (token.expiry)
+ [defaults setObject: token.expiry forKey: kFBStoreTokenExpiry];
+ else
+ [defaults removeObjectForKey: kFBStoreTokenExpiry];
[defaults setObject: token.permissions forKey: kFBStoreAccessPermissions];
[result setObject: [NSNumber numberWithBool: YES] forKey: @"valid"];
@@ -94,18 +97,17 @@ - (void) getAccessTokenForPermissions: (NSArray*) permissions cached: (BOOL) can
NSString *accessToken = [defaults stringForKey: kFBStoreAccessToken];
NSDate *date = [defaults objectForKey: kFBStoreTokenExpiry];
NSString *perms = [defaults stringForKey: kFBStoreAccessPermissions];
- if (accessToken && date && perms)
+ if (accessToken && perms)
{
- NSTimeInterval seconds = [date timeIntervalSinceNow];
// Do not notify delegate yet...
- [self setAccessToken: accessToken expires: seconds permissions: perms];
+ [self setAccessToken: accessToken expires: [date timeIntervalSinceNow] permissions: perms];
}
}
if ([_authToken.permissions isCaseInsensitiveLike: scope])
{
// We already have a token for these permissions; check if it has expired or not
- if ([[_authToken.expiry laterDate: [NSDate date]] isEqual: _authToken.expiry])
+ if (_authToken.expiry == nil || [[_authToken.expiry laterDate: [NSDate date]] isEqual: _authToken.expiry])
validToken = YES;
}
View
14 classes/PhWebViewController.m
@@ -58,7 +58,12 @@ - (void) webView: (WebView*) sender didCommitLoadForFrame: (WebFrame*) frame;
NSString *url = [sender mainFrameURL];
DebugLog(@"didCommitLoadForFrame: {%@}", url);
- NSComparisonResult res = [url compare: kFBUIServerURL options: NSCaseInsensitiveSearch range: NSMakeRange(0, [kFBUIServerURL length])];
+ NSString *urlWithoutSchema = [url substringFromIndex: [@"http://" length]];
+ if ([url hasPrefix: @"https://"])
+ urlWithoutSchema = [url substringFromIndex: [@"https://" length]];
+
+ NSString *uiServerURLWithoutSchema = [kFBUIServerURL substringFromIndex: [@"http://" length]];
+ NSComparisonResult res = [urlWithoutSchema compare: uiServerURLWithoutSchema options: NSCaseInsensitiveSearch range: NSMakeRange(0, [uiServerURLWithoutSchema length])];
if (res == NSOrderedSame)
[self showUI];
@@ -90,7 +95,12 @@ - (void) webView: (WebView*) sender didFinishLoadForFrame: (WebFrame*) frame
NSString *url = [sender mainFrameURL];
DebugLog(@"didFinishLoadForFrame: {%@}", url);
- NSComparisonResult res = [url compare: kFBLoginSuccessURL options: NSCaseInsensitiveSearch range: NSMakeRange(0, [kFBLoginSuccessURL length])];
+ NSString *urlWithoutSchema = [url substringFromIndex: [@"http://" length]];
+ if ([url hasPrefix: @"https://"])
+ urlWithoutSchema = [url substringFromIndex: [@"https://" length]];
+
+ NSString *loginSuccessURLWithoutSchema = [kFBLoginSuccessURL substringFromIndex: 7];
+ NSComparisonResult res = [urlWithoutSchema compare: loginSuccessURLWithoutSchema options: NSCaseInsensitiveSearch range: NSMakeRange(0, [loginSuccessURLWithoutSchema length])];
if (res == NSOrderedSame)
{
NSString *accessToken = [self extractParameter: kFBAccessToken fromURL: url];
Something went wrong with that request. Please try again.