Skip to content

Commit

Permalink
Merge pull request #92 from PSPDFKit-labs/matej/re-auth-fix
Browse files Browse the repository at this point in the history
Fixes HTTP redirect issues when posting a second time
  • Loading branch information
amyworrall committed Jul 10, 2016
2 parents 91a8dae + 21bff07 commit f2d554e
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 2 deletions.
16 changes: 14 additions & 2 deletions QuickRadar/QRRadarSubmissionService.m
Expand Up @@ -116,10 +116,14 @@ - (void)submitAsyncWithProgressBlock:(void (^)())progressBlock completionBlock:(
* Page 1: login page *
**********************/

self.submissionStatusText = @"Fetching RadarWeb signin page";
self.submissionStatusText = @"Fetching RadarWeb signin page";
QRWebScraper *loginPage = [[QRWebScraper alloc] init];
loginPage.URL = [NSURL URLWithString:@"https://idmsa.apple.com/IDMSWebAuth/classicLogin.html?appIdKey=77e2a60d4bdfa6b7311c854a56505800be3c24e3a27a670098ff61b69fc5214b&sslEnabled=true&rv=3"];


// Start with a clean slate. Should be enough to just delete the "myacinfo" cookie,
// to fix re-authentication issues, but let's rather make it more predictable by purging all.
[loginPage deleteCookies];

if (![loginPage fetch:&error])
{
dispatch_sync(dispatch_get_main_queue(), ^{
Expand Down Expand Up @@ -425,6 +429,14 @@ - (void)submitAsyncWithProgressBlock:(void (^)())progressBlock completionBlock:(
});
}

// DEBUG: Enable to prevent posting dummy radars if debugging authentication.
#if 0
dispatch_sync(dispatch_get_main_queue(), ^{
self.submissionStatusValue = submissionStatusFailed;
completionBlock(NO, [NSError errorWithDomain:@"QRDebugDomain" code:0 userInfo:@{NSLocalizedDescriptionKey: @"Manually canceled in `submitAsyncWithProgressBlock:`!"}]);
});
return;
#endif


/***************************
Expand Down
3 changes: 3 additions & 0 deletions QuickRadar/QRWebScraper.h
Expand Up @@ -27,6 +27,9 @@
/* A synchronous method */
- (BOOL)fetch:(NSError**)error;

/* Deletes any cookies currently present. Set the URL before invoking this method. */
- (BOOL)deleteCookies;

- (NSDictionary*)stringValuesForXPathsDictionary:(NSDictionary*)dict error:(NSError**)error;

@end
17 changes: 17 additions & 0 deletions QuickRadar/QRWebScraper.m
Expand Up @@ -167,6 +167,23 @@ - (BOOL)fetch:(NSError**)returnError;
}


- (BOOL)deleteCookies
{
NSURL *url = self.URL;
NSAssert(url != nil, @"Set the URL before invoking this method.");

BOOL deleted = NO;
NSHTTPCookieStorage *storage = [NSHTTPCookieStorage sharedHTTPCookieStorage];
NSArray<NSHTTPCookie *> *cookies = [storage cookiesForURL:url];
for (NSHTTPCookie *cookie in cookies)
{
[storage deleteCookie:cookie];
deleted = YES;
}
return deleted;
}


- (NSDictionary*)stringValuesForXPathsDictionary:(NSDictionary*)dict error:(NSError**)retError;
{
// NSLog(@"Data %@", [[NSString alloc] initWithData:self.returnedData encoding:NSUTF8StringEncoding]);
Expand Down

0 comments on commit f2d554e

Please sign in to comment.