Skip to content

Commit

Permalink
Merge pull request openid#158 from WilliamDenniss/issue146
Browse files Browse the repository at this point in the history
Resolved the "-Wpartial-availability" warning.
  • Loading branch information
WilliamDenniss authored Oct 12, 2017
2 parents c055052 + 1ffac3c commit 96ea3e3
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 49 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ xcode_scheme: AppAuth-iOS
before_script:
- sudo gem install xcpretty
script:
- xcodebuild -project AppAuth.xcodeproj -scheme "AppAuth-iOS" -sdk iphonesimulator11.0 -destination 'platform=iOS Simulator,name=iPhone 6,OS=11.0' -enableCodeCoverage YES GCC_INSTRUMENT_PROGRAM_FLOW_ARCS=YES GCC_GENERATE_TEST_COVERAGE_FILES=YES test | xcpretty
- xcodebuild -project AppAuth.xcodeproj -scheme "AppAuth-iOS" -sdk iphonesimulator11.0 -destination 'platform=iOS Simulator,name=iPhone 6,OS=11.0' -enableCodeCoverage YES GCC_INSTRUMENT_PROGRAM_FLOW_ARCS=YES GCC_GENERATE_TEST_COVERAGE_FILES=YES OTHERCFLAGS="-Werror" test | xcpretty
after_success:
- bash <(curl -s https://codecov.io/bash)

5 changes: 0 additions & 5 deletions AppAuth.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,6 @@ It follows the OAuth 2.0 for Native Apps best current practice

s.source = { :git => "https://github.com/openid/AppAuth-iOS.git", :tag => s.version }

s.pod_target_xcconfig = {
# Treat warnings as errors.
'GCC_TREAT_WARNINGS_AS_ERRORS' => 'YES',
}

s.source_files = "Source/*.{h,m}"
s.requires_arc = true

Expand Down
66 changes: 36 additions & 30 deletions Source/OIDURLQueryComponent.m
Original file line number Diff line number Diff line change
Expand Up @@ -39,30 +39,34 @@ - (nullable instancetype)init {
- (nullable instancetype)initWithURL:(NSURL *)URL {
self = [self init];
if (self) {
if (!gOIDURLQueryComponentForceIOS7Handling && [NSURLQueryItem class]) {
if (@available(iOS 8.0, *)) {
// If NSURLQueryItem is available, use it for deconstructing the new URL. (iOS 8+)
NSURLComponents *components =
[NSURLComponents componentsWithURL:URL resolvingAgainstBaseURL:NO];
NSArray<NSURLQueryItem *> *queryItems = components.queryItems;
for (NSURLQueryItem *queryItem in queryItems) {
[self addParameter:queryItem.name value:queryItem.value];
}
} else {
// Fallback for iOS 7
NSString *query = URL.query;
NSArray<NSString *> *queryParts = [query componentsSeparatedByString:@"&"];
for (NSString *queryPart in queryParts) {
NSRange equalsRange = [queryPart rangeOfString:@"="];
if (equalsRange.location == NSNotFound) {
continue;
if (!gOIDURLQueryComponentForceIOS7Handling) {
NSURLComponents *components =
[NSURLComponents componentsWithURL:URL resolvingAgainstBaseURL:NO];
NSArray<NSURLQueryItem *> *queryItems = components.queryItems;
for (NSURLQueryItem *queryItem in queryItems) {
[self addParameter:queryItem.name value:queryItem.value];
}
NSString *name = [queryPart substringToIndex:equalsRange.location];
name = name.stringByRemovingPercentEncoding;
NSString *value = [queryPart substringFromIndex:equalsRange.location + equalsRange.length];
value = value.stringByRemovingPercentEncoding;
[self addParameter:name value:value];
return self;
}
}

// Fallback for iOS 7
NSString *query = URL.query;
NSArray<NSString *> *queryParts = [query componentsSeparatedByString:@"&"];
for (NSString *queryPart in queryParts) {
NSRange equalsRange = [queryPart rangeOfString:@"="];
if (equalsRange.location == NSNotFound) {
continue;
}
NSString *name = [queryPart substringToIndex:equalsRange.location];
name = name.stringByRemovingPercentEncoding;
NSString *value = [queryPart substringFromIndex:equalsRange.location + equalsRange.length];
value = value.stringByRemovingPercentEncoding;
[self addParameter:name value:value];
}
return self;
}
return self;
}
Expand Down Expand Up @@ -108,7 +112,7 @@ - (void)addParameters:(NSDictionary<NSString *, NSString *> *)parameters {
@discussion The parameter names and values are NOT URL encoded.
@return An array of unencoded @c NSURLQueryItem objects.
*/
- (NSMutableArray<NSURLQueryItem *> *)queryItems {
- (NSMutableArray<NSURLQueryItem *> *)queryItems NS_AVAILABLE_IOS(8.0) {
NSMutableArray<NSURLQueryItem *> *queryParameters = [NSMutableArray array];
for (NSString *parameterName in _parameters.allKeys) {
NSArray<NSString *> *values = _parameters[parameterName];
Expand Down Expand Up @@ -154,15 +158,17 @@ - (NSString *)percentEncodedQueryString {

- (NSString *)URLEncodedParameters {
// If NSURLQueryItem is available, uses it for constructing the encoded parameters. (iOS 8+)
if (!gOIDURLQueryComponentForceIOS7Handling && [NSURLQueryItem class]) {
NSURLComponents *components = [[NSURLComponents alloc] init];
components.queryItems = [self queryItems];
NSString *encodedQuery = components.percentEncodedQuery;
// NSURLComponents.percentEncodedQuery creates a validly escaped URL query component, but
// doesn't encode the '+' leading to potential ambiguity with application/x-www-form-urlencoded
// encoding. Percent encodes '+' to avoid this ambiguity.
encodedQuery = [encodedQuery stringByReplacingOccurrencesOfString:@"+" withString:@"%2B"];
return encodedQuery;
if (@available(iOS 8.0, *)) {
if (!gOIDURLQueryComponentForceIOS7Handling) {
NSURLComponents *components = [[NSURLComponents alloc] init];
components.queryItems = [self queryItems];
NSString *encodedQuery = components.percentEncodedQuery;
// NSURLComponents.percentEncodedQuery creates a validly escaped URL query component, but
// doesn't encode the '+' leading to potential ambiguity with application/x-www-form-urlencoded
// encoding. Percent encodes '+' to avoid this ambiguity.
encodedQuery = [encodedQuery stringByReplacingOccurrencesOfString:@"+" withString:@"%2B"];
return encodedQuery;
}
}

// else, falls back to building query string manually (iOS 7)
Expand Down
40 changes: 27 additions & 13 deletions Source/iOS/OIDAuthorizationUICoordinatorIOS.m
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,11 @@ @implementation OIDAuthorizationUICoordinatorIOS {

BOOL _authorizationFlowInProgress;
__weak id<OIDAuthorizationFlowSession> _session;
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wpartial-availability"
__weak SFSafariViewController *_safariVC;
id _authenticationVC;
SFAuthenticationSession *_authenticationVC;
#pragma clang diagnostic pop
}

/** @brief Obtains the current @c OIDSafariViewControllerFactory; creating a new default instance if
Expand Down Expand Up @@ -85,7 +88,6 @@ - (BOOL)presentAuthorizationRequest:(OIDAuthorizationRequest *)request
BOOL openedSafari = NO;
NSURL *requestURL = [request authorizationRequestURL];

#if __IPHONE_OS_VERSION_MAX_ALLOWED >= 110000
if (@available(iOS 11.0, *)) {
NSString *redirectScheme = request.redirectURL.scheme;
SFAuthenticationSession* authenticationVC =
Expand All @@ -106,17 +108,14 @@ - (BOOL)presentAuthorizationRequest:(OIDAuthorizationRequest *)request
}];
_authenticationVC = authenticationVC;
openedSafari = [authenticationVC start];
} else
#endif // __IPHONE_OS_VERSION_MAX_ALLOWED >= 110000
{
if ([SFSafariViewController class]) {
} else if (@available(iOS 9.0, *)) {
SFSafariViewController *safariVC =
[[[self class] safariViewControllerFactory] safariViewControllerWithURL:requestURL];
[[[self class] safariViewControllerFactory] safariViewControllerWithURL:requestURL];
safariVC.delegate = self;
_safariVC = safariVC;
[_presentingViewController presentViewController:safariVC animated:YES completion:nil];
return YES;
}
openedSafari = YES;
} else {
openedSafari = [[UIApplication sharedApplication] openURL:requestURL];
}

Expand All @@ -135,10 +134,24 @@ - (void)dismissAuthorizationAnimated:(BOOL)animated completion:(void (^)(void))c
// Ignore this call if there is no authorization flow in progress.
return;
}

#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wpartial-availability"
SFSafariViewController *safariVC = _safariVC;
SFAuthenticationSession *authenticationVC = _authenticationVC;
#pragma clang diagnostic pop

[self cleanUp];
if (safariVC) {
[safariVC dismissViewControllerAnimated:YES completion:completion];

if (@available(iOS 11.0, *)) {
[authenticationVC cancel];
if (completion) completion();
} else if (@available(iOS 9.0, *)) {
if (safariVC) {
[safariVC dismissViewControllerAnimated:YES completion:completion];
} else {
if (completion) completion();
}
} else {
if (completion) completion();
}
Expand All @@ -148,13 +161,14 @@ - (void)cleanUp {
// The weak references to |_safariVC| and |_session| are set to nil to avoid accidentally using
// them while not in an authorization flow.
_safariVC = nil;
_authenticationVC = nil;
_session = nil;
_authorizationFlowInProgress = NO;
}

#pragma mark - SFSafariViewControllerDelegate

- (void)safariViewControllerDidFinish:(SFSafariViewController *)controller {
- (void)safariViewControllerDidFinish:(SFSafariViewController *)controller NS_AVAILABLE_IOS(9.0) {
if (controller != _safariVC) {
// Ignore this call if the safari view controller do not match.
return;
Expand All @@ -175,7 +189,7 @@ - (void)safariViewControllerDidFinish:(SFSafariViewController *)controller {

@implementation OIDDefaultSafariViewControllerFactory

- (SFSafariViewController *)safariViewControllerWithURL:(NSURL *)URL {
- (SFSafariViewController *)safariViewControllerWithURL:(NSURL *)URL NS_AVAILABLE_IOS(9.0) {
SFSafariViewController *safariViewController =
[[SFSafariViewController alloc] initWithURL:URL entersReaderIfAvailable:NO];
return safariViewController;
Expand Down

0 comments on commit 96ea3e3

Please sign in to comment.