Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Should get parameter from NSURL query property. #75

Merged
merged 1 commit into from
Jun 8, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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