Skip to content

Commit

Permalink
Should get parameter from NSURL query property.
Browse files Browse the repository at this point in the history
  • Loading branch information
ruqli committed May 31, 2016
1 parent 53fa6d6 commit 4381e22
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions IOSLinkedInAPI/LIALinkedInAuthorizationViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,8 @@ - (void)tappedCancelButton:(id)sender {
@implementation LIALinkedInAuthorizationViewController (UIWebViewDelegate)

- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType {
NSString *url = [[request URL] absoluteString];
NSURL *requestURL = [request URL];
NSString *url = [requestURL absoluteString];

//prevent loading URL if it is the redirectURL
handlingRedirectURL = [url hasPrefix:self.application.redirectURL];
Expand All @@ -106,19 +107,19 @@ - (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)
if (accessDenied) {
self.cancelCallback();
} else {
NSString* errorDescription = [self extractGetParameter:@"error_description" fromURLString:url];
NSString* errorDescription = [self extractGetParameter:@"error_description" fromURL:requestURL];
NSError *error = [[NSError alloc] initWithDomain:kLinkedInErrorDomain
code:1
userInfo:@{
NSLocalizedDescriptionKey: errorDescription}];
self.failureCallback(error);
}
} else {
NSString *receivedState = [self extractGetParameter:@"state" fromURLString: url];
NSString *receivedState = [self extractGetParameter:@"state" fromURL: requestURL];
//assert that the state is as we expected it to be
if ([receivedState containsString:self.application.state]) {
if ([receivedState isEqualToString:self.application.state]) {
//extract the code from the url
NSString *authorizationCode = [self extractGetParameter:@"code" fromURLString: url];
NSString *authorizationCode = [self extractGetParameter:@"code" fromURL: requestURL];
self.successCallback(authorizationCode);
} else {
NSError *error = [[NSError alloc] initWithDomain:kLinkedInErrorDomain code:2 userInfo:[[NSMutableDictionary alloc] init]];
Expand All @@ -129,9 +130,9 @@ - (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)
return !handlingRedirectURL;
}

- (NSString *)extractGetParameter: (NSString *) parameterName fromURLString:(NSString *)urlString {
- (NSString *)extractGetParameter: (NSString *) parameterName fromURL:(NSURL *)url {
NSMutableDictionary *mdQueryStrings = [[NSMutableDictionary alloc] init];
urlString = [[urlString componentsSeparatedByString:@"?"] objectAtIndex:1];
NSString *urlString = url.query;
for (NSString *qs in [urlString componentsSeparatedByString:@"&"]) {
[mdQueryStrings setValue:[[[[qs componentsSeparatedByString:@"="] objectAtIndex:1]
stringByReplacingOccurrencesOfString:@"+" withString:@" "]
Expand Down

0 comments on commit 4381e22

Please sign in to comment.