Skip to content

Commit

Permalink
Merge pull request #152 from box/loginredirect
Browse files Browse the repository at this point in the history
Extracting check for login redirection into a method
  • Loading branch information
sowmiya committed Dec 18, 2015
2 parents 30e3643 + 2156b0a commit 1b77cc1
Showing 1 changed file with 10 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,15 @@ - (BOOL)webViewCanBeUsedDirectlyForHost:(NSString *)host
return [self.hostsThatCanUseWebViewDirectly containsObject:host];
}

- (BOOL)isLoginRedirectionRequest:(NSURLRequest *)request
{
BOOL requestIsForLoginRedirectScheme = NO;
if ([self.redirectURI length] > 0) {
requestIsForLoginRedirectScheme = [[[request URL] scheme] isEqualToString:[[NSURL URLWithString:self.redirectURI] scheme]];
}
return (requestIsForLoginRedirectScheme && [[[request URL] absoluteString] hasPrefix:self.redirectURI]);
}

#pragma mark - UIWebViewDelegate methods

- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType
Expand All @@ -311,12 +320,7 @@ - (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)
[self.activityIndicator startAnimating];

// Figure out whether this request is the redirect used at the end of the authentication process
BOOL requestIsForLoginRedirectScheme = NO;
if ([self.redirectURI length] > 0) {
requestIsForLoginRedirectScheme = [[[request URL] scheme] isEqualToString:[[NSURL URLWithString:self.redirectURI] scheme]];
}
BOOL requestIsForLoginRedirection = (requestIsForLoginRedirectScheme &&
[[[request URL] absoluteString] hasPrefix:self.redirectURI]);
BOOL requestIsForLoginRedirection = [self isLoginRedirectionRequest:request];

if (requestIsForLoginRedirection) {
BOXOAuth2Session *OAuth2Session = (BOXOAuth2Session *)self.SDKClient.session;
Expand Down

0 comments on commit 1b77cc1

Please sign in to comment.